*** empty log message ***

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@308 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
David Craine
2002-07-11 21:50:11 +00:00
parent 8cdcd55f44
commit 2cbac431f6
8 changed files with 339 additions and 21 deletions

View File

@ -33,7 +33,7 @@
<property category="sys" name="InstanceVisibility" value="2"/>
<property category="sys" name="JDK" value="java 1.3.1-b24"/>
<property category="sys" name="LastTag" value="0"/>
<property category="sys" name="Libraries" value="Open Tools SDK;PMD;Ant;Xerces"/>
<property category="sys" name="Libraries" value="Open Tools SDK;Ant;Xerces;PMD-0.3"/>
<property category="sys" name="MakeStable" value="0"/>
<property category="sys" name="OutPath" value="classes"/>
<property category="sys" name="SourcePath" value="src;test;../PMD/src"/>
@ -43,12 +43,19 @@
<property category="sys" name="Version" value="1.0"/>
<property category="sys" name="VersionLabel" value="@version"/>
<property category="sys" name="WorkingDirectory" value="."/>
<node name="Copy to JBuilder OpenTools Dir" type="ExternalTask">
<property category="external" name="dependencies" value="archive"/>
<property category="external" name="executable" value="&quot;C:\Documents and Settings\David Craine\jbproject\pmd-jbuilder\copyfile.bat&quot;"/>
<property category="external" name="params" value="c:\JBuilder7\lib\ext\"/>
<property category="external" name="phase" value="package"/>
</node>
<node name="PMDOpenTool" type="Archive">
<property category="archiving" name="archiverClass" value="com.borland.jbuilder.wizard.archive.OpenToolArchiver"/>
<property category="archiving" name="extraDeployRoots.1" value="C:pmdopentool.PMDOpenTool"/>
<property category="archiving" name="overrideManifestPath" value="classes.opentools"/>
<property category="archiving" name="targetPath" value="C%|/JBuilder7/lib/ext/PMDOpenTool.jar"/>
<property category="archiving" name="targetPath" value="lib/PMDOpenTool.jar"/>
</node>
<file path="classes.opentools"/>
<file path="copyfile.bat"/>
<file path="src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java"/>
</project>

View File

@ -25,9 +25,24 @@ debug.NoTracingClasses.6[0]=30 com.borland.jbuilder.runtime.*1 1 -1
debug.NoTracingClasses.7[0]=17 com.borland.sql.*1 1 -1
debug.NoTracingClasses.8[0]=9 com.sun.*1 1 -1
debug.NoTracingClasses.9[0]=6 java.*1 1 -1
history.files.active[0]=C%|/JBuilder7/lib/ext/PMDOpenTool.jar
history.files.open.1[0]=C%|/JBuilder7/lib/ext/PMDOpenTool.jar
history.files.open.2[0]=src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java,F;0,0
history.files.active[0]=src/net/sourceforge/pmd/jbuilder/RuleSetPropertyGroup.java
history.files.open.1[0]=src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java,F;136,1658
history.files.open.2[0]=src/net/sourceforge/pmd/jbuilder/RuleSetPropertyGroup.java,F;13,593
history.files.open.3[0]=src/net/sourceforge/pmd/jbuilder/RuleSetPropertyPage.java,F;0,754
import.optimize.packageprefixgroupings.1[0]=java
import.optimize.packageprefixgroupings.2[0]=<blank line>
import.optimize.packageprefixgroupings.3[0]=javax
import.optimize.packageprefixgroupings.4[0]=<blank line>
import.optimize.packageprefixgroupings.5[0]=<*>
sys.Author[0]=David Craine
sys.DefaultPackage[0]=pmdopentool
wizard.package.package_history.1[0]=pmdopentool
sys.DefaultPackage[0]=net.sourceforge.pmd.jbuilder
team.ActiveVCS[0]=CVS
team.CvsAccessMethod[0]=ext
team.CvsAutosaveEnabled[0]=1
team.CvsModule[0]=pmd-jbuilder
team.CvsRepository[0]=/cvsroot/pmd
team.CvsServer[0]=cvs.pmd.sourceforge.net
team.CvsShowConsole[0]=0
team.CvsUsername[0]=dcraine
wizard.package.package_history.1[0]=net.sourceforge.pmd.jbuilder
wizard.package.package_history.2[0]=pmdopentool

View File

@ -1 +1 @@
OpenTools-UI: pmdopentool.PMDOpenTool
OpenTools-UI: net.sourceforge.pmd.jbuilder.PMDOpenTool

2
pmd-jbuilder/copyfile.bat Executable file
View File

@ -0,0 +1,2 @@
copy lib\PMDOpenTOol.jar %1
copy lib\pmd-0.3.jar %1

Binary file not shown.

View File

@ -1,26 +1,26 @@
package net.sourceforge.pmd.jbuilder;
import java.awt.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.text.*;
import com.borland.jbuilder.*;
import com.borland.jbuilder.node.*;
import com.borland.primetime.*;
import com.borland.primetime.editor.*;
import com.borland.primetime.ide.*;
import com.borland.primetime.node.*;
import com.borland.primetime.viewer.*;
import net.sourceforge.pmd.*;
import net.sourceforge.pmd.reports.*;
import com.borland.primetime.actions.DelegateHandler;
import com.borland.primetime.actions.DelegateAction;
import javax.swing.Action;
import com.borland.primetime.editor.LineMark;
import com.borland.primetime.editor.EditorPane;
import com.borland.primetime.editor.EditorManager;
import com.borland.primetime.editor.MasterStyleContext;
import java.awt.Color;
import com.borland.primetime.actions.ActionGroup;
import com.borland.primetime.properties.NodeProperty;
import com.borland.primetime.properties.GlobalProperty;
import com.borland.primetime.properties.PropertyManager;
import com.borland.primetime.properties.PropertyDialog;
/**
@ -33,9 +33,9 @@ import java.awt.Color;
*/
public class PMDOpenTool {
static MessageCategory msgCat = new MessageCategory("PMD Results");
public static ActionGroup GROUP_PMD = new ActionGroup("PMD", 'p', true);
public PMDOpenTool() {
int i;
@ -44,11 +44,15 @@ public class PMDOpenTool {
public static void initOpenTool(byte majorVersion, byte minorVersion) {
if (majorVersion == PrimeTime.CURRENT_MAJOR_VERSION) {
JBuilderMenu.GROUP_Tools.add(ACTION_PMDCheck);
GROUP_PMD.add(ACTION_PMDCheck);
GROUP_PMD.add(ACTION_PMDConfig);
JBuilderMenu.GROUP_Tools.add(GROUP_PMD);
registerWithContentManager();
PropertyManager.registerPropertyGroup(new RuleSetPropertyGroup());
}
}
/**
* Registers an "PMD Checker" action with the ContentManager (Tabs)
* The action will not be visible if multiple nodes are selected
@ -66,6 +70,23 @@ public class PMDOpenTool {
ContentManager.registerContextActionProvider(cap);
}
private static RuleSet constructRuleSets(RuleSetFactory ruleSetFactory, PMD pmd) {
RuleSet masterRuleSet = null;
for (int i = 0; i<RuleSetPropertyGroup.PROPKEYS.length; i++) {
if (Boolean.valueOf(RuleSetPropertyGroup.PROPKEYS[i].getValue()).booleanValue()){
RuleSet rules= ruleSetFactory.createRuleSet(pmd.getClass().getClassLoader().getResourceAsStream("rulesets/"+RuleSetPropertyGroup.RULESET_NAMES[i]+".xml"));
if (masterRuleSet == null) {
masterRuleSet = rules;
}
else {
masterRuleSet.addRuleSet(rules);
}
}
}
return masterRuleSet;
}
public static Report instanceCheck(String text) {
PMD pmd = new PMD();
@ -73,7 +94,9 @@ public class PMDOpenTool {
ReportFactory rf = new ReportFactory();
RuleContext ctx = new RuleContext();
RuleSetFactory ruleSetFactory = new RuleSetFactory();
RuleSet rules = ruleSetFactory.createRuleSet(pmd.getClass().getClassLoader().getResourceAsStream("rulesets/unusedcode.xml"));
//RuleSet rules = ruleSetFactory.createRuleSet(pmd.getClass().getClassLoader().getResourceAsStream("rulesets/unusedcode.xml"));
RuleSet rules = constructRuleSets(ruleSetFactory, pmd);
if (rules == null) return null;
ctx.setReport(rf.createReport("xml"));
ctx.setSourceCodeFilename("this");
@ -90,7 +113,6 @@ public class PMDOpenTool {
}
public static /*final*/ BrowserAction ACTION_PMDCheck =
// A new action with short menu string, mnemonic, and long menu string
new BrowserAction("PMD Checker", 'P', "Displays PMD statistics about a Java File") {
@ -114,6 +136,7 @@ public class PMDOpenTool {
for (Iterator i = rpt.iterator(); i.hasNext(); ) {
RuleViolation rv = (RuleViolation)i.next();
PMDMessage pmdMsg = new PMDMessage(rv.getDescription() + " at line " + rv.getLine(), rv.getLine(), (JavaFileNode)node);
pmdMsg.setForeground(Color.red);
Browser.getActiveBrowser().getMessageView().addMessage(msgCat, pmdMsg);//add the result message
}
}
@ -127,6 +150,18 @@ public class PMDOpenTool {
}
};
public static BrowserAction ACTION_PMDConfig =
new BrowserAction("Configure PMD", 'C', "Configure the PMD Settings") {
public void actionPerformed(Browser browser) {
PropertyManager.showPropertyDialog(browser,
"PMD Options",
RuleSetPropertyGroup.RULESETS_TOPIC,
PropertyDialog.getLastSelectedPage());
}
};
/**
* Main method for testing purposes
* @param args standard arguments

View File

@ -0,0 +1,72 @@
package net.sourceforge.pmd.jbuilder;
import com.borland.primetime.properties.PropertyGroup;
import com.borland.primetime.properties.PropertyPageFactory;
import com.borland.primetime.properties.GlobalProperty;
import com.borland.primetime.properties.PropertyPage;
/**
* <p>Title: JBuilder OpenTool for PMD</p>
* <p>Description: Provides an environemnt for using the PMD aplication from within JBuilder</p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: InfoEther</p>
* @author David Craine
* @version 1.0
*/
public class RuleSetPropertyGroup implements PropertyGroup {
/**
BEGIN - RULE DEFINITION SECTION
To add new rule sets simply create a new rule set name constant, create GlobalProperty constant,
and add each to their respective arrays.
*/
public static final String RULESETS="RuleSets";
public static final String RULESET_BASIC = "basic";
public static final String RULESET_DESIGN = "design";
public static final String RULESET_UNUSEDCODE = "unusedcode";
public static final String RULESET_COUGAAR = "cougaar";
public static final String RULESET_TICBUILD = "ticbuild";
public static final Object RULESETS_TOPIC = new Object();
public static final GlobalProperty PROPKEY_RULESET_DESIGN = new GlobalProperty(RULESETS, RULESET_DESIGN, "true");
public static final GlobalProperty PROPKEY_RULESET_BASIC = new GlobalProperty(RULESETS, RULESET_BASIC, "true");
public static final GlobalProperty PROPKEY_RULESET_UNUSEDCODE = new GlobalProperty(RULESETS, RULESET_UNUSEDCODE, "true");
public static final GlobalProperty PROPKEY_RULESET_COUGAAR = new GlobalProperty(RULESETS, RULESET_COUGAAR, "true");
public static final GlobalProperty PROPKEY_RULESET_TICBUILD = new GlobalProperty(RULESETS, RULESET_TICBUILD, "true");
//make sure that these two arrays are synchronized
public static final String[] RULESET_NAMES = {
RULESET_BASIC,
RULESET_DESIGN,
RULESET_UNUSEDCODE,
RULESET_COUGAAR,
RULESET_TICBUILD};
public static final GlobalProperty[] PROPKEYS = {
PROPKEY_RULESET_BASIC,
PROPKEY_RULESET_DESIGN,
PROPKEY_RULESET_UNUSEDCODE,
PROPKEY_RULESET_COUGAAR,
PROPKEY_RULESET_TICBUILD};
/**
* END - RULE DEFINITION SECTION
*/
public RuleSetPropertyGroup() {
}
public void initializeProperties() {
/**@todo Implement this com.borland.primetime.properties.PropertyGroup method*/
throw new java.lang.UnsupportedOperationException("Method initializeProperties() not yet implemented.");
}
public PropertyPageFactory getPageFactory(Object topic) {
if (topic == RULESETS_TOPIC) {
return new PropertyPageFactory("PMD Properties", "Set PMD RuleSet Properties") {
public PropertyPage createPropertyPage() {
return new RuleSetPropertyPage();
}
};
}
return null;
}
}

View File

@ -0,0 +1,187 @@
package net.sourceforge.pmd.jbuilder;
import com.borland.primetime.properties.*;
import com.borland.primetime.help.HelpTopic;
import javax.swing.*;
import java.awt.*;
import java.util.HashMap;
import javax.swing.border.*;
import javax.swing.ListModel;
import javax.swing.DefaultListModel;
import java.awt.event.*;
import com.borland.primetime.ide.Browser;
import com.borland.primetime.ide.MessageCategory;
import java.util.Enumeration;
/**
* <p>Title: JBuilder OpenTool for PMD</p>
* <p>Description: Provides an environemnt for using the PMD aplication from within JBuilder</p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: InfoEther</p>
* @author David Craine
* @version 1.0
*/
public class RuleSetPropertyPage extends PropertyPage {
//static MessageCategory cat = new MessageCategory("test");
private BorderLayout borderLayout1 = new BorderLayout();
private JSplitPane jSplitPane1 = new JSplitPane();
private Border border1;
private TitledBorder titledBorder1;
private Border border2;
private TitledBorder titledBorder2;
private DefaultListModel dlmAvailableRuleSets = new DefaultListModel();
private DefaultListModel dlmSelectedRuleSets = new DefaultListModel();
private JPanel jpAvailableRuleSets = new JPanel();
private JScrollPane jspAvailableRuleSets = new JScrollPane();
private JList jlistAvailableRuleSets = new JList();
private JPanel jpSelectedRuleSets = new JPanel();
private JList jlistSelectedRuleSets = new JList();
private JScrollPane jspSelecedRuleSets = new JScrollPane();
private BorderLayout borderLayout2 = new BorderLayout();
private BorderLayout borderLayout3 = new BorderLayout();
private JButton jbSelectRuleSets = new JButton();
private JButton jbDeselectRuleSets = new JButton();
private Border border3;
private Border border4;
public RuleSetPropertyPage() {
try {
jbInit();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
private void initRuleSplitPanes() {
//loop through the sets of rules and place them in the appropriate pane based upon setting
for (int i=0;i<RuleSetPropertyGroup.RULESET_NAMES.length; i++) {
ListEntry le = new ListEntry(RuleSetPropertyGroup.RULESET_NAMES[i], RuleSetPropertyGroup.PROPKEYS[i]);
if (Boolean.valueOf(RuleSetPropertyGroup.PROPKEYS[i].getValue()).booleanValue())
dlmSelectedRuleSets.addElement(le);
else
dlmAvailableRuleSets.addElement(le);
}
}
protected void jbInit() throws Exception {
border1 = BorderFactory.createEtchedBorder(Color.white,new Color(178, 178, 178));
titledBorder1 = new TitledBorder(border1,"Available Rule Sets");
border2 = BorderFactory.createEtchedBorder(Color.white,new Color(178, 178, 178));
titledBorder2 = new TitledBorder(border2,"Selected Rule Sets");
border3 = BorderFactory.createEtchedBorder(Color.white,new Color(165, 163, 151));
border4 = BorderFactory.createCompoundBorder(border3,titledBorder1);
this.setLayout(borderLayout1);
jlistAvailableRuleSets.setModel(dlmAvailableRuleSets);
jlistSelectedRuleSets.setModel(dlmSelectedRuleSets);
jpAvailableRuleSets.setLayout(borderLayout2);
jpSelectedRuleSets.setLayout(borderLayout3);
jbSelectRuleSets.setText("Select ===>>>");
jbSelectRuleSets.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jbSelectRuleSets_actionPerformed(e);
}
});
jbDeselectRuleSets.setText("<<<===Remove");
jbDeselectRuleSets.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jbDeselectRuleSets_actionPerformed(e);
}
});
jpAvailableRuleSets.setBorder(titledBorder1);
jpSelectedRuleSets.setBorder(titledBorder2);
this.add(jSplitPane1, BorderLayout.CENTER);
jSplitPane1.add(jpAvailableRuleSets, JSplitPane.LEFT);
jSplitPane1.add(jpSelectedRuleSets, JSplitPane.RIGHT);
jpAvailableRuleSets.add(jspAvailableRuleSets, BorderLayout.CENTER);
jpSelectedRuleSets.add(jspSelecedRuleSets, BorderLayout.CENTER);
jspSelecedRuleSets.getViewport().add(jlistSelectedRuleSets, null);
jspAvailableRuleSets.getViewport().add(jlistAvailableRuleSets, null);
jpAvailableRuleSets.add(jbSelectRuleSets, BorderLayout.SOUTH);
jpSelectedRuleSets.add(jbDeselectRuleSets, BorderLayout.SOUTH);
initRuleSplitPanes();
jSplitPane1.setDividerLocation(200);
}
public void writeProperties() {
//set the properties for the items items in the selected list to true
for (Enumeration e = dlmSelectedRuleSets.elements(); e.hasMoreElements(); ) {
ListEntry le = (ListEntry)e.nextElement();
le.getProp().setValue("true");
}
//set the properties for the items items in the available list to false
for (Enumeration e = dlmAvailableRuleSets.elements(); e.hasMoreElements(); ) {
ListEntry le = (ListEntry)e.nextElement();
le.getProp().setValue("false");
}
}
public HelpTopic getHelpTopic() {
return null;
}
public void readProperties() {
}
void jbSelectRuleSets_actionPerformed(ActionEvent e) {
//get the selected elements in the selected list and move to the available list
int [] selectedItems = jlistAvailableRuleSets.getSelectedIndices();
if (selectedItems != null) {
for (int i=0; i<selectedItems.length; i++) {
ListEntry le = (ListEntry)dlmAvailableRuleSets.get(selectedItems[i]);
dlmSelectedRuleSets.addElement(le);
dlmAvailableRuleSets.remove(selectedItems[i]);
jlistSelectedRuleSets.updateUI();
jlistAvailableRuleSets.updateUI();
}
}
}
void jbDeselectRuleSets_actionPerformed(ActionEvent e) {
//get the selected elements in the available list and move to the selected list
int [] selectedItems = jlistSelectedRuleSets.getSelectedIndices();
if (selectedItems != null) {
for (int i=0; i<selectedItems.length; i++) {
ListEntry le = (ListEntry)dlmSelectedRuleSets.get(selectedItems[i]);
dlmAvailableRuleSets.addElement(le);
dlmSelectedRuleSets.remove(selectedItems[i]);
jlistSelectedRuleSets.updateUI();
jlistAvailableRuleSets.updateUI();
}
}
}
}
class ListEntry {
GlobalProperty prop;
String displayName;
public ListEntry(String name, GlobalProperty prop) {
this.displayName = name;
this.prop = prop;
}
public GlobalProperty getProp() {
return prop;
}
public String getDisplayName() {
return displayName;
}
public String toString() {
return displayName;
}
}