diff --git a/pmd-jbuilder/lib/PMDOpenTool.jar b/pmd-jbuilder/lib/PMDOpenTool.jar index a53ed567cc..0078bfec74 100644 Binary files a/pmd-jbuilder/lib/PMDOpenTool.jar and b/pmd-jbuilder/lib/PMDOpenTool.jar differ diff --git a/pmd-jbuilder/src/images/cpd.gif b/pmd-jbuilder/src/images/cpd.gif new file mode 100644 index 0000000000..5efb7c8b44 Binary files /dev/null and b/pmd-jbuilder/src/images/cpd.gif differ diff --git a/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/CPDDialog.java b/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/CPDDialog.java new file mode 100644 index 0000000000..5e19f37137 --- /dev/null +++ b/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/CPDDialog.java @@ -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(); + } +} \ No newline at end of file diff --git a/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java b/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java index 1000606444..a5c590b70d 100644 --- a/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java +++ b/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java @@ -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