Renamed to PMDJEditPlugin to PMDPlugin

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@2262 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Jiger Patel
2003-09-15 09:16:44 +00:00
parent ae463d3826
commit 5ef6d00ce6
19 changed files with 1376 additions and 0 deletions

View File

@ -0,0 +1,2 @@
http://cougaar.org/docman/view.php/17/58/license.html

View File

@ -0,0 +1,49 @@
<?xml version="1.0"?>
<!DOCTYPE ACTIONS SYSTEM "actions.dtd">
<ACTIONS>
<ACTION NAME="pmd-check-current-buffer">
<CODE>
net.sourceforge.pmd.jedit.PMDJEditPlugin.check(buffer, view);
</CODE>
</ACTION>
<ACTION NAME="pmd-check-all-open-buffers">
<CODE>
net.sourceforge.pmd.jedit.PMDJEditPlugin.checkAllOpenBuffers(view);
</CODE>
</ACTION>
<ACTION NAME="pmd-check-current-directory">
<CODE>
net.sourceforge.pmd.jedit.PMDJEditPlugin.checkDirectory(view);
</CODE>
</ACTION>
<ACTION NAME="pmd-check-current-directory-recursively">
<CODE>
net.sourceforge.pmd.jedit.PMDJEditPlugin.checkDirectoryRecursively(view);
</CODE>
</ACTION>
<ACTION NAME="pmd-clear-errorlist">
<CODE>
net.sourceforge.pmd.jedit.PMDJEditPlugin.clearErrorList();
</CODE>
</ACTION>
<ACTION NAME="cpd-currentfile">
<CODE>
net.sourceforge.pmd.jedit.PMDJEditPlugin.cpdCurrentFile(view);
</CODE>
</ACTION>
<ACTION NAME="cpd-dir">
<CODE>
net.sourceforge.pmd.jedit.PMDJEditPlugin.cpdDir(view,false);
</CODE>
</ACTION>
<ACTION NAME="cpd-dir-recursively">
<CODE>
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>

View File

@ -0,0 +1,19 @@
<?xml version="1.0"?>
<!DOCTYPE ACTIONS SYSTEM "actions.dtd">
<ACTIONS>
<ACTION NAME="pmd-check-file">
<CODE>
net.sourceforge.pmd.jedit.PMDJEditPlugin.checkFile(view,browser);
</CODE>
</ACTION>
<ACTION NAME="pmd-check-current-directory">
<CODE>
net.sourceforge.pmd.jedit.PMDJEditPlugin.checkDirectory(view, browser,false);
</CODE>
</ACTION>
<ACTION NAME="pmd-check-current-directory-recursively">
<CODE>
net.sourceforge.pmd.jedit.PMDJEditPlugin.checkDirectory(view, browser,true);
</CODE>
</ACTION>
</ACTIONS>

View File

@ -0,0 +1,2 @@
jedit.install.dir=c:\\jiger\\jedit42
install.dir=${jedit.install.dir}\\jars

View File

@ -0,0 +1,78 @@
<project name="PMDPlugin" default="jar" basedir=".">
<property file="build.properties"></property>
<property name="config" value="."/>
<property name="src" value="src/"/>
<property name="lib" value="lib"/>
<property name="build" value="build"/>
<property name="pmdjar" value="pmd-1.2.1.jar"/>
<property name="pluginversion" value="2.2"/>
<property name="jedit.install.dir" value="../.."/>
<property name="jedit.jars.dir" value="${jedit.install.dir}\jars"/>
<property name="install.dir" value=".."/>
<path id="project.class.path">
<pathelement location="${jedit.install.dir}/jedit.jar"/>
<pathelement location="${jedit.jars.dir}/ErrorList.jar"/>
<pathelement location="${lib}/${pmdjar}"/>
<pathelement location="${lib}/jaxen-core-1.0-fcs.jar"/>
<pathelement location="${lib}/pmd-swingui-0.1.jar"/>
<pathelement location="${lib}/saxpath-1.0-fcs.jar"/>
<pathelement location="${build}"/>
</path>
<target name="delete">
<delete file="${install.dir}/${ant.project.name}.jar"/>
<delete dir="${build}"/>
<mkdir dir="${build}"/>
</target>
<target name="compile">
<mkdir dir="${build}"/>
<javac
srcdir="${src}"
destdir="${build}"
debug="on"
deprecation="on">
<classpath refid="project.class.path"/>
</javac>
</target>
<target name="jar" depends="compile">
<jar jarfile="${install.dir}/${ant.project.name}.jar">
<fileset dir="${build}"/>
<fileset dir="${config}">
<include name="*.props"/>
<include name="*.xml"/>
<include name="*.html"/>
</fileset>
</jar>
</target>
<target name="dist" depends="clean">
<antcall target="jar"/>
<copy todir="${install.dir}">
<fileset casesensitive="false" dir="${lib}" includes="*.jar"></fileset>
</copy>
</target>
<target name="release">
<antcall target="clean"/>
<antcall target="jar"/>
<mkdir dir="tmp/jars"/>
<copy file="${install.dir}/${ant.project.name}.jar" todir="tmp/jars"/>
<copy file="${install.dir}/${pmdjar}" todir="tmp/jars"/>
<copy file="${lib}/jaxen-core-1.0-fcs.jar" todir="tmp/jars"/>
<copy file="${lib}/saxpath-1.0-fcs.jar" todir="tmp/jars"/>
<copy file="${lib}/pmd-swingui-0.1.jar" todir="tmp/jars"/>
<zip zipfile="pmd-jedit-bin-${pluginversion}.zip" basedir="tmp"/>
<move file="pmd-jedit-bin-${pluginversion}.zip" todir="${install.dir}"/>
<delete dir="tmp"/>
</target>
<target name="clean" depends="delete,compile">
</target>
</project>

View File

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<!DOCTYPE DOCKABLES SYSTEM "dockables.dtd">
<DOCKABLES>
<DOCKABLE NAME="cpd-viewer">
new net.sourceforge.pmd.jedit.CPDDuplicateCodeViewer(view);
</DOCKABLE>
</DOCKABLES>

View File

@ -0,0 +1,71 @@
August 18th 2003 - 2.2
1. Updated to PMD 1.2.1
2. Updated to jEdit 4.2 API changes
3. Added PMD in jEdit's File System Browser Plugins Menu.
May 19th 2003 - 2.1:
Added "clear ErrorList" option - thanks to Randall Schultz for the suggestion.
Added "check all open buffers" option - thanks to Randall Schultz for the suggestion.
Added support to define Custom RuleSets thereby facilitating integration of Custom Rulesets with built-in rulesets & their independent development.
Added C/C++, PHP support to Copy/Paste Detector. Now you can find out duplicate code in your C/C++ & PHP code besides the usual Java code.
April 18 2003 - 2.0:
Jiger Patel integrated CPD functionality.
Upgraded to work with pmd-1.05.
March 24 2003 - 1.5:
Upgraded to work with pmd-1.04.
February 11 2003 - 1.4:
Upgraded to work with pmd-1.03.
January 24 2003 - 1.3:
Upgraded to work with pmd-1.02.
November 20 2002 - 1.2:
Added some more fixes from Jiger.
November 14 2002 - 1.1:
Added "directory popup option" feature; thanks to Jiger Patel for the suggestions.
November 7 2002 - 1.0:
Updated to use pmd-1.01.
October 4 2002 - 0.9:
Updated to use pmd-1.0rc3
Augst 16 2002 - 0.8:
Fixed GUI lockup problem
Added example text to option pane
Updated to use pmd-0.9
August 2 2002 - 0.7:
Updated to use pmd-0.8
Now individual rules can be selected
July 26 2002 - 0.6:
Updated to use pmd-0.7.
PMD can be run on 1) all files in a directory or 2) recursively into a directory tree.
Added some detail to the Options area.
July 22 2002 - 0.5:
Moved options into Global Options area and made them look nicer.
Cleaned up menus.
Cleaned up help text.
July 18 2002 - 0.4:
Updated to use pmd-0.6
Modified to use ErrorList plugin
Fixed bug - displayed a popup if no messages are found
July 12 2002 - 0.3:
Updated to use pmd-0.4.
Messages are displayed in a list.
July 9 2002 - 0.2:
Fixed bug - a message, not an empty box, is now displayed if no errors are found.
Added options pane so rulesets are selectable and selections are persistant.
July 8 2002 - 0.1:
Initial release

View File

@ -0,0 +1,36 @@
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 2.2
change config/jedit.html to reflect pmd-jedit release 2.2
change the build.xml to reflect pmd-jedit release 2.2
update doing_the_next_pmd_jedit_release.txt to the new release version
comit the above changes FIRST!!
Create the binary release - 'ant release'
Unzip it into jedit.home/jars
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?
4) Does CPD work?
Create the src release:
cvs -q rtag -D tomorrow "pmd_jedit_release_2_1" pmd-jedit
rm -rf ~/tmp/pmd-jedit
mkdir -p ~/tmp/pmd-jedit
cvs -q export -d tmp -r pmd_jedit_release_2_1 pmd-jedit
mv tmp/* ~/tmp/pmd-jedit
rmdir tmp/
cp pmd-jedit/lib/PMDJEditPlugin-2.2.jar ~/tmp/pmd-jedit/lib
cd ~/tmp
zip -q -r pmd-jedit-src-2.2.zip pmd-jedit
rm -rf pmd-jedit
ncftpput upload.sourceforge.net incoming/ pmd-jedit-src-2.2.zip pmd-jedit-bin-2.2.zip
Go to Admin, Edit/Release Files, click on Add new release
Paste stuff into the changelog/readme boxes
Add the 2 zip files
Classify the file
Submit some news saying "hey, new release of the JEdit plugin!"

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:

View File

@ -0,0 +1,4 @@
#!/bin/sh
CLASSPATH=../build/
CLASSPATH=$CLASSPATH:../lib/jedit.jar
export CLASSPATH

View File

@ -0,0 +1,3 @@
#!/bin/bash
ant -Djedit.home=/home/tom/jedit/4.1/ $1

View File

@ -0,0 +1,64 @@
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>
PMD-JEdit Plug-in Users' Guide
</title>
<body>
<h1>PMD-JEdit Plug-in Users' Guide</h1>
<hr>
<p>PMD is a Java source code analyzer - it finds unused variables, questionable design decisions, empty catch blocks, and so forth.
You can read much more about PMD here - http://pmd.sf.net/.</p>
<h3>Installation</h3>
<ul>
<li>Uninstall any old PMD-JEdit plugins
<li>Unzip the PMD-JEdit-bin-2.0.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>
<p>There's a new 'PMD' menu item in the Plugins menu. This has several submenu options</p>
<ul>
<li>"Check current file" checks your currently displayed Java code</li>
<li>"Check all files in current directory" does just that</li>
<li>"Check directory recursively" does just that, too! </li>
<li>Detect Duplicate Code
<ul>
<li>"In current file" checks your currently displayed Java code for duplicates</li>
<li>"Check all files in current directory" same thing for the directory</li>
<li>"Check directory recursively" same thing for the directory, recursively</li>
</ul>
</ul>
<p>"Current directory" means "the directory which is displayed in the file system browser". So, for
example, if you wanted to run PMD on your whole source tree, and your top level
source directory is named "src", you would 1) double-click on the "src" directory and
then 2) select the "PMD->Check directory recursively" menu option.</p>
<p>All those options put any errors into the ErrorList so you can then go jumping around your project fixing stuff.
<p>There's a section in the Utilities->Global Options->Plugins configuration panel that lets you pick which rule sets you want to use.</p>
<p>Note that the configuration panel also contains the minimum tile size for CPD to turn up a duplicate chunk.
<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>PMD jEdit 2.2 adds updates PMD plugin to the latest and the greatest PMD release, updates to Dynamic class loading feature of jEdit and adds PMD to jEdit's File System Browser for easy access.</p>
<h2>Release Notes</h2>
<h3>2.2</h3>
<ol>
<li>Updated to PMD 1.2.1</li>
<li>Updated to jEdit 4.2 API changes</li>
<li>Added PMD in jEdit's File System Browser Plugins Menu.</li>
</ol>
<h3>2.1</h3>
<ol>
<li>Added "clear ErrorList" option.</li>
<li>Added "check all open buffers" option.</li>
<li>Added support to define Custom RuleSets thereby facilitating integration of Custom Rulesets with built-in rulesets & their independent development.</li>
<li>Added C/C++, PHP support to Copy/Paste Detector. Now you can find out duplicate code in your C/C++ & PHP code besides the usual Java code.</li>
</ol>
<h3>2.0</h3>
<ol>
<li>Integrated Copy/Paste Detector(CPD) in jEdit.</li>
<li>Updated to use pmd-1.05</li>
</ol>
<h3>License</h3>
<p>The PMD-JEdit plugin is free software released under the Apache license.</p>
</body>
</html>

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,53 @@
#
# Plugin properties
#
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.name=PMD
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.author=Jiger Patel, Tom Copeland
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.version=2.2
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.02.01.00
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.depend.2=plugin errorlist.ErrorListPlugin 1.2
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.jars=pmd-1.2.1.jar jaxen-core-1.0-fcs.jar saxpath-1.0-fcs.jar pmd-swingui-0.1.jar
#
# Menu properties
#
#New jEdit 4.2 properties
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
pmd-check-current-buffer.label=Check current buffer
pmd-check-all-open-buffers.label=Check all open buffers
pmd-check-current-directory.label=Check all files in current directory
pmd-check-current-directory-recursively.label=Check directory recursively
pmd-clear-errorlist.label=Clear ErrorList
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
#
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.option-pane=pmd
options.pmd.label=PMD
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

View File

@ -0,0 +1,194 @@
package net.sourceforge.pmd.jedit;
//Imports
import org.gjt.sp.jedit.Buffer;
import org.gjt.sp.jedit.View;
import org.gjt.sp.jedit.io.VFSManager;
import org.gjt.sp.jedit.jEdit;
import org.gjt.sp.jedit.textarea.Selection;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeSelectionModel;
import java.awt.BorderLayout;
import java.util.List;
import java.util.ArrayList;
//End of Imports
/**
* A GUI Component to display Duplicate code.
*
* @created 05 Apr 2003
* @author Jiger Patel
*
*/
public class CPDDuplicateCodeViewer extends JPanel
{
JTree tree;
DefaultTreeModel treeModel = new DefaultTreeModel(new DefaultMutableTreeNode("CPD Results",true));
View view;
public CPDDuplicateCodeViewer(View view)
{
this.view = view;
setLayout(new BorderLayout());
tree = new JTree(treeModel);
tree.getSelectionModel().setSelectionMode
(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.addTreeSelectionListener(new TreeSelectionListener()
{
public void valueChanged(TreeSelectionEvent e)
{
DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
if (node != null)
{
//System.out.println("Node is " + node +" class "+ node.getClass());
if (node.isLeaf() && node instanceof Duplicate)
{
Duplicate duplicate = (Duplicate)node;
gotoDuplicate(duplicate);
//System.out.println("Got!! " + duplicate);
}
}
}
});
add(new JScrollPane(tree));
}//End of CPDDuplicateCodeViewer constructor
public void refreshTree()
{
treeModel.reload();
}
public void gotoDuplicate(final Duplicate duplicate)
{
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);
//Since an AIOOB Exception is thrown if the end is the end of file. we do a -1 from end to fix it.
view.getTextArea().setSelection(new Selection.Range(start,end -1));
view.getTextArea().moveCaretPosition(start);
}
});
}
}
public DefaultMutableTreeNode getRoot()
{
return (DefaultMutableTreeNode)treeModel.getRoot();
}
public void addDuplicates(Duplicates duplicates)
{
//System.out.println("Inside addDuplicates " + duplicates +" Root child count "+ treeModel.getChildCount(treeModel.getRoot()));
getRoot().add(duplicates);
//vecDuplicates.addElement(duplicates);
}
public class Duplicates extends DefaultMutableTreeNode
{
List vecduplicate = new ArrayList();
String message, sourcecode;
public Duplicates(String message, String sourcecode)
{
this.message = message;
this.sourcecode = sourcecode;
}
public String getSourceCode()
{
return sourcecode;
}
public void addDuplicate(Duplicate duplicate)
{
add(duplicate);
//vecduplicate.addElement(duplicate);
}
public String toString()
{
return message;
}
}
public class Duplicate extends DefaultMutableTreeNode
{
private String filename;
private int beginLine, endLine;
public Duplicate(String filename,int beginLine, int endLine)
{
this.filename = filename;
this.beginLine = beginLine;
this.endLine = endLine;
}
public String getFilename()
{
return filename;
}
public int getBeginLine()
{
return beginLine;
}
public int getEndLine()
{
return endLine;
}
public String toString()
{
return filename + ":"+ getBeginLine()+"-"+getEndLine();
}
}
public void expandAll()
{
int row = 0;
while (row < tree.getRowCount())
{
tree.expandRow(row);
row++;
}
}
public void collapseAll()
{
int row = tree.getRowCount() - 1;
while (row >= 0) {
tree.collapseRow(row);
row--;
}
}
public void clearDuplicates()
{
getRoot().removeAllChildren();
}
}//End of class CPDDuplicateCodeViewer

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,157 @@
/*
* User: tom
* Date: Jul 8, 2002
* Time: 4:29:19 PM
*/
package net.sourceforge.pmd.jedit;
import net.sourceforge.pmd.RuleSetNotFoundException;
import org.gjt.sp.jedit.AbstractOptionPane;
import org.gjt.sp.jedit.OptionPane;
import org.gjt.sp.jedit.jEdit;
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.JTextField;
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.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class PMDOptionPane extends AbstractOptionPane implements OptionPane {
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);
private JCheckBox directoryPopupBox, chkRunPMDOnSave;
JTextField txtMinTileSize;
JTextField txtCustomRules;
public PMDOptionPane() {
super(PMDJEditPlugin.NAME);
try {
rules = new SelectedRules();
} catch (RuleSetNotFoundException rsne) {
rsne.printStackTrace();
}
}
public void _init() {
removeAll();
addComponent(new JLabel("Please see http://pmd.sf.net/ for more information"));
JPanel rulesPanel = new JPanel(new BorderLayout());
rulesPanel.setBorder(BorderFactory.createTitledBorder("Rules"));
JList list = new CheckboxList(rules.getAllBoxes());
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
rulesPanel.add(new JScrollPane(list), BorderLayout.NORTH);
//Custom Rule Panel Defination.
JPanel pnlCustomRules = new JPanel(new FlowLayout(FlowLayout.LEFT));
pnlCustomRules.add(new JLabel("Path to custom rules.xml files(seperated by comma)"));
pnlCustomRules.add((txtCustomRules = new JTextField(jEdit.getProperty(PMDJEditPlugin.CUSTOM_RULES_PATH_KEY,""),30)));
rulesPanel.add(pnlCustomRules, BorderLayout.CENTER);
JPanel textPanel = new JPanel();
textPanel.setBorder(BorderFactory.createTitledBorder("Example"));
textPanel.add(new JScrollPane(exampleTextArea));
if (!jEdit.getProperties().containsKey(PMDJEditPlugin.OPTION_UI_DIRECTORY_POPUP)) {
jEdit.setBooleanProperty(PMDJEditPlugin.OPTION_UI_DIRECTORY_POPUP, false);
}
directoryPopupBox = new JCheckBox("Ask for directory?", jEdit.getBooleanProperty(PMDJEditPlugin.OPTION_UI_DIRECTORY_POPUP));
chkRunPMDOnSave = new JCheckBox("Run PMD on Save", jEdit.getBooleanProperty(PMDJEditPlugin.RUN_PMD_ON_SAVE));
JPanel pnlSouth = new JPanel(new GridLayout(0,1));
JPanel pnlTileSize = new JPanel();
((FlowLayout)pnlTileSize.getLayout()).setAlignment(FlowLayout.LEFT);
JLabel lblMinTileSize = new JLabel("Minimum Tile Size :");
txtMinTileSize = new JTextField(jEdit.getProperty(PMDJEditPlugin.DEFAULT_TILE_MINSIZE_PROPERTY,"100"),5);
pnlTileSize.add(lblMinTileSize);
pnlTileSize.add(txtMinTileSize);
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
mainPanel.add(rulesPanel, BorderLayout.NORTH);
mainPanel.add(textPanel, BorderLayout.CENTER);
pnlSouth.add(directoryPopupBox);
pnlSouth.add(chkRunPMDOnSave);
pnlSouth.add(pnlTileSize);
mainPanel.add(pnlSouth, BorderLayout.SOUTH);
addComponent(mainPanel);
}
public void _save() {
rules.save();
if (directoryPopupBox != null) {
jEdit.setBooleanProperty(PMDJEditPlugin.OPTION_UI_DIRECTORY_POPUP, directoryPopupBox.isSelected());
}
jEdit.setIntegerProperty(PMDJEditPlugin.DEFAULT_TILE_MINSIZE_PROPERTY,(txtMinTileSize.getText().length() == 0)?100:Integer.parseInt(txtMinTileSize.getText()));
jEdit.setBooleanProperty(PMDJEditPlugin.RUN_PMD_ON_SAVE,(chkRunPMDOnSave.isSelected()));
if(txtCustomRules != null)
{
jEdit.setProperty(PMDJEditPlugin.CUSTOM_RULES_PATH_KEY,txtCustomRules.getText());
}
}
}

View File

@ -0,0 +1,195 @@
/*
* User: tom
* Date: Jul 9, 2002
* Time: 1:18:38 PM
*/
package net.sourceforge.pmd.jedit;
import net.sourceforge.pmd.Rule;
import net.sourceforge.pmd.RuleSet;
import net.sourceforge.pmd.RuleSetFactory;
import net.sourceforge.pmd.RuleSetNotFoundException;
import org.gjt.sp.jedit.jEdit;
import javax.swing.JCheckBox;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;
/**
* Description of the Class
*
* @author jiger.p
* @created April 22, 2003
*/
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());
}
});
/**
* Constructor for the SelectedRules object
*
* @exception RuleSetNotFoundException Description of the Exception
*/
public SelectedRules() throws RuleSetNotFoundException
{
RuleSetFactory rsf = new RuleSetFactory();
for(Iterator i = rsf.getRegisteredRuleSets(); i.hasNext(); )
{
RuleSet rs = (RuleSet)i.next();
addRuleSet2Rules(rs);
}
//Load custom RuleSets if any.
String customRuleSetPath = jEdit.getProperty("pmd.customRulesPath");
if(!(customRuleSetPath == null))
{
StringTokenizer strtok = new StringTokenizer(customRuleSetPath, ",");
while(strtok.hasMoreTokens())
{
RuleSet rs = rsf.createRuleSet(strtok.nextToken());
addRuleSet2Rules(rs);
}
}
}
/**
* Description of the Method
*
* @return Description of the Return Value
*/
public int size()
{
return rules.size();
}
/**
* Gets the rule attribute of the SelectedRules object
*
* @param candidate Description of the Parameter
* @return The rule value
*/
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);
}
/**
* Description of the Method
*
* @param key Description of the Parameter
* @return Description of the Return Value
*/
public JCheckBox get(Object key)
{
return (JCheckBox)rules.get(key);
}
/**
* Gets the allBoxes attribute of the SelectedRules object
*
* @return The allBoxes value
*/
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;
}
/** Description of the Method */
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());
}
}
/**
* Gets the selectedRules attribute of the SelectedRules object
*
* @return The selectedRules value
*/
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;
}
/**
* Description of the Method
*
* @param name Description of the Parameter
* @return Description of the Return Value
*/
private JCheckBox createCheckBox(String name)
{
JCheckBox box = new JCheckBox(name);
box.setSelected(jEdit.getBooleanProperty(PMDJEditPlugin.OPTION_RULES_PREFIX + name, true));
return box;
}
/**
* Adds a feature to the RuleSet2Rules attribute of the SelectedRules object
*
* @param rs The feature to be added to the RuleSet2Rules attribute
*/
private void addRuleSet2Rules(RuleSet rs)
{
for(Iterator j = rs.getRules().iterator(); j.hasNext(); )
{
Rule rule = (Rule)j.next();
rules.put(rule, createCheckBox(rule.getName()));
}
}
}