From c195365a79bbc2cbf115d0b3bbd72ea5d1c19085 Mon Sep 17 00:00:00 2001 From: Andrey Lumyanski Date: Fri, 9 Jul 2004 19:27:21 +0000 Subject: [PATCH] bug #973177 fixed git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@2792 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd-gel/etc/changelog.txt | 8 +++++ .../net/sourceforge/pmd/gel/PMDPlugin.java | 33 ++++++++++++++++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/pmd-gel/etc/changelog.txt b/pmd-gel/etc/changelog.txt index 4a33c8e893..92f410ccd5 100644 --- a/pmd-gel/etc/changelog.txt +++ b/pmd-gel/etc/changelog.txt @@ -1,3 +1,11 @@ +July 09, 2004 - 0.7 +Author: Andrey Lumyanski +Some bugs fixed (also #973177). + +May 24, 2004 - 0.6: +Rewritten by Andrey Lumyanski +Now any ruleset can be selected. All messages show in Gel Messages Console + October 15, 2003 - 0.5: Backed up essentially to 0.2 - the newer code was locking up. Updated to pmd-1.2.2. diff --git a/pmd-gel/src/net/sourceforge/pmd/gel/PMDPlugin.java b/pmd-gel/src/net/sourceforge/pmd/gel/PMDPlugin.java index e6dc1f6f51..c45298a37f 100644 --- a/pmd-gel/src/net/sourceforge/pmd/gel/PMDPlugin.java +++ b/pmd-gel/src/net/sourceforge/pmd/gel/PMDPlugin.java @@ -14,6 +14,8 @@ import java.io.StringReader; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Properties; +import java.util.StringTokenizer; import javax.swing.ProgressMonitor; @@ -79,14 +81,26 @@ public class PMDPlugin implements GelAction, Runnable, ReportListener { report = new Report(); report.addListener(this); gel.clearMessages(); + if (gel.getProject() == null && gel.getEditor() == null) { + gel.showMessage("There are no java files to analyse!"); + return; + } gel.addMessage("PMD started"); try { RuleSetFactory rsf = new RuleSetFactory(); - Iterator it = rsf.getRegisteredRuleSets(); + Properties props = new Properties(); + props.load(rsf.getClass().getResourceAsStream("/rulesets/rulesets.properties")); + String rulesetFilenames = props.getProperty("rulesets.filenames"); ArrayList listOfRuleSet = new ArrayList(); - while (it.hasNext()) { - listOfRuleSet.add((RuleSet)it.next()); + StringTokenizer st = new StringTokenizer(rulesetFilenames, ","); + RuleSet ruleSet = null; + String rsFileName = null; + while (st.hasMoreTokens()) { + rsFileName = st.nextToken(); + ruleSet = rsf.createRuleSet(rsFileName); + ruleSet.setFileName(rsFileName); + listOfRuleSet.add(ruleSet); } arrayRuleSet = new RuleSet[listOfRuleSet.size()]; for (int i = 0; i < arrayRuleSet.length; ++i) { @@ -103,7 +117,7 @@ public class PMDPlugin implements GelAction, Runnable, ReportListener { if (gel.getProject() != null) { listOfFiles = new ArrayList(); - it = gel.getProject().getSourcePaths().iterator(); + Iterator it = gel.getProject().getSourcePaths().iterator(); FileFinder ff = new FileFinder(); FilenameFilter filter = new JavaLanguage.JavaFileOrDirectoryFilter(); @@ -116,6 +130,15 @@ public class PMDPlugin implements GelAction, Runnable, ReportListener { listOfFiles.addAll(files); } } + if (listOfFiles.isEmpty()) { + if (gel.getEditor() != null) { + gel.addMessage("WARNING: There are no java files in project source paths. Try to analyse current data in editor."); + } else { + gel.addMessage("WARNING: There are no java files to analyse."); + gel.addMessage("PMD finished"); + return; + } + } } else { String name = gel.getEditor().getFileName(); @@ -176,7 +199,7 @@ public class PMDPlugin implements GelAction, Runnable, ReportListener { if (ruleSet.size() > 0) { ctx.setReport(report); - if (gel.getProject() == null) { + if (gel.getProject() == null || listOfFiles.isEmpty()) { String code = gel.getEditor().getContents(); String name = gel.getEditor().getFileName();