Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
[FIXED JENKINS-20516] Do show warning if rule description is not found.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Jan 5, 2017
1 parent 11ec337 commit fb3dfc8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Expand Up @@ -52,13 +52,19 @@ public void initialize() {
"imports", "javadoc", "metrics", "misc", "modifier", "naming", "regexp", "reporting",
"sizes", "whitespace"};
for (int i = 0; i < ruleFiles.length; i++) {
InputStream inputStream = CheckStyleRules.class.getResourceAsStream("config_" + ruleFiles[i] + ".xml");
String ruleFile = ruleFiles[i];
InputStream inputStream = CheckStyleRules.class.getResourceAsStream("config_" + ruleFile + ".xml");
Digester digester = createDigester();
List<Rule> rules = new ArrayList<Rule>();
digester.push(rules);
digester.parse(inputStream);
for (Rule rule : rules) {
rulesByName.put(rule.getName(), rule);
if (StringUtils.isNotBlank(rule.getDescription())) {
rulesByName.put(rule.getName(), rule);
}
else {
System.out.printf("%s: %s\n", ruleFile, rule.getName());
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/checkstyle/rules/Rule.java
Expand Up @@ -9,7 +9,7 @@
*/
public class Rule {
/** Description to indicate that the rules stored in this plug-in don't match with the generators version. */
static final String UNDEFINED_DESCRIPTION = "No description available. Please upgrade to latest checkstyle version.";
static final String UNDEFINED_DESCRIPTION = StringUtils.EMPTY;
/** The name of the subsection that defines a description in the docbook files. */
private static final String DESCRIPTION_SUBSECTION_NAME = "Description";
/** The name of this rule. */
Expand Down
Expand Up @@ -17,15 +17,15 @@ public void checkRuleLoader() {
CheckStyleRules reader = CheckStyleRules.getInstance();
reader.initialize();

assertEquals("Wrong number of rules detected.", 163, reader.getRules().size());
assertEquals("Wrong number of rules detected.", 158, reader.getRules().size());
assertNotNull("No EmptyBlock rule found.", reader.getRule("EmptyBlock"));
assertEquals("Description for EmptyBlock found.", "<p> Checks for empty blocks. </p>", reader.getRule("EmptyBlock").getDescription());
assertNotSame("No description for AnnotationUseStyle found.", Rule.UNDEFINED_DESCRIPTION, reader.getRule("AnnotationUseStyle").getDescription());
assertNotSame("No description for AnnotationUseStyle found.", Rule.UNDEFINED_DESCRIPTION, reader.getDescription("AnnotationUseStyle"));
assertSame("No default text available for undefined rule.", Rule.UNDEFINED_DESCRIPTION, reader.getRule("Undefined").getDescription());

for (Rule rule : reader.getRules()) {
assertNotSame("Rule " + rule.getName() + " has no description.", Rule.UNDEFINED_DESCRIPTION, rule.getDescription());
assertNotEquals("Rule " + rule.getName() + " has no description.", Rule.UNDEFINED_DESCRIPTION, rule.getDescription());
}
}
}

0 comments on commit fb3dfc8

Please sign in to comment.