Added PMD to FS Browser
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@2193 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -28,17 +28,22 @@
|
||||
</ACTION>
|
||||
<ACTION NAME="cpd-currentfile">
|
||||
<CODE>
|
||||
net.sourceforge.pmd.jedit.PMDJEditPlugin.CPDCurrentFile(view);
|
||||
net.sourceforge.pmd.jedit.PMDJEditPlugin.cpdCurrentFile(view);
|
||||
</CODE>
|
||||
</ACTION>
|
||||
<ACTION NAME="cpd-dir">
|
||||
<CODE>
|
||||
net.sourceforge.pmd.jedit.PMDJEditPlugin.CPDDir(view,false);
|
||||
net.sourceforge.pmd.jedit.PMDJEditPlugin.cpdDir(view,false);
|
||||
</CODE>
|
||||
</ACTION>
|
||||
<ACTION NAME="cpd-dir-recursively">
|
||||
<CODE>
|
||||
net.sourceforge.pmd.jedit.PMDJEditPlugin.CPDDir(view,true);
|
||||
net.sourceforge.pmd.jedit.PMDJEditPlugin.cpdDir(view,true);
|
||||
</CODE>
|
||||
</ACTION>
|
||||
<ACTION NAME="pmd-check-file">
|
||||
<CODE>
|
||||
net.sourceforge.pmd.jedit.PMDJEditPlugin.checkFile(view,browser);
|
||||
</CODE>
|
||||
</ACTION>
|
||||
</ACTIONS>
|
||||
|
@ -19,7 +19,8 @@ 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
|
||||
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
|
||||
@ -30,6 +31,7 @@ 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
|
||||
#
|
||||
@ -40,3 +42,12 @@ 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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -16,7 +16,8 @@ import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreeSelectionModel;
|
||||
import java.awt.BorderLayout;
|
||||
import java.util.Vector;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
//End of Imports
|
||||
|
||||
/**
|
||||
@ -54,10 +55,6 @@ public class CPDDuplicateCodeViewer extends JPanel
|
||||
gotoDuplicate(duplicate);
|
||||
//System.out.println("Got!! " + duplicate);
|
||||
}
|
||||
else
|
||||
{
|
||||
//System.out.println("Something else. Please check ");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -78,13 +75,13 @@ public class CPDDuplicateCodeViewer extends JPanel
|
||||
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);
|
||||
@ -110,7 +107,7 @@ public class CPDDuplicateCodeViewer extends JPanel
|
||||
|
||||
public class Duplicates extends DefaultMutableTreeNode
|
||||
{
|
||||
Vector vecduplicate = new Vector();
|
||||
List vecduplicate = new ArrayList();
|
||||
String message, sourcecode;
|
||||
|
||||
public Duplicates(String message, String sourcecode)
|
||||
|
@ -21,12 +21,11 @@ import net.sourceforge.pmd.cpd.CPPLanguage;
|
||||
import net.sourceforge.pmd.cpd.Mark;
|
||||
import net.sourceforge.pmd.cpd.Match;
|
||||
import org.gjt.sp.jedit.Buffer;
|
||||
import org.gjt.sp.jedit.EditPlugin;
|
||||
import org.gjt.sp.jedit.GUIUtilities;
|
||||
import org.gjt.sp.jedit.View;
|
||||
import org.gjt.sp.jedit.browser.VFSBrowser;
|
||||
import org.gjt.sp.jedit.gui.OptionsDialog;
|
||||
import org.gjt.sp.jedit.EditPlugin;
|
||||
import org.gjt.sp.jedit.jEdit;
|
||||
import org.gjt.sp.jedit.browser.*;
|
||||
import org.gjt.sp.jedit.io.*;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JLabel;
|
||||
@ -43,7 +42,6 @@ import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Vector;
|
||||
|
||||
|
||||
public class PMDJEditPlugin extends EditPlugin {
|
||||
@ -85,7 +83,7 @@ public class PMDJEditPlugin extends EditPlugin {
|
||||
public void instanceCheckDirectory(View view) {
|
||||
if (jEdit.getBooleanProperty(PMDJEditPlugin.OPTION_UI_DIRECTORY_POPUP))
|
||||
{
|
||||
final String dir = JOptionPane.showInputDialog(jEdit.getFirstView(), "Please type in a directory to scan", NAME, JOptionPane.QUESTION_MESSAGE);
|
||||
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() )
|
||||
@ -98,7 +96,7 @@ public class PMDJEditPlugin extends EditPlugin {
|
||||
}
|
||||
else
|
||||
{
|
||||
final VFSBrowser browser = (VFSBrowser)view.getDockableWindowManager().getDockable("vfs.browser");
|
||||
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;
|
||||
@ -143,7 +141,7 @@ public class PMDJEditPlugin extends EditPlugin {
|
||||
public void instanceCheckDirectoryRecursively(View view) {
|
||||
if (jEdit.getBooleanProperty(PMDJEditPlugin.OPTION_UI_DIRECTORY_POPUP))
|
||||
{
|
||||
final String dir = JOptionPane.showInputDialog(jEdit.getFirstView(), "Please type in a directory to scan recursively", NAME, JOptionPane.QUESTION_MESSAGE);
|
||||
String dir = JOptionPane.showInputDialog(jEdit.getFirstView(), "Please type in a directory to scan recursively", NAME, JOptionPane.QUESTION_MESSAGE);
|
||||
if (dir != null && dir.trim() != null)
|
||||
{
|
||||
if (!(new File(dir)).exists() || !(new File(dir)).isDirectory() ) {
|
||||
@ -156,7 +154,7 @@ public class PMDJEditPlugin extends EditPlugin {
|
||||
}
|
||||
else
|
||||
{
|
||||
final VFSBrowser browser = (VFSBrowser)view.getDockableWindowManager().getDockable("vfs.browser");
|
||||
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;
|
||||
@ -264,7 +262,7 @@ public class PMDJEditPlugin extends EditPlugin {
|
||||
return f.findFilesFrom(dir, new JavaLanguage.JavaFileOrDirectoryFilter(), recurse);
|
||||
}
|
||||
|
||||
public static void CPDCurrentFile(View view) throws IOException
|
||||
public static void cpdCurrentFile(View view) throws IOException
|
||||
{
|
||||
/* if(!view.getBuffer().getMode().getName().equals("java"))
|
||||
{
|
||||
@ -302,7 +300,7 @@ public class PMDJEditPlugin extends EditPlugin {
|
||||
instance.processDuplicates(cpd, view);
|
||||
}
|
||||
|
||||
public static void CPDDir(View view, boolean recursive) throws IOException
|
||||
public static void cpdDir(View view, boolean recursive) throws IOException
|
||||
{
|
||||
JFileChooser chooser = new JFileChooser(jEdit.getProperty("pmd.cpd.lastDirectory"));
|
||||
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||
@ -394,4 +392,44 @@ public class PMDJEditPlugin extends EditPlugin {
|
||||
return (CPDDuplicateCodeViewer)view.getDockableWindowManager().getDockableWindow("cpd-viewer");
|
||||
|
||||
}
|
||||
|
||||
public static void checkFile(View view, VFSBrowser browser)
|
||||
{
|
||||
instance.checkFile(view, browser.getSelectedFiles());
|
||||
}
|
||||
|
||||
public void checkFile(View view, VFS.DirectoryEntry de[])
|
||||
{
|
||||
if(view != null && de != null)
|
||||
{
|
||||
List files = new ArrayList();
|
||||
for(int i=0;i<de.length;i++)
|
||||
{
|
||||
if(de[i].type == VFS.DirectoryEntry.FILE)
|
||||
{
|
||||
files.add(new File(de[i].path));
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("See final files to process " + files);
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkDirectory(View view, VFSBrowser browser, boolean recursive)
|
||||
{
|
||||
VFS.DirectoryEntry de[] = browser.getSelectedFiles();
|
||||
if(de == null || de.length == 0 || de[0].type != VFS.DirectoryEntry.DIRECTORY)
|
||||
{
|
||||
JOptionPane.showMessageDialog(view, "Selection must be a directory",NAME, JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
instance.process(instance.findFiles(de[0].path, recursive));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user