forked from phoedos/pmd
Modernizing: StringBuffer -> StringBuilder switchover
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@7295 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -43,7 +43,7 @@ public class StringUtilTest {
|
||||
*/
|
||||
@Test
|
||||
public void testUTF8NotSupported() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String test = "é";
|
||||
StringUtil.appendXmlEscaped(sb, test, false);
|
||||
assertEquals("é", sb.toString());
|
||||
@ -51,7 +51,7 @@ public class StringUtilTest {
|
||||
|
||||
@Test
|
||||
public void testUTF8Supported() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String test = "é";
|
||||
StringUtil.appendXmlEscaped(sb, test, true);
|
||||
assertEquals("é", sb.toString());
|
||||
|
@ -101,7 +101,7 @@ public class Formatter {
|
||||
}
|
||||
|
||||
private static String unknownRendererMessage(String userSpecifiedType) {
|
||||
StringBuffer sb = new StringBuffer(100);
|
||||
StringBuilder sb = new StringBuilder(100);
|
||||
sb.append("Formatter type must be one of: '");
|
||||
String[] typeCodes = validRendererCodes();
|
||||
sb.append(typeCodes[0]);
|
||||
|
@ -22,7 +22,7 @@ public class CSVRenderer extends AbstractIncrementingRenderer {
|
||||
private int violationCount = 1;
|
||||
|
||||
public CSVRenderer(Properties properties) {
|
||||
super(NAME, "Comma-separated values tabular format.", properties);
|
||||
super(NAME, "Comma-separated values tabular format.", properties);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -30,17 +30,17 @@ public class CSVRenderer extends AbstractIncrementingRenderer {
|
||||
*/
|
||||
@Override
|
||||
public void start() throws IOException {
|
||||
StringBuffer buf = new StringBuffer(300);
|
||||
quoteAndCommify(buf, "Problem");
|
||||
quoteAndCommify(buf, "Package");
|
||||
quoteAndCommify(buf, "File");
|
||||
quoteAndCommify(buf, "Priority");
|
||||
quoteAndCommify(buf, "Line");
|
||||
quoteAndCommify(buf, "Description");
|
||||
quoteAndCommify(buf, "Rule set");
|
||||
quote(buf, "Rule");
|
||||
buf.append(PMD.EOL);
|
||||
getWriter().write(buf.toString());
|
||||
StringBuilder buf = new StringBuilder(300);
|
||||
quoteAndCommify(buf, "Problem");
|
||||
quoteAndCommify(buf, "Package");
|
||||
quoteAndCommify(buf, "File");
|
||||
quoteAndCommify(buf, "Priority");
|
||||
quoteAndCommify(buf, "Line");
|
||||
quoteAndCommify(buf, "Description");
|
||||
quoteAndCommify(buf, "Rule set");
|
||||
quote(buf, "Rule");
|
||||
buf.append(PMD.EOL);
|
||||
getWriter().write(buf.toString());
|
||||
}
|
||||
|
||||
public String defaultFileExtension() { return "csv"; }
|
||||
@ -50,33 +50,33 @@ public class CSVRenderer extends AbstractIncrementingRenderer {
|
||||
*/
|
||||
@Override
|
||||
public void renderFileViolations(Iterator<RuleViolation> violations) throws IOException {
|
||||
StringBuffer buf = new StringBuffer(300);
|
||||
Writer writer = getWriter();
|
||||
|
||||
RuleViolation rv;
|
||||
while (violations.hasNext()) {
|
||||
buf.setLength(0);
|
||||
rv = violations.next();
|
||||
quoteAndCommify(buf, Integer.toString(violationCount));
|
||||
quoteAndCommify(buf, rv.getPackageName());
|
||||
quoteAndCommify(buf, rv.getFilename());
|
||||
quoteAndCommify(buf, Integer.toString(rv.getRule().getPriority().getPriority()));
|
||||
quoteAndCommify(buf, Integer.toString(rv.getBeginLine()));
|
||||
quoteAndCommify(buf, StringUtil.replaceString(rv.getDescription(), '\"', "'"));
|
||||
quoteAndCommify(buf, rv.getRule().getRuleSetName());
|
||||
quote(buf, rv.getRule().getName());
|
||||
buf.append(PMD.EOL);
|
||||
writer.write(buf.toString());
|
||||
violationCount++;
|
||||
}
|
||||
StringBuilder buf = new StringBuilder(300);
|
||||
Writer writer = getWriter();
|
||||
|
||||
RuleViolation rv;
|
||||
while (violations.hasNext()) {
|
||||
buf.setLength(0);
|
||||
rv = violations.next();
|
||||
quoteAndCommify(buf, Integer.toString(violationCount));
|
||||
quoteAndCommify(buf, rv.getPackageName());
|
||||
quoteAndCommify(buf, rv.getFilename());
|
||||
quoteAndCommify(buf, Integer.toString(rv.getRule().getPriority().getPriority()));
|
||||
quoteAndCommify(buf, Integer.toString(rv.getBeginLine()));
|
||||
quoteAndCommify(buf, StringUtil.replaceString(rv.getDescription(), '\"', "'"));
|
||||
quoteAndCommify(buf, rv.getRule().getRuleSetName());
|
||||
quote(buf, rv.getRule().getName());
|
||||
buf.append(PMD.EOL);
|
||||
writer.write(buf.toString());
|
||||
violationCount++;
|
||||
}
|
||||
}
|
||||
|
||||
private void quote(StringBuffer buffer, String s) {
|
||||
buffer.append('"').append(s).append('"');
|
||||
private void quote(StringBuilder buffer, String s) {
|
||||
buffer.append('"').append(s).append('"');
|
||||
}
|
||||
|
||||
private void quoteAndCommify(StringBuffer buffer, String s) {
|
||||
quote(buffer, s);
|
||||
buffer.append(',');
|
||||
private void quoteAndCommify(StringBuilder buffer, String s) {
|
||||
quote(buffer, s);
|
||||
buffer.append(',');
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public class EmacsRenderer extends AbstractIncrementingRenderer {
|
||||
protected static final String EOL = System.getProperty("line.separator", "\n");
|
||||
|
||||
public EmacsRenderer(Properties properties) {
|
||||
super(NAME, "GNU Emacs integration.", properties);
|
||||
super(NAME, "GNU Emacs integration.", properties);
|
||||
}
|
||||
|
||||
public String defaultFileExtension() { return "emacs"; }
|
||||
@ -30,15 +30,15 @@ public class EmacsRenderer extends AbstractIncrementingRenderer {
|
||||
*/
|
||||
@Override
|
||||
public void renderFileViolations(Iterator<RuleViolation> violations) throws IOException {
|
||||
Writer writer = getWriter();
|
||||
StringBuffer buf = new StringBuffer();
|
||||
while (violations.hasNext()) {
|
||||
RuleViolation rv = violations.next();
|
||||
buf.setLength(0);
|
||||
buf.append(rv.getFilename());
|
||||
buf.append(':').append(Integer.toString(rv.getBeginLine()));
|
||||
buf.append(": ").append(rv.getDescription()).append(EOL);
|
||||
writer.write(buf.toString());
|
||||
}
|
||||
Writer writer = getWriter();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
while (violations.hasNext()) {
|
||||
RuleViolation rv = violations.next();
|
||||
buf.setLength(0);
|
||||
buf.append(rv.getFilename());
|
||||
buf.append(':').append(Integer.toString(rv.getBeginLine()));
|
||||
buf.append(": ").append(rv.getDescription()).append(EOL);
|
||||
writer.write(buf.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public class TextRenderer extends AbstractIncrementingRenderer {
|
||||
public static final String NAME = "text";
|
||||
|
||||
public TextRenderer(Properties properties) {
|
||||
super(NAME, "Text format.", properties);
|
||||
super(NAME, "Text format.", properties);
|
||||
}
|
||||
|
||||
|
||||
@ -38,17 +38,17 @@ public class TextRenderer extends AbstractIncrementingRenderer {
|
||||
*/
|
||||
@Override
|
||||
public void renderFileViolations(Iterator<RuleViolation> violations) throws IOException {
|
||||
Writer writer = getWriter();
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
while (violations.hasNext()) {
|
||||
buf.setLength(0);
|
||||
RuleViolation rv = violations.next();
|
||||
buf.append(rv.getFilename());
|
||||
buf.append(':').append(Integer.toString(rv.getBeginLine()));
|
||||
buf.append('\t').append(rv.getDescription()).append(PMD.EOL);
|
||||
writer.write(buf.toString());
|
||||
}
|
||||
Writer writer = getWriter();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
|
||||
while (violations.hasNext()) {
|
||||
buf.setLength(0);
|
||||
RuleViolation rv = violations.next();
|
||||
buf.append(rv.getFilename());
|
||||
buf.append(':').append(Integer.toString(rv.getBeginLine()));
|
||||
buf.append('\t').append(rv.getDescription()).append(PMD.EOL);
|
||||
writer.write(buf.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,26 +56,26 @@ public class TextRenderer extends AbstractIncrementingRenderer {
|
||||
*/
|
||||
@Override
|
||||
public void end() throws IOException {
|
||||
Writer writer = getWriter();
|
||||
StringBuffer buf = new StringBuffer(500);
|
||||
if (!errors.isEmpty()) {
|
||||
|
||||
for (Report.ProcessingError error : errors) {
|
||||
buf.setLength(0);
|
||||
buf.append(error.getFile());
|
||||
buf.append("\t-\t").append(error.getMsg()).append(PMD.EOL);
|
||||
writer.write(buf.toString());
|
||||
}
|
||||
}
|
||||
|
||||
for (Report.SuppressedViolation excluded : suppressed) {
|
||||
buf.setLength(0);
|
||||
buf.append(excluded.getRuleViolation().getRule().getName());
|
||||
buf.append(" rule violation suppressed by ");
|
||||
buf.append(excluded.suppressedByNOPMD() ? "//NOPMD" : "Annotation");
|
||||
buf.append(" in ").append(excluded.getRuleViolation().getFilename()).append(PMD.EOL);
|
||||
writer.write(buf.toString());
|
||||
}
|
||||
Writer writer = getWriter();
|
||||
StringBuilder buf = new StringBuilder(500);
|
||||
if (!errors.isEmpty()) {
|
||||
|
||||
for (Report.ProcessingError error : errors) {
|
||||
buf.setLength(0);
|
||||
buf.append(error.getFile());
|
||||
buf.append("\t-\t").append(error.getMsg()).append(PMD.EOL);
|
||||
writer.write(buf.toString());
|
||||
}
|
||||
}
|
||||
|
||||
for (Report.SuppressedViolation excluded : suppressed) {
|
||||
buf.setLength(0);
|
||||
buf.append(excluded.getRuleViolation().getRule().getName());
|
||||
buf.append(" rule violation suppressed by ");
|
||||
buf.append(excluded.suppressedByNOPMD() ? "//NOPMD" : "Annotation");
|
||||
buf.append(" in ").append(excluded.getRuleViolation().getFilename()).append(PMD.EOL);
|
||||
writer.write(buf.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public class VBHTMLRenderer extends AbstractIncrementingRenderer {
|
||||
public static final String NAME = "vbhtml";
|
||||
|
||||
public VBHTMLRenderer(Properties properties) {
|
||||
super(NAME, "Vladimir Bossicard HTML format.", properties);
|
||||
super(NAME, "Vladimir Bossicard HTML format.", properties);
|
||||
}
|
||||
|
||||
public String defaultFileExtension() { return "vb.html"; }
|
||||
@ -31,7 +31,7 @@ public class VBHTMLRenderer extends AbstractIncrementingRenderer {
|
||||
*/
|
||||
@Override
|
||||
public void start() throws IOException {
|
||||
getWriter().write(header());
|
||||
getWriter().write(header());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -39,48 +39,48 @@ public class VBHTMLRenderer extends AbstractIncrementingRenderer {
|
||||
*/
|
||||
@Override
|
||||
public void renderFileViolations(Iterator<RuleViolation> violations) throws IOException {
|
||||
if (!violations.hasNext()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Writer writer = getWriter();
|
||||
StringBuffer sb = new StringBuffer(500);
|
||||
String filename = null;
|
||||
String lineSep = PMD.EOL;
|
||||
|
||||
boolean colorize = false;
|
||||
while (violations.hasNext()) {
|
||||
sb.setLength(0);
|
||||
RuleViolation rv = violations.next();
|
||||
if (!rv.getFilename().equals(filename)) { // New File
|
||||
if (filename != null) {
|
||||
sb.append("</table></br>");
|
||||
colorize = false;
|
||||
if (!violations.hasNext()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Writer writer = getWriter();
|
||||
StringBuilder sb = new StringBuilder(500);
|
||||
String filename = null;
|
||||
String lineSep = PMD.EOL;
|
||||
|
||||
boolean colorize = false;
|
||||
while (violations.hasNext()) {
|
||||
sb.setLength(0);
|
||||
RuleViolation rv = violations.next();
|
||||
if (!rv.getFilename().equals(filename)) { // New File
|
||||
if (filename != null) {
|
||||
sb.append("</table></br>");
|
||||
colorize = false;
|
||||
}
|
||||
filename = rv.getFilename();
|
||||
sb.append("<table border=\"0\" width=\"80%\">");
|
||||
sb.append("<tr id=TableHeader><td colspan=\"2\"><font class=title> ").append(filename).append(
|
||||
"</font></tr>");
|
||||
sb.append(lineSep);
|
||||
}
|
||||
|
||||
if (colorize) {
|
||||
sb.append("<tr id=RowColor1>");
|
||||
} else {
|
||||
sb.append("<tr id=RowColor2>");
|
||||
}
|
||||
|
||||
colorize = !colorize;
|
||||
sb.append("<td width=\"50\" align=\"right\"><font class=body>" + rv.getBeginLine()
|
||||
+ " </font></td>");
|
||||
sb.append("<td><font class=body>" + rv.getDescription() + "</font></td>");
|
||||
sb.append("</tr>");
|
||||
sb.append(lineSep);
|
||||
writer.write(sb.toString());
|
||||
}
|
||||
if (filename != null) {
|
||||
writer.write("</table>");
|
||||
}
|
||||
filename = rv.getFilename();
|
||||
sb.append("<table border=\"0\" width=\"80%\">");
|
||||
sb.append("<tr id=TableHeader><td colspan=\"2\"><font class=title> ").append(filename).append(
|
||||
"</font></tr>");
|
||||
sb.append(lineSep);
|
||||
}
|
||||
|
||||
if (colorize) {
|
||||
sb.append("<tr id=RowColor1>");
|
||||
} else {
|
||||
sb.append("<tr id=RowColor2>");
|
||||
}
|
||||
|
||||
colorize = !colorize;
|
||||
sb.append("<td width=\"50\" align=\"right\"><font class=body>" + rv.getBeginLine()
|
||||
+ " </font></td>");
|
||||
sb.append("<td><font class=body>" + rv.getDescription() + "</font></td>");
|
||||
sb.append("</tr>");
|
||||
sb.append(lineSep);
|
||||
writer.write(sb.toString());
|
||||
}
|
||||
if (filename != null) {
|
||||
writer.write("</table>");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,58 +88,55 @@ public class VBHTMLRenderer extends AbstractIncrementingRenderer {
|
||||
*/
|
||||
@Override
|
||||
public void end() throws IOException {
|
||||
Writer writer = getWriter();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
writer.write("<br>");
|
||||
|
||||
// output the problems
|
||||
if (!errors.isEmpty()) {
|
||||
sb.setLength(0);
|
||||
sb.append("<table border=\"0\" width=\"80%\">");
|
||||
sb.append("<tr id=TableHeader><td><font class=title> Problems found</font></td></tr>");
|
||||
boolean colorize = false;
|
||||
for (Report.ProcessingError error : errors) {
|
||||
if (colorize) {
|
||||
sb.append("<tr id=RowColor1>");
|
||||
} else {
|
||||
sb.append("<tr id=RowColor2>");
|
||||
Writer writer = getWriter();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
writer.write("<br>");
|
||||
|
||||
// output the problems
|
||||
if (!errors.isEmpty()) {
|
||||
sb.setLength(0);
|
||||
sb.append("<table border=\"0\" width=\"80%\">");
|
||||
sb.append("<tr id=TableHeader><td><font class=title> Problems found</font></td></tr>");
|
||||
boolean colorize = false;
|
||||
for (Report.ProcessingError error : errors) {
|
||||
if (colorize) {
|
||||
sb.append("<tr id=RowColor1>");
|
||||
} else {
|
||||
sb.append("<tr id=RowColor2>");
|
||||
}
|
||||
colorize = !colorize;
|
||||
sb.append("<td><font class=body>").append(error).append("\"</font></td></tr>");
|
||||
}
|
||||
sb.append("</table>");
|
||||
writer.write(sb.toString());
|
||||
}
|
||||
colorize = !colorize;
|
||||
sb.append("<td><font class=body>").append(error).append("\"</font></td></tr>");
|
||||
}
|
||||
sb.append("</table>");
|
||||
writer.write(sb.toString());
|
||||
}
|
||||
|
||||
writer.write(footer());
|
||||
|
||||
writer.write(footer());
|
||||
}
|
||||
|
||||
private String header() {
|
||||
StringBuffer sb = new StringBuffer(600);
|
||||
sb.append("<html><head><title>PMD</title></head>");
|
||||
sb.append("<style type=\"text/css\">");
|
||||
sb.append("<!--" + PMD.EOL);
|
||||
sb
|
||||
.append("body { background-color: white; font-family:verdana, arial, helvetica, geneva; font-size: 16px; font-style: italic; color: black; }"
|
||||
+ PMD.EOL);
|
||||
sb
|
||||
.append(".title { font-family: verdana, arial, helvetica,geneva; font-size: 12px; font-weight:bold; color: white; }"
|
||||
+ PMD.EOL);
|
||||
sb
|
||||
.append(".body { font-family: verdana, arial, helvetica, geneva; font-size: 12px; font-weight:plain; color: black; }"
|
||||
+ PMD.EOL);
|
||||
sb.append("#TableHeader { background-color: #003366; }" + PMD.EOL);
|
||||
sb.append("#RowColor1 { background-color: #eeeeee; }" + PMD.EOL);
|
||||
sb.append("#RowColor2 { background-color: white; }" + PMD.EOL);
|
||||
sb.append("-->");
|
||||
sb.append("</style>");
|
||||
sb.append("<body><center>");
|
||||
return sb.toString();
|
||||
StringBuilder sb = new StringBuilder(600);
|
||||
sb.append("<html><head><title>PMD</title></head>");
|
||||
sb.append("<style type=\"text/css\">");
|
||||
sb.append("<!--" + PMD.EOL);
|
||||
sb.append("body { background-color: white; font-family:verdana, arial, helvetica, geneva; font-size: 16px; font-style: italic; color: black; }"
|
||||
+ PMD.EOL);
|
||||
sb.append(".title { font-family: verdana, arial, helvetica,geneva; font-size: 12px; font-weight:bold; color: white; }"
|
||||
+ PMD.EOL);
|
||||
sb.append(".body { font-family: verdana, arial, helvetica, geneva; font-size: 12px; font-weight:plain; color: black; }"
|
||||
+ PMD.EOL);
|
||||
sb.append("#TableHeader { background-color: #003366; }" + PMD.EOL);
|
||||
sb.append("#RowColor1 { background-color: #eeeeee; }" + PMD.EOL);
|
||||
sb.append("#RowColor2 { background-color: white; }" + PMD.EOL);
|
||||
sb.append("-->");
|
||||
sb.append("</style>");
|
||||
sb.append("<body><center>");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String footer() {
|
||||
return "</center></body></html>" + PMD.EOL;
|
||||
return "</center></body></html>" + PMD.EOL;
|
||||
}
|
||||
|
||||
}
|
@ -28,12 +28,12 @@ public class XMLRenderer extends AbstractIncrementingRenderer {
|
||||
protected String encoding = "UTF-8";
|
||||
|
||||
public XMLRenderer(Properties properties) {
|
||||
super(NAME, "XML format.", properties);
|
||||
defineProperty(ENCODING, "XML encoding format, defaults to UTF-8.");
|
||||
|
||||
if (properties.containsKey(ENCODING)) {
|
||||
this.encoding = properties.getProperty(ENCODING);
|
||||
}
|
||||
super(NAME, "XML format.", properties);
|
||||
defineProperty(ENCODING, "XML encoding format, defaults to UTF-8.");
|
||||
|
||||
if (properties.containsKey(ENCODING)) {
|
||||
encoding = properties.getProperty(ENCODING);
|
||||
}
|
||||
}
|
||||
|
||||
public String defaultFileExtension() { return "xml"; }
|
||||
@ -43,15 +43,15 @@ public class XMLRenderer extends AbstractIncrementingRenderer {
|
||||
*/
|
||||
@Override
|
||||
public void start() throws IOException {
|
||||
Writer writer = getWriter();
|
||||
StringBuffer buf = new StringBuffer(500);
|
||||
buf.append("<?xml version=\"1.0\" encoding=\"" + this.encoding + "\"?>").append(PMD.EOL);
|
||||
createVersionAttr(buf);
|
||||
createTimestampAttr(buf);
|
||||
// FIXME: elapsed time not available until the end of the processing
|
||||
//buf.append(createTimeElapsedAttr(report));
|
||||
buf.append('>').append(PMD.EOL);
|
||||
writer.write(buf.toString());
|
||||
Writer writer = getWriter();
|
||||
StringBuilder buf = new StringBuilder(500);
|
||||
buf.append("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>").append(PMD.EOL);
|
||||
createVersionAttr(buf);
|
||||
createTimestampAttr(buf);
|
||||
// FIXME: elapsed time not available until the end of the processing
|
||||
//buf.append(createTimeElapsedAttr(report));
|
||||
buf.append('>').append(PMD.EOL);
|
||||
writer.write(buf.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,52 +59,52 @@ public class XMLRenderer extends AbstractIncrementingRenderer {
|
||||
*/
|
||||
@Override
|
||||
public void renderFileViolations(Iterator<RuleViolation> violations) throws IOException {
|
||||
Writer writer = getWriter();
|
||||
StringBuffer buf = new StringBuffer(500);
|
||||
String filename = null;
|
||||
|
||||
// rule violations
|
||||
while (violations.hasNext()) {
|
||||
buf.setLength(0);
|
||||
RuleViolation rv = violations.next();
|
||||
if (!rv.getFilename().equals(filename)) { // New File
|
||||
if (filename != null) {// Not first file ?
|
||||
buf.append("</file>").append(PMD.EOL);
|
||||
Writer writer = getWriter();
|
||||
StringBuilder buf = new StringBuilder(500);
|
||||
String filename = null;
|
||||
|
||||
// rule violations
|
||||
while (violations.hasNext()) {
|
||||
buf.setLength(0);
|
||||
RuleViolation rv = violations.next();
|
||||
if (!rv.getFilename().equals(filename)) { // New File
|
||||
if (filename != null) {// Not first file ?
|
||||
buf.append("</file>").append(PMD.EOL);
|
||||
}
|
||||
filename = rv.getFilename();
|
||||
buf.append("<file name=\"");
|
||||
StringUtil.appendXmlEscaped(buf, filename);
|
||||
buf.append("\">").append(PMD.EOL);
|
||||
}
|
||||
|
||||
buf.append("<violation beginline=\"").append(rv.getBeginLine());
|
||||
buf.append("\" endline=\"").append(rv.getEndLine());
|
||||
buf.append("\" begincolumn=\"").append(rv.getBeginColumn());
|
||||
buf.append("\" endcolumn=\"").append(rv.getEndColumn());
|
||||
buf.append("\" rule=\"");
|
||||
StringUtil.appendXmlEscaped(buf, rv.getRule().getName());
|
||||
buf.append("\" ruleset=\"");
|
||||
StringUtil.appendXmlEscaped(buf, rv.getRule().getRuleSetName());
|
||||
buf.append('"');
|
||||
maybeAdd("package", rv.getPackageName(), buf);
|
||||
maybeAdd("class", rv.getClassName(), buf);
|
||||
maybeAdd("method", rv.getMethodName(), buf);
|
||||
maybeAdd("variable", rv.getVariableName(), buf);
|
||||
maybeAdd("externalInfoUrl", rv.getRule().getExternalInfoUrl(), buf);
|
||||
buf.append(" priority=\"");
|
||||
buf.append(rv.getRule().getPriority().getPriority());
|
||||
buf.append("\">").append(PMD.EOL);
|
||||
StringUtil.appendXmlEscaped(buf, rv.getDescription());
|
||||
|
||||
buf.append(PMD.EOL);
|
||||
buf.append("</violation>");
|
||||
buf.append(PMD.EOL);
|
||||
writer.write(buf.toString());
|
||||
}
|
||||
if (filename != null) { // Not first file ?
|
||||
writer.write("</file>");
|
||||
writer.write(PMD.EOL);
|
||||
}
|
||||
filename = rv.getFilename();
|
||||
buf.append("<file name=\"");
|
||||
StringUtil.appendXmlEscaped(buf, filename);
|
||||
buf.append("\">").append(PMD.EOL);
|
||||
}
|
||||
|
||||
buf.append("<violation beginline=\"").append(rv.getBeginLine());
|
||||
buf.append("\" endline=\"").append(rv.getEndLine());
|
||||
buf.append("\" begincolumn=\"").append(rv.getBeginColumn());
|
||||
buf.append("\" endcolumn=\"").append(rv.getEndColumn());
|
||||
buf.append("\" rule=\"");
|
||||
StringUtil.appendXmlEscaped(buf, rv.getRule().getName());
|
||||
buf.append("\" ruleset=\"");
|
||||
StringUtil.appendXmlEscaped(buf, rv.getRule().getRuleSetName());
|
||||
buf.append('"');
|
||||
maybeAdd("package", rv.getPackageName(), buf);
|
||||
maybeAdd("class", rv.getClassName(), buf);
|
||||
maybeAdd("method", rv.getMethodName(), buf);
|
||||
maybeAdd("variable", rv.getVariableName(), buf);
|
||||
maybeAdd("externalInfoUrl", rv.getRule().getExternalInfoUrl(), buf);
|
||||
buf.append(" priority=\"");
|
||||
buf.append(rv.getRule().getPriority().getPriority());
|
||||
buf.append("\">").append(PMD.EOL);
|
||||
StringUtil.appendXmlEscaped(buf, rv.getDescription());
|
||||
|
||||
buf.append(PMD.EOL);
|
||||
buf.append("</violation>");
|
||||
buf.append(PMD.EOL);
|
||||
writer.write(buf.toString());
|
||||
}
|
||||
if (filename != null) { // Not first file ?
|
||||
writer.write("</file>");
|
||||
writer.write(PMD.EOL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,54 +112,54 @@ public class XMLRenderer extends AbstractIncrementingRenderer {
|
||||
*/
|
||||
@Override
|
||||
public void end() throws IOException {
|
||||
Writer writer = getWriter();
|
||||
StringBuffer buf = new StringBuffer(500);
|
||||
// errors
|
||||
for (Report.ProcessingError pe : errors) {
|
||||
buf.setLength(0);
|
||||
buf.append("<error ").append("filename=\"");
|
||||
StringUtil.appendXmlEscaped(buf, pe.getFile());
|
||||
buf.append("\" msg=\"");
|
||||
StringUtil.appendXmlEscaped(buf, pe.getMsg());
|
||||
buf.append("\"/>").append(PMD.EOL);
|
||||
writer.write(buf.toString());
|
||||
}
|
||||
|
||||
// suppressed violations
|
||||
if (showSuppressedViolations) {
|
||||
for (Report.SuppressedViolation s : suppressed) {
|
||||
buf.setLength(0);
|
||||
buf.append("<suppressedviolation ").append("filename=\"");
|
||||
StringUtil.appendXmlEscaped(buf, s.getRuleViolation().getFilename());
|
||||
buf.append("\" suppressiontype=\"");
|
||||
StringUtil.appendXmlEscaped(buf, s.suppressedByNOPMD() ? "nopmd" : "annotation");
|
||||
buf.append("\" msg=\"");
|
||||
StringUtil.appendXmlEscaped(buf, s.getRuleViolation().getDescription());
|
||||
buf.append("\" usermsg=\"");
|
||||
StringUtil.appendXmlEscaped(buf, s.getUserMessage() == null ? "" : s.getUserMessage());
|
||||
buf.append("\"/>").append(PMD.EOL);
|
||||
writer.write(buf.toString());
|
||||
}
|
||||
}
|
||||
|
||||
writer.write("</pmd>" + PMD.EOL);
|
||||
Writer writer = getWriter();
|
||||
StringBuilder buf = new StringBuilder(500);
|
||||
// errors
|
||||
for (Report.ProcessingError pe : errors) {
|
||||
buf.setLength(0);
|
||||
buf.append("<error ").append("filename=\"");
|
||||
StringUtil.appendXmlEscaped(buf, pe.getFile());
|
||||
buf.append("\" msg=\"");
|
||||
StringUtil.appendXmlEscaped(buf, pe.getMsg());
|
||||
buf.append("\"/>").append(PMD.EOL);
|
||||
writer.write(buf.toString());
|
||||
}
|
||||
|
||||
// suppressed violations
|
||||
if (showSuppressedViolations) {
|
||||
for (Report.SuppressedViolation s : suppressed) {
|
||||
buf.setLength(0);
|
||||
buf.append("<suppressedviolation ").append("filename=\"");
|
||||
StringUtil.appendXmlEscaped(buf, s.getRuleViolation().getFilename());
|
||||
buf.append("\" suppressiontype=\"");
|
||||
StringUtil.appendXmlEscaped(buf, s.suppressedByNOPMD() ? "nopmd" : "annotation");
|
||||
buf.append("\" msg=\"");
|
||||
StringUtil.appendXmlEscaped(buf, s.getRuleViolation().getDescription());
|
||||
buf.append("\" usermsg=\"");
|
||||
StringUtil.appendXmlEscaped(buf, s.getUserMessage() == null ? "" : s.getUserMessage());
|
||||
buf.append("\"/>").append(PMD.EOL);
|
||||
writer.write(buf.toString());
|
||||
}
|
||||
}
|
||||
|
||||
writer.write("</pmd>" + PMD.EOL);
|
||||
}
|
||||
|
||||
private void maybeAdd(String attr, String value, StringBuffer buf) {
|
||||
if (value != null && value.length() > 0) {
|
||||
buf.append(' ').append(attr).append("=\"");
|
||||
StringUtil.appendXmlEscaped(buf, value);
|
||||
buf.append('"');
|
||||
}
|
||||
private void maybeAdd(String attr, String value, StringBuilder buf) {
|
||||
if (value != null && value.length() > 0) {
|
||||
buf.append(' ').append(attr).append("=\"");
|
||||
StringUtil.appendXmlEscaped(buf, value);
|
||||
buf.append('"');
|
||||
}
|
||||
}
|
||||
|
||||
private void createVersionAttr(StringBuffer buffer) {
|
||||
buffer.append("<pmd version=\"").append(PMD.VERSION).append('"');
|
||||
private void createVersionAttr(StringBuilder buffer) {
|
||||
buffer.append("<pmd version=\"").append(PMD.VERSION).append('"');
|
||||
}
|
||||
|
||||
private void createTimestampAttr(StringBuffer buffer) {
|
||||
buffer.append(" timestamp=\"").append(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(new Date()))
|
||||
.append('"');
|
||||
private void createTimestampAttr(StringBuilder buffer) {
|
||||
buffer.append(" timestamp=\"").append(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(new Date()))
|
||||
.append('"');
|
||||
}
|
||||
|
||||
// FIXME: elapsed time not available until the end of the processing
|
||||
|
@ -160,13 +160,13 @@ public final class StringUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends to a StringBuffer the String src where non-ASCII and
|
||||
* Appends to a StringBuilder the String src where non-ASCII and
|
||||
* XML special chars are escaped.
|
||||
*
|
||||
* @param buf The destination XML stream
|
||||
* @param src The String to append to the stream
|
||||
*/
|
||||
public static void appendXmlEscaped(StringBuffer buf, String src) {
|
||||
public static void appendXmlEscaped(StringBuilder buf, String src) {
|
||||
appendXmlEscaped(buf, src, SUPPORTS_UTF8);
|
||||
}
|
||||
|
||||
@ -189,7 +189,7 @@ public final class StringUtil {
|
||||
*
|
||||
* public to support unit testing - make this package private, once the unit test classes are in the same package.
|
||||
*/
|
||||
public static void appendXmlEscaped(StringBuffer buf, String src, boolean supportUTF8) {
|
||||
public static void appendXmlEscaped(StringBuilder buf, String src, boolean supportUTF8) {
|
||||
char c;
|
||||
for (int i = 0; i < src.length(); i++) {
|
||||
c = src.charAt(i);
|
||||
|
Reference in New Issue
Block a user