Initial revision

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1465 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2003-02-24 17:45:07 +00:00
parent 1339ec6fe3
commit 38d13ff0fc
12 changed files with 582 additions and 0 deletions

View File

@ -0,0 +1,13 @@
Manifest-Version: 1.0
Created-By: Apache Ant 1.5.1
AddinCount: 1
Addin0: net.sourceforge.pmd.jdeveloper.Plugin
Name: net/sourceforge/pmd/jdeveloper/
Specification-Title: PMD Static Code Analyzer
Specification-Version: 0.1
Specification-Vendor: Tom Copeland
Implementation-Title: net.sourceforge.pmd.jdeveloper
Implementation-Version: 0.1
Implementation-Vendor: Tom Copeland
Implementation-URL: http://pmd.sf.net/

View File

@ -0,0 +1,63 @@
<project name="pmd-jdeveloper" default="compile" basedir="../">
<property name="config" value="config/"/>
<property name="src" value="src/"/>
<property name="lib" value="lib/"/>
<property name="etc" value="etc/"/>
<property name="build" value="build/"/>
<property name="pmdjar" value="pmd-1.03.jar"/>
<property name="pluginversion" value="0.1"/>
<property name="jdeveloper.install.dir" value="C:\downloads\jdev9031\jdev\lib\ext\${ant.project.name}-${pluginversion}"/>
<path id="project.class.path">
<pathelement location="${lib}/${pmdjar}"/>
<pathelement location="${lib}/jdeveloper.jar"/>
<pathelement location="${build}"/>
</path>
<target name="delete">
<delete file="${lib}/${ant.project.name}.jar"/>
<delete file="${jdeveloper.install.dir}/${ant.project.name}.jar"/>
<delete dir="${build}"/>
<mkdir dir="${build}"/>
</target>
<target name="compile">
<javac
srcdir="${src}"
destdir="${build}"
debug="on"
deprecation="on">
<classpath refid="project.class.path"/>
</javac>
</target>
<target name="jar">
<jar jarfile="${lib}/${ant.project.name}-${pluginversion}.jar" manifest="${etc}\manifest.mf">
<fileset dir="${build}"/>
</jar>
</target>
<target name="dist" depends="compile,jar">
<mkdir dir="${jdeveloper.install.dir}/lib"/>
<copy file="${lib}/${ant.project.name}-${pluginversion}.jar" todir="${jdeveloper.install.dir}/lib"/>
<copy file="${lib}/${pmdjar}" todir="${jdeveloper.install.dir}/lib"/>
</target>
<target name="release">
<antcall target="clean"/>
<antcall target="jar"/>
<mkdir dir="tmp/jars"/>
<copy file="${lib}/${ant.project.name}-${pluginversion}.jar" todir="tmp/jars"/>
<copy file="${lib}/${pmdjar}" todir="tmp/jars"/>
<zip zipfile="pmd-jdeveloper-bin-${pluginversion}.zip" basedir="tmp"/>
<move file="pmd-jdeveloper-bin-${pluginversion}.zip" todir="c:\tmp"/>
<delete dir="tmp"/>
</target>
<target name="clean" depends="delete,compile">
</target>
</project>

View File

@ -0,0 +1,2 @@
??? - 0.1:
Initial release

View File

@ -0,0 +1,39 @@
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 1.4
change config/jedit.html to reflect pmd-jedit release 1.4
change the build.xml to reflect pmd-jedit release 1.4
Create the binary release:
ant release
move the zip file into c:\tmp
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?
Create the src release:
cvs -q rtag -D tomorrow "pmd_jedit_release_1_4" pmd-jedit
rmdir /q /s c:\tmp\pmd-jedit
mkdir c:\tmp\pmd-jedit
cvs -q export -d c:\tmp\pmd-jedit -r pmd_jedit_release_1_4 pmd-jedit
copy pmd-jedit\lib\PMDJEditPlugin-1.4.jar c:\tmp\pmd-jedit\lib
cd c:\tmp
"c:\program files\winzip\wzzip.exe" -r -p pmd-jedit-src-1.4.zip pmd-jedit
rmdir /q /s pmd-jedit
FTP the zip file to SF
ftp upload.sourceforge.net
generic userid/password: anonymous/tom@infoether.com
cd incoming
bin
put pmd-jedit-src-1.4.zip
put pmd-jedit-bin-1.4.zip
Go to Admin, Edit/Release Files, click on Add new release
Paste stuff into the changelog/readme boxes
Add the pmd-jedit-src-1.4.zip file
Add the pmd-jedit-bin-1.4.zip file
Classify the file
Submit some news saying "hey, new release of the JEdit plugin!"

6
pmd-jdeveloper/etc/scp.bat Executable file
View File

@ -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:

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,75 @@
package net.sourceforge.pmd.jdeveloper;
import net.sourceforge.pmd.ExternalRuleID;
import net.sourceforge.pmd.Rule;
import net.sourceforge.pmd.RuleSet;
import net.sourceforge.pmd.RuleSetFactory;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.InputStream;
public class JDeveloperRuleSetFactory extends RuleSetFactory {
public RuleSet createRuleSet(InputStream inputStream) {
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
org.w3c.dom.Document doc = builder.parse(inputStream);
org.w3c.dom.Element root = doc.getDocumentElement();
RuleSet ruleSet = new RuleSet();
ruleSet.setName(root.getAttribute("name"));
ruleSet.setDescription(root.getChildNodes().item(1).getFirstChild().getNodeValue());
NodeList rules = root.getElementsByTagName("rule");
for (int i =0; i<rules.getLength(); i++) {
Node ruleNode = rules.item(i);
Rule rule = null;
if (ruleNode.getAttributes().getNamedItem("ref") != null) {
ExternalRuleID externalRuleID = new ExternalRuleID(ruleNode.getAttributes().getNamedItem("ref").getNodeValue());
RuleSetFactory rsf = new RuleSetFactory();
RuleSet externalRuleSet = rsf.createRuleSet(getClass().getClassLoader().getResourceAsStream(externalRuleID.getFilename()));
rule = externalRuleSet.getRuleByName(externalRuleID.getRuleName());
} else {
rule = (Rule)Class.forName(ruleNode.getAttributes().getNamedItem("class").getNodeValue()).newInstance();
rule.setName(ruleNode.getAttributes().getNamedItem("name").getNodeValue());
rule.setMessage(ruleNode.getAttributes().getNamedItem("message").getNodeValue());
}
// get the description, priority, example and properties (if any)
Node node = ruleNode.getFirstChild();
while (node != null) {
if (node.getNodeName() != null && node.getNodeName().equals("description")) {
rule.setDescription(node.getFirstChild().getNodeValue());
} else if (node.getNodeName() != null && node.getNodeName().equals("priority")) {
rule.setPriority(Integer.parseInt(node.getFirstChild().getNodeValue()));
} else if (node.getNodeName() != null && node.getNodeName().equals("example")) {
rule.setExample((node.getFirstChild().getNodeValue()));
}
if (node.getNodeName().equals("properties")) {
Node propNode = node.getFirstChild().getNextSibling();
while (propNode != null && propNode.getAttributes() != null) {
String propName = propNode.getAttributes().getNamedItem("name").getNodeValue();
String propValue = propNode.getAttributes().getNamedItem("value").getNodeValue();
rule.addProperty(propName, propValue);
propNode = propNode.getNextSibling().getNextSibling();
}
}
node = node.getNextSibling();
}
ruleSet.addRule(rule);
}
return ruleSet;
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Couldn't read from that source: " + e.getMessage());
}
}
}

View File

@ -0,0 +1,192 @@
package net.sourceforge.pmd.jdeveloper;
import net.sourceforge.pmd.PMD;
import net.sourceforge.pmd.Report;
import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.RuleViolation;
import oracle.ide.AddinManager;
import oracle.ide.ContextMenu;
import oracle.ide.Ide;
import oracle.ide.IdeAction;
import oracle.ide.log.LogWindow;
import oracle.ide.addin.Addin;
import oracle.ide.addin.Context;
import oracle.ide.addin.ContextMenuListener;
import oracle.ide.addin.Controller;
import oracle.ide.config.IdeSettings;
import oracle.ide.model.DirectoryFolder;
import oracle.ide.model.Element;
import oracle.ide.model.PackageFolder;
import oracle.ide.model.Workspace;
import oracle.ide.model.Workspaces;
import oracle.ide.panels.Navigable;
import oracle.jdeveloper.model.BusinessComponents;
import oracle.jdeveloper.model.EnterpriseJavaBeans;
import oracle.jdeveloper.model.JProject;
import oracle.jdeveloper.model.JavaSourceNode;
import oracle.jdeveloper.model.JavaSources;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import java.io.InputStream;
import java.util.Iterator;
public class Plugin implements Addin, Controller, ContextMenuListener {
public static final String CHECK_CMD = "net.sourceforge.pmd.jdeveloper.Check";
public static final int CHECK_CMD_ID = Ide.newCmd("PMDJDeveloperPlugin.CHECK_CMD_ID");
private static final int INVALID = -1;
private static final int SOURCE = 0;
private static final int SOURCES = 1;
private static final int WORKSPACE = 2;
private static final int WORKSPACES = 3;
private static final int PACKAGE = 4;
private static final int DIRECTORY = 5;
private static final int PROJECT = 6;
private static final int EJB = 7;
private static final int BUSINESS = 8;
private JMenuItem checkItem;
public Plugin() {
super();
}
// Addin
public void initialize() {
AddinManager addinManager = Ide.getAddinManager();
String command = addinManager.getCommand(CHECK_CMD_ID, CHECK_CMD);
String category = "PMD";
IdeAction action = IdeAction.get(CHECK_CMD_ID, command, "PMD", category, null, null, null, true);
action.setController(this);
checkItem = Ide.getMenubar().createMenuItem(action);
checkItem.setText("PMD");
checkItem.setMnemonic('P');
Ide.getNavigatorManager().addContextMenuListener(this, null);
Ide.getEditorManager().getContextMenu().addContextMenuListener(this, null);
System.out.println("PMD JDeveloper Extension " + getVersion());
IdeSettings.registerUI(new Navigable("PMD", SettingsPanel.class, new Navigable[] {}));
Ide.getVersionInfo().addComponent("PMD", " JDeveloper Extension " + getVersion());
}
public void shutdown() {
Ide.getNavigatorManager().removeContextMenuListener(this);
Ide.getEditorManager().getContextMenu().removeContextMenuListener(this);
}
public float version() {
return 0.1f;
}
public float ideVersion() {
return 0.1f;
}
public boolean canShutdown() {
return true;
}
// Addin
// Controller
public Controller supervisor() {
return null;
}
public boolean handleEvent(IdeAction ideAction, Context context) {
if (ideAction.getCommandId() == CHECK_CMD_ID) {
try {
LogWindow window = Ide.getLogWindow();
if (!window.isVisible()) {
window.show();
}
PMD pmd = new PMD();
RuleContext ctx = new RuleContext();
ctx.setReport(new Report());
ctx.setSourceCodeFilename(context.getElement().toString());
SelectedRules rs = new SelectedRules();
pmd.processFile(context.getDocument().getInputStream(), rs.getSelectedRules(), ctx);
if (ctx.getReport().isEmpty()) {
JOptionPane.showMessageDialog(null, "No problems found", "PMD", JOptionPane.INFORMATION_MESSAGE);
} else {
for (Iterator i = ctx.getReport().iterator(); i.hasNext();) {
RuleViolation rv = (RuleViolation)i.next();
window.log(rv.getFilename() + ":" + rv.getLine() +":"+ rv.getDescription());
System.out.println("rv = " + rv.getDescription());
}
}
return true;
} catch (Exception e) {
e.printStackTrace();
}
}
return true;
}
public boolean update(IdeAction ideAction, Context context) {
return false;
}
public void checkCommands(Context context, Controller controller) {
}
// Controller
// Controller
public void poppingUp(ContextMenu contextMenu) {
if (contextMenu != null) {
Context context = contextMenu.getContext();
if (context != null) {
Element doc = context.getDocument();
if (resolveType(doc) == PROJECT || resolveType(doc) == SOURCE) {
contextMenu.add(checkItem);
}
}
}
}
public void poppingDown(ContextMenu contextMenu) {
}
public boolean handleDefaultAction(Context context) {
return false;
}
// Controller
public static String getVersion() {
return Package.getPackage("net.sourceforge.pmd.jdeveloper").getImplementationVersion();
}
private int resolveType(Element element)
{
if (element instanceof JavaSourceNode) {
return SOURCE;
}
if (element instanceof JavaSources) {
return SOURCES;
}
if (element instanceof JProject) {
return PROJECT;
}
if (element instanceof PackageFolder) {
return PACKAGE;
}
if (element instanceof DirectoryFolder) {
return DIRECTORY;
}
if (element instanceof BusinessComponents) {
return BUSINESS;
}
if (element instanceof EnterpriseJavaBeans) {
return EJB;
}
if (element instanceof Workspace) {
return WORKSPACE;
}
if (element instanceof Workspaces) {
return WORKSPACES;
}
return INVALID;
}
}

View File

@ -0,0 +1,90 @@
package net.sourceforge.pmd.jdeveloper;
import net.sourceforge.pmd.Rule;
import net.sourceforge.pmd.RuleSet;
import net.sourceforge.pmd.RuleSetFactory;
import net.sourceforge.pmd.RuleSetNotFoundException;
import oracle.ide.Ide;
import javax.swing.JCheckBox;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
public class SelectedRules {
// Rule -> 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());
}
});
public SelectedRules() throws RuleSetNotFoundException {
RuleSetFactory rsf = new JDeveloperRuleSetFactory();
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 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);
}
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();
Ide.setProperty("pmd.rule." + rule.getName(), String.valueOf(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(Boolean.valueOf(Ide.getProperty("pmd.rule." + name)).booleanValue());
return box;
}
}

View File

@ -0,0 +1,102 @@
package net.sourceforge.pmd.jdeveloper;
import net.sourceforge.pmd.RuleSetNotFoundException;
import oracle.ide.panels.DefaultTraversablePanel;
import oracle.ide.panels.TraversableContext;
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ListCellRenderer;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class SettingsPanel extends DefaultTraversablePanel {
public class CheckboxList extends JList {
private class MyMouseAdapter extends MouseAdapter {
public void mouseEntered(MouseEvent e) {
int index = locationToIndex(e.getPoint());
if (index != -1) {
JCheckBox box = (JCheckBox)getModel().getElementAt(index);
String example = rules.getRule(box).getExample();
exampleTextArea.setText(example);
exampleTextArea.setCaretPosition(0);
}
}
public void mousePressed(MouseEvent e) {
int index = locationToIndex(e.getPoint());
if (index != -1) {
JCheckBox box = (JCheckBox)getModel().getElementAt(index);
box.setSelected(!box.isSelected());
repaint();
}
}
}
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 MyMouseAdapter());
}
}
private SelectedRules rules;
private JTextArea exampleTextArea= new JTextArea(10, 50);
public void onEntry(TraversableContext tc) {
super.removeAll();
try {
rules = new SelectedRules();
} catch (RuleSetNotFoundException rsne) {
rsne.printStackTrace();
}
JPanel boxesPanel = new JPanel();
boxesPanel.setBorder(BorderFactory.createTitledBorder("Rules"));
JList list = new CheckboxList(rules.getAllBoxes());
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
boxesPanel.add(new JScrollPane(list), BorderLayout.NORTH);
JPanel textPanel = new JPanel();
textPanel.setBorder(BorderFactory.createTitledBorder("Example"));
textPanel.add(new JScrollPane(exampleTextArea));
JPanel selectionPanel = new JPanel();
selectionPanel.setLayout(new BorderLayout());
selectionPanel.add(boxesPanel, BorderLayout.NORTH);
selectionPanel.add(textPanel, BorderLayout.CENTER);
JPanel mainPanel = new JPanel(new BorderLayout());
mainPanel.add(new JLabel("Please see http://pmd.sf.net/ for more information"), BorderLayout.NORTH);
mainPanel.add(selectionPanel, BorderLayout.CENTER);
add(mainPanel);
}
public void onExit(TraversableContext tc) {
rules.save();
}
}