diff --git a/pmd-gel/etc/build.xml b/pmd-gel/etc/build.xml
index dda6a6ea15..f80ef546a0 100644
--- a/pmd-gel/etc/build.xml
+++ b/pmd-gel/etc/build.xml
@@ -46,7 +46,7 @@
-
+
diff --git a/pmd-gel/etc/changelog.txt b/pmd-gel/etc/changelog.txt
index 6ec46f9275..4a33c8e893 100644
--- a/pmd-gel/etc/changelog.txt
+++ b/pmd-gel/etc/changelog.txt
@@ -1,3 +1,7 @@
+October 15, 2003 - 0.5:
+Backed up essentially to 0.2 - the newer code was locking up.
+Updated to pmd-1.2.2.
+
August 06, 2003 - 0.4:
Updated to pmd-1.2.1.
diff --git a/pmd-gel/etc/doing_the_next_pmd_gel_release.txt b/pmd-gel/etc/doing_the_next_pmd_gel_release.txt
index 9b9f500f45..d80b3224ae 100644
--- a/pmd-gel/etc/doing_the_next_pmd_gel_release.txt
+++ b/pmd-gel/etc/doing_the_next_pmd_gel_release.txt
@@ -1,5 +1,5 @@
-Change version in build.xml to 0.4
-cvs tag r0_4 pmd-gel
+Change version in build.xml to 0.5
+cvs tag r0_5 pmd-gel
ant release
upload zip file to sourceforge
use readme.txt as release notes
diff --git a/pmd-gel/etc/readme.txt b/pmd-gel/etc/readme.txt
index 82b9b3099a..28407e1a48 100644
--- a/pmd-gel/etc/readme.txt
+++ b/pmd-gel/etc/readme.txt
@@ -1,12 +1,9 @@
Files Tested
-When you invoke PMD, you can choose whether you want to run it on the
-current file or all the files in your project.
+When you invoke PMD, it is run on the current file.
Rules
-You can select which rulesets you want to use when you run the PMD plugin.
-Currently the "imports", "unusedcode", and "basic" rulesets are selected
-automatically. These rulesets catch things like unused local variables, empty try blocks,
-unused imports, and so forth.
+The "unused code" and "basic" rulesets are run on the code you select - these rulesets catch things like unused local variables, empty try blocks,
+unused imports, empty catch blocks, and so forth.
You can view all the PMD rules with examples and details at
http://pmd.sf.net/.
diff --git a/pmd-gel/lib/pmd-1.2.1.jar b/pmd-gel/lib/pmd-1.2.2.jar
similarity index 60%
rename from pmd-gel/lib/pmd-1.2.1.jar
rename to pmd-gel/lib/pmd-1.2.2.jar
index 96942d8a7d..e06c88a42f 100644
Binary files a/pmd-gel/lib/pmd-1.2.1.jar and b/pmd-gel/lib/pmd-1.2.2.jar differ
diff --git a/pmd-gel/pmd-gel.jde b/pmd-gel/pmd-gel.jde
index cf752be5b8..952fe52910 100644
--- a/pmd-gel/pmd-gel.jde
+++ b/pmd-gel/pmd-gel.jde
@@ -8,7 +8,7 @@
0
- 3
+ 2
33
3
@@ -24,19 +24,26 @@
1
- 38
- 5
+ 13
+ 3
$(PROJECT)\src\net\sourceforge\pmd\gel\Test.java
1
1
{C34B000D-B5C9-415F-933A-552FB0590E44}
- 7
- 142
+ 75
+ 161
$(PROJECT)\src\net\sourceforge\pmd\gel\PMDPlugin.java
1
- 142
+ 124
+
+
+ 49
+ 53
+ $(PROJECT)\etc\build.xml
+ 1
+ 23
@@ -54,7 +61,7 @@
- {39092503-5AAE-4A31-9847-014A46DADA1E}
+ {714E29CF-11C4-4BB0-9D7D-58F72AF09CA3}
$(PROJECT)\docs
$(PROJECT)\classes
$(PROJECT)\src
diff --git a/pmd-gel/src/net/sourceforge/pmd/gel/PMDPlugin.java b/pmd-gel/src/net/sourceforge/pmd/gel/PMDPlugin.java
index 2b93bb3803..3402df63cb 100644
--- a/pmd-gel/src/net/sourceforge/pmd/gel/PMDPlugin.java
+++ b/pmd-gel/src/net/sourceforge/pmd/gel/PMDPlugin.java
@@ -1,366 +1,96 @@
-
package net.sourceforge.pmd.gel;
-import java.util.AbstractList;
-import com.gexperts.gel.Gel;
-import com.gexperts.gel.GelAction;
+
+import java.awt.Color;
import java.awt.BorderLayout;
-import java.awt.Font;
-import java.awt.GridLayout;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import java.io.File;
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.StringReader;
+import java.util.List;
import java.util.Iterator;
-import java.util.Properties;
-import java.util.StringTokenizer;
-import javax.swing.ButtonGroup;
-import javax.swing.JButton;
-import javax.swing.JCheckBox;
-import javax.swing.JDialog;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JRadioButton;
-import javax.swing.BorderFactory;
-import javax.swing.border.Border;
-import net.sourceforge.pmd.PMD;
-import net.sourceforge.pmd.Report;
-import net.sourceforge.pmd.RuleContext;
-import net.sourceforge.pmd.RuleSet;
-import net.sourceforge.pmd.RuleSetFactory;
-import net.sourceforge.pmd.RuleViolation;
-import net.sourceforge.pmd.cpd.FileFinder;
-import net.sourceforge.pmd.cpd.JavaLanguage;
+import java.util.Vector;
+import java.io.*;
+import javax.swing.*;
+import com.gexperts.gel.*;
+import net.sourceforge.pmd.*;
+import net.sourceforge.pmd.cpd.*;
-/** This class allows Gel to invoke PMD on Java files */
public class PMDPlugin implements GelAction {
- private boolean selectedAll;
- private boolean haveFile;
- private boolean haveProject;
- private String savedFilename;
- private JDialog options;
- private Gel savedGel;
- private String[] rulesetFilenames;
- private boolean[] rulesetInuse;
- private JCheckBox[] rulesetChecks;
- private static final String DEFAULT_RULES =
- "rulesets/unusedcode.xml,rulesets/basic.xml,rulesets/imports.xml";
- private static final String PROPERTIES_FILE =
- "/rulesets/rulesets.properties";
- private Properties descriptions = new Properties();
- /**
- * Called by Gel to see if plugin is invokable (active)
- *
- * @param gel Our pointer back to Gel
- * @return The active value
- */
- public boolean isActive(Gel gel) {
- boolean haveFile = (gel.getEditor() != null
- && gel.getEditor().getFileName() != null
- && gel.getEditor().getFileName().endsWith(".java"));
- boolean haveProject = (gel.getProject() != null);
- return (haveFile || haveProject);
- }
-
- /**
- * Called by Gel to invoke the plugin
- *
- * @param gel Our pointer back to Gel
- */
- public void perform(Gel gel) {
- try {
- selectedAll = true;
- savedGel = gel;
- haveFile = (gel.getEditor() != null
- && gel.getEditor().getFileName() != null
- && gel.getEditor().getFileName().endsWith(".java"));
- if (haveFile) {
- savedFilename = gel.getEditor().getFileName();
- if (savedFilename == null) {
- savedFilename = "Unnamed.java";
- }
- }
- haveProject = (gel.getProject() != null);
- createConfigPanel(haveFile, haveProject);
- } catch (Exception ex) {
- gel.addMessage("ERROR " + ex.getClass().getName() + ":" + ex.getMessage());
+ // GelAction
+ public boolean isActive(Gel p0) {
+ return true;
}
- }
- /** Does the actual work of calling PMD */
- private void invokePlugin() {
- java.io.Reader reader = null;
- try {
- PMD pmd = new PMD();
- RuleContext ctx = new RuleContext();
- RuleSetFactory rsf = new RuleSetFactory();
- RuleSet ruleSet = new RuleSet();
- StringBuffer rules = new StringBuffer();
- for (int i = 0; i < rulesetFilenames.length; i++) {
- if (rulesetInuse[i]) {
- if (rules.length() != 0) {
- rules.append(",");
- }
- rules.append(rulesetFilenames[i]);
- }
- }
- if (rules.length() == 0) {
- return;
- }
- savedGel.addMessage("PMD plugin activated on "
- + (selectedAll ? "all files" : savedFilename));
- ruleSet.addRuleSet(rsf.createRuleSet(rules.toString()));
- ctx.setReport(new Report());
- if (!selectedAll) {
- String code = savedGel.getEditor().getContents();
- ctx.setSourceCodeFilename(savedFilename);
- reader = new StringReader(code);
- pmd.processFile(reader, ruleSet, ctx);
- } else {
- Iterator iter = savedGel.getProject().getSourcePaths().iterator();
- while (iter.hasNext()) {
- String srcDir = (String) iter.next();
- FileFinder ff = new FileFinder();
- java.util.List files = ff.findFilesFrom(srcDir,
- new JavaLanguage.JavaFileOrDirectoryFilter(), true);
- Iterator fileIter = files.iterator();
- while (fileIter.hasNext()) {
- File fileName = (File) fileIter.next();
- ctx.setSourceCodeFilename(fileName.getAbsolutePath());
- reader = new FileReader(fileName);
- pmd.processFile(reader, ruleSet, ctx);
- reader.close();
- }
- }
- }
- Report r = ctx.getReport();
- if (r.isEmpty()) {
- savedGel.addMessage("No problems found");
- } else {
- savedGel.addMessage(r.size() + " problems found");
- Iterator i = r.iterator();
- while (i.hasNext()) {
- RuleViolation rv = (RuleViolation) i.next();
- savedGel.addMessage(rv.getFilename() + ":"
- + rv.getLine() + ":"
- + rv.getDescription());
- }
- }
- } catch (Exception ex) {
- savedGel.addMessage("ERROR " + ex.getClass().getName() + ":" + ex.getMessage());
- } finally {
- if (reader != null) {
+ public void perform(Gel p0) {
try {
- reader.close();
- } catch (Exception ex1) { }
- }
- }
- savedGel.addMessage("Done");
- savedGel = null;
- }
-
- /**
- * Gel uses this name in the plugin menu
- *
- * @return The name value
- */
- public String getName() {
- return "PMD";
- }
-
- private void createConfigPanel(boolean haveFile, boolean haveProject) {
- final JFrame optionsFrame = new JFrame();
- Font headingFont = new Font("SansSerif", Font.BOLD, 12);
-// javax.swing.UIManager.put("ToolTipUI","JoeToolTipUI");
-
- options = new JDialog(optionsFrame, "PMD Options");
- Border padding = BorderFactory.createEmptyBorder(10, 10, 5, 5);
- JPanel outerPanel = new JPanel();
- options.getContentPane().add(outerPanel);
- outerPanel.setLayout(new BorderLayout());
-
- // file options
- JPanel fileOptionsPanel = new JPanel();
- fileOptionsPanel.setBorder(padding);
- ButtonGroup btngroup = new ButtonGroup();
- fileOptionsPanel.setLayout(new GridLayout(haveFile && haveProject ? 3 : 2, 1));
- JLabel fileOptionsLabel = new JLabel("Files to process:");
- fileOptionsLabel.setFont(headingFont);
- fileOptionsPanel.add(fileOptionsLabel);
-
- if (haveFile) {
- JRadioButton rbfile = new JRadioButton("Process current file: " + savedFilename, !haveProject);
- btngroup.add(rbfile);
- rbfile.addItemListener(
- new ItemListener() {
- public void itemStateChanged(ItemEvent ev) {
- selectedAll = false;
- }
- });
- fileOptionsPanel.add(rbfile);
+ int unusedLocalTest =2;
+ PMD pmd = new PMD();
+ RuleContext ctx = new RuleContext();
+ RuleSetFactory rsf = new RuleSetFactory();
+ RuleSet ruleSet = new RuleSet();
+ ruleSet.addRuleSet(rsf.createRuleSet("rulesets/unusedcode.xml,rulesets/basic.xml"));
+ ctx.setReport(new Report());
+ if (p0.getProject() == null) {
+ String code = p0.getEditor().getContents();
+ String name = p0.getEditor().getFileName();
+ if (name == null) {
+ name = "Unnamed.java";
+ }
+ ctx.setSourceCodeFilename(name);
+ Reader reader = new StringReader(code);
+ pmd.processFile(reader, ruleSet, ctx);
+ } else {
+ for (Iterator iter = p0.getProject().getSourcePaths().iterator(); iter.hasNext();) {
+ String srcDir = (String)iter.next();
+ FileFinder ff = new FileFinder();
+ List files = ff.findFilesFrom(srcDir, new JavaLanguage.JavaFileOrDirectoryFilter(), true);
+ for (Iterator fileIter = files.iterator(); fileIter.hasNext();) {
+ File fileName = (File)fileIter.next();
+ ctx.setSourceCodeFilename(fileName.getAbsolutePath());
+ Reader reader = new FileReader(fileName);
+ pmd.processFile(reader, ruleSet, ctx);
+ }
+ }
+ }
+ if (ctx.getReport().isEmpty()) {
+ JOptionPane.showMessageDialog(null, "No problems found", "PMD", JOptionPane.INFORMATION_MESSAGE);
+ } else {
+ createProblemFrame(ctx.getReport());
+ }
+ } catch (Exception e) {
+ JOptionPane.showMessageDialog(null, "ERROR " + e.getClass().getName() + ":" + e.getMessage());
+ e.printStackTrace();
+ }
}
- if (haveProject) {
- JRadioButton rball = new JRadioButton("Process all files in sourcepath", true);
- btngroup.add(rball);
- rball.addItemListener(
- new ItemListener() {
- public void itemStateChanged(ItemEvent e) {
- selectedAll = true;
- }
- });
- fileOptionsPanel.add(rball);
+ public String getName() {
+ return "PMD";
+ }
+ // GelAction
+
+ private JFrame createProblemFrame(Report report) {
+ JFrame newFrame = new JFrame();
+ JDialog dialog = new JDialog(newFrame, report.size() + " problems found");
+ dialog.setContentPane(createProblemListPanel(report));
+ dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
+ dialog.pack();
+ dialog.setLocationRelativeTo(newFrame);
+ dialog.setVisible(true);
+ return newFrame;
}
- outerPanel.add(fileOptionsPanel, BorderLayout.NORTH);
+ private JPanel createProblemListPanel(Report report) {
+ Vector v = new Vector();
+ for (Iterator i = report.iterator(); i.hasNext();) {
+ RuleViolation rv = (RuleViolation)i.next();
+ String msg = rv.getFilename() + " - line " + (rv.getLine()-1) + " - " + rv.getDescription();
+ v.add(msg);
- // rules
- JPanel rulesPanel = new JPanel();
- rulesPanel.setBorder(padding);
- outerPanel.add(rulesPanel, BorderLayout.CENTER);
- Properties props = new Properties(System.getProperties());
- java.io.InputStream in = null;
- try {
- in = this.getClass().getResourceAsStream(PROPERTIES_FILE);
- props.load(in);
- } catch (Exception ex) {
- savedGel.showMessage("Error getting rulesets file (" + PROPERTIES_FILE
- + "): " + ex.getMessage());
- return;
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch (Exception ex1) { }
- }
- }
- String files = props.getProperty("rulesets.filenames");
- StringTokenizer st = new StringTokenizer(files, ",");
- int size = st.countTokens();
- rulesPanel.setLayout(new GridLayout(size + 1, 1));
- JLabel rulesLabel = new JLabel("Rulesets to use:");
- rulesLabel.setFont(headingFont);
- rulesPanel.add(rulesLabel);
- int index = 0;
- rulesetFilenames = new String[size];
- rulesetInuse = new boolean[size];
- rulesetChecks = new JCheckBox[size];
- while (st.hasMoreTokens()) {
- String label = st.nextToken();
- boolean initialValue = (DEFAULT_RULES.indexOf(label) != -1);
- JCheckBox jb = new JCheckBox(label, initialValue);
- rulesPanel.add(jb);
- jb.setToolTipText(getDescription(label));
- rulesetFilenames[index] = label;
- rulesetInuse[index] = initialValue;
- rulesetChecks[index] = jb;
- jb.addItemListener(
- new ItemListener() {
- public void itemStateChanged(ItemEvent ce) {
- int i = 0;
- while (i < rulesetChecks.length) {
- if (ce.getSource() == rulesetChecks[i]) {
- break;
}
- i++;
- }
- rulesetInuse[i] = (ce.getStateChange() == ItemEvent.SELECTED);
- }
- });
- index++;
+ JList list = new JList(v);
+ list.setForeground(Color.red);
+ list.setBackground(Color.white);
+ list.setVisibleRowCount(20);
+
+ JPanel container = new JPanel(new BorderLayout());
+ container.add(list, BorderLayout.CENTER);
+ return container;
}
-
- // buttons
- JPanel buttonsPanel = new JPanel();
- buttonsPanel.setBorder(padding);
- JButton processButton = new JButton("Process");
- processButton.setMnemonic('p');
- buttonsPanel.add(processButton);
- processButton.addActionListener(
- new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- options.setVisible(false);
- options.dispose();
- optionsFrame.dispose();
- options = null;
- invokePlugin();
- }
- });
- JButton cancelButton = new JButton("Cancel");
- cancelButton.setMnemonic('c');
- buttonsPanel.add(cancelButton);
- cancelButton.addActionListener(
- new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- options.setVisible(false);
- options.dispose();
- optionsFrame.dispose();
- options = null;
- }
- });
- outerPanel.add(buttonsPanel, BorderLayout.SOUTH);
-
- options.setDefaultCloseOperation(2);
- options.pack();
- options.setLocationRelativeTo(optionsFrame);
- options.setVisible(true);
- }
-
- private static final String START_TOKEN = "";
- private static final String END_TOKEN = "";
-
- // simplistic XML parsing routine - only one field of interest
- private String getDescription(String rulesFilename) {
- if (descriptions.containsKey(rulesFilename)) {
- return descriptions.getProperty(rulesFilename);
- }
- BufferedReader br = null;
- try {
- int endPosn = 0;
- int startPosn;
- br = new BufferedReader(
- new java.io.InputStreamReader(
- this.getClass().getClassLoader().getResourceAsStream(rulesFilename)));
- StringBuffer sb = new StringBuffer();
- String line;
- boolean found = false;
- while (true) {
- line = br.readLine();
- if (line == null) {
- break;
- }
- sb.append(line);
- sb.append(" \n");
- endPosn = line.indexOf(END_TOKEN);
- if (endPosn != -1) {
- found = true;
- break;
- }
- }
- if (!found) {
- return rulesFilename;
- }
- String lines = sb.toString();
- startPosn = lines.indexOf(START_TOKEN);
- endPosn = lines.indexOf(END_TOKEN);
- if (startPosn == -1) {
- return rulesFilename;
- }
- return (lines.substring(startPosn + START_TOKEN.length(), endPosn).trim());
- } catch (Exception ex) {
- return rulesFilename;
- } finally {
- try {
- if (br != null) {
- br.close();
- }
- } catch (Exception ignore) { }
- }
- }
-
}
\ No newline at end of file