diff --git a/pmd/src/net/sourceforge/pmd/ant/PMDTask.java b/pmd/src/net/sourceforge/pmd/ant/PMDTask.java index e407bf9a8a..2139e8a144 100644 --- a/pmd/src/net/sourceforge/pmd/ant/PMDTask.java +++ b/pmd/src/net/sourceforge/pmd/ant/PMDTask.java @@ -30,6 +30,8 @@ import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguageVersion; import net.sourceforge.pmd.renderers.AbstractRenderer; import net.sourceforge.pmd.renderers.Renderer; +import net.sourceforge.pmd.util.IOUtil; +import net.sourceforge.pmd.util.StringUtil; import net.sourceforge.pmd.util.datasource.DataSource; import net.sourceforge.pmd.util.datasource.FileDataSource; import net.sourceforge.pmd.util.log.AntLogHandler; @@ -199,15 +201,14 @@ public class PMDTask extends Task { ruleSetFactory.setClassLoader(configuration.getClassLoader()); try { // This is just used to validate and display rules. Each thread will create its own ruleset - RuleSets rules; ruleSetFactory.setMinimumPriority(configuration.getMinimumPriority()); ruleSetFactory.setWarnDeprecated(true); String ruleSets = configuration.getRuleSets(); - if (ruleSets != null) { + if (StringUtil.isNotEmpty(ruleSets)) { // Substitute env variables/properties configuration.setRuleSets(getProject().replaceProperties(ruleSets)); } - rules = ruleSetFactory.createRuleSets(configuration.getRuleSets()); + RuleSets rules = ruleSetFactory.createRuleSets(configuration.getRuleSets()); ruleSetFactory.setWarnDeprecated(false); logRulesUsed(rules); } catch (RuleSetNotFoundException e) { @@ -280,6 +281,7 @@ public class PMDTask extends Task { PrintWriter printWriter = new PrintWriter(strWriter); pmde.getCause().printStackTrace(printWriter); log(strWriter.toString(), Project.MSG_VERBOSE); + IOUtil.closeQuietly(printWriter); } if (pmde.getCause() != null && pmde.getCause().getMessage() != null) { log(pmde.getCause().getMessage(), Project.MSG_VERBOSE); diff --git a/pmd/src/net/sourceforge/pmd/lang/java/rule/comments/CommentContentRule.java b/pmd/src/net/sourceforge/pmd/lang/java/rule/comments/CommentContentRule.java index 939723212b..cafa4b9dd5 100644 --- a/pmd/src/net/sourceforge/pmd/lang/java/rule/comments/CommentContentRule.java +++ b/pmd/src/net/sourceforge/pmd/lang/java/rule/comments/CommentContentRule.java @@ -13,6 +13,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit; import net.sourceforge.pmd.lang.java.ast.Comment; import net.sourceforge.pmd.lang.rule.properties.BooleanProperty; import net.sourceforge.pmd.lang.rule.properties.StringMultiProperty; +import net.sourceforge.pmd.util.CollectionUtil; import net.sourceforge.pmd.util.StringUtil; /** @@ -136,7 +137,8 @@ public class CommentContentRule extends AbstractCommentRule { } public boolean hasDissallowedTerms() { - return getProperty(DISSALLOWED_TERMS_DESCRIPTOR).length > 0; + String[] terms = getProperty(DISSALLOWED_TERMS_DESCRIPTOR); + return CollectionUtil.isNotEmpty(terms); } public String dysfunctionReason() { diff --git a/pmd/src/net/sourceforge/pmd/lang/java/rule/coupling/LoosePackageCouplingRule.java b/pmd/src/net/sourceforge/pmd/lang/java/rule/coupling/LoosePackageCouplingRule.java index d5ba7a6d97..8789e22bab 100644 --- a/pmd/src/net/sourceforge/pmd/lang/java/rule/coupling/LoosePackageCouplingRule.java +++ b/pmd/src/net/sourceforge/pmd/lang/java/rule/coupling/LoosePackageCouplingRule.java @@ -10,6 +10,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTPackageDeclaration; import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule; import net.sourceforge.pmd.lang.rule.properties.StringMultiProperty; +import net.sourceforge.pmd.util.CollectionUtil; /** * The loose package coupling Rule can be used to ensure coupling outside of @@ -32,10 +33,10 @@ import net.sourceforge.pmd.lang.rule.properties.StringMultiProperty; */ public class LoosePackageCouplingRule extends AbstractJavaRule { - private static final StringMultiProperty PACKAGES_DESCRIPTOR = new StringMultiProperty("packages", "Restricted packages", + public static final StringMultiProperty PACKAGES_DESCRIPTOR = new StringMultiProperty("packages", "Restricted packages", new String[] {}, 1.0f, ','); - private static final StringMultiProperty CLASSES_DESCRIPTOR = new StringMultiProperty("classes", "Allowed classes", + public static final StringMultiProperty CLASSES_DESCRIPTOR = new StringMultiProperty("classes", "Allowed classes", new String[] {}, 2.0f, ','); // The package of this source file @@ -122,11 +123,11 @@ public class LoosePackageCouplingRule extends AbstractJavaRule { return false; } - public boolean checksNothing() { - return getProperty(PACKAGES_DESCRIPTOR).length == 0 && - getProperty(CLASSES_DESCRIPTOR).length == 0 ; + return + CollectionUtil.isEmpty(getProperty(PACKAGES_DESCRIPTOR)) && + CollectionUtil.isEmpty(getProperty(CLASSES_DESCRIPTOR)) ; } public String dysfunctionReason() {