From 5ef6d00ce693f2ab00237eaaea8c8416bc552d42 Mon Sep 17 00:00:00 2001 From: Jiger Patel Date: Mon, 15 Sep 2003 09:16:44 +0000 Subject: [PATCH] Renamed to PMDJEditPlugin to PMDPlugin git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@2262 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd-jedit/PMDPlugin/LICENSE.txt | 2 + pmd-jedit/PMDPlugin/actions.xml | 49 ++ pmd-jedit/PMDPlugin/browser.actions.xml | 19 + pmd-jedit/PMDPlugin/build.properties | 2 + pmd-jedit/PMDPlugin/build.xml | 78 ++++ pmd-jedit/PMDPlugin/dockables.xml | 9 + pmd-jedit/PMDPlugin/etc/changelog.txt | 71 +++ .../etc/doing_the_next_pmd_jedit_release.txt | 36 ++ pmd-jedit/PMDPlugin/etc/scp.bat | 6 + pmd-jedit/PMDPlugin/etc/scp.sh | 4 + pmd-jedit/PMDPlugin/etc/tomant.sh | 3 + pmd-jedit/PMDPlugin/jedit.html | 64 +++ .../PMDPlugin/lib/jaxen-core-1.0-fcs.jar | Bin 0 -> 129 bytes pmd-jedit/PMDPlugin/lib/saxpath-1.0-fcs.jar | Bin 0 -> 763 bytes pmd-jedit/PMDPlugin/pmd.props | 53 +++ .../pmd/jedit/CPDDuplicateCodeViewer.java | 194 ++++++++ .../sourceforge/pmd/jedit/PMDJEditPlugin.java | 434 ++++++++++++++++++ .../sourceforge/pmd/jedit/PMDOptionPane.java | 157 +++++++ .../sourceforge/pmd/jedit/SelectedRules.java | 195 ++++++++ 19 files changed, 1376 insertions(+) create mode 100644 pmd-jedit/PMDPlugin/LICENSE.txt create mode 100644 pmd-jedit/PMDPlugin/actions.xml create mode 100644 pmd-jedit/PMDPlugin/browser.actions.xml create mode 100644 pmd-jedit/PMDPlugin/build.properties create mode 100644 pmd-jedit/PMDPlugin/build.xml create mode 100644 pmd-jedit/PMDPlugin/dockables.xml create mode 100644 pmd-jedit/PMDPlugin/etc/changelog.txt create mode 100644 pmd-jedit/PMDPlugin/etc/doing_the_next_pmd_jedit_release.txt create mode 100755 pmd-jedit/PMDPlugin/etc/scp.bat create mode 100644 pmd-jedit/PMDPlugin/etc/scp.sh create mode 100644 pmd-jedit/PMDPlugin/etc/tomant.sh create mode 100644 pmd-jedit/PMDPlugin/jedit.html create mode 100644 pmd-jedit/PMDPlugin/lib/jaxen-core-1.0-fcs.jar create mode 100644 pmd-jedit/PMDPlugin/lib/saxpath-1.0-fcs.jar create mode 100644 pmd-jedit/PMDPlugin/pmd.props create mode 100644 pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/CPDDuplicateCodeViewer.java create mode 100644 pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java create mode 100644 pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/PMDOptionPane.java create mode 100644 pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/SelectedRules.java diff --git a/pmd-jedit/PMDPlugin/LICENSE.txt b/pmd-jedit/PMDPlugin/LICENSE.txt new file mode 100644 index 0000000000..801cb60717 --- /dev/null +++ b/pmd-jedit/PMDPlugin/LICENSE.txt @@ -0,0 +1,2 @@ +http://cougaar.org/docman/view.php/17/58/license.html + diff --git a/pmd-jedit/PMDPlugin/actions.xml b/pmd-jedit/PMDPlugin/actions.xml new file mode 100644 index 0000000000..bed3103487 --- /dev/null +++ b/pmd-jedit/PMDPlugin/actions.xml @@ -0,0 +1,49 @@ + + + + + + net.sourceforge.pmd.jedit.PMDJEditPlugin.check(buffer, view); + + + + + net.sourceforge.pmd.jedit.PMDJEditPlugin.checkAllOpenBuffers(view); + + + + + net.sourceforge.pmd.jedit.PMDJEditPlugin.checkDirectory(view); + + + + + net.sourceforge.pmd.jedit.PMDJEditPlugin.checkDirectoryRecursively(view); + + + + + net.sourceforge.pmd.jedit.PMDJEditPlugin.clearErrorList(); + + + + + net.sourceforge.pmd.jedit.PMDJEditPlugin.cpdCurrentFile(view); + + + + + net.sourceforge.pmd.jedit.PMDJEditPlugin.cpdDir(view,false); + + + + + net.sourceforge.pmd.jedit.PMDJEditPlugin.cpdDir(view,true); + + + + + net.sourceforge.pmd.jedit.PMDJEditPlugin.checkFile(view,browser); + + + diff --git a/pmd-jedit/PMDPlugin/browser.actions.xml b/pmd-jedit/PMDPlugin/browser.actions.xml new file mode 100644 index 0000000000..1696e81f55 --- /dev/null +++ b/pmd-jedit/PMDPlugin/browser.actions.xml @@ -0,0 +1,19 @@ + + + + + + net.sourceforge.pmd.jedit.PMDJEditPlugin.checkFile(view,browser); + + + + + net.sourceforge.pmd.jedit.PMDJEditPlugin.checkDirectory(view, browser,false); + + + + + net.sourceforge.pmd.jedit.PMDJEditPlugin.checkDirectory(view, browser,true); + + + diff --git a/pmd-jedit/PMDPlugin/build.properties b/pmd-jedit/PMDPlugin/build.properties new file mode 100644 index 0000000000..ba058fd030 --- /dev/null +++ b/pmd-jedit/PMDPlugin/build.properties @@ -0,0 +1,2 @@ +jedit.install.dir=c:\\jiger\\jedit42 +install.dir=${jedit.install.dir}\\jars diff --git a/pmd-jedit/PMDPlugin/build.xml b/pmd-jedit/PMDPlugin/build.xml new file mode 100644 index 0000000000..8cbad6dfa0 --- /dev/null +++ b/pmd-jedit/PMDPlugin/build.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pmd-jedit/PMDPlugin/dockables.xml b/pmd-jedit/PMDPlugin/dockables.xml new file mode 100644 index 0000000000..294912f7bf --- /dev/null +++ b/pmd-jedit/PMDPlugin/dockables.xml @@ -0,0 +1,9 @@ + + + + + + + new net.sourceforge.pmd.jedit.CPDDuplicateCodeViewer(view); + + diff --git a/pmd-jedit/PMDPlugin/etc/changelog.txt b/pmd-jedit/PMDPlugin/etc/changelog.txt new file mode 100644 index 0000000000..8a8094e46e --- /dev/null +++ b/pmd-jedit/PMDPlugin/etc/changelog.txt @@ -0,0 +1,71 @@ +August 18th 2003 - 2.2 +1. Updated to PMD 1.2.1 +2. Updated to jEdit 4.2 API changes +3. Added PMD in jEdit's File System Browser Plugins Menu. + + +May 19th 2003 - 2.1: +Added "clear ErrorList" option - thanks to Randall Schultz for the suggestion. +Added "check all open buffers" option - thanks to Randall Schultz for the suggestion. +Added support to define Custom RuleSets thereby facilitating integration of Custom Rulesets with built-in rulesets & their independent development. +Added C/C++, PHP support to Copy/Paste Detector. Now you can find out duplicate code in your C/C++ & PHP code besides the usual Java code. + +April 18 2003 - 2.0: +Jiger Patel integrated CPD functionality. +Upgraded to work with pmd-1.05. + +March 24 2003 - 1.5: +Upgraded to work with pmd-1.04. + +February 11 2003 - 1.4: +Upgraded to work with pmd-1.03. + +January 24 2003 - 1.3: +Upgraded to work with pmd-1.02. + +November 20 2002 - 1.2: +Added some more fixes from Jiger. + +November 14 2002 - 1.1: +Added "directory popup option" feature; thanks to Jiger Patel for the suggestions. + +November 7 2002 - 1.0: +Updated to use pmd-1.01. + +October 4 2002 - 0.9: +Updated to use pmd-1.0rc3 + +Augst 16 2002 - 0.8: +Fixed GUI lockup problem +Added example text to option pane +Updated to use pmd-0.9 + +August 2 2002 - 0.7: +Updated to use pmd-0.8 +Now individual rules can be selected + +July 26 2002 - 0.6: +Updated to use pmd-0.7. +PMD can be run on 1) all files in a directory or 2) recursively into a directory tree. +Added some detail to the Options area. + +July 22 2002 - 0.5: +Moved options into Global Options area and made them look nicer. +Cleaned up menus. +Cleaned up help text. + +July 18 2002 - 0.4: +Updated to use pmd-0.6 +Modified to use ErrorList plugin +Fixed bug - displayed a popup if no messages are found + +July 12 2002 - 0.3: +Updated to use pmd-0.4. +Messages are displayed in a list. + +July 9 2002 - 0.2: +Fixed bug - a message, not an empty box, is now displayed if no errors are found. +Added options pane so rulesets are selectable and selections are persistant. + +July 8 2002 - 0.1: +Initial release diff --git a/pmd-jedit/PMDPlugin/etc/doing_the_next_pmd_jedit_release.txt b/pmd-jedit/PMDPlugin/etc/doing_the_next_pmd_jedit_release.txt new file mode 100644 index 0000000000..3bdbd8eac8 --- /dev/null +++ b/pmd-jedit/PMDPlugin/etc/doing_the_next_pmd_jedit_release.txt @@ -0,0 +1,36 @@ +update the release date in the changelog +change config/pmd.props to reflect actual pmd.jar file version +change config/pmd.props to reflect pmd-jedit release 2.2 +change config/jedit.html to reflect pmd-jedit release 2.2 +change the build.xml to reflect pmd-jedit release 2.2 +update doing_the_next_pmd_jedit_release.txt to the new release version +comit the above changes FIRST!! + +Create the binary release - 'ant release' +Unzip it into jedit.home/jars +TESTS: +1) Can you run jedit ok? +2) Can you run it it on a file and find some unused code? +3) Are options persistant? +4) Does CPD work? + +Create the src release: +cvs -q rtag -D tomorrow "pmd_jedit_release_2_1" pmd-jedit +rm -rf ~/tmp/pmd-jedit +mkdir -p ~/tmp/pmd-jedit +cvs -q export -d tmp -r pmd_jedit_release_2_1 pmd-jedit +mv tmp/* ~/tmp/pmd-jedit +rmdir tmp/ +cp pmd-jedit/lib/PMDJEditPlugin-2.2.jar ~/tmp/pmd-jedit/lib +cd ~/tmp +zip -q -r pmd-jedit-src-2.2.zip pmd-jedit +rm -rf pmd-jedit + +ncftpput upload.sourceforge.net incoming/ pmd-jedit-src-2.2.zip pmd-jedit-bin-2.2.zip + +Go to Admin, Edit/Release Files, click on Add new release +Paste stuff into the changelog/readme boxes +Add the 2 zip files +Classify the file + +Submit some news saying "hey, new release of the JEdit plugin!" diff --git a/pmd-jedit/PMDPlugin/etc/scp.bat b/pmd-jedit/PMDPlugin/etc/scp.bat new file mode 100755 index 0000000000..946fc5684a --- /dev/null +++ b/pmd-jedit/PMDPlugin/etc/scp.bat @@ -0,0 +1,6 @@ +@echo off +set CLASSPATH=..\build +set CLASSPATH=%CLASSPATH%;..\lib\ErrorList.jar +set CLASSPATH=%CLASSPATH%;..\lib\jedit.jar +set CVS_RSH=c:\bin\ssh\ssh +set HOME=c: diff --git a/pmd-jedit/PMDPlugin/etc/scp.sh b/pmd-jedit/PMDPlugin/etc/scp.sh new file mode 100644 index 0000000000..4c31f4185d --- /dev/null +++ b/pmd-jedit/PMDPlugin/etc/scp.sh @@ -0,0 +1,4 @@ +#!/bin/sh +CLASSPATH=../build/ +CLASSPATH=$CLASSPATH:../lib/jedit.jar +export CLASSPATH diff --git a/pmd-jedit/PMDPlugin/etc/tomant.sh b/pmd-jedit/PMDPlugin/etc/tomant.sh new file mode 100644 index 0000000000..17160462e5 --- /dev/null +++ b/pmd-jedit/PMDPlugin/etc/tomant.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +ant -Djedit.home=/home/tom/jedit/4.1/ $1 diff --git a/pmd-jedit/PMDPlugin/jedit.html b/pmd-jedit/PMDPlugin/jedit.html new file mode 100644 index 0000000000..443af49e8c --- /dev/null +++ b/pmd-jedit/PMDPlugin/jedit.html @@ -0,0 +1,64 @@ + + + +PMD-JEdit Plug-in Users' Guide + + +

PMD-JEdit Plug-in Users' Guide

+
+

PMD is a Java source code analyzer - it finds unused variables, questionable design decisions, empty catch blocks, and so forth. +You can read much more about PMD here - http://pmd.sf.net/.

+

Installation

+ +

Integration

+

There's a new 'PMD' menu item in the Plugins menu. This has several submenu options

+ +

"Current directory" means "the directory which is displayed in the file system browser". So, for +example, if you wanted to run PMD on your whole source tree, and your top level +source directory is named "src", you would 1) double-click on the "src" directory and +then 2) select the "PMD->Check directory recursively" menu option.

+

All those options put any errors into the ErrorList so you can then go jumping around your project fixing stuff. +

There's a section in the Utilities->Global Options->Plugins configuration panel that lets you pick which rule sets you want to use.

+

Note that the configuration panel also contains the minimum tile size for CPD to turn up a duplicate chunk. + +

Starting 2.1, you can now add Custom Defined Rulesets with PMD plugin. Previously, if you want to use your own rulesets with the PMD plugin, you had to unjar the pmd.jar file & add your ruleset defination in the jar file & re-jar it & use it. But this procedure had to be repeated whenever a new PMD is out. But not anymore. Now you can simply point PMD plugin to your custom rulesets.xml file & drop your custom ruleset jars in either of jEdit jars directory(either system or user). Once this is done, you will be able to manipulate your Custom Rulesets just the way like the built-in ones.

+ +

PMD jEdit 2.2 adds updates PMD plugin to the latest and the greatest PMD release, updates to Dynamic class loading feature of jEdit and adds PMD to jEdit's File System Browser for easy access.

+

Release Notes

+

2.2

+
    +
  1. Updated to PMD 1.2.1
  2. +
  3. Updated to jEdit 4.2 API changes
  4. +
  5. Added PMD in jEdit's File System Browser Plugins Menu.
  6. +
+

2.1

+
    +
  1. Added "clear ErrorList" option.
  2. +
  3. Added "check all open buffers" option.
  4. +
  5. Added support to define Custom RuleSets thereby facilitating integration of Custom Rulesets with built-in rulesets & their independent development.
  6. +
  7. Added C/C++, PHP support to Copy/Paste Detector. Now you can find out duplicate code in your C/C++ & PHP code besides the usual Java code.
  8. +
+

2.0

+
    +
  1. Integrated Copy/Paste Detector(CPD) in jEdit.
  2. +
  3. Updated to use pmd-1.05
  4. +
+ +

License

+

The PMD-JEdit plugin is free software released under the Apache license.

+ + \ No newline at end of file diff --git a/pmd-jedit/PMDPlugin/lib/jaxen-core-1.0-fcs.jar b/pmd-jedit/PMDPlugin/lib/jaxen-core-1.0-fcs.jar new file mode 100644 index 0000000000000000000000000000000000000000..86618d142eaa12614c31a612774fb3f9fda23228 GIT binary patch literal 129 zcmWIWW@h1H00FkhSvp__l;8x?zOEsTx}JV+`T;;?A`Bcrh^|ZoS(&e+pQoE^aEP9- v+h^Z1r+vJ2^)B*y>uQ}lbAEG>!4=~NPmA=te04m1FP5&_5>#+Tn~@6u0e2n7 literal 0 HcmV?d00001 diff --git a/pmd-jedit/PMDPlugin/lib/saxpath-1.0-fcs.jar b/pmd-jedit/PMDPlugin/lib/saxpath-1.0-fcs.jar new file mode 100644 index 0000000000000000000000000000000000000000..5bb1924aa76af6cd4b28c5193db5367e06672f58 GIT binary patch literal 763 zcmWIWW@h1H0D-sDX6b+#P=Ws>0&Lih{(F3_Kb@ zcIOwR<59r_RYBM+5j2$2s}%;!1QqOUvPo4aHP2n|5={dgV z#L{PPP7XY)bY0phIO~W)+bwdyr$W# zeam+Fu%Fm1x&9BX#qrwBM&ixiQg(X(y7g`K4d2RCpRoC}wtf4UyL90j2h&@QSC2hm zJ^Aga%3(u|w^OD_Tco-_yfN)D+p0s0d%~VB*n59NH#?X5M7hm*<|1O=nNNRDZcSf* zEPQp;t%DPDas&M2zbSuzvqPA-dBf$yThG0AG=H=8&_l)QPl=13?eKk*an0tA@#Uwh z{T7F7AG4VgxaZv!(R`EhXU*n#h0b~KrByv$;yeEwE3tWZX77;yFxU5Y^X5czE%{H5 c#Rnf`U*WHt=d!%o{o(ct3(mfKu;YU*00^fUMF0Q* literal 0 HcmV?d00001 diff --git a/pmd-jedit/PMDPlugin/pmd.props b/pmd-jedit/PMDPlugin/pmd.props new file mode 100644 index 0000000000..6981629c85 --- /dev/null +++ b/pmd-jedit/PMDPlugin/pmd.props @@ -0,0 +1,53 @@ +# +# Plugin properties +# +plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.name=PMD +plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.author=Jiger Patel, Tom Copeland +plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.version=2.2 +plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.docs=jedit.html +plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.depend.0=jdk 1.3 +plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.depend.1=jedit 04.02.01.00 +plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.depend.2=plugin errorlist.ErrorListPlugin 1.2 +plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.jars=pmd-1.2.1.jar jaxen-core-1.0-fcs.jar saxpath-1.0-fcs.jar pmd-swingui-0.1.jar + +# +# Menu properties +# + +#New jEdit 4.2 properties +plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.activate=defer + +plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.menu.label=$PMD + +plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.menu=pmd-check-current-buffer pmd-check-all-open-buffers pmd-check-current-directory pmd-check-current-directory-recursively pmd-clear-errorlist %pmd-cpd +pmd-cpd=cpd-currentfile cpd-dir cpd-dir-recursively + +pmd-check-current-buffer.label=Check current buffer +pmd-check-all-open-buffers.label=Check all open buffers +pmd-check-current-directory.label=Check all files in current directory +pmd-check-current-directory-recursively.label=Check directory recursively +pmd-clear-errorlist.label=Clear ErrorList +pmd-cpd.label=Detect Duplicate Code +cpd-currentfile.label=In Current File +cpd-dir.label=In Directory +cpd-dir-recursively.label=In Directory Recursively +pmd-check-file.label=Check selected file(s) +# +# Option pane properties +# + +plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.option-pane=pmd +options.pmd.label=PMD +options.pmd.code=new net.sourceforge.pmd.jedit.PMDOptionPane() + +#Dockables properties. +cpd-viewer.title=Copy/Paste Detector + +#FS Browser properties + +plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.browser-menu=pmd-check-file pmd-check-current-directory pmd-check-current-directory-recursively + + + + + diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/CPDDuplicateCodeViewer.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/CPDDuplicateCodeViewer.java new file mode 100644 index 0000000000..a387014d31 --- /dev/null +++ b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/CPDDuplicateCodeViewer.java @@ -0,0 +1,194 @@ +package net.sourceforge.pmd.jedit; + +//Imports +import org.gjt.sp.jedit.Buffer; +import org.gjt.sp.jedit.View; +import org.gjt.sp.jedit.io.VFSManager; +import org.gjt.sp.jedit.jEdit; +import org.gjt.sp.jedit.textarea.Selection; + +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTree; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeSelectionModel; +import java.awt.BorderLayout; +import java.util.List; +import java.util.ArrayList; +//End of Imports + +/** + * A GUI Component to display Duplicate code. + * + * @created 05 Apr 2003 + * @author Jiger Patel + * + */ + +public class CPDDuplicateCodeViewer extends JPanel +{ + JTree tree; + DefaultTreeModel treeModel = new DefaultTreeModel(new DefaultMutableTreeNode("CPD Results",true)); + View view; + + public CPDDuplicateCodeViewer(View view) + { + this.view = view; + setLayout(new BorderLayout()); + tree = new JTree(treeModel); + tree.getSelectionModel().setSelectionMode + (TreeSelectionModel.SINGLE_TREE_SELECTION); + tree.addTreeSelectionListener(new TreeSelectionListener() + { + public void valueChanged(TreeSelectionEvent e) + { + DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent(); + if (node != null) + { + //System.out.println("Node is " + node +" class "+ node.getClass()); + if (node.isLeaf() && node instanceof Duplicate) + { + Duplicate duplicate = (Duplicate)node; + gotoDuplicate(duplicate); + //System.out.println("Got!! " + duplicate); + } + } + } + }); + + + add(new JScrollPane(tree)); + + }//End of CPDDuplicateCodeViewer constructor + + + public void refreshTree() + { + treeModel.reload(); + } + + public void gotoDuplicate(final Duplicate duplicate) + { + if(duplicate != null) + { + final Buffer buffer = jEdit.openFile(view,duplicate.getFilename()); + + VFSManager.runInAWTThread(new Runnable() + { + public void run() + { + view.setBuffer(buffer); + + int start = buffer.getLineStartOffset(duplicate.getBeginLine()); + int end = buffer.getLineEndOffset(duplicate.getEndLine()-2); + //Log.log(Log.DEBUG, this.getClass(), "Start Line "+ duplicate.getBeginLine() + " End Line "+ duplicate.getEndLine() + " Start " + start + " End "+ end); + //Since an AIOOB Exception is thrown if the end is the end of file. we do a -1 from end to fix it. + view.getTextArea().setSelection(new Selection.Range(start,end -1)); + view.getTextArea().moveCaretPosition(start); + } + }); + } + } + + public DefaultMutableTreeNode getRoot() + { + return (DefaultMutableTreeNode)treeModel.getRoot(); + } + + public void addDuplicates(Duplicates duplicates) + { + //System.out.println("Inside addDuplicates " + duplicates +" Root child count "+ treeModel.getChildCount(treeModel.getRoot())); + getRoot().add(duplicates); + //vecDuplicates.addElement(duplicates); + } + + public class Duplicates extends DefaultMutableTreeNode + { + List vecduplicate = new ArrayList(); + String message, sourcecode; + + public Duplicates(String message, String sourcecode) + { + this.message = message; + this.sourcecode = sourcecode; + } + + public String getSourceCode() + { + return sourcecode; + } + + public void addDuplicate(Duplicate duplicate) + { + add(duplicate); + //vecduplicate.addElement(duplicate); + } + + public String toString() + { + return message; + } + } + + public class Duplicate extends DefaultMutableTreeNode + { + private String filename; + private int beginLine, endLine; + + public Duplicate(String filename,int beginLine, int endLine) + { + this.filename = filename; + this.beginLine = beginLine; + this.endLine = endLine; + } + + public String getFilename() + { + return filename; + } + + public int getBeginLine() + { + return beginLine; + } + + public int getEndLine() + { + return endLine; + } + + public String toString() + { + return filename + ":"+ getBeginLine()+"-"+getEndLine(); + } + } + + public void expandAll() + { + int row = 0; + while (row < tree.getRowCount()) + { + tree.expandRow(row); + row++; + } + } + + public void collapseAll() + { + int row = tree.getRowCount() - 1; + while (row >= 0) { + tree.collapseRow(row); + row--; + } + } + + public void clearDuplicates() + { + getRoot().removeAllChildren(); + } + +}//End of class CPDDuplicateCodeViewer + diff --git a/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java new file mode 100644 index 0000000000..e953800761 --- /dev/null +++ b/pmd-jedit/PMDPlugin/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java @@ -0,0 +1,434 @@ +/* + * User: tom + * Date: Jul 3, 2002 + * Time: 2:33:24 PM + */ +package net.sourceforge.pmd.jedit; + +import errorlist.*; +import net.sourceforge.pmd.*; +import net.sourceforge.pmd.cpd.*; +import org.gjt.sp.jedit.*; +import org.gjt.sp.jedit.browser.*; +import org.gjt.sp.jedit.io.*; + +import javax.swing.*; +import java.io.*; +import java.util.*; +import org.gjt.sp.jedit.msg.*; + + +public class PMDJEditPlugin extends EBPlugin { + + public static final String NAME = "PMD"; + public static final String OPTION_RULES_PREFIX = "options.pmd.rules."; + public static final String OPTION_UI_DIRECTORY_POPUP = "options.pmd.ui.directorypopup"; + public static final String DEFAULT_TILE_MINSIZE_PROPERTY = "pmd.cpd.defMinTileSize"; + public static final String RUN_PMD_ON_SAVE = "pmd.runPMDOnSave"; + public static final String CUSTOM_RULES_PATH_KEY = "pmd.customRulesPath"; + //private static RE re = new UncheckedRE("Starting at line ([0-9]*) of (\\S*)"); + + private static PMDJEditPlugin instance; + + static { + instance = new PMDJEditPlugin(); + instance.start(); + } + + private DefaultErrorSource errorSource; + + // boilerplate JEdit code + public void start() { + errorSource = new DefaultErrorSource(NAME); + ErrorSource.registerErrorSource(errorSource); + } + +/* public void createMenuItems(Vector menuItems) { + menuItems.addElement(GUIUtilities.loadMenu("pmd-menu")); + } + + public void createOptionPanes(OptionsDialog optionsDialog) { + optionsDialog.addOptionPane(new PMDOptionPane()); + } */ + // boilerplate JEdit code + + public static void checkDirectory(View view) { + instance.instanceCheckDirectory(view); + } + + public void instanceCheckDirectory(View view) { + if (jEdit.getBooleanProperty(PMDJEditPlugin.OPTION_UI_DIRECTORY_POPUP)) + { + String dir = JOptionPane.showInputDialog(jEdit.getFirstView(), "Please type in a directory to scan", NAME, JOptionPane.QUESTION_MESSAGE); + if (dir != null) + { + if (!(new File(dir)).exists() || !(new File(dir)).isDirectory() ) + { + JOptionPane.showMessageDialog(jEdit.getFirstView(), dir + " is not a valid directory name", NAME, JOptionPane.ERROR_MESSAGE); + return; + } + process(findFiles(dir, false)); + } + } + else + { + VFSBrowser browser = (VFSBrowser)view.getDockableWindowManager().getDockable("vfs.browser"); + if(browser == null) { + JOptionPane.showMessageDialog(jEdit.getFirstView(), "Can't run PMD on a directory unless the file browser is open", NAME, JOptionPane.ERROR_MESSAGE); + return; + } + process(findFiles(browser.getDirectory(), false)); + } + } + + public void handleMessage(EBMessage ebmess) + { + if (ebmess instanceof BufferUpdate) + { + if(jEdit.getBooleanProperty(PMDJEditPlugin.RUN_PMD_ON_SAVE)) + { + BufferUpdate bu = (BufferUpdate)ebmess; + if (bu.getWhat() == BufferUpdate.SAVED) + { + instance.check(bu.getBuffer(),bu.getView()); + } + } + } + } + + // check all open buffers + public static void checkAllOpenBuffers(View view) { + instance.instanceCheckAllOpenBuffers(view); + } + + public void instanceCheckAllOpenBuffers(View view) { + // I'm putting the files in a Set to work around some + // odd behavior in jEdit - the buffer.getNext() + // seems to iterate over the files twice. + Buffer buffers[] = jEdit.getBuffers(); + + if(buffers != null) + { + for (int i=0; i JCheckBox + private Map rules = new TreeMap( + new Comparator() + { + public int compare(Object o1, Object o2) + { + Rule r1 = (Rule)o1; + Rule r2 = (Rule)o2; + return r1.getName().compareTo(r2.getName()); + } + }); + + + /** + * Constructor for the SelectedRules object + * + * @exception RuleSetNotFoundException Description of the Exception + */ + public SelectedRules() throws RuleSetNotFoundException + { + RuleSetFactory rsf = new RuleSetFactory(); + for(Iterator i = rsf.getRegisteredRuleSets(); i.hasNext(); ) + { + RuleSet rs = (RuleSet)i.next(); + addRuleSet2Rules(rs); + } + + //Load custom RuleSets if any. + + String customRuleSetPath = jEdit.getProperty("pmd.customRulesPath"); + + if(!(customRuleSetPath == null)) + { + StringTokenizer strtok = new StringTokenizer(customRuleSetPath, ","); + while(strtok.hasMoreTokens()) + { + RuleSet rs = rsf.createRuleSet(strtok.nextToken()); + addRuleSet2Rules(rs); + } + } + } + + + /** + * Description of the Method + * + * @return Description of the Return Value + */ + public int size() + { + return rules.size(); + } + + + /** + * Gets the rule attribute of the SelectedRules object + * + * @param candidate Description of the Parameter + * @return The rule value + */ + public Rule getRule(JCheckBox candidate) + { + for(Iterator i = rules.keySet().iterator(); i.hasNext(); ) + { + Rule rule = (Rule)i.next(); + JCheckBox box = (JCheckBox)rules.get(rule); + if(box.equals(candidate)) + { + return rule; + } + } + throw new RuntimeException("Couldn't find a rule that mapped to the passed in JCheckBox " + candidate); + } + + + /** + * Description of the Method + * + * @param key Description of the Parameter + * @return Description of the Return Value + */ + public JCheckBox get(Object key) + { + return (JCheckBox)rules.get(key); + } + + + /** + * Gets the allBoxes attribute of the SelectedRules object + * + * @return The allBoxes value + */ + public Object[] getAllBoxes() + { + Object[] foo = new Object[rules.size()]; + int idx = 0; + for(Iterator i = rules.values().iterator(); i.hasNext(); ) + { + foo[idx] = i.next(); + idx++; + } + return foo; + } + + + /** Description of the Method */ + public void save() + { + for(Iterator i = rules.keySet().iterator(); i.hasNext(); ) + { + Rule rule = (Rule)i.next(); + jEdit.setBooleanProperty(PMDJEditPlugin.OPTION_RULES_PREFIX + rule.getName(), get(rule).isSelected()); + } + } + + + /** + * Gets the selectedRules attribute of the SelectedRules object + * + * @return The selectedRules value + */ + public RuleSet getSelectedRules() + { + RuleSet newRuleSet = new RuleSet(); + for(Iterator i = rules.keySet().iterator(); i.hasNext(); ) + { + Rule rule = (Rule)i.next(); + if(get(rule).isSelected()) + { + newRuleSet.addRule(rule); + } + } + return newRuleSet; + } + + + /** + * Description of the Method + * + * @param name Description of the Parameter + * @return Description of the Return Value + */ + private JCheckBox createCheckBox(String name) + { + JCheckBox box = new JCheckBox(name); + box.setSelected(jEdit.getBooleanProperty(PMDJEditPlugin.OPTION_RULES_PREFIX + name, true)); + return box; + } + + + /** + * Adds a feature to the RuleSet2Rules attribute of the SelectedRules object + * + * @param rs The feature to be added to the RuleSet2Rules attribute + */ + private void addRuleSet2Rules(RuleSet rs) + { + for(Iterator j = rs.getRules().iterator(); j.hasNext(); ) + { + Rule rule = (Rule)j.next(); + rules.put(rule, createCheckBox(rule.getName())); + } + } +} +