Enabled ability to cancel the CPD Run

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@805 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
David Craine
2002-08-28 15:12:07 +00:00
parent 1db5929a81
commit 8855c49995
6 changed files with 143 additions and 65 deletions

View File

@ -1,18 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--JBuilder XML Project-->
<project>
<property category="idl" name="ProcessIDL" value="false"/>
<property category="runtime" name="DefaultConfiguration" value="-1"/>
<property category="runtime.0" name="BuildTargetOnRun" value="com.borland.jbuilder.build.ProjectBuilder$ProjectBuildAction;make"/>
<property category="runtime.0" name="ConfigurationName" value="Untitled Runtime Configuration"/>
<property category="runtime.0" name="RunnableType" value="com.borland.jbuilder.runtime.ApplicationRunner"/>
<property category="runtime.0" name="application.class" value="pmdopentool.PMDOpenTool"/>
<property category="runtime.0" name="appserver.parameters" value=""/>
<property category="runtime.0" name="appserver.servername" value=""/>
<property category="runtime.0" name="appserver.vmparameters" value=""/>
<property category="runtime.0" name="server.arguments" value=""/>
<property category="runtime.0" name="server.disableServerClassTracing" value="0"/>
<property category="runtime.0" name="server.instance.name" value=""/>
<property category="runtime.0" name="server.name" value="Tomcat 4.0"/>
<property category="runtime.0" name="server.vmparameters" value=""/>
<property category="runtime.0" name="test.harness" value="com.borland.jbuilder.unittest.JBTestRunner"/>
<property category="serverservices" name="single.server.name" value="Tomcat 4.0"/>
<property category="sys" name="AuthorLabel" value="@author"/>
<property category="sys" name="BackupPath" value="bak"/>
<property category="sys" name="CheckStable" value="1"/>
<property category="sys" name="Company" value="InfoEther"/>
<property category="sys" name="CompanyLabel" value="Company:"/>
<property category="sys" name="Copyright" value="Copyright (c) 2002"/>
<property category="sys" name="CopyrightLabel" value="Copyright:"/>
<property category="sys" name="DefaultPath" value="src"/>
<property category="sys" name="Description" value="Provides an environemnt for using the PMD aplication from within JBuilder"/>
<property category="sys" name="DescriptionLabel" value="Description:"/>
<property category="sys" name="DocPath" value="doc"/>
<property category="sys" name="ExcludeClassEnabled" value="0"/>
<property category="sys" name="IncludeTestPath" value="1"/>
<property category="sys" name="InstanceVisibility" value="2"/>
<property category="sys" name="JDK" value="java 1.4.0-b92"/>
<property category="sys" name="Libraries" value="Open Tools SDK;Ant;Xerces;JBCL;PMD-0.9"/>
<property category="sys" name="LastTag" value="0"/>
<property category="sys" name="Libraries" value="Open Tools SDK;Ant;Xerces;JBCL;PMD-DEVEL"/>
<property category="sys" name="MakeStable" value="0"/>
<property category="sys" name="OutPath" value="classes"/>
<property category="sys" name="SourcePath" value="src;test;doc"/>
<property category="sys" name="TestPath" value="test"/>
<property category="sys" name="Title" value="JBuilder OpenTool for PMD"/>
<property category="sys" name="TitleLabel" value="Title:"/>
<property category="sys" name="Version" value="1.0"/>
<property category="sys" name="VersionLabel" value="@version"/>
<property category="sys" name="WorkingDirectory" value="."/>
<property category="sys"
name="uidesign.size.net.sourceforge.pmd.jbuilder.AcceleratorPropertyPage" value="476,387"/>
<property category="sys"
name="uidesign.size.net.sourceforge.pmd.jbuilder.ConfigureRuleSetPropertyPage" value="545,418"/>
<property category="sys"
name="uidesign.size.net.sourceforge.pmd.jbuilder.ImportedRuleSetPropertyPage" value="539,429"/>
<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\My Documents\InfoEther-SF\pmd\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="F:html/active-ruleset-props.html"/>
@ -22,4 +64,10 @@
<property category="archiving" name="overrideManifestPath" value="classes.opentools"/>
<property category="archiving" name="targetPath" value="lib/PMDOpenTool.jar"/>
</node>
</project>
<file path="classes.opentools"/>
<file path="copyfile.bat">
<property category="lh.cmdline" name="command" value="C:\Documents and Settings\David Craine\My Documents\InfoEther-SF\pmd\pmd-jbuilder\copyfile.bat"/>
</file>
<file path="src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java"/>
<file path="Things to do.txt"/>
</project>

View File

@ -27,10 +27,8 @@ debug.NoTracingClasses.8[0]=9 com.sun.*1 1 -1
debug.NoTracingClasses.9[0]=6 java.*1 1 -1
editor.search.file_filter_history.1[0]=*.java
history.files.active[0]=src/net/sourceforge/pmd/jbuilder/CPDDialog.java
history.files.open.1[0]=src/net/sourceforge/pmd/jbuilder/AcceleratorPropertyPage.java,F;64,3022
history.files.open.2[0]=src/net/sourceforge/pmd/jbuilder/ConfigureRuleSetPropertyPage.java,F;117,4630
history.files.open.3[0]=src/net/sourceforge/pmd/jbuilder/CPDDialog.java,F;42,2046
history.files.open.4[0]=src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java,F;284,14186
history.files.open.1[0]=src/net/sourceforge/pmd/jbuilder/CPDDialog.java,F;68,2295
history.files.open.2[0]=src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java,F;339,16263
import.optimize.packageprefixgroupings.1[0]=java
import.optimize.packageprefixgroupings.2[0]=<blank line>
import.optimize.packageprefixgroupings.3[0]=javax
@ -48,6 +46,6 @@ team.CvsRepository[0]=/cvsroot/pmd
team.CvsServer[0]=cvs.pmd.sourceforge.net
team.CvsShowConsole[0]=0
team.CvsUsername[0]=dcraine
team.prunedDirectories[0]=bak/pmdopentool;classes
team.prunedDirectories[0]=bak/pmdopentool;classes/images;classes/net
wizard.package.package_history.1[0]=net.sourceforge.pmd.jbuilder
wizard.package.package_history.2[0]=pmdopentool

View File

@ -1,2 +1,2 @@
copy lib\PMDOpenTool.jar %1
rem copy lib\pmd-0.8.jar %1
rem copy lib\pmd-dev.jar %1

Binary file not shown.

View File

@ -11,7 +11,7 @@ import java.awt.event.WindowListener;
import java.awt.event.WindowEvent;
import net.sourceforge.pmd.cpd.Tile;
public class CPDDialog extends JFrame implements CPDListener {
public class CPDDialog extends JFrame implements CPDListener, WindowListener {
private CPD cpd;
int progress = 0;
boolean firstToken = true;
@ -20,6 +20,7 @@ public class CPDDialog extends JFrame implements CPDListener {
private VerticalFlowLayout verticalFlowLayout1 = new VerticalFlowLayout();
private JLabel jLabel1 = new JLabel();
private JProgressBar jProgressBar1 = new JProgressBar();
private boolean retCode = true;
public CPDDialog(CPD cpd) {
super("CPD Status Monitor");
@ -33,10 +34,12 @@ public class CPDDialog extends JFrame implements CPDListener {
}
}
public void update(String msg) {
public boolean update(String msg) {
return retCode;
}
public void addedFile(int fileCount, File file) {
public boolean addedFile(int fileCount, File file) {
if (firstFile) {
firstFile = false;
jLabel1.setText("Adding Files...");
@ -45,20 +48,22 @@ public class CPDDialog extends JFrame implements CPDListener {
progress = 0;
}
jProgressBar1.setValue(++progress);
return retCode;
}
public void addingTokens(int tokenSetCount, int doneSoFar, String tokenSrcID) {
public boolean addingTokens(int tokenSetCount, int doneSoFar, String tokenSrcID) {
if (firstToken) {
firstToken = false;
jLabel1.setText("Adding Tokens...");
jProgressBar1.setMaximum(tokenSetCount);
}
jProgressBar1.setValue(doneSoFar);
return retCode;
}
public void addedNewTile(Tile tile, int tilesSoFar, int totalTiles) {
public boolean addedNewTile(Tile tile, int tilesSoFar, int totalTiles) {
if (firstNewTile) {
firstNewTile = false;
jLabel1.setText("Adding Tiles... ");
@ -68,6 +73,11 @@ public class CPDDialog extends JFrame implements CPDListener {
jProgressBar1.setMaximum(totalTiles);
jProgressBar1.setValue(tilesSoFar);
return retCode;
}
public boolean wasCancelled() {
return !retCode;
}
public void close() {
@ -95,6 +105,23 @@ public class CPDDialog extends JFrame implements CPDListener {
int xpos = (Toolkit.getDefaultToolkit().getScreenSize().width - this.getSize().width)/2;
int ypos = (Toolkit.getDefaultToolkit().getScreenSize().height - this.getSize().height)/2;
this.setLocation(xpos, ypos);
this.addWindowListener(this);
this.show();
}
public void windowOpened(WindowEvent e) {
}
public void windowClosing(WindowEvent e) {
retCode = false;
}
public void windowClosed(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowActivated(WindowEvent e) {
}
public void windowDeactivated(WindowEvent e) {
}
}

View File

@ -107,18 +107,18 @@ public class PMDOpenTool {
EditorManager.getKeymap().removeKeyStrokeBinding(KeyStroke.getKeyStroke(AcceleratorPropertyGroup.PROP_CHECKFILE_KEY.getInteger(),
AcceleratorPropertyGroup.PROP_CHECKFILE_MOD.getInteger()));
EditorManager.getKeymap().removeKeyStrokeBinding(KeyStroke.getKeyStroke(AcceleratorPropertyGroup.PROP_CHECKPROJ_KEY.getInteger(),
AcceleratorPropertyGroup.PROP_CHECKPROJ_MOD.getInteger()));
AcceleratorPropertyGroup.PROP_CHECKPROJ_MOD.getInteger()));
}
static void registerShortCuts() {
EditorManager.getKeymap().addActionForKeyStroke(KeyStroke.getKeyStroke(AcceleratorPropertyGroup.PROP_CHECKFILE_KEY.getInteger(),
AcceleratorPropertyGroup.PROP_CHECKFILE_MOD.getInteger()),
E_ACTION_PMDCheck);
E_ACTION_PMDCheck);
EditorManager.getKeymap().addActionForKeyStroke(KeyStroke.getKeyStroke(AcceleratorPropertyGroup.PROP_CHECKPROJ_KEY.getInteger(),
AcceleratorPropertyGroup.PROP_CHECKPROJ_MOD.getInteger()),
E_ACTION_PMDCheckProject);
AcceleratorPropertyGroup.PROP_CHECKPROJ_MOD.getInteger()),
E_ACTION_PMDCheckProject);
}
/**
@ -193,7 +193,7 @@ public class PMDOpenTool {
//create EditorAction for performing a PMD Check
public static EditorAction E_ACTION_PMDCheck =
new EditorAction("Displays PMD statistics about a Java File") {
new EditorAction("Displays PMD statistics about a Java File") {
public void actionPerformed(ActionEvent e) {
pmdCheck();
}
@ -201,7 +201,7 @@ public class PMDOpenTool {
//create EditorAction for performing a PMD Check on a project
public static EditorAction E_ACTION_PMDCheckProject =
new EditorAction("Displays PMD statistics about a Java File") {
new EditorAction("Displays PMD statistics about a Java File") {
public void actionPerformed(ActionEvent e) {
pmdCheckProject();
}
@ -235,6 +235,7 @@ public class PMDOpenTool {
}
};
//create the project menu action for running a PMD check against all the java files within the active project
public static BrowserAction B_ACTION_CPDProjectCheck = new BrowserAction ("CPD Check Project", 'P', "Run CPD on all the java files in the project",
new ImageIcon(PMDOpenTool.class.getClassLoader().getSystemResource("images/cpd.gif"))) {
@ -335,55 +336,59 @@ public class PMDOpenTool {
}
private static void pmdCPD() {
try {
Browser.getActiveBrowser().getMessageView().clearMessages(cpdCat); //clear the message window
CPD cpd = new CPD();
cpd.setMinimumTileSize(CPDPropertyGroup.PROP_MIN_TOKEN_COUNT.getInteger());
Node[] nodes = Browser.getActiveBrowser().getActiveProject().getDisplayChildren();
CPDDialog cpdd = new CPDDialog(cpd);
for (int i=0; i<nodes.length; i++ ) {
if (nodes[i] instanceof PackageNode) {
PackageNode node = (PackageNode)nodes[i];
Node[] fileNodes = node.getDisplayChildren();
for (int j=0; j<fileNodes.length; j++) {
if (fileNodes[j] instanceof JavaFileNode) {
try {
cpd.add(new File(fileNodes[j].getLongDisplayName()));
}
catch (Exception e){
}
}
}
}
}
cpd.go();
Results results = cpd.getResults();
int resultCount = 0;
if (results != null) {
for (Iterator iter = results.getTiles(); iter.hasNext(); ) {
Tile t = (Tile)iter.next();
resultCount++;
int tileLineCount = cpd.getLineCountFor(t);
int dupCount = results.getOccurrenceCountFor(t);
CPDMessage msg = CPDMessage.createMessage(String.valueOf(dupCount)+" duplicates in code set: " + resultCount, cpd.getImage(t));
for (Iterator iter2 = results.getOccurrences(t); iter2.hasNext(); ) {
TokenEntry te = (TokenEntry)iter2.next();
msg.addChildMessage(te.getBeginLine(), tileLineCount, te.getTokenSrcID());
try {
Browser.getActiveBrowser().getMessageView().clearMessages(cpdCat); //clear the message window
final CPD cpd = new CPD();
cpd.setMinimumTileSize(CPDPropertyGroup.PROP_MIN_TOKEN_COUNT.getInteger());
Node[] nodes = Browser.getActiveBrowser().getActiveProject().getDisplayChildren();
CPDDialog cpdd = new CPDDialog(cpd);
for (int i=0; i<nodes.length; i++ ) {
if (nodes[i] instanceof PackageNode) {
PackageNode node = (PackageNode)nodes[i];
Node[] fileNodes = node.getDisplayChildren();
for (int j=0; j<fileNodes.length; j++) {
if (fileNodes[j] instanceof JavaFileNode) {
try {
cpd.add(new File(fileNodes[j].getLongDisplayName()));
}
catch (Exception e){
}
}
}
}
}
cpd.go();
if (cpdd.wasCancelled()) { //if the dialog was cancelled by the user then let's get out of here
cpdd.close();
return;
}
Results results = cpd.getResults();
int resultCount = 0;
if (results != null) {
for (Iterator iter = results.getTiles(); iter.hasNext(); ) {
Tile t = (Tile)iter.next();
resultCount++;
int tileLineCount = cpd.getLineCountFor(t);
int dupCount = results.getOccurrenceCountFor(t);
CPDMessage msg = CPDMessage.createMessage(String.valueOf(dupCount)+" duplicates in code set: " + resultCount, cpd.getImage(t));
for (Iterator iter2 = results.getOccurrences(t); iter2.hasNext(); ) {
TokenEntry te = (TokenEntry)iter2.next();
msg.addChildMessage(te.getBeginLine(), tileLineCount, te.getTokenSrcID());
}
Browser.getActiveBrowser().getMessageView().addMessage(cpdCat, msg);
}
}
cpdd.close();
}
catch (Exception e) {
Browser.getActiveBrowser().getMessageView().addMessage(cpdCat, e.toString());
}
}
}
cpdd.close();
}
catch (Exception e) {
Browser.getActiveBrowser().getMessageView().addMessage(cpdCat, e.toString());
}
}
/**
* Main method for testing purposes
* @param args standard arguments
*/
* Main method for testing purposes
* @param args standard arguments
*/
public static void main (String[] args) {
//Report ret = PMDOpenTool.instanceCheck("package abc; \npublic class foo {\npublic void bar() {int i;}\n}");
//System.out.println("PMD: " + ret);
@ -596,7 +601,7 @@ class CodeFragmentMessage extends Message {
}
catch (Exception e){}
}
}
}