diff --git a/pmd-jbuilder/PMDOpenTool.jpx b/pmd-jbuilder/PMDOpenTool.jpx index a4fe697105..a8e9523997 100644 --- a/pmd-jbuilder/PMDOpenTool.jpx +++ b/pmd-jbuilder/PMDOpenTool.jpx @@ -45,7 +45,7 @@ - + diff --git a/pmd-jbuilder/PMDOpenTool.jpx.local b/pmd-jbuilder/PMDOpenTool.jpx.local index 45adf16513..f81ff4b91e 100644 --- a/pmd-jbuilder/PMDOpenTool.jpx.local +++ b/pmd-jbuilder/PMDOpenTool.jpx.local @@ -27,7 +27,7 @@ debug.NoTracingClasses.8[0]=9 com.sun.*1 1 -1 debug.NoTracingClasses.9[0]=6 java.*1 1 -1 history.files.active[0]=src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java history.files.open.1[0]=copyfile.bat,F;0,28 -history.files.open.2[0]=src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java,F;221,9073 +history.files.open.2[0]=src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java,F;214,9073 history.files.open.3[0]=src/net/sourceforge/pmd/jbuilder/RuleSetPropertyGroup.java,F;28,1143 history.files.open.4[0]=src/net/sourceforge/pmd/jbuilder/RuleSetPropertyPage.java,F;224,9845 import.optimize.packageprefixgroupings.1[0]=java diff --git a/pmd-jbuilder/bak/net/sourceforge/pmd/jbuilder/PMDOpenTool.java~21~ b/pmd-jbuilder/bak/net/sourceforge/pmd/jbuilder/PMDOpenTool.java~21~ deleted file mode 100644 index 24172edb31..0000000000 --- a/pmd-jbuilder/bak/net/sourceforge/pmd/jbuilder/PMDOpenTool.java~21~ +++ /dev/null @@ -1,212 +0,0 @@ -package net.sourceforge.pmd.jbuilder; - -import java.awt.*; -import java.io.*; -import java.util.*; - -import javax.swing.*; -import javax.swing.text.*; - -import com.borland.jbuilder.*; -import com.borland.jbuilder.node.*; -import com.borland.primetime.*; -import com.borland.primetime.editor.*; -import com.borland.primetime.ide.*; -import com.borland.primetime.node.*; -import com.borland.primetime.viewer.*; -import net.sourceforge.pmd.*; -import net.sourceforge.pmd.reports.*; -import com.borland.primetime.actions.ActionGroup; -import com.borland.primetime.properties.NodeProperty; -import com.borland.primetime.properties.GlobalProperty; -import com.borland.primetime.properties.PropertyManager; -import com.borland.primetime.properties.PropertyDialog; - - -/** - *

Title: JBuilder OpenTool for PMD

- *

Description: Provides an environemnACTION_PMDCheckt for using the PMD aplication from within JBuilder

- *

Copyright: Copyright (c) 2002

- *

Company: InfoEther

- * @author David Craine - * @version 1.0 - */ - -public class PMDOpenTool { - - static MessageCategory msgCat = new MessageCategory("PMD Results"); - public static ActionGroup GROUP_PMD = new ActionGroup("PMD", 'p', true); - - public PMDOpenTool() { - int i; - int a; - } - - public static void initOpenTool(byte majorVersion, byte minorVersion) { - if (majorVersion == PrimeTime.CURRENT_MAJOR_VERSION) { - GROUP_PMD.add(ACTION_PMDCheck); - GROUP_PMD.add(ACTION_PMDConfig); - JBuilderMenu.GROUP_Tools.add(GROUP_PMD); - registerWithContentManager(); - PropertyManager.registerPropertyGroup(new RuleSetPropertyGroup()); - } - } - - - /** - * Registers an "PMD Checker" action with the ContentManager (Tabs) - * The action will not be visible if multiple nodes are selected - */ - private static void registerWithContentManager() - { - ContextActionProvider cap = new ContextActionProvider() - { - public Action getContextAction(Browser browser, Node[] nodes) - { - return ACTION_PMDCheck; - } - }; - - ContentManager.registerContextActionProvider(cap); - } - - - public static Report instanceCheck(String text) { - - PMD pmd = new PMD(); - - ReportFactory rf = new ReportFactory(); - RuleContext ctx = new RuleContext(); - RuleSetFactory ruleSetFactory = new RuleSetFactory(); - RuleSet rules = ruleSetFactory.createRuleSet(pmd.getClass().getClassLoader().getResourceAsStream("rulesets/unusedcode.xml")); - - - ctx.setReport(rf.createReport("xml")); - ctx.setSourceCodeFilename("this"); - try { - // TODO switch to use StringReader once PMD 0.4 gets released - pmd.processFile(new StringBufferInputStream(text), rules, ctx); - return ctx.getReport(); - - } catch (FileNotFoundException fnfe) { - fnfe.printStackTrace(); - } - return null; - - } - - public static /*final*/ BrowserAction ACTION_PMDCheck = - // A new action with short menu string, mnemonic, and long menu string - new BrowserAction("PMD Checker", 'P', "Displays PMD statistics about a Java File") { - - // The function called when the menu is selected - public void actionPerformed(Browser browser) { - Node node = Browser.getActiveBrowser().getActiveNode(); - if (node instanceof JavaFileNode) { - TextNodeViewer viewer = (TextNodeViewer)Browser.getActiveBrowser().getViewerOfType(node, TextNodeViewer.class); - if (viewer != null) { - Document doc = viewer.getEditor().getDocument(); - try { - Report rpt = instanceCheck(doc.getText(0, doc.getLength())); - Browser.getActiveBrowser().getMessageView().clearMessages(msgCat);//clear the message window - if (rpt == null) { - Browser.getActiveBrowser().getMessageView().addMessage(msgCat, "Error Processing File"); - } - else if (rpt.size() == 0) { - Browser.getActiveBrowser().getMessageView().addMessage(msgCat, "No violations detexted."); - } - else { - for (Iterator i = rpt.iterator(); i.hasNext(); ) { - RuleViolation rv = (RuleViolation)i.next(); - PMDMessage pmdMsg = new PMDMessage(rv.getDescription() + " at line " + rv.getLine(), rv.getLine(), (JavaFileNode)node); - pmdMsg.setForeground(Color.red); - Browser.getActiveBrowser().getMessageView().addMessage(msgCat, pmdMsg);//add the result message - } - } - } - catch (Exception e) { - e.printStackTrace(); - } - - } - } - - } - }; - - public static BrowserAction ACTION_PMDConfig = - new BrowserAction("Configure PMD", 'C', "Configure the PMD Settings") { - public void actionPerformed(Browser browser) { - PropertyManager.showPropertyDialog(browser, - "PMD Options", - RuleSetPropertyGroup.RULESETS_TOPIC, - PropertyDialog.getLastSelectedPage()); - - } - }; - - /** - * Main method for testing purposes - * @param args standard arguments - */ - public static void main(String[] args) { - Report ret = PMDOpenTool.instanceCheck("package abc; \npublic class foo {\npublic void bar() {int i;}\n}"); - System.out.println("PMD: " + ret); - } - -} -class PMDMessage extends Message { - - final LineMark MARK = new HighlightMark(); - JavaFileNode javaNode; - int line=0; - int column=0; - - public PMDMessage(String msg, int line, JavaFileNode node) { - super(msg); - this.line = line; - this.javaNode = node; - - } - public void selectAction(Browser browser) { - displayResult(browser, false); - } - - public void messageAction(Browser browser) { - displayResult(browser, true); - } - - private void displayResult(Browser browser, boolean requestFocus) { - try { - if (requestFocus || browser.isOpenNode(javaNode)) { - browser.setActiveNode(javaNode, requestFocus); - TextNodeViewer viewer = (TextNodeViewer)browser.getViewerOfType(javaNode, TextNodeViewer.class); - browser.setActiveViewer(javaNode, viewer, requestFocus); - EditorPane editor = viewer.getEditor(); - editor.gotoPosition(line, column, false, EditorPane.CENTER_IF_NEAR_EDGE); - if (requestFocus) - editor.requestFocus(); - else - editor.setTemporaryMark(line, MARK); - } - } - catch (Exception ex) { - ex.printStackTrace(); - } - } -} - -class HighlightMark extends LineMark { - static Style highlightStyle; - static { - StyleContext context = EditorManager.getStyleContext(); - highlightStyle = context.addStyle("line_highlight", null); - highlightStyle.addAttribute(MasterStyleContext.DISPLAY_NAME, "Line highlight"); - StyleConstants.setBackground(highlightStyle, Color.yellow); - StyleConstants.setForeground(highlightStyle, Color.black); - } - - public HighlightMark() { - super(highlightStyle); - } -} diff --git a/pmd-jbuilder/bak/net/sourceforge/pmd/jbuilder/PMDOpenTool.java~22~ b/pmd-jbuilder/bak/net/sourceforge/pmd/jbuilder/PMDOpenTool.java~22~ deleted file mode 100644 index f1d21b2270..0000000000 --- a/pmd-jbuilder/bak/net/sourceforge/pmd/jbuilder/PMDOpenTool.java~22~ +++ /dev/null @@ -1,214 +0,0 @@ -package net.sourceforge.pmd.jbuilder; - -import java.awt.*; -import java.io.*; -import java.util.*; - -import javax.swing.*; -import javax.swing.text.*; - -import com.borland.jbuilder.*; -import com.borland.jbuilder.node.*; -import com.borland.primetime.*; -import com.borland.primetime.editor.*; -import com.borland.primetime.ide.*; -import com.borland.primetime.node.*; -import com.borland.primetime.viewer.*; -import net.sourceforge.pmd.*; -import net.sourceforge.pmd.reports.*; -import com.borland.primetime.actions.ActionGroup; -import com.borland.primetime.properties.NodeProperty; -import com.borland.primetime.properties.GlobalProperty; -import com.borland.primetime.properties.PropertyManager; -import com.borland.primetime.properties.PropertyDialog; - - -/** - *

Title: JBuilder OpenTool for PMD

- *

Description: Provides an environemnACTION_PMDCheckt for using the PMD aplication from within JBuilder

- *

Copyright: Copyright (c) 2002

- *

Company: InfoEther

- * @author David Craine - * @version 1.0 - */ - -public class PMDOpenTool { - - static MessageCategory msgCat = new MessageCategory("PMD Results"); - public static ActionGroup GROUP_PMD = new ActionGroup("PMD", 'p', true); - - public PMDOpenTool() { - int i; - int a; - } - - public static void initOpenTool(byte majorVersion, byte minorVersion) { - if (majorVersion == PrimeTime.CURRENT_MAJOR_VERSION) { - GROUP_PMD.add(ACTION_PMDCheck); - GROUP_PMD.add(ACTION_PMDConfig); - JBuilderMenu.GROUP_Tools.add(GROUP_PMD); - registerWithContentManager(); - PropertyManager.registerPropertyGroup(new RuleSetPropertyGroup()); - } - } - - - /** - * Registers an "PMD Checker" action with the ContentManager (Tabs) - * The action will not be visible if multiple nodes are selected - */ - private static void registerWithContentManager() - { - ContextActionProvider cap = new ContextActionProvider() - { - public Action getContextAction(Browser browser, Node[] nodes) - { - return ACTION_PMDCheck; - } - }; - - ContentManager.registerContextActionProvider(cap); - } - - - private static constructRuleSets() { - - } - public static Report instanceCheck(String text) { - - PMD pmd = new PMD(); - - ReportFactory rf = new ReportFactory(); - RuleContext ctx = new RuleContext(); - RuleSetFactory ruleSetFactory = new RuleSetFactory(); - RuleSet rules = ruleSetFactory.createRuleSet(pmd.getClass().getClassLoader().getResourceAsStream("rulesets/unusedcode.xml")); - - ctx.setReport(rf.createReport("xml")); - ctx.setSourceCodeFilename("this"); - try { - // TODO switch to use StringReader once PMD 0.4 gets released - pmd.processFile(new StringBufferInputStream(text), rules, ctx); - return ctx.getReport(); - - } catch (FileNotFoundException fnfe) { - fnfe.printStackTrace(); - } - return null; - - } - - public static /*final*/ BrowserAction ACTION_PMDCheck = - // A new action with short menu string, mnemonic, and long menu string - new BrowserAction("PMD Checker", 'P', "Displays PMD statistics about a Java File") { - - // The function called when the menu is selected - public void actionPerformed(Browser browser) { - Node node = Browser.getActiveBrowser().getActiveNode(); - if (node instanceof JavaFileNode) { - TextNodeViewer viewer = (TextNodeViewer)Browser.getActiveBrowser().getViewerOfType(node, TextNodeViewer.class); - if (viewer != null) { - Document doc = viewer.getEditor().getDocument(); - try { - Report rpt = instanceCheck(doc.getText(0, doc.getLength())); - Browser.getActiveBrowser().getMessageView().clearMessages(msgCat);//clear the message window - if (rpt == null) { - Browser.getActiveBrowser().getMessageView().addMessage(msgCat, "Error Processing File"); - } - else if (rpt.size() == 0) { - Browser.getActiveBrowser().getMessageView().addMessage(msgCat, "No violations detexted."); - } - else { - for (Iterator i = rpt.iterator(); i.hasNext(); ) { - RuleViolation rv = (RuleViolation)i.next(); - PMDMessage pmdMsg = new PMDMessage(rv.getDescription() + " at line " + rv.getLine(), rv.getLine(), (JavaFileNode)node); - pmdMsg.setForeground(Color.red); - Browser.getActiveBrowser().getMessageView().addMessage(msgCat, pmdMsg);//add the result message - } - } - } - catch (Exception e) { - e.printStackTrace(); - } - - } - } - - } - }; - - public static BrowserAction ACTION_PMDConfig = - new BrowserAction("Configure PMD", 'C', "Configure the PMD Settings") { - public void actionPerformed(Browser browser) { - PropertyManager.showPropertyDialog(browser, - "PMD Options", - RuleSetPropertyGroup.RULESETS_TOPIC, - PropertyDialog.getLastSelectedPage()); - - } - }; - - /** - * Main method for testing purposes - * @param args standard arguments - */ - public static void main(String[] args) { - Report ret = PMDOpenTool.instanceCheck("package abc; \npublic class foo {\npublic void bar() {int i;}\n}"); - System.out.println("PMD: " + ret); - } - -} -class PMDMessage extends Message { - - final LineMark MARK = new HighlightMark(); - JavaFileNode javaNode; - int line=0; - int column=0; - - public PMDMessage(String msg, int line, JavaFileNode node) { - super(msg); - this.line = line; - this.javaNode = node; - - } - public void selectAction(Browser browser) { - displayResult(browser, false); - } - - public void messageAction(Browser browser) { - displayResult(browser, true); - } - - private void displayResult(Browser browser, boolean requestFocus) { - try { - if (requestFocus || browser.isOpenNode(javaNode)) { - browser.setActiveNode(javaNode, requestFocus); - TextNodeViewer viewer = (TextNodeViewer)browser.getViewerOfType(javaNode, TextNodeViewer.class); - browser.setActiveViewer(javaNode, viewer, requestFocus); - EditorPane editor = viewer.getEditor(); - editor.gotoPosition(line, column, false, EditorPane.CENTER_IF_NEAR_EDGE); - if (requestFocus) - editor.requestFocus(); - else - editor.setTemporaryMark(line, MARK); - } - } - catch (Exception ex) { - ex.printStackTrace(); - } - } -} - -class HighlightMark extends LineMark { - static Style highlightStyle; - static { - StyleContext context = EditorManager.getStyleContext(); - highlightStyle = context.addStyle("line_highlight", null); - highlightStyle.addAttribute(MasterStyleContext.DISPLAY_NAME, "Line highlight"); - StyleConstants.setBackground(highlightStyle, Color.yellow); - StyleConstants.setForeground(highlightStyle, Color.black); - } - - public HighlightMark() { - super(highlightStyle); - } -} diff --git a/pmd-jbuilder/bak/net/sourceforge/pmd/jbuilder/RuleSetPropertyGroup.java~6~ b/pmd-jbuilder/bak/net/sourceforge/pmd/jbuilder/RuleSetPropertyGroup.java~6~ deleted file mode 100644 index ecc3678fd6..0000000000 --- a/pmd-jbuilder/bak/net/sourceforge/pmd/jbuilder/RuleSetPropertyGroup.java~6~ +++ /dev/null @@ -1,43 +0,0 @@ -package net.sourceforge.pmd.jbuilder; - -import com.borland.primetime.properties.PropertyGroup; -import com.borland.primetime.properties.PropertyPageFactory; -import com.borland.primetime.properties.GlobalProperty; -import com.borland.primetime.properties.PropertyPage; - -/** - *

Title: JBuilder OpenTool for PMD

- *

Description: Provides an environemnt for using the PMD aplication from within JBuilder

- *

Copyright: Copyright (c) 2002

- *

Company: InfoEther

- * @author David Craine - * @version 1.0 - */ - -public class RuleSetPropertyGroup implements PropertyGroup { - public static final String RULESETS="RuleSets"; - public static final String RULESET_BASIC = "basic"; - public static final String RULESET_DESIGN = "design"; - public static final String RULESET_UNUSEDCODE = "unusedcode"; - public static final Object RULESETS_TOPIC = new Object(); - public static final GlobalProperty PROPKEY_RULESET_DESIGN = new GlobalProperty(RULESETS, RULESET_DESIGN, "true"); - public static final GlobalProperty PROPKEY_RULESET_BASIC = new GlobalProperty(RULESETS, RULESET_BASIC, "true"); - public static final GlobalProperty PROPKEY_RULESET_UNUSEDCODE = new GlobalProperty(RULESETS, RULESET_UNUSEDCODE, "true"); - - public RuleSetPropertyGroup() { - } - public void initializeProperties() { - /**@todo Implement this com.borland.primetime.properties.PropertyGroup method*/ - throw new java.lang.UnsupportedOperationException("Method initializeProperties() not yet implemented."); - } - public PropertyPageFactory getPageFactory(Object topic) { - if (topic == RULESETS_TOPIC) { - return new PropertyPageFactory("PMD Properties", "Set PMD RuleSet Properties") { - public PropertyPage createPropertyPage() { - return new RuleSetPropertyPage(); - } - }; - } - return null; - } -} \ No newline at end of file diff --git a/pmd-jbuilder/lib/PMDOpenTool.jar b/pmd-jbuilder/lib/PMDOpenTool.jar index de2cf8a882..ad5d4eb943 100644 Binary files a/pmd-jbuilder/lib/PMDOpenTool.jar and b/pmd-jbuilder/lib/PMDOpenTool.jar differ