updated to allow individual rules to be selected
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@613 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -7,7 +7,7 @@ plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.version=0.7
|
||||
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.00.99.00
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.jars=pmd-0.7.jar
|
||||
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.jars=pmd-0.8.jar
|
||||
|
||||
#
|
||||
# Menu properties
|
||||
|
@ -4,7 +4,7 @@
|
||||
<property name="src" value="src/"/>
|
||||
<property name="lib" value="lib/"/>
|
||||
<property name="build" value="build/"/>
|
||||
<property name="pmdjar" value="pmd-0.7.jar"/>
|
||||
<property name="pmdjar" value="pmd-0.8.jar"/>
|
||||
<property name="pluginversion" value="0.7"/>
|
||||
<property name="jedit.install.dir" value="c:\jedit\jars"/>
|
||||
|
||||
|
@ -25,8 +25,8 @@ public class PMDJEditPlugin extends EditPlugin {
|
||||
|
||||
public static final String NAME = "PMD";
|
||||
public static final String PROPERTY_PREFIX = "plugin.net.sourceforge.pmd.jedit.";
|
||||
public static final String OPTION_RULESETS_PREFIX = "options.pmd.rulesets.";
|
||||
|
||||
public static final String OPTION_RULES_PREFIX = "options.pmd.rules.";
|
||||
|
||||
public static class JavaFileOrDirectoryFilter implements FilenameFilter {
|
||||
public boolean accept(File dir, String filename) {
|
||||
return filename.endsWith("java") || (new File(dir.getAbsolutePath() + System.getProperty("file.separator") + filename).isDirectory());
|
||||
@ -41,13 +41,13 @@ public class PMDJEditPlugin extends EditPlugin {
|
||||
}
|
||||
|
||||
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"));
|
||||
}
|
||||
@ -68,7 +68,7 @@ public class PMDJEditPlugin extends EditPlugin {
|
||||
JOptionPane.showMessageDialog(jEdit.getFirstView(), "Can't run PMD on a directory unless the file browser is open", NAME, JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
processFiles(findFilesInDirectory(browser.getDirectory()), browser);
|
||||
processFiles(findFilesInDirectory(browser.getDirectory()));
|
||||
}
|
||||
|
||||
public static void checkDirectoryRecursively(View view) {
|
||||
@ -82,7 +82,7 @@ public class PMDJEditPlugin extends EditPlugin {
|
||||
JOptionPane.showMessageDialog(jEdit.getFirstView(), "Can't run PMD on a directory unless the file browser is open", NAME, JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
processFiles(findFilesRecursively(browser.getDirectory()), browser);
|
||||
processFiles(findFilesRecursively(browser.getDirectory()));
|
||||
}
|
||||
|
||||
public static void check(Buffer buffer, View view) {
|
||||
@ -94,11 +94,11 @@ public class PMDJEditPlugin extends EditPlugin {
|
||||
errorSource.clear();
|
||||
|
||||
PMD pmd = new PMD();
|
||||
SelectedRuleSetsMap selectedRuleSets = new SelectedRuleSetsMap();
|
||||
SelectedRules selectedRuleSets = new SelectedRules();
|
||||
RuleContext ctx = new RuleContext();
|
||||
ctx.setReport(new Report());
|
||||
ctx.setSourceCodeFilename(buffer.getPath());
|
||||
pmd.processFile(new StringReader(view.getTextArea().getText()), selectedRuleSets.getSelectedRuleSets(), ctx);
|
||||
pmd.processFile(new StringReader(view.getTextArea().getText()), selectedRuleSets.getSelectedRules(), ctx);
|
||||
if (ctx.getReport().isEmpty()) {
|
||||
JOptionPane.showMessageDialog(jEdit.getFirstView(), "No problems found", "PMD", JOptionPane.INFORMATION_MESSAGE);
|
||||
errorSource.clear();
|
||||
@ -113,13 +113,13 @@ public class PMDJEditPlugin extends EditPlugin {
|
||||
rsne.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void processFiles(List files, VFSBrowser browser) {
|
||||
|
||||
private void processFiles(List files) {
|
||||
errorSource.clear();
|
||||
PMD pmd = new PMD();
|
||||
SelectedRuleSetsMap selectedRuleSets = null;
|
||||
SelectedRules selectedRuleSets = null;
|
||||
try {
|
||||
selectedRuleSets = new SelectedRuleSetsMap();
|
||||
selectedRuleSets = new SelectedRules();
|
||||
} catch (RuleSetNotFoundException rsne) {
|
||||
// should never happen since rulesets are fetched via getRegisteredRuleSet, nonetheless:
|
||||
System.out.println("PMD ERROR: Couldn't find a ruleset");
|
||||
@ -136,7 +136,7 @@ public class PMDJEditPlugin extends EditPlugin {
|
||||
ctx.setReport(new Report());
|
||||
ctx.setSourceCodeFilename(file.getAbsolutePath());
|
||||
try {
|
||||
pmd.processFile(new FileInputStream(file), selectedRuleSets.getSelectedRuleSets(), ctx);
|
||||
pmd.processFile(new FileInputStream(file), selectedRuleSets.getSelectedRules(), ctx);
|
||||
} catch (FileNotFoundException fnfe) {
|
||||
// should never happen, but if it does, carry on to the next file
|
||||
System.out.println("PMD ERROR: Unable to open file " + file.getAbsolutePath());
|
||||
|
@ -11,24 +11,57 @@ import org.gjt.sp.jedit.jEdit;
|
||||
import org.gjt.sp.jedit.View;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.sourceforge.pmd.RuleSetNotFoundException;
|
||||
import net.sourceforge.pmd.RuleSet;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
|
||||
public class PMDOptionPane extends AbstractOptionPane implements OptionPane {
|
||||
|
||||
private SelectedRuleSetsMap selectedRuleSets;
|
||||
public static class CheckboxList extends JList {
|
||||
public class CheckboxListCellRenderer implements ListCellRenderer {
|
||||
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||
JCheckBox box = (JCheckBox)value;
|
||||
box.setEnabled(isEnabled());
|
||||
box.setFont(getFont());
|
||||
box.setFocusPainted(false);
|
||||
box.setBorderPainted(true);
|
||||
box.setBorder(isSelected ? UIManager.getBorder("List.focusCellHighlightBorder") : new EmptyBorder(1,1,1,1));
|
||||
return box;
|
||||
}
|
||||
}
|
||||
|
||||
public CheckboxList(Object[] args) {
|
||||
super(args);
|
||||
setCellRenderer(new CheckboxListCellRenderer());
|
||||
addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
int index = locationToIndex(e.getPoint());
|
||||
if (index != -1) {
|
||||
JCheckBox box = (JCheckBox)getModel().getElementAt(index);
|
||||
box.setSelected(!box.isSelected());
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private SelectedRules rules;
|
||||
|
||||
public PMDOptionPane() {
|
||||
super(PMDJEditPlugin.NAME);
|
||||
try {
|
||||
selectedRuleSets = new SelectedRuleSetsMap();
|
||||
rules = new SelectedRules();
|
||||
} catch (RuleSetNotFoundException rsne) {
|
||||
rsne.printStackTrace();
|
||||
}
|
||||
@ -36,17 +69,13 @@ public class PMDOptionPane extends AbstractOptionPane implements OptionPane {
|
||||
|
||||
public void init() {
|
||||
removeAll();
|
||||
addComponent(new JLabel("Please see http://pmd.sourceforge.net/ for more information on what's in each rule set."));
|
||||
for (Iterator i = selectedRuleSets.keys(); i.hasNext();) {
|
||||
RuleSet rs = (RuleSet)i.next();
|
||||
JPanel oneBoxPanel = new JPanel();
|
||||
oneBoxPanel.add((JCheckBox)selectedRuleSets.get(rs));
|
||||
oneBoxPanel.add(new JLabel(rs.getDescription()));
|
||||
addComponent(oneBoxPanel);
|
||||
}
|
||||
addComponent(new JLabel("Please see http://pmd.sf.net/ for more information"));
|
||||
JList list = new CheckboxList(rules.getAllBoxes());
|
||||
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
||||
addComponent(new JScrollPane(list));
|
||||
}
|
||||
|
||||
public void save() {
|
||||
selectedRuleSets.save();
|
||||
rules.save();
|
||||
}
|
||||
}
|
||||
|
@ -1,71 +0,0 @@
|
||||
/*
|
||||
* User: tom
|
||||
* Date: Jul 9, 2002
|
||||
* Time: 1:18:38 PM
|
||||
*/
|
||||
package net.sourceforge.pmd.jedit;
|
||||
|
||||
import org.gjt.sp.jedit.jEdit;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
import java.awt.Color;
|
||||
|
||||
import net.sourceforge.pmd.RuleSetFactory;
|
||||
import net.sourceforge.pmd.RuleSet;
|
||||
import net.sourceforge.pmd.RuleSetNotFoundException;
|
||||
|
||||
public class SelectedRuleSetsMap {
|
||||
|
||||
private Map ruleSets = new TreeMap(new Comparator() {
|
||||
public int compare(Object o1, Object o2) {
|
||||
RuleSet r1 = (RuleSet)o1;
|
||||
RuleSet r2 = (RuleSet)o2;
|
||||
return r1.getName().compareTo(r2.getName());
|
||||
}
|
||||
});
|
||||
|
||||
public SelectedRuleSetsMap() throws RuleSetNotFoundException {
|
||||
RuleSetFactory rsf = new RuleSetFactory();
|
||||
for (Iterator i = rsf.getRegisteredRuleSets(); i.hasNext();) {
|
||||
RuleSet rs = (RuleSet)i.next();
|
||||
ruleSets.put(rs, createCheckBox(rs.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
public Iterator keys() {
|
||||
return ruleSets.keySet().iterator();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return ruleSets.size();
|
||||
}
|
||||
|
||||
public JCheckBox get(Object key) {
|
||||
return (JCheckBox)ruleSets.get(key);
|
||||
}
|
||||
|
||||
public void save() {
|
||||
for (Iterator i = keys(); i.hasNext();) {
|
||||
RuleSet rs = (RuleSet)i.next();
|
||||
jEdit.setBooleanProperty(PMDJEditPlugin.OPTION_RULESETS_PREFIX + rs.getName(), get(rs).isSelected());
|
||||
}
|
||||
}
|
||||
|
||||
public RuleSet getSelectedRuleSets() {
|
||||
RuleSet newRuleSet = new RuleSet();
|
||||
for (Iterator i = keys(); i.hasNext();) {
|
||||
RuleSet rs = (RuleSet)i.next();
|
||||
if (get(rs).isSelected()) {
|
||||
newRuleSet.addRuleSet(rs);
|
||||
}
|
||||
}
|
||||
return newRuleSet;
|
||||
}
|
||||
|
||||
private JCheckBox createCheckBox(String name) {
|
||||
JCheckBox box = new JCheckBox(name);
|
||||
box.setSelected(jEdit.getBooleanProperty(PMDJEditPlugin.OPTION_RULESETS_PREFIX + name, true));
|
||||
return box;
|
||||
}
|
||||
}
|
81
pmd-jedit/src/net/sourceforge/pmd/jedit/SelectedRules.java
Normal file
81
pmd-jedit/src/net/sourceforge/pmd/jedit/SelectedRules.java
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* User: tom
|
||||
* Date: Jul 9, 2002
|
||||
* Time: 1:18:38 PM
|
||||
*/
|
||||
package net.sourceforge.pmd.jedit;
|
||||
|
||||
import org.gjt.sp.jedit.jEdit;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
import java.awt.Color;
|
||||
|
||||
import net.sourceforge.pmd.RuleSetFactory;
|
||||
import net.sourceforge.pmd.RuleSet;
|
||||
import net.sourceforge.pmd.RuleSetNotFoundException;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
|
||||
public class SelectedRules {
|
||||
|
||||
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());
|
||||
}
|
||||
});
|
||||
|
||||
public SelectedRules() throws RuleSetNotFoundException {
|
||||
RuleSetFactory rsf = new RuleSetFactory();
|
||||
for (Iterator i = rsf.getRegisteredRuleSets(); i.hasNext();) {
|
||||
RuleSet rs = (RuleSet)i.next();
|
||||
for (Iterator j = rs.getRules().iterator(); j.hasNext();) {
|
||||
Rule rule = (Rule)j.next();
|
||||
rules.put(rule, createCheckBox(rule.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return rules.size();
|
||||
}
|
||||
|
||||
public JCheckBox get(Object key) {
|
||||
return (JCheckBox)rules.get(key);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private JCheckBox createCheckBox(String name) {
|
||||
JCheckBox box = new JCheckBox(name);
|
||||
box.setSelected(jEdit.getBooleanProperty(PMDJEditPlugin.OPTION_RULES_PREFIX + name, true));
|
||||
return box;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user