@ -185,6 +185,7 @@ are deprecated as internal API.
|
|||||||
* [#2727](https://github.com/pmd/pmd/pull/2727): Cleanup: replace indexOf() < 0 with contains - [XenoAmess](https://github.com/XenoAmess)
|
* [#2727](https://github.com/pmd/pmd/pull/2727): Cleanup: replace indexOf() < 0 with contains - [XenoAmess](https://github.com/XenoAmess)
|
||||||
* [#2728](https://github.com/pmd/pmd/pull/2728): Cleanup: javadoc issues - [XenoAmess](https://github.com/XenoAmess)
|
* [#2728](https://github.com/pmd/pmd/pull/2728): Cleanup: javadoc issues - [XenoAmess](https://github.com/XenoAmess)
|
||||||
* [#2729](https://github.com/pmd/pmd/pull/2729): Cleanup: use print instead of printf if no format exists - [XenoAmess](https://github.com/XenoAmess)
|
* [#2729](https://github.com/pmd/pmd/pull/2729): Cleanup: use print instead of printf if no format exists - [XenoAmess](https://github.com/XenoAmess)
|
||||||
|
* [#2730](https://github.com/pmd/pmd/pull/2730): Cleanup: StringBuilder issues - [XenoAmess](https://github.com/XenoAmess)
|
||||||
* [#2731](https://github.com/pmd/pmd/pull/2731): Cleanup: avoid compiling Patterns repeatedly - [XenoAmess](https://github.com/XenoAmess)
|
* [#2731](https://github.com/pmd/pmd/pull/2731): Cleanup: avoid compiling Patterns repeatedly - [XenoAmess](https://github.com/XenoAmess)
|
||||||
* [#2732](https://github.com/pmd/pmd/pull/2732): Cleanup: use StandardCharsets instead of Charset.forName - [XenoAmess](https://github.com/XenoAmess)
|
* [#2732](https://github.com/pmd/pmd/pull/2732): Cleanup: use StandardCharsets instead of Charset.forName - [XenoAmess](https://github.com/XenoAmess)
|
||||||
* [#2734](https://github.com/pmd/pmd/pull/2734): Cleanup: use try with resources - [XenoAmess](https://github.com/XenoAmess)
|
* [#2734](https://github.com/pmd/pmd/pull/2734): Cleanup: use try with resources - [XenoAmess](https://github.com/XenoAmess)
|
||||||
|
@ -60,10 +60,10 @@ public final class PMDCommandLineInterface {
|
|||||||
public static String buildUsageText(JCommander jcommander) {
|
public static String buildUsageText(JCommander jcommander) {
|
||||||
StringBuilder usage = new StringBuilder();
|
StringBuilder usage = new StringBuilder();
|
||||||
|
|
||||||
String allCommandsDescription = null;
|
StringBuilder allCommandsDescription = null;
|
||||||
if (jcommander != null && jcommander.getCommands() != null) {
|
if (jcommander != null && jcommander.getCommands() != null) {
|
||||||
for (String command : jcommander.getCommands().keySet()) {
|
for (String command : jcommander.getCommands().keySet()) {
|
||||||
allCommandsDescription += jcommander.getCommandDescription(command) + PMD.EOL;
|
allCommandsDescription.append(jcommander.getCommandDescription(command)).append(PMD.EOL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ public final class PMDCommandLineInterface {
|
|||||||
Renderer renderer = RendererFactory.createRenderer(reportName, new Properties());
|
Renderer renderer = RendererFactory.createRenderer(reportName, new Properties());
|
||||||
buf.append(" ").append(reportName).append(": ");
|
buf.append(" ").append(reportName).append(": ");
|
||||||
if (!reportName.equals(renderer.getName())) {
|
if (!reportName.equals(renderer.getName())) {
|
||||||
buf.append(" Deprecated alias for '" + renderer.getName()).append(PMD.EOL);
|
buf.append(" Deprecated alias for '").append(renderer.getName()).append(PMD.EOL);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
buf.append(renderer.getDescription()).append(PMD.EOL);
|
buf.append(renderer.getDescription()).append(PMD.EOL);
|
||||||
|
@ -33,9 +33,8 @@ public class VSRenderer implements Renderer, CPDRenderer {
|
|||||||
for (Iterator<Mark> iterator = match.iterator(); iterator.hasNext();) {
|
for (Iterator<Mark> iterator = match.iterator(); iterator.hasNext();) {
|
||||||
mark = iterator.next();
|
mark = iterator.next();
|
||||||
writer.append(mark.getFilename())
|
writer.append(mark.getFilename())
|
||||||
.append('(').append(String.valueOf(mark.getBeginLine())).append("):")
|
.append('(').append(String.valueOf(mark.getBeginLine())).append("):")
|
||||||
.append(" Between lines " + mark.getBeginLine() + " and "
|
.append(" Between lines ").append(String.valueOf(mark.getBeginLine())).append(" and ").append(String.valueOf(mark.getBeginLine() + match.getLineCount())).append(PMD.EOL);
|
||||||
+ (mark.getBeginLine() + match.getLineCount()) + PMD.EOL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
writer.flush();
|
writer.flush();
|
||||||
|
@ -131,8 +131,7 @@ public class ReportHTMLPrintVisitor extends ReportVisitor {
|
|||||||
|
|
||||||
vnode.getParent().addNumberOfViolation(1);
|
vnode.getParent().addNumberOfViolation(1);
|
||||||
RuleViolation vio = vnode.getRuleViolation();
|
RuleViolation vio = vnode.getRuleViolation();
|
||||||
classBuf.append("<tr>" + " <td>" + vio.getMethodName() + "</td>" + " <td>" + this.displayRuleViolation(vio)
|
classBuf.append("<tr>" + " <td>").append(vio.getMethodName()).append("</td>").append(" <td>").append(this.displayRuleViolation(vio)).append("</td>").append("</tr>");
|
||||||
+ "</td>" + "</tr>");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderPackage(PackageNode pnode) {
|
private void renderPackage(PackageNode pnode) {
|
||||||
|
@ -145,27 +145,38 @@ public class CodeClimateRenderer extends AbstractIncrementingRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private <T> String getBody() {
|
private <T> String getBody() {
|
||||||
String result = "## " + rule.getName() + "\\n\\n" + "Since: PMD " + rule.getSince() + "\\n\\n" + "Priority: "
|
StringBuilder result = new StringBuilder();
|
||||||
+ rule.getPriority() + "\\n\\n"
|
result.append("## ")
|
||||||
+ "[Categories](https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#categories): "
|
.append(rule.getName())
|
||||||
+ Arrays.toString(getCategories()).replaceAll("[\\[\\]]", "") + "\\n\\n"
|
.append("\\n\\n")
|
||||||
+ "[Remediation Points](https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#remediation-points): "
|
.append("Since: PMD ")
|
||||||
+ getRemediationPoints() + "\\n\\n" + cleaned(rule.getDescription());
|
.append(rule.getSince())
|
||||||
|
.append("\\n\\n")
|
||||||
|
.append("Priority: ")
|
||||||
|
.append(rule.getPriority())
|
||||||
|
.append("\\n\\n")
|
||||||
|
.append("[Categories](https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#categories): ")
|
||||||
|
.append(Arrays.toString(getCategories()).replaceAll("[\\[\\]]", ""))
|
||||||
|
.append("\\n\\n")
|
||||||
|
.append("[Remediation Points](https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#remediation-points): ")
|
||||||
|
.append(getRemediationPoints())
|
||||||
|
.append("\\n\\n")
|
||||||
|
.append(cleaned(rule.getDescription()));
|
||||||
|
|
||||||
if (!rule.getExamples().isEmpty()) {
|
if (!rule.getExamples().isEmpty()) {
|
||||||
result += "\\n\\n### Example:\\n\\n";
|
result.append("\\n\\n### Example:\\n\\n");
|
||||||
|
|
||||||
for (String snippet : rule.getExamples()) {
|
for (String snippet : rule.getExamples()) {
|
||||||
String exampleSnippet = snippet.replaceAll("\\n", "\\\\n");
|
String exampleSnippet = snippet.replaceAll("\\n", "\\\\n");
|
||||||
exampleSnippet = exampleSnippet.replaceAll("\\t", "\\\\t");
|
exampleSnippet = exampleSnippet.replaceAll("\\t", "\\\\t");
|
||||||
result += "```java\\n" + exampleSnippet + "\\n``` ";
|
result.append("```java\\n").append(exampleSnippet).append("\\n``` ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rule.getPropertyDescriptors().isEmpty()) {
|
if (!rule.getPropertyDescriptors().isEmpty()) {
|
||||||
result += "\\n\\n### [PMD properties](" + PMD_PROPERTIES_URL + ")\\n\\n";
|
result.append("\\n\\n### [PMD properties](").append(PMD_PROPERTIES_URL).append(")\\n\\n");
|
||||||
result += "Name | Value | Description\\n";
|
result.append("Name | Value | Description\\n");
|
||||||
result += "--- | --- | ---\\n";
|
result.append("--- | --- | ---\\n");
|
||||||
|
|
||||||
for (PropertyDescriptor<?> property : rule.getPropertyDescriptors()) {
|
for (PropertyDescriptor<?> property : rule.getPropertyDescriptors()) {
|
||||||
String propertyName = property.name().replaceAll("\\_", "\\\\_");
|
String propertyName = property.name().replaceAll("\\_", "\\\\_");
|
||||||
@ -182,10 +193,10 @@ public class CodeClimateRenderer extends AbstractIncrementingRenderer {
|
|||||||
}
|
}
|
||||||
propertyValue = propertyValue.replaceAll("(\n|\r\n|\r)", "\\\\n");
|
propertyValue = propertyValue.replaceAll("(\n|\r\n|\r)", "\\\\n");
|
||||||
|
|
||||||
result += propertyName + " | " + propertyValue + " | " + property.description() + "\\n";
|
result.append(propertyName).append(" | ").append(propertyValue).append(" | ").append(property.description()).append("\\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cleaned(result);
|
return cleaned(result.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String cleaned(String original) {
|
private String cleaned(String original) {
|
||||||
|
@ -128,12 +128,13 @@ public class HTMLRenderer extends AbstractIncrementingRenderer {
|
|||||||
buf.append(" bgcolor=\"lightgrey\"");
|
buf.append(" bgcolor=\"lightgrey\"");
|
||||||
}
|
}
|
||||||
colorize = !colorize;
|
colorize = !colorize;
|
||||||
buf.append("> " + PMD.EOL);
|
buf.append("> ").append(PMD.EOL);
|
||||||
buf.append("<td align=\"center\">" + violationCount + "</td>" + PMD.EOL);
|
buf.append("<td align=\"center\">").append(violationCount).append("</td>").append(PMD.EOL);
|
||||||
buf.append("<td width=\"*%\">"
|
buf.append("<td width=\"*%\">")
|
||||||
+ renderFileName(rv.getFilename(), rv.getBeginLine())
|
.append(renderFileName(rv.getFilename(), rv.getBeginLine()))
|
||||||
+ "</td>" + PMD.EOL);
|
.append("</td>")
|
||||||
buf.append("<td align=\"center\" width=\"5%\">" + Integer.toString(rv.getBeginLine()) + "</td>" + PMD.EOL);
|
.append(PMD.EOL);
|
||||||
|
buf.append("<td align=\"center\" width=\"5%\">").append(rv.getBeginLine()).append("</td>").append(PMD.EOL);
|
||||||
|
|
||||||
String d = StringEscapeUtils.escapeHtml4(rv.getDescription());
|
String d = StringEscapeUtils.escapeHtml4(rv.getDescription());
|
||||||
|
|
||||||
@ -141,8 +142,8 @@ public class HTMLRenderer extends AbstractIncrementingRenderer {
|
|||||||
if (StringUtils.isNotBlank(infoUrl)) {
|
if (StringUtils.isNotBlank(infoUrl)) {
|
||||||
d = "<a href=\"" + infoUrl + "\">" + d + "</a>";
|
d = "<a href=\"" + infoUrl + "\">" + d + "</a>";
|
||||||
}
|
}
|
||||||
buf.append("<td width=\"*\">" + d + "</td>" + PMD.EOL);
|
buf.append("<td width=\"*\">").append(d).append("</td>").append(PMD.EOL);
|
||||||
buf.append("</tr>" + PMD.EOL);
|
buf.append("</tr>").append(PMD.EOL);
|
||||||
writer.write(buf.toString());
|
writer.write(buf.toString());
|
||||||
violationCount++;
|
violationCount++;
|
||||||
}
|
}
|
||||||
@ -182,10 +183,10 @@ public class HTMLRenderer extends AbstractIncrementingRenderer {
|
|||||||
buf.append(" bgcolor=\"lightgrey\"");
|
buf.append(" bgcolor=\"lightgrey\"");
|
||||||
}
|
}
|
||||||
colorize = !colorize;
|
colorize = !colorize;
|
||||||
buf.append("> " + PMD.EOL);
|
buf.append("> ").append(PMD.EOL);
|
||||||
buf.append("<td>" + renderFileName(pe.getFile(), -1) + "</td>" + PMD.EOL);
|
buf.append("<td>").append(renderFileName(pe.getFile(), -1)).append("</td>").append(PMD.EOL);
|
||||||
buf.append("<td><pre>" + pe.getDetail() + "</pre></td>" + PMD.EOL);
|
buf.append("<td><pre>").append(pe.getDetail()).append("</pre></td>").append(PMD.EOL);
|
||||||
buf.append("</tr>" + PMD.EOL);
|
buf.append("</tr>").append(PMD.EOL);
|
||||||
writer.write(buf.toString());
|
writer.write(buf.toString());
|
||||||
}
|
}
|
||||||
writer.write("</table>");
|
writer.write("</table>");
|
||||||
@ -210,15 +211,14 @@ public class HTMLRenderer extends AbstractIncrementingRenderer {
|
|||||||
buf.append(" bgcolor=\"lightgrey\"");
|
buf.append(" bgcolor=\"lightgrey\"");
|
||||||
}
|
}
|
||||||
colorize = !colorize;
|
colorize = !colorize;
|
||||||
buf.append("> " + PMD.EOL);
|
buf.append("> ").append(PMD.EOL);
|
||||||
RuleViolation rv = sv.getRuleViolation();
|
RuleViolation rv = sv.getRuleViolation();
|
||||||
buf.append("<td align=\"left\">" + renderFileName(rv.getFilename(), rv.getBeginLine()) + "</td>" + PMD.EOL);
|
buf.append("<td align=\"left\">").append(renderFileName(rv.getFilename(), rv.getBeginLine())).append("</td>").append(PMD.EOL);
|
||||||
buf.append("<td align=\"center\">" + rv.getBeginLine() + "</td>" + PMD.EOL);
|
buf.append("<td align=\"center\">").append(rv.getBeginLine()).append("</td>").append(PMD.EOL);
|
||||||
buf.append("<td align=\"center\">" + renderRuleName(rv.getRule()) + "</td>" + PMD.EOL);
|
buf.append("<td align=\"center\">").append(renderRuleName(rv.getRule())).append("</td>").append(PMD.EOL);
|
||||||
buf.append("<td align=\"center\">" + (sv.suppressedByNOPMD() ? "NOPMD" : "Annotation") + "</td>" + PMD.EOL);
|
buf.append("<td align=\"center\">").append(sv.suppressedByNOPMD() ? "NOPMD" : "Annotation").append("</td>").append(PMD.EOL);
|
||||||
buf.append("<td align=\"center\">" + (sv.getUserMessage() == null ? "" : sv.getUserMessage()) + "</td>"
|
buf.append("<td align=\"center\">").append(sv.getUserMessage() == null ? "" : sv.getUserMessage()).append("</td>").append(PMD.EOL);
|
||||||
+ PMD.EOL);
|
buf.append("</tr>").append(PMD.EOL);
|
||||||
buf.append("</tr>" + PMD.EOL);
|
|
||||||
writer.write(buf.toString());
|
writer.write(buf.toString());
|
||||||
}
|
}
|
||||||
writer.write("</table>");
|
writer.write("</table>");
|
||||||
@ -243,10 +243,10 @@ public class HTMLRenderer extends AbstractIncrementingRenderer {
|
|||||||
buf.append(" bgcolor=\"lightgrey\"");
|
buf.append(" bgcolor=\"lightgrey\"");
|
||||||
}
|
}
|
||||||
colorize = !colorize;
|
colorize = !colorize;
|
||||||
buf.append("> " + PMD.EOL);
|
buf.append("> ").append(PMD.EOL);
|
||||||
buf.append("<td>" + renderRuleName(ce.rule()) + "</td>" + PMD.EOL);
|
buf.append("<td>").append(renderRuleName(ce.rule())).append("</td>").append(PMD.EOL);
|
||||||
buf.append("<td>" + ce.issue() + "</td>" + PMD.EOL);
|
buf.append("<td>").append(ce.issue()).append("</td>").append(PMD.EOL);
|
||||||
buf.append("</tr>" + PMD.EOL);
|
buf.append("</tr>").append(PMD.EOL);
|
||||||
writer.write(buf.toString());
|
writer.write(buf.toString());
|
||||||
}
|
}
|
||||||
writer.write("</table>");
|
writer.write("</table>");
|
||||||
|
@ -66,7 +66,7 @@ public class IDEAJRenderer extends AbstractIncrementingRenderer {
|
|||||||
while (violations.hasNext()) {
|
while (violations.hasNext()) {
|
||||||
buf.setLength(0);
|
buf.setLength(0);
|
||||||
RuleViolation rv = violations.next();
|
RuleViolation rv = violations.next();
|
||||||
buf.append(rv.getDescription() + PMD.EOL);
|
buf.append(rv.getDescription()).append(PMD.EOL);
|
||||||
buf.append(" at ").append(getFullyQualifiedClassName(rv.getFilename(), sourcePath)).append(".method(");
|
buf.append(" at ").append(getFullyQualifiedClassName(rv.getFilename(), sourcePath)).append(".method(");
|
||||||
buf.append(getSimpleFileName(rv.getFilename())).append(':').append(rv.getBeginLine()).append(')')
|
buf.append(getSimpleFileName(rv.getFilename())).append(':').append(rv.getBeginLine()).append(')')
|
||||||
.append(PMD.EOL);
|
.append(PMD.EOL);
|
||||||
|
@ -125,17 +125,41 @@ public class TextColorRenderer extends AbstractAccumulatingRenderer {
|
|||||||
String nextFile = determineFileName(rv.getFilename());
|
String nextFile = determineFileName(rv.getFilename());
|
||||||
if (!nextFile.equals(lastFile)) {
|
if (!nextFile.equals(lastFile)) {
|
||||||
lastFile = nextFile;
|
lastFile = nextFile;
|
||||||
buf.append(this.yellowBold + "*" + this.colorReset + " file: " + this.whiteBold
|
buf.append(this.yellowBold)
|
||||||
+ this.getRelativePath(lastFile) + this.colorReset + PMD.EOL);
|
.append("*")
|
||||||
|
.append(this.colorReset)
|
||||||
|
.append(" file: ")
|
||||||
|
.append(this.whiteBold)
|
||||||
|
.append(this.getRelativePath(lastFile))
|
||||||
|
.append(this.colorReset)
|
||||||
|
.append(PMD.EOL);
|
||||||
}
|
}
|
||||||
buf.append(
|
buf.append(this.green)
|
||||||
this.green + " src: " + this.cyan + lastFile.substring(lastFile.lastIndexOf(File.separator) + 1)
|
.append(" src: ")
|
||||||
+ this.colorReset + ":" + this.cyan + rv.getBeginLine()
|
.append(this.cyan)
|
||||||
+ (rv.getEndLine() == -1 ? "" : ":" + rv.getEndLine()) + this.colorReset + PMD.EOL);
|
.append(lastFile.substring(lastFile.lastIndexOf(File.separator) + 1))
|
||||||
buf.append(this.green + " rule: " + this.colorReset + rv.getRule().getName() + PMD.EOL);
|
.append(this.colorReset).append(":")
|
||||||
buf.append(this.green + " msg: " + this.colorReset + rv.getDescription() + PMD.EOL);
|
.append(this.cyan)
|
||||||
buf.append(this.green + " code: " + this.colorReset + this.getLine(lastFile, rv.getBeginLine()) + PMD.EOL
|
.append(rv.getBeginLine())
|
||||||
+ PMD.EOL);
|
.append(rv.getEndLine() == -1 ? "" : ":" + rv.getEndLine())
|
||||||
|
.append(this.colorReset)
|
||||||
|
.append(PMD.EOL);
|
||||||
|
buf.append(this.green)
|
||||||
|
.append(" rule: ")
|
||||||
|
.append(this.colorReset)
|
||||||
|
.append(rv.getRule().getName())
|
||||||
|
.append(PMD.EOL);
|
||||||
|
buf.append(this.green)
|
||||||
|
.append(" msg: ")
|
||||||
|
.append(this.colorReset)
|
||||||
|
.append(rv.getDescription())
|
||||||
|
.append(PMD.EOL);
|
||||||
|
buf.append(this.green)
|
||||||
|
.append(" code: ")
|
||||||
|
.append(this.colorReset)
|
||||||
|
.append(this.getLine(lastFile, rv.getBeginLine()))
|
||||||
|
.append(PMD.EOL)
|
||||||
|
.append(PMD.EOL);
|
||||||
writer.write(buf.toString());
|
writer.write(buf.toString());
|
||||||
}
|
}
|
||||||
writer.write(PMD.EOL + PMD.EOL);
|
writer.write(PMD.EOL + PMD.EOL);
|
||||||
@ -155,11 +179,26 @@ public class TextColorRenderer extends AbstractAccumulatingRenderer {
|
|||||||
String nextFile = determineFileName(error.getFile());
|
String nextFile = determineFileName(error.getFile());
|
||||||
if (!nextFile.equals(lastFile)) {
|
if (!nextFile.equals(lastFile)) {
|
||||||
lastFile = nextFile;
|
lastFile = nextFile;
|
||||||
buf.append(this.redBold + "*" + this.colorReset + " file: " + this.whiteBold
|
buf.append(this.redBold)
|
||||||
+ this.getRelativePath(lastFile) + this.colorReset + PMD.EOL);
|
.append("*")
|
||||||
|
.append(this.colorReset)
|
||||||
|
.append(" file: ")
|
||||||
|
.append(this.whiteBold)
|
||||||
|
.append(this.getRelativePath(lastFile))
|
||||||
|
.append(this.colorReset)
|
||||||
|
.append(PMD.EOL);
|
||||||
}
|
}
|
||||||
buf.append(this.green + " err: " + this.cyan + error.getMsg() + this.colorReset + PMD.EOL)
|
buf.append(this.green)
|
||||||
.append(this.red).append(error.getDetail()).append(colorReset).append(PMD.EOL).append(PMD.EOL);
|
.append(" err: ")
|
||||||
|
.append(this.cyan)
|
||||||
|
.append(error.getMsg())
|
||||||
|
.append(this.colorReset)
|
||||||
|
.append(PMD.EOL)
|
||||||
|
.append(this.red)
|
||||||
|
.append(error.getDetail())
|
||||||
|
.append(colorReset)
|
||||||
|
.append(PMD.EOL)
|
||||||
|
.append(PMD.EOL);
|
||||||
writer.write(buf.toString());
|
writer.write(buf.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,9 +206,21 @@ public class TextColorRenderer extends AbstractAccumulatingRenderer {
|
|||||||
buf.setLength(0);
|
buf.setLength(0);
|
||||||
numberOfErrors++;
|
numberOfErrors++;
|
||||||
Report.ConfigurationError error = i.next();
|
Report.ConfigurationError error = i.next();
|
||||||
buf.append(this.redBold + "*" + this.colorReset + " rule: " + this.whiteBold
|
buf.append(this.redBold)
|
||||||
+ error.rule().getName() + this.colorReset + PMD.EOL);
|
.append("*")
|
||||||
buf.append(this.green + " err: " + this.cyan + error.issue() + this.colorReset + PMD.EOL + PMD.EOL);
|
.append(this.colorReset)
|
||||||
|
.append(" rule: ")
|
||||||
|
.append(this.whiteBold)
|
||||||
|
.append(error.rule().getName())
|
||||||
|
.append(this.colorReset)
|
||||||
|
.append(PMD.EOL);
|
||||||
|
buf.append(this.green)
|
||||||
|
.append(" err: ")
|
||||||
|
.append(this.cyan)
|
||||||
|
.append(error.issue())
|
||||||
|
.append(this.colorReset)
|
||||||
|
.append(PMD.EOL)
|
||||||
|
.append(PMD.EOL);
|
||||||
writer.write(buf.toString());
|
writer.write(buf.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public class TextPadRenderer extends AbstractIncrementingRenderer {
|
|||||||
RuleViolation rv = violations.next();
|
RuleViolation rv = violations.next();
|
||||||
buf.setLength(0);
|
buf.setLength(0);
|
||||||
// Filename
|
// Filename
|
||||||
buf.append(determineFileName(rv.getFilename()) + "(");
|
buf.append(determineFileName(rv.getFilename())).append("(");
|
||||||
// Line number
|
// Line number
|
||||||
buf.append(Integer.toString(rv.getBeginLine())).append(", ");
|
buf.append(Integer.toString(rv.getBeginLine())).append(", ");
|
||||||
// Name of violated rule
|
// Name of violated rule
|
||||||
|
@ -68,9 +68,8 @@ public class VBHTMLRenderer extends AbstractIncrementingRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
colorize = !colorize;
|
colorize = !colorize;
|
||||||
sb.append("<td width=\"50\" align=\"right\"><font class=body>" + rv.getBeginLine()
|
sb.append("<td width=\"50\" align=\"right\"><font class=body>").append(rv.getBeginLine()).append(" </font></td>");
|
||||||
+ " </font></td>");
|
sb.append("<td><font class=body>").append(rv.getDescription()).append("</font></td>");
|
||||||
sb.append("<td><font class=body>" + rv.getDescription() + "</font></td>");
|
|
||||||
sb.append("</tr>");
|
sb.append("</tr>");
|
||||||
sb.append(lineSep);
|
sb.append(lineSep);
|
||||||
writer.write(sb.toString());
|
writer.write(sb.toString());
|
||||||
@ -130,7 +129,7 @@ public class VBHTMLRenderer extends AbstractIncrementingRenderer {
|
|||||||
|
|
||||||
private String header() {
|
private String header() {
|
||||||
StringBuilder sb = new StringBuilder(600).append("<html><head><title>PMD</title></head>")
|
StringBuilder sb = new StringBuilder(600).append("<html><head><title>PMD</title></head>")
|
||||||
.append("<style type=\"text/css\">").append("<!--" + PMD.EOL)
|
.append("<style type=\"text/css\">").append("<!--").append(PMD.EOL)
|
||||||
.append("body { background-color: white; font-family:verdana, arial, helvetica, geneva; font-size: 16px; font-style: italic; color: black; }")
|
.append("body { background-color: white; font-family:verdana, arial, helvetica, geneva; font-size: 16px; font-style: italic; color: black; }")
|
||||||
.append(PMD.EOL)
|
.append(PMD.EOL)
|
||||||
.append(".title { font-family: verdana, arial, helvetica,geneva; font-size: 12px; font-weight:bold; color: white; }")
|
.append(".title { font-family: verdana, arial, helvetica,geneva; font-size: 12px; font-weight:bold; color: white; }")
|
||||||
|
@ -188,25 +188,25 @@ public class ClassScope extends AbstractScope {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String res = "ClassScope (" + className + "): ";
|
StringBuilder res = new StringBuilder("ClassScope (").append(className).append("): ");
|
||||||
Map<ClassNameDeclaration, List<NameOccurrence>> classNames = getClassDeclarations();
|
Map<ClassNameDeclaration, List<NameOccurrence>> classNames = getClassDeclarations();
|
||||||
Map<MethodNameDeclaration, List<NameOccurrence>> methodNames = getMethodDeclarations();
|
Map<MethodNameDeclaration, List<NameOccurrence>> methodNames = getMethodDeclarations();
|
||||||
Map<VariableNameDeclaration, List<NameOccurrence>> variableNames = getVariableDeclarations();
|
Map<VariableNameDeclaration, List<NameOccurrence>> variableNames = getVariableDeclarations();
|
||||||
if (!classNames.isEmpty()) {
|
if (!classNames.isEmpty()) {
|
||||||
res += "(" + classNames.keySet() + ")";
|
res.append('(').append(classNames.keySet()).append(')');
|
||||||
}
|
}
|
||||||
if (!methodNames.isEmpty()) {
|
if (!methodNames.isEmpty()) {
|
||||||
for (MethodNameDeclaration mnd : methodNames.keySet()) {
|
for (MethodNameDeclaration mnd : methodNames.keySet()) {
|
||||||
res += mnd.toString();
|
res.append(mnd.toString());
|
||||||
int usages = methodNames.get(mnd).size();
|
int usages = methodNames.get(mnd).size();
|
||||||
res += "(begins at line " + mnd.getNode().getBeginLine() + ", " + usages + " usages)";
|
res.append("(begins at line ").append(mnd.getNode().getBeginLine()).append(", ").append(usages).append(" usages)");
|
||||||
res += ",";
|
res.append(',');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!variableNames.isEmpty()) {
|
if (!variableNames.isEmpty()) {
|
||||||
res += "(" + variableNames.keySet() + ")";
|
res.append('(').append(variableNames.keySet()).append(')');
|
||||||
}
|
}
|
||||||
return res;
|
return res.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String clipClassName(String s) {
|
private String clipClassName(String s) {
|
||||||
|
@ -102,7 +102,7 @@ public abstract class AbstractRuleSetFactoryTest {
|
|||||||
int invalidClassName = 0;
|
int invalidClassName = 0;
|
||||||
int invalidRegexSuppress = 0;
|
int invalidRegexSuppress = 0;
|
||||||
int invalidXPathSuppress = 0;
|
int invalidXPathSuppress = 0;
|
||||||
String messages = "";
|
StringBuilder messages = new StringBuilder();
|
||||||
List<String> ruleSetFileNames = getRuleSetFileNames();
|
List<String> ruleSetFileNames = getRuleSetFileNames();
|
||||||
for (String fileName : ruleSetFileNames) {
|
for (String fileName : ruleSetFileNames) {
|
||||||
RuleSet ruleSet = loadRuleSetByFileName(fileName);
|
RuleSet ruleSet = loadRuleSetByFileName(fileName);
|
||||||
@ -123,13 +123,22 @@ public abstract class AbstractRuleSetFactoryTest {
|
|||||||
// Is since missing ?
|
// Is since missing ?
|
||||||
if (rule.getSince() == null) {
|
if (rule.getSince() == null) {
|
||||||
invalidSinceAttributes++;
|
invalidSinceAttributes++;
|
||||||
messages += "Rule " + fileName + "/" + rule.getName() + " is missing 'since' attribute" + PMD.EOL;
|
messages.append("Rule ")
|
||||||
|
.append(fileName)
|
||||||
|
.append("/")
|
||||||
|
.append(rule.getName())
|
||||||
|
.append(" is missing 'since' attribute")
|
||||||
|
.append(PMD.EOL);
|
||||||
}
|
}
|
||||||
// Is URL valid ?
|
// Is URL valid ?
|
||||||
if (rule.getExternalInfoUrl() == null || "".equalsIgnoreCase(rule.getExternalInfoUrl())) {
|
if (rule.getExternalInfoUrl() == null || "".equalsIgnoreCase(rule.getExternalInfoUrl())) {
|
||||||
invalidExternalInfoURL++;
|
invalidExternalInfoURL++;
|
||||||
messages += "Rule " + fileName + "/" + rule.getName() + " is missing 'externalInfoURL' attribute"
|
messages.append("Rule ")
|
||||||
+ PMD.EOL;
|
.append(fileName)
|
||||||
|
.append("/")
|
||||||
|
.append(rule.getName())
|
||||||
|
.append(" is missing 'externalInfoURL' attribute")
|
||||||
|
.append(PMD.EOL);
|
||||||
} else {
|
} else {
|
||||||
String expectedExternalInfoURL = "https?://pmd.(sourceforge.net|github.io)/.+/pmd_rules_"
|
String expectedExternalInfoURL = "https?://pmd.(sourceforge.net|github.io)/.+/pmd_rules_"
|
||||||
+ language.getTerseName() + "_"
|
+ language.getTerseName() + "_"
|
||||||
@ -139,9 +148,15 @@ public abstract class AbstractRuleSetFactoryTest {
|
|||||||
if (rule.getExternalInfoUrl() == null
|
if (rule.getExternalInfoUrl() == null
|
||||||
|| !rule.getExternalInfoUrl().matches(expectedExternalInfoURL)) {
|
|| !rule.getExternalInfoUrl().matches(expectedExternalInfoURL)) {
|
||||||
invalidExternalInfoURL++;
|
invalidExternalInfoURL++;
|
||||||
messages += "Rule " + fileName + "/" + rule.getName()
|
messages.append("Rule ")
|
||||||
+ " seems to have an invalid 'externalInfoURL' value (" + rule.getExternalInfoUrl()
|
.append(fileName)
|
||||||
+ "), it should be:" + expectedExternalInfoURL + PMD.EOL;
|
.append("/")
|
||||||
|
.append(rule.getName())
|
||||||
|
.append(" seems to have an invalid 'externalInfoURL' value (")
|
||||||
|
.append(rule.getExternalInfoUrl())
|
||||||
|
.append("), it should be:")
|
||||||
|
.append(expectedExternalInfoURL)
|
||||||
|
.append(PMD.EOL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Proper class name/packaging?
|
// Proper class name/packaging?
|
||||||
@ -150,22 +165,32 @@ public abstract class AbstractRuleSetFactoryTest {
|
|||||||
if (!rule.getRuleClass().equals(expectedClassName)
|
if (!rule.getRuleClass().equals(expectedClassName)
|
||||||
&& !validXPathClassNames.contains(rule.getRuleClass())) {
|
&& !validXPathClassNames.contains(rule.getRuleClass())) {
|
||||||
invalidClassName++;
|
invalidClassName++;
|
||||||
messages += "Rule " + fileName + "/" + rule.getName() + " seems to have an invalid 'class' value ("
|
messages.append("Rule ")
|
||||||
+ rule.getRuleClass() + "), it should be:" + expectedClassName + PMD.EOL;
|
.append(fileName)
|
||||||
|
.append("/")
|
||||||
|
.append(rule.getName())
|
||||||
|
.append(" seems to have an invalid 'class' value (")
|
||||||
|
.append(rule.getRuleClass())
|
||||||
|
.append("), it should be:")
|
||||||
|
.append(expectedClassName)
|
||||||
|
.append(PMD.EOL);
|
||||||
}
|
}
|
||||||
// Should not have violation suppress regex property
|
// Should not have violation suppress regex property
|
||||||
if (rule.getProperty(Rule.VIOLATION_SUPPRESS_REGEX_DESCRIPTOR) != null) {
|
if (rule.getProperty(Rule.VIOLATION_SUPPRESS_REGEX_DESCRIPTOR) != null) {
|
||||||
invalidRegexSuppress++;
|
invalidRegexSuppress++;
|
||||||
messages += "Rule " + fileName + "/" + rule.getName() + " should not have '"
|
messages.append("Rule ")
|
||||||
+ Rule.VIOLATION_SUPPRESS_REGEX_DESCRIPTOR.name()
|
.append(fileName)
|
||||||
+ "', this is intended for end user customization only." + PMD.EOL;
|
.append("/")
|
||||||
|
.append(rule.getName())
|
||||||
|
.append(" should not have '")
|
||||||
|
.append(Rule.VIOLATION_SUPPRESS_REGEX_DESCRIPTOR.name())
|
||||||
|
.append("', this is intended for end user customization only.")
|
||||||
|
.append(PMD.EOL);
|
||||||
}
|
}
|
||||||
// Should not have violation suppress xpath property
|
// Should not have violation suppress xpath property
|
||||||
if (rule.getProperty(Rule.VIOLATION_SUPPRESS_XPATH_DESCRIPTOR) != null) {
|
if (rule.getProperty(Rule.VIOLATION_SUPPRESS_XPATH_DESCRIPTOR) != null) {
|
||||||
invalidXPathSuppress++;
|
invalidXPathSuppress++;
|
||||||
messages += "Rule " + fileName + "/" + rule.getName() + " should not have '"
|
messages.append("Rule ").append(fileName).append("/").append(rule.getName()).append(" should not have '").append(Rule.VIOLATION_SUPPRESS_XPATH_DESCRIPTOR.name()).append("', this is intended for end user customization only.").append(PMD.EOL);
|
||||||
+ Rule.VIOLATION_SUPPRESS_XPATH_DESCRIPTOR.name()
|
|
||||||
+ "', this is intended for end user customization only." + PMD.EOL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user