<No Comment Entered>
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@661 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Binary file not shown.
BIN
pmd-jbuilder/src/images/cpd.gif
Normal file
BIN
pmd-jbuilder/src/images/cpd.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 305 B |
96
pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/CPDDialog.java
Normal file
96
pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/CPDDialog.java
Normal file
@ -0,0 +1,96 @@
|
||||
package net.sourceforge.pmd.jbuilder;
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import com.borland.jbcl.layout.*;
|
||||
import javax.swing.plaf.ProgressBarUI;
|
||||
import java.io.File;
|
||||
import net.sourceforge.pmd.cpd.CPDListener;
|
||||
import net.sourceforge.pmd.cpd.CPD;
|
||||
|
||||
public class CPDDialog extends JFrame implements CPDListener {
|
||||
private CPD cpd;
|
||||
int progress = 0;
|
||||
boolean firstUpdate = true;
|
||||
boolean firstToken = true;
|
||||
boolean firstFile = true;
|
||||
boolean firstExpansion = true;
|
||||
private static final int PROG_MAX = 100;
|
||||
private VerticalFlowLayout verticalFlowLayout1 = new VerticalFlowLayout();
|
||||
private JLabel jLabel1 = new JLabel();
|
||||
private JProgressBar jProgressBar1 = new JProgressBar();
|
||||
|
||||
public CPDDialog(CPD cpd) {
|
||||
super("CPD Status Monitor");
|
||||
this.cpd = cpd;
|
||||
cpd.setListener(this);
|
||||
try {
|
||||
jbInit();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void update(String msg) {
|
||||
if (firstUpdate) {
|
||||
firstUpdate = false;
|
||||
jLabel1.setText("Updating...");
|
||||
jProgressBar1.setString(msg);
|
||||
}
|
||||
jProgressBar1.setValue(progress++ % PROG_MAX);
|
||||
}
|
||||
|
||||
public void addedFile(int fileCount, File file) {
|
||||
if (firstFile) {
|
||||
firstFile = false;
|
||||
jLabel1.setText("Adding Files...");
|
||||
jProgressBar1.setString(file.getName());
|
||||
}
|
||||
jProgressBar1.setValue(progress++ % PROG_MAX);
|
||||
}
|
||||
|
||||
|
||||
public void addingTokens(int tokenSetCount, int doneSoFar, String tokenSrcID) {
|
||||
if (firstToken) {
|
||||
firstToken = false;
|
||||
jLabel1.setText("Adding Tokens...");
|
||||
jProgressBar1.setMaximum(tokenSetCount);
|
||||
progress = 0;
|
||||
}
|
||||
jProgressBar1.setValue(progress++);
|
||||
}
|
||||
|
||||
public void expandingTile(String tileImage) {
|
||||
if (firstExpansion) {
|
||||
firstExpansion = false;
|
||||
jLabel1.setText("Expanding Tokens...");
|
||||
jProgressBar1.setMaximum(PROG_MAX);
|
||||
progress = 0;
|
||||
}
|
||||
jProgressBar1.setValue(progress++ % PROG_MAX);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
this.dispose();
|
||||
}
|
||||
|
||||
public CPDDialog() {
|
||||
try {
|
||||
jbInit();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private void jbInit() throws Exception {
|
||||
jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
jLabel1.setText("CPD Status");
|
||||
this.getContentPane().setLayout(verticalFlowLayout1);
|
||||
this.getContentPane().add(jLabel1, null);
|
||||
this.getContentPane().add(jProgressBar1, null);
|
||||
this.setSize(400,400);
|
||||
this.setVisible(true) ;
|
||||
this.show();
|
||||
}
|
||||
}
|
@ -27,11 +27,18 @@ import com.borland.primetime.properties.*;
|
||||
import com.borland.primetime.viewer.*;
|
||||
import net.sourceforge.pmd.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import net.sourceforge.pmd.cpd.CPD;
|
||||
import net.sourceforge.pmd.cpd.Results;
|
||||
import net.sourceforge.pmd.cpd.Tile;
|
||||
import net.sourceforge.pmd.cpd.CPDNullListener;
|
||||
import net.sourceforge.pmd.cpd.CPDListener;
|
||||
import javax.swing.ProgressMonitor;
|
||||
|
||||
|
||||
|
||||
public class PMDOpenTool {
|
||||
static MessageCategory msgCat = new MessageCategory("PMD Results");
|
||||
static MessageCategory cpdCat = new MessageCategory("CPD Results");
|
||||
public static ActionGroup GROUP_PMD = new ActionGroup("PMD", 'p', true);
|
||||
static Font fileNameMsgFont = new Font("Dialog", Font.BOLD, 12);
|
||||
static Font stdMsgFont = new Font("Dialog", Font.PLAIN, 12);
|
||||
@ -59,6 +66,7 @@ public class PMDOpenTool {
|
||||
JBuilderMenu.GROUP_Tools.add(GROUP_PMD);
|
||||
JBuilderToolBar.GROUP_RunBar.add(B_ACTION_PMDCheck);
|
||||
JBuilderToolBar.GROUP_RunBar.add(B_ACTION_PMDProjectCheck);
|
||||
JBuilderToolBar.GROUP_RunBar.add(B_ACTION_CPDProjectCheck);
|
||||
registerWithContentManager();
|
||||
registerWithProjectView();
|
||||
|
||||
@ -218,6 +226,19 @@ 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"))) {
|
||||
public void actionPerformed(Browser browser) {
|
||||
Runnable r = new Runnable() {
|
||||
public void run() {
|
||||
pmdCPD();
|
||||
}
|
||||
};
|
||||
Thread t = new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
};
|
||||
|
||||
static void checkCode(String srcCode, JavaFileNode node, RuleSet rules) {
|
||||
try {
|
||||
@ -304,6 +325,44 @@ public class PMDOpenTool {
|
||||
}
|
||||
}
|
||||
|
||||
private static void pmdCPD() {
|
||||
try {
|
||||
Browser.getActiveBrowser().getMessageView().clearMessages(cpdCat); //clear the message window
|
||||
CPD cpd = new CPD();
|
||||
cpd.setMinimumTileSize(25);
|
||||
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();
|
||||
if (results != null) {
|
||||
for (Iterator iter = results.getTiles(); iter.hasNext(); ) {
|
||||
Tile t = (Tile)iter.next();
|
||||
Browser.getActiveBrowser().getMessageView().addMessage(cpdCat, String.valueOf(t.getTokenCount()+": " + t.getImage()));
|
||||
}
|
||||
}
|
||||
cpdd.close();
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
Browser.getActiveBrowser().getMessageView().addMessage(cpdCat, e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main method for testing purposes
|
||||
* @param args standard arguments
|
||||
|
Reference in New Issue
Block a user