diff --git a/pmd-jbuilder/lib/PMDOpenTool.jar b/pmd-jbuilder/lib/PMDOpenTool.jar index 063407ae21..d60b794ee3 100644 Binary files a/pmd-jbuilder/lib/PMDOpenTool.jar and b/pmd-jbuilder/lib/PMDOpenTool.jar differ diff --git a/pmd-jbuilder/lib/jaxen-core-1.0-fcs.jar b/pmd-jbuilder/lib/jaxen-core-1.0-fcs.jar new file mode 100644 index 0000000000..e52bf679cc Binary files /dev/null and b/pmd-jbuilder/lib/jaxen-core-1.0-fcs.jar differ diff --git a/pmd-jbuilder/lib/pmd-0.9.jar b/pmd-jbuilder/lib/pmd-0.9.jar deleted file mode 100644 index f39718da86..0000000000 Binary files a/pmd-jbuilder/lib/pmd-0.9.jar and /dev/null differ diff --git a/pmd-jbuilder/lib/pmd-1.0rc1.jar b/pmd-jbuilder/lib/pmd-1.0rc1.jar deleted file mode 100644 index 80e83b045c..0000000000 Binary files a/pmd-jbuilder/lib/pmd-1.0rc1.jar and /dev/null differ diff --git a/pmd-jbuilder/lib/pmd-1.0rc2.jar b/pmd-jbuilder/lib/pmd-1.0rc2.jar deleted file mode 100644 index 2a13274ab1..0000000000 Binary files a/pmd-jbuilder/lib/pmd-1.0rc2.jar and /dev/null differ diff --git a/pmd-jbuilder/lib/pmd-1.1.jar b/pmd-jbuilder/lib/pmd-1.1.jar new file mode 100644 index 0000000000..b08dde86c3 Binary files /dev/null and b/pmd-jbuilder/lib/pmd-1.1.jar differ diff --git a/pmd-jbuilder/lib/pmd-bin-1.0rc2.zip b/pmd-jbuilder/lib/pmd-bin-1.0rc2.zip deleted file mode 100644 index 7abc501862..0000000000 Binary files a/pmd-jbuilder/lib/pmd-bin-1.0rc2.zip and /dev/null differ diff --git a/pmd-jbuilder/lib/saxpath-1.0-fcs.jar b/pmd-jbuilder/lib/saxpath-1.0-fcs.jar new file mode 100644 index 0000000000..2b43955bab Binary files /dev/null and b/pmd-jbuilder/lib/saxpath-1.0-fcs.jar differ diff --git a/pmd-jbuilder/lib/xercesImpl-2.0.2.jar b/pmd-jbuilder/lib/xercesImpl-2.0.2.jar new file mode 100644 index 0000000000..f25d73cd77 Binary files /dev/null and b/pmd-jbuilder/lib/xercesImpl-2.0.2.jar differ diff --git a/pmd-jbuilder/lib/xmlParserAPIs-2.0.2.jar b/pmd-jbuilder/lib/xmlParserAPIs-2.0.2.jar new file mode 100644 index 0000000000..c1fa1d6454 Binary files /dev/null and b/pmd-jbuilder/lib/xmlParserAPIs-2.0.2.jar differ diff --git a/pmd-jbuilder/src/images/checkFile.gif b/pmd-jbuilder/src/images/checkFile.gif index 8f099fd538..7a8f0cb1ec 100644 Binary files a/pmd-jbuilder/src/images/checkFile.gif and b/pmd-jbuilder/src/images/checkFile.gif differ diff --git a/pmd-jbuilder/src/images/checkProject.gif b/pmd-jbuilder/src/images/checkProject.gif index ab1ad43c33..8ed1e125c2 100644 Binary files a/pmd-jbuilder/src/images/checkProject.gif and b/pmd-jbuilder/src/images/checkProject.gif differ diff --git a/pmd-jbuilder/src/images/checkSelectedFile.gif b/pmd-jbuilder/src/images/checkSelectedFile.gif index 78886ffb2e..2efe17158c 100644 Binary files a/pmd-jbuilder/src/images/checkSelectedFile.gif and b/pmd-jbuilder/src/images/checkSelectedFile.gif differ diff --git a/pmd-jbuilder/src/images/checkSelectedPackage.gif b/pmd-jbuilder/src/images/checkSelectedPackage.gif index 607eedd5c6..62f86cbd76 100644 Binary files a/pmd-jbuilder/src/images/checkSelectedPackage.gif and b/pmd-jbuilder/src/images/checkSelectedPackage.gif differ diff --git a/pmd-jbuilder/src/images/configurePMD.gif b/pmd-jbuilder/src/images/configurePMD.gif index e80a72bd1b..dd685693a8 100644 Binary files a/pmd-jbuilder/src/images/configurePMD.gif and b/pmd-jbuilder/src/images/configurePMD.gif differ diff --git a/pmd-jbuilder/src/images/cpd.gif b/pmd-jbuilder/src/images/cpd.gif index f539b9f81f..6d026c07ee 100644 Binary files a/pmd-jbuilder/src/images/cpd.gif and b/pmd-jbuilder/src/images/cpd.gif differ diff --git a/pmd-jbuilder/src/images/cpdSelectedPackage.gif b/pmd-jbuilder/src/images/cpdSelectedPackage.gif index 68b7b92b3f..9284fe755c 100644 Binary files a/pmd-jbuilder/src/images/cpdSelectedPackage.gif and b/pmd-jbuilder/src/images/cpdSelectedPackage.gif differ diff --git a/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/CPDDialog.java b/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/CPDDialog.java index 9dd23810e7..28ad4a596e 100644 --- a/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/CPDDialog.java +++ b/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/CPDDialog.java @@ -9,7 +9,7 @@ import net.sourceforge.pmd.cpd.CPDListener; import net.sourceforge.pmd.cpd.CPD; import java.awt.event.WindowListener; import java.awt.event.WindowEvent; -import net.sourceforge.pmd.cpd.Tile; +//import net.sourceforge.pmd.cpd.Tile; public class CPDDialog extends JFrame implements CPDListener, WindowListener { private CPD cpd; @@ -25,7 +25,7 @@ public class CPDDialog extends JFrame implements CPDListener, WindowListener { public CPDDialog(CPD cpd) { super("CPD Status Monitor"); this.cpd = cpd; - cpd.setListener(this); + cpd.setCpdListener(this); try { jbInit(); } @@ -39,7 +39,7 @@ public class CPDDialog extends JFrame implements CPDListener, WindowListener { } - public boolean addedFile(int fileCount, File file) { + public void addedFile(int fileCount, File file) { if (firstFile) { firstFile = false; jLabel1.setText("Adding Files..."); @@ -48,7 +48,6 @@ public class CPDDialog extends JFrame implements CPDListener, WindowListener { progress = 0; } jProgressBar1.setValue(++progress); - return retCode; } @@ -63,7 +62,7 @@ public class CPDDialog extends JFrame implements CPDListener, WindowListener { } - public boolean addedNewTile(Tile tile, int tilesSoFar, int totalTiles) { + /*public boolean addedNewTile(Tile tile, int tilesSoFar, int totalTiles) { if (firstNewTile) { firstNewTile = false; jLabel1.setText("Adding Tiles... "); @@ -74,6 +73,11 @@ public class CPDDialog extends JFrame implements CPDListener, WindowListener { jProgressBar1.setValue(tilesSoFar); return retCode; + }*/ + + public void comparisonCountUpdate(long long0) { + jLabel1.setText("Doing comparisons... " + long0); + jProgressBar1.setValue((int)long0); } public boolean wasCancelled() { diff --git a/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java b/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java index 49abb0535a..0a8fc04df6 100644 --- a/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java +++ b/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java @@ -30,6 +30,7 @@ import com.borland.primetime.viewer.*; import net.sourceforge.pmd.*; import net.sourceforge.pmd.cpd.*; import com.borland.jbcl.control.MessageDialog; +import net.sourceforge.pmd.cpd.LanguageFactory; @@ -52,6 +53,7 @@ public class PMDOpenTool { static { try { + IMAGE_CHECK_PROJECT = new ImageIcon(PMDOpenTool.class.getClassLoader().getSystemResource("images/checkProject.gif")); IMAGE_CHECK_SELECTED_PACKAGE = new ImageIcon(PMDOpenTool.class.getClassLoader().getSystemResource("images/checkSelectedPackage.gif")); IMAGE_CPD = new ImageIcon(PMDOpenTool.class.getClassLoader().getSystemResource("images/cpd.gif")); @@ -211,7 +213,6 @@ public class PMDOpenTool { */ public static Report instanceCheck (String text, RuleSet rules) { PMD pmd = new PMD(); - RuleContext ctx = new RuleContext(); if (rules == null) { rules = constructRuleSets(); @@ -238,264 +239,273 @@ public class PMDOpenTool { } }; - //create EditorAction for performing a PMD Check on a project - public static EditorAction E_ACTION_PMDCheckProject = - new EditorAction("Displays PMD statistics about a Java File") { - public void actionPerformed(ActionEvent e) { - pmdCheckProject(); - } - }; - - //create the Menu action item for initiating the PMD check - public static BrowserAction B_ACTION_PMDCheckCurrentFile = - // A new action with short menu string, mnemonic, and long menu string - new BrowserAction("PMD Check File", 'P', "Displays PMD statistics about a Java File", IMAGE_CHECK_FILE) { - // The function called when the menu is selected - public void actionPerformed (Browser browser) { - pmdCheck(); - } - }; - - //create the Menu action item for initiating the PMD check - public static BrowserAction B_ACTION_PMDCheckSelectedFile = - // A new action with short menu string, mnemonic, and long menu string - new BrowserAction("PMD Check File", 'P', "Displays PMD statistics about a Java File", IMAGE_CHECK_SELECTED_FILE) { - // The function called when the menu is selected - public void actionPerformed (Browser browser) { - try { - browser.setActiveNode(browser.getProjectView().getSelectedNode(), true); - pmdCheck(); - } - catch (Exception e) {} - } - }; - - //Create the menu action item for configuring PMD - public static BrowserAction B_ACTION_PMDConfig = new BrowserAction("Configure PMD", - 'C', "Configure the PMD Settings", IMAGE_CONFIGURE_PMD) { - public void actionPerformed (Browser browser) { - PropertyManager.showPropertyDialog(browser, "PMD Options", Constants.RULESETS_TOPIC, - PropertyDialog.getLastSelectedPage()); - } - }; - - //create the project menu action for running a PMD check against all the java files within the active project - public static BrowserAction B_ACTION_PMDProjectCheck = new BrowserAction ("PMD Check Project", 'P', "Check all the java files in the project", IMAGE_CHECK_PROJECT) { - public void actionPerformed(Browser browser) { - pmdCheckProject(); - } - - }; - - //create the project menu action for running a PMD check against all the java files within the active project - public static BrowserAction B_ACTION_PMDPackageCheck = new BrowserAction ("PMD Check Package", 'P', "Check all the java files in the selected package", IMAGE_CHECK_SELECTED_PACKAGE) { - public void actionPerformed(Browser browser) { - browser.waitMessage("PMD Status", "Please wait while PMD checks the files in this package."); - RuleSet rules = constructRuleSets(); - PackageNode node = (PackageNode)browser.getProjectView().getSelectedNode(); - pmdCheckPackage(node, rules); - browser.clearWaitMessages(); - } - - }; - - //create the project menu action for running a PMD check against all the java files within the active project - public static BrowserAction B_ACTION_CPDPackageCheck = new BrowserAction ("CPD Check Package", 'P', "Check all the java files in the selected package", IMAGE_CPD_SELECTED_PACKAGE) { - public void actionPerformed(final Browser browser) { - Runnable r = new Runnable() { - public void run() { - pmdCPD((PackageNode)browser.getProjectView().getSelectedNode()); + //create EditorAction for performing a PMD Check on a project + public static EditorAction E_ACTION_PMDCheckProject = + new EditorAction("Displays PMD statistics about a Java File") { + public void actionPerformed(ActionEvent e) { + pmdCheckProject(); } }; - Thread t = new Thread(r); - t.start(); - } - }; - - - //create the project menu action for running a PMD check against all the java files within the active project - public static BrowserAction B_ACTION_CPDProjectCheck = new BrowserAction ("CPD Check Project", 'P', "Run CPD on all the java files in the project", IMAGE_CPD) { - public void actionPerformed(Browser browser) { - Runnable r = new Runnable() { - public void run() { - pmdCPD(null); - } - }; - Thread t = new Thread(r); - t.start(); - } - }; - - static void checkCode(String srcCode, JavaFileNode node, RuleSet rules) { - try { - Report rpt = instanceCheck(srcCode, rules); - - if (rpt == null) { - Message msg = new Message("Error Processing File"); - msg.setFont(stdMsgFont); - Browser.getActiveBrowser().getMessageView().addMessage(msgCat, msg, false); - } - else if (rpt.size() == 0) { - Message msg = new Message("No violations detected."); - msg.setFont(stdMsgFont); - Browser.getActiveBrowser().getMessageView().addMessage(msgCat, msg, false); - } - else { - for (Iterator i = rpt.iterator(); i.hasNext();) { - RuleViolation rv = (RuleViolation)i.next(); - PMDMessage pmdMsg = new PMDMessage(rv.getRule().getName() + ": " + rv.getDescription() - + " at line " + rv.getLine(), rv.getLine(), - node); - pmdMsg.setForeground(Color.red); - pmdMsg.setFont(stdMsgFont); - Browser.getActiveBrowser().getMessageView().addMessage(msgCat, pmdMsg, false); //add the result message - } - } - } catch (Exception e) { - e.printStackTrace(); - } - - } - - private static void pmdCheck() { - Node node = Browser.getActiveBrowser().getActiveNode(); - if (node instanceof JavaFileNode) { - Browser.getActiveBrowser().getMessageView().clearMessages(msgCat); //clear the message window - TextNodeViewer viewer = (TextNodeViewer)Browser.getActiveBrowser().getViewerOfType(node, - TextNodeViewer.class); - if (viewer != null) { - Document doc = viewer.getEditor().getDocument(); - try { - checkCode(doc.getText(0, doc.getLength()), (JavaFileNode)node, null); - } - catch (Exception e){ - e.printStackTrace(); - } - } - } - } - - private static void pmdCheckPackage(PackageNode packageNode, RuleSet rules) { - Node[] fileNodes = packageNode.getDisplayChildren(); - for (int j=0; j package - so ignore it so we don't get duplicates - pmdCheckPackage(node, rules); - } - } - } - Browser.getActiveBrowser().clearWaitMessages(); - } - - private static void pmdCPDPackage(PackageNode packageNode, CPD cpd) { - Node[] fileNodes = packageNode.getDisplayChildren(); - for (int j=0; j package - so ignore it so we don't get duplicates - pmdCPDPackage(node, cpd); + //create the Menu action item for initiating the PMD check + public static BrowserAction B_ACTION_PMDCheckCurrentFile = + // A new action with short menu string, mnemonic, and long menu string + new BrowserAction("PMD Check File", 'P', "Displays PMD statistics about a Java File", IMAGE_CHECK_FILE) { + // The function called when the menu is selected + public void actionPerformed (Browser browser) { + pmdCheck(); } - } - } - } - cpd.go(); - if (cpdd.wasCancelled()) { //if the dialog was cancelled by the user then let's get out of here - cpdd.close(); - return; - } - Results results = cpd.getResults(); - int resultCount = 0; - if (results != null) { - for (Iterator iter = results.getTiles(); iter.hasNext(); ) { - Tile t = (Tile)iter.next(); - resultCount++; - int tileLineCount = cpd.getLineCountFor(t); - int dupCount = ((TileOccurrences)results).getOccurrenceCountFor(t); - CPDMessage msg = CPDMessage.createMessage(String.valueOf(dupCount)+" duplicates in code set: " + resultCount, cpd.getImage(t)); - for (Iterator iter2 = results.getOccurrences(t); iter2.hasNext(); ) { - TokenEntry te = (TokenEntry)iter2.next(); - msg.addChildMessage(te.getBeginLine(), tileLineCount, te.getTokenSrcID()); - } - Browser.getActiveBrowser().getMessageView().addMessage(cpdCat, msg, false); - } - } - cpdd.close(); - } - catch (Exception e) { - Browser.getActiveBrowser().getMessageView().addMessage(cpdCat, new Message(e.toString()), false); - } - } + }; - /** - * 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); - } + //create the Menu action item for initiating the PMD check + public static BrowserAction B_ACTION_PMDCheckSelectedFile = + // A new action with short menu string, mnemonic, and long menu string + new BrowserAction("PMD Check File", 'P', "Displays PMD statistics about a Java File", IMAGE_CHECK_SELECTED_FILE) { + // The function called when the menu is selected + public void actionPerformed (Browser browser) { + try { + browser.setActiveNode(browser.getProjectView().getSelectedNode(), true); + pmdCheck(); + } + catch (Exception e) {} + } + }; + + //Create the menu action item for configuring PMD + public static BrowserAction B_ACTION_PMDConfig = new BrowserAction("Configure PMD", + 'C', "Configure the PMD Settings", IMAGE_CONFIGURE_PMD) { + public void actionPerformed (Browser browser) { + PropertyManager.showPropertyDialog(browser, "PMD Options", Constants.RULESETS_TOPIC, + PropertyDialog.getLastSelectedPage()); + } + }; + + //create the project menu action for running a PMD check against all the java files within the active project + public static BrowserAction B_ACTION_PMDProjectCheck = new BrowserAction ("PMD Check Project", 'P', "Check all the java files in the project", IMAGE_CHECK_PROJECT) { + public void actionPerformed(Browser browser) { + pmdCheckProject(); + } + + }; + + //create the project menu action for running a PMD check against all the java files within the active project + public static BrowserAction B_ACTION_PMDPackageCheck = new BrowserAction ("PMD Check Package", 'P', "Check all the java files in the selected package", IMAGE_CHECK_SELECTED_PACKAGE) { + public void actionPerformed(Browser browser) { + browser.waitMessage("PMD Status", "Please wait while PMD checks the files in this package."); + RuleSet rules = constructRuleSets(); + PackageNode node = (PackageNode)browser.getProjectView().getSelectedNode(); + pmdCheckPackage(node, rules); + browser.clearWaitMessages(); + } + + }; + + //create the project menu action for running a PMD check against all the java files within the active project + public static BrowserAction B_ACTION_CPDPackageCheck = new BrowserAction ("CPD Check Package", 'P', "Check all the java files in the selected package", IMAGE_CPD_SELECTED_PACKAGE) { + public void actionPerformed(final Browser browser) { + Runnable r = new Runnable() { + public void run() { + pmdCPD((PackageNode)browser.getProjectView().getSelectedNode()); + } + }; + Thread t = new Thread(r); + t.start(); + } + + }; + + + //create the project menu action for running a PMD check against all the java files within the active project + public static BrowserAction B_ACTION_CPDProjectCheck = new BrowserAction ("CPD Check Project", 'P', "Run CPD on all the java files in the project", IMAGE_CPD) { + public void actionPerformed(Browser browser) { + Runnable r = new Runnable() { + public void run() { + pmdCPD(null); + } + }; + Thread t = new Thread(r); + t.start(); + } + }; + + static void checkCode(String srcCode, JavaFileNode node, RuleSet rules) { + try { + + Report rpt = instanceCheck(srcCode, rules); + if (rpt == null) { + Message msg = new Message("Error Processing File"); + msg.setFont(stdMsgFont); + Browser.getActiveBrowser().getMessageView().addMessage(msgCat, msg, false); + } + else if (rpt.size() == 0) { + Message msg = new Message("No violations detected."); + msg.setFont(stdMsgFont); + Browser.getActiveBrowser().getMessageView().addMessage(msgCat, msg, false); + } + else { + for (Iterator i = rpt.iterator(); i.hasNext();) { + RuleViolation rv = (RuleViolation)i.next(); + PMDMessage pmdMsg = new PMDMessage(rv.getRule().getName() + ": " + rv.getDescription() + + " at line " + rv.getLine(), rv.getLine(), + node); + pmdMsg.setForeground(Color.red); + pmdMsg.setFont(stdMsgFont); + Browser.getActiveBrowser().getMessageView().addMessage(msgCat, pmdMsg, false); //add the result message + } + } + } catch (Exception e) { + e.printStackTrace(); + } + + } + + private static void pmdCheck() { + Node node = Browser.getActiveBrowser().getActiveNode(); + if (node instanceof JavaFileNode) { + Browser.getActiveBrowser().getMessageView().clearMessages(msgCat); //clear the message window + TextNodeViewer viewer = (TextNodeViewer)Browser.getActiveBrowser().getViewerOfType(node, TextNodeViewer.class); + if (viewer != null) { + Document doc = viewer.getEditor().getDocument(); + try { + checkCode(doc.getText(0, doc.getLength()), (JavaFileNode)node, null); + } + catch (Exception e){ + Browser.getActiveBrowser().getMessageView().addMessage(msgCat, "Error: " + e.toString()); + e.printStackTrace(); + } + } + else { + Browser.getActiveBrowser().getMessageView().addMessage(msgCat, "No active Browser."); + } + } + } + + private static void pmdCheckPackage(PackageNode packageNode, RuleSet rules) { + Node[] fileNodes = packageNode.getDisplayChildren(); + for (int j=0; j package - so ignore it so we don't get duplicates + pmdCheckPackage(node, rules); + } + } + } + Browser.getActiveBrowser().clearWaitMessages(); + } + + private static void pmdCPDPackage(PackageNode packageNode, CPD cpd) { + Node[] fileNodes = packageNode.getDisplayChildren(); + for (int j=0; j package - so ignore it so we don't get duplicates + pmdCPDPackage(node, cpd); + } + } + } + } + cpd.go(); + if (cpdd.wasCancelled()) { //if the dialog was cancelled by the user then let's get out of here + cpdd.close(); + return; + } + //Results results = cpd.getResults(); + int resultCount = 0; + //if (results != null) { + //for (Iterator iter = results.getTiles(); iter.hasNext(); ) { + for (Iterator iter = cpd.getMatches(); iter.hasNext(); ) { + //Tile t = (Tile)iter.next(); + Match m = (Match)iter.next(); + resultCount++; + int tileLineCount = m.getLineCount(); + int dupCount = 0; + for (Iterator iter2 = m.iterator(); iter2.hasNext(); ) { + dupCount++; + iter2.next(); + } + CPDMessage msg = CPDMessage.createMessage(String.valueOf(dupCount)+" duplicates in code set: " + resultCount, m.getSourceCodeSlice()); + for (Iterator iter2 = m.iterator(); iter2.hasNext(); ) { + Mark mark = (Mark)iter2.next(); + msg.addChildMessage(mark.getBeginLine(), tileLineCount, mark.getTokenSrcID()); + } + Browser.getActiveBrowser().getMessageView().addMessage(cpdCat, msg, false); + } + + cpdd.close(); + } + catch (Exception e) { + Browser.getActiveBrowser().getMessageView().addMessage(cpdCat, new Message(e.toString()), false); + } + } + + /** + * 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); + } } @@ -732,4 +742,3 @@ class HighlightMark extends LineMark { super(isLightWeight, highlightStyle); } } -