Updates so CPD can check all supported files, not just Java files. CPD support JSP, PHP, Ruby, C/C++, and Fortran. This is not quite complete, still need to fix the CPD access from the File System Browser. CPD from the Plugins menu works now.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@7006 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -3,11 +3,11 @@
|
||||
#
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.name=PMDPlugin
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.author=Jiger Patel, Tom Copeland, Alan Ezust, Dale Anson
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.version=3.1
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.version=3.2
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.docs=doc/jedit.html
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.depend.0=jdk 1.5
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.depend.1=jedit 04.03.03.00
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.depend.2=plugin errorlist.ErrorListPlugin 1.3.2
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.depend.1=jedit 04.03.18.00
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.depend.2=plugin errorlist.ErrorListPlugin 1.8
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.jars=pmd-4.2.5.jar jaxen-1.1.1.jar asm-3.1.jar
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.description=The PMD plugin is a Java source code analysis tool.
|
||||
#
|
||||
@ -18,7 +18,7 @@ plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.description=The PMD plugin is a
|
||||
# user unchecks the option to run on save, this setting will change to 'defer'.
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.activate=startup
|
||||
|
||||
# default is to run on save
|
||||
# default is to run on save
|
||||
pmd.runPMDOnSave=true
|
||||
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.menu.label=$PMD
|
||||
|
@ -196,7 +196,7 @@ options.pmd.rules.SystemPrintln=false
|
||||
options.pmd.rules.TestClassWithoutTestCases=false
|
||||
options.pmd.rules.TooFewBranchesForASwitchStatement=false
|
||||
options.pmd.rules.TooManyFields=false
|
||||
options.pmd.rules.TooManyMethods=true
|
||||
options.pmd.rules.TooManyMethods=false
|
||||
options.pmd.rules.TooManyStaticImports=true
|
||||
options.pmd.rules.UncommentedEmptyConstructor=false
|
||||
options.pmd.rules.UncommentedEmptyMethod=false
|
||||
|
@ -18,7 +18,7 @@ You can read much more about PMD here - http://pmd.sf.net/.</p>
|
||||
Use the plugin manager for easiest installation. To install manually, follow these steps:
|
||||
<ul>
|
||||
<li>Uninstall any old PMD-JEdit plugins
|
||||
<li>Unzip the PMD-JEdit-bin-2.6.zip file into your JEdit directory; it'll put a couple of jar files into your jars directory.
|
||||
<li>Unzip the PMD-JEdit.zip file into your JEdit directory; it'll put a couple of jar files into your jars directory.
|
||||
<li>Restart JEdit and you'll be ready to go.
|
||||
</ul>
|
||||
<h3>Integration</h3>
|
||||
@ -51,6 +51,11 @@ These should be pretty much self-explanatory. One non-obvious thing is that if
|
||||
|
||||
Take a look at the <a href="#releasenotes">Release Notes and Changelog</a> for more details on new features in this release. <br>
|
||||
|
||||
<h3>CPD, the Copy/Paste Detector</h3>
|
||||
The PMD plugin provides access to the Copy/Paste Detector. This can help identify and eliminate duplicate code in a project. The heuristics used in the detection are a little "fuzzy" in that it is able to detect code that is very close to the same as code found elsewhere and can identify duplicate code regardless of the formatting of whitespace.
|
||||
<p>
|
||||
The CPD is very fast. It can also work on a variety of languages. Currently supported languages are Java, JSP, PHP, C/C++, Fortran, and Ruby.
|
||||
|
||||
<h3>Custom Rules</h3>
|
||||
<p>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.</p>
|
||||
<p>
|
||||
@ -74,7 +79,7 @@ As of version 3.0, the PMD Plugin provides access to the PMD Rule Designer, whic
|
||||
<li>Split the option pane into smaller panes so they are easier to use.</li>
|
||||
<li>Selected some default rules for first-time users. This makes it much easier for new users to get started.</li>
|
||||
<li>Changed plugin to start on jEdit startup and to check on file save. This makes it easier for PMD to be useful right away.</li>
|
||||
<li>Upgraded to PMD 2.4.5, which includes some new rulesets, including one specifically for Android programming.</li>
|
||||
<li>Upgraded to PMD 4.2.5, which includes some new rulesets, including one specifically for Android programming.</li>
|
||||
<li>Mouse-over on ruleset names now gives description of the ruleset in the example box. This makes it easier to understand what the group of rules is about.</li>
|
||||
<li>Added menu item to access PMD Rule Designer.</li>
|
||||
</ol>
|
||||
|
@ -0,0 +1,74 @@
|
||||
package net.sourceforge.pmd.jedit;
|
||||
|
||||
import java.io.File;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
|
||||
/**
|
||||
* This is a file filter for CPD. I wanted to use a FileNameExtension filter, but
|
||||
* Java 1.5 doesn't have a FileNameExtensionFilter, so this one is pretty close.
|
||||
* One difference is I've added "mode" as a parameter to the constructor to make
|
||||
* it easy to match a filter against a supported language in CPD.
|
||||
*/
|
||||
public class CPDFileFilter extends FileFilter {
|
||||
|
||||
private String mode;
|
||||
private String description;
|
||||
private String[] extensions;
|
||||
|
||||
/**
|
||||
* @param mode A language known to CPD. So far, these line up nicely with
|
||||
* the mode names in jEdit, e.g. "java" = "java".
|
||||
* @param description Some text to show in the "Files of Type" drop down in
|
||||
* a JFileChooser.
|
||||
* @param extensions A list of file name extensions supported by this filter.
|
||||
*/
|
||||
public CPDFileFilter(String mode, String description, String... extensions) {
|
||||
this.mode = mode;
|
||||
this.description = description;
|
||||
this.extensions = extensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param f A file to check to see if this filter will accept it.
|
||||
* @return true if the file is acceptable.
|
||||
*/
|
||||
public boolean accept(File f) {
|
||||
if (f == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// always accept directories so JFileChooser works correctly
|
||||
if (f.isDirectory()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// get the file name extension
|
||||
String name = f.getName();
|
||||
int index = name.lastIndexOf(".");
|
||||
if (index == -1) {
|
||||
return false;
|
||||
}
|
||||
if (index + 1 >= name.length()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// check the extension against acceptable extensions
|
||||
String extension = name.substring(index + 1);
|
||||
for (String ext : extensions) {
|
||||
if (ext.equals(extension)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// no match
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getMode() {
|
||||
return mode;
|
||||
}
|
||||
}
|
@ -268,7 +268,11 @@ public class PMDJEditPlugin extends EBPlugin
|
||||
if (ctx.getReport().isEmpty())
|
||||
{
|
||||
/// danson, this is annoying if 'Run PMD on Save' is checked
|
||||
///JOptionPane.showMessageDialog(view, "No problems found", NAME, JOptionPane.INFORMATION_MESSAGE);
|
||||
boolean run_on_save = jEdit.getBooleanProperty( PMDJEditPlugin.RUN_PMD_ON_SAVE );
|
||||
if (!run_on_save) {
|
||||
// TODO: put string in properties file
|
||||
JOptionPane.showMessageDialog(view, "No problems found", NAME, JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
errorSource.clear();
|
||||
}
|
||||
|
||||
@ -307,6 +311,7 @@ public class PMDJEditPlugin extends EBPlugin
|
||||
|
||||
catch(Exception e)
|
||||
{
|
||||
// TODO: is this useful to log?
|
||||
Log.log(Log.ERROR, this, "Exception processing file "+ buffer.getPath(), e);
|
||||
}
|
||||
}// check current buffer
|
||||
@ -442,7 +447,7 @@ public class PMDJEditPlugin extends EBPlugin
|
||||
{
|
||||
String modeName = getFileType(view.getBuffer().getMode().getName());
|
||||
if (modeName == null) {
|
||||
JOptionPane.showMessageDialog(view, "Copy/Paste detection can only be performed on Java,C/C++,PHP code.", "Copy/Paste Detector", JOptionPane.INFORMATION_MESSAGE);
|
||||
JOptionPane.showMessageDialog(view, "Copy/Paste detection can not be performed on this file\nbecause the mode can not be determined.", "Copy/Paste Detector", JOptionPane.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
instance.instanceCPDCurrentFile(view, view.getBuffer().getPath(), modeName);
|
||||
@ -497,7 +502,7 @@ public class PMDJEditPlugin extends EBPlugin
|
||||
}
|
||||
else
|
||||
{
|
||||
view.getStatus().setMessageAndClear("Cannot run CPD on an Invalid file type");
|
||||
view.getStatus().setMessageAndClear("CPD does not yet support this file type: " + fileType);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -506,8 +511,15 @@ public class PMDJEditPlugin extends EBPlugin
|
||||
public static void cpdDir(View view)
|
||||
{
|
||||
JFileChooser chooser = new JFileChooser(jEdit.getProperty(LAST_DIRECTORY));
|
||||
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
|
||||
|
||||
chooser.addChoosableFileFilter(new CPDFileFilter("ruby", "Ruby files", "rb", "rbw"));
|
||||
chooser.addChoosableFileFilter(new CPDFileFilter("php", "PHP files", "php", "php3", "php4", "phtml", "inc"));
|
||||
chooser.addChoosableFileFilter(new CPDFileFilter("jsp", "JSP files", "jsp", "jsf", "jspf"));
|
||||
chooser.addChoosableFileFilter(new CPDFileFilter("fortran", "Fortran files", "for", "fort", "f77", "f90"));
|
||||
chooser.addChoosableFileFilter(new CPDFileFilter("cpp", "C/C++ files", "c", "cc", "cpp"));
|
||||
chooser.addChoosableFileFilter(new CPDFileFilter("java", "Java files", "java"));
|
||||
|
||||
JPanel pnlAccessory = new JPanel(new BorderLayout());
|
||||
|
||||
JPanel pnlTile = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
@ -527,10 +539,12 @@ public class PMDJEditPlugin extends EBPlugin
|
||||
|
||||
int returnVal = chooser.showOpenDialog(view);
|
||||
File selectedFile = null;
|
||||
String mode = null;
|
||||
|
||||
if(returnVal == JFileChooser.APPROVE_OPTION)
|
||||
{
|
||||
selectedFile = chooser.getSelectedFile();
|
||||
mode = ((CPDFileFilter)chooser.getFileFilter()).getMode();
|
||||
|
||||
if(!selectedFile.isDirectory())
|
||||
{
|
||||
@ -553,7 +567,7 @@ public class PMDJEditPlugin extends EBPlugin
|
||||
try
|
||||
{
|
||||
jEdit.setBooleanProperty(CHECK_DIR_RECURSIVE,chkRecursive.isSelected());
|
||||
instance.instanceCPDDir(view, selectedFile.getCanonicalPath(), tilesize, chkRecursive.isSelected());
|
||||
instance.instanceCPDDir(view, selectedFile.getCanonicalPath(), tilesize, chkRecursive.isSelected(), mode);
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
@ -578,17 +592,17 @@ public class PMDJEditPlugin extends EBPlugin
|
||||
JOptionPane.showMessageDialog(view, "Selected file must be a Directory.", NAME, JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
instance.instanceCPDDir(view, selectedDir[0].getPath(), jEdit.getIntegerProperty(DEFAULT_TILE_MINSIZE_PROPERTY,100), recursive);
|
||||
instance.instanceCPDDir(view, selectedDir[0].getPath(), jEdit.getIntegerProperty(DEFAULT_TILE_MINSIZE_PROPERTY,100), recursive, "java");
|
||||
}
|
||||
}
|
||||
|
||||
private void instanceCPDDir(View view, String dir, int tileSize, boolean recursive) throws IOException
|
||||
private void instanceCPDDir(View view, String dir, int tileSize, boolean recursive, String mode) throws IOException
|
||||
{
|
||||
if(dir != null)
|
||||
{
|
||||
jEdit.setProperty(LAST_DIRECTORY,dir);
|
||||
instance.errorSource.clear();
|
||||
CPD cpd = getCPD(tileSize, "java", view);
|
||||
CPD cpd = getCPD(tileSize, mode, view);
|
||||
|
||||
if(cpd != null)
|
||||
{
|
||||
@ -830,6 +844,19 @@ public class PMDJEditPlugin extends EBPlugin
|
||||
{
|
||||
Language lang;
|
||||
LanguageFactory lf = new LanguageFactory();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean supported = false;
|
||||
for (String s : lf.supportedLanguages) {
|
||||
sb.append(s).append(", ");
|
||||
if (s.equals(fileType)) {
|
||||
supported = true;
|
||||
}
|
||||
}
|
||||
if (!supported) {
|
||||
JOptionPane.showMessageDialog(view,"Copy/Paste detection can only be performed on " + sb.toString().substring(0, sb.length() - 2) + " code.","Copy/Paste Detector",JOptionPane.INFORMATION_MESSAGE);
|
||||
return null;
|
||||
}
|
||||
|
||||
if ("java".equals(fileType))
|
||||
{
|
||||
//Log.log(Log.DEBUG, PMDJEditPlugin.class, "Doing java");
|
||||
@ -837,20 +864,8 @@ public class PMDJEditPlugin extends EBPlugin
|
||||
props.setProperty(JavaTokenizer.IGNORE_LITERALS, String.valueOf(jEdit.getBooleanProperty(PMDJEditPlugin.IGNORE_LITERALS)));
|
||||
lang = lf.createLanguage("java", props);
|
||||
}
|
||||
else if ("php".equals(fileType))
|
||||
{
|
||||
//Log.log(Log.DEBUG, PMDJEditPlugin.class, "Doing PHP");
|
||||
lang = lf.createLanguage("php");
|
||||
}
|
||||
else if ("cpp".equals(fileType))
|
||||
{
|
||||
//Log.log(Log.DEBUG, PMDJEditPlugin.class, "Doing C/C++");
|
||||
lang = lf.createLanguage("cpp");
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(view,"Copy/Paste detection can only be performed on Java,C/C++,PHP code.","Copy/Paste Detector",JOptionPane.INFORMATION_MESSAGE);
|
||||
return null;
|
||||
else {
|
||||
lang = lf.createLanguage(fileType);
|
||||
}
|
||||
return new CPD(tileSize,lang);
|
||||
}
|
||||
|
Reference in New Issue
Block a user