Skip to content

Commit

Permalink
xml output
Browse files Browse the repository at this point in the history
  • Loading branch information
ryaneberly committed Feb 8, 2014
1 parent 62914a4 commit 40c69c4
Showing 1 changed file with 57 additions and 42 deletions.
99 changes: 57 additions & 42 deletions src/main/java/com/cflint/XMLOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public void output(final BugList bugList, final Writer writer) throws IOExceptio
writer.append("<issues>").append("\r\n");
for (final Entry<String, List<BugInfo>> bugEntry : bugList.getBugList().entrySet()) {
final Iterator<BugInfo> iterator = bugEntry.getValue().iterator();
BugInfo bugInfo = iterator.hasNext()?iterator.next():null;
BugInfo prevbugInfo=null;
BugInfo bugInfo = iterator.hasNext() ? iterator.next() : null;
BugInfo prevbugInfo = null;

while (bugInfo != null) {
writer.append("<issue");
writer.append(" severity=\"").append(bugEntry.getValue().get(0).getSeverity()).append("\"");
Expand All @@ -31,7 +31,7 @@ public void output(final BugList bugList, final Writer writer) throws IOExceptio
writer.append(" category=\"CFLint\"");
writer.append(" abbrev=\"").append(abbrev(bugEntry.getValue().get(0).getMessageCode())).append("\"");
writer.append(">");
do{
do {
writer.append("<location");
writer.append(" file=\"").append(bugInfo.getFilename()).append("\"");
writer.append(" fileName=\"").append(filename(bugInfo.getFilename())).append("\"");
Expand All @@ -41,44 +41,45 @@ public void output(final BugList bugList, final Writer writer) throws IOExceptio
writer.append(" variable=\"").append(bugInfo.getVariable()).append("\"");
writer.append(">");
writer.append("<Expression><![CDATA[")
.append(bugInfo.getExpression()==null?"":bugInfo.getExpression().replace("<![CDATA[","").replace("]]>",""))
.append("]]></Expression>");
.append(bugInfo.getExpression() == null ? "" : bugInfo.getExpression()
.replace("<![CDATA[", "").replace("]]>", "")).append("]]></Expression>");
writer.append("</location>").append("\r\n");
prevbugInfo=bugInfo;
bugInfo = iterator.hasNext()?iterator.next():null;
}while(isGrouped(prevbugInfo,bugInfo));
//writer.append(" function=\"").append(bugInfo.getFunction()).append("\"");
writer.append("</issue>").append("\r\n");
prevbugInfo = bugInfo;
bugInfo = iterator.hasNext() ? iterator.next() : null;
} while (isGrouped(prevbugInfo, bugInfo));
// writer.append(" function=\"").append(bugInfo.getFunction()).append("\"");
writer.append("</issue>").append("\r\n");
}
}
writer.append("</issues>");
writer.close();
}

List<String> CODE_GROUPBY_FUNCTION= Arrays.asList("PARSE_ERROR");

private boolean isGrouped(BugInfo prevbugInfo, BugInfo bugInfo) {
if(prevbugInfo == null || bugInfo == null){
List<String> CODE_GROUPBY_FUNCTION = Arrays.asList("PARSE_ERROR");

private boolean isGrouped(final BugInfo prevbugInfo, final BugInfo bugInfo) {
if (prevbugInfo == null || bugInfo == null) {
return false;
}
//Different message types are not grouped
if(!safeEquals(prevbugInfo.getMessageCode(),bugInfo.getMessageCode())){
// Different message types are not grouped
if (!safeEquals(prevbugInfo.getMessageCode(), bugInfo.getMessageCode())) {
return false;
}
//Different files are not grouped
if(!safeEquals(prevbugInfo.getFilename(),bugInfo.getFilename())){
// Different files are not grouped
if (!safeEquals(prevbugInfo.getFilename(), bugInfo.getFilename())) {
return false;
}
//Some message codes (such as parse error are grouped at the function level
if(CODE_GROUPBY_FUNCTION.contains(bugInfo.getMessageCode())){
if(safeEquals(prevbugInfo.getFunction(),bugInfo.getFunction())){
// Some message codes (such as parse error are grouped at the function
// level
if (CODE_GROUPBY_FUNCTION.contains(bugInfo.getMessageCode())) {
if (safeEquals(prevbugInfo.getFunction(), bugInfo.getFunction())) {
return true;
}
}
return false;
}
private boolean safeEquals(String a, String b){

private boolean safeEquals(final String a, final String b) {
return a != null && b != null && a.equals(b);
}

Expand Down Expand Up @@ -121,23 +122,37 @@ private CharSequence abbrev(final String messageCode) {
}
}

String xmlEscapeText(String t) {
StringBuilder sb = new StringBuilder();
for(int i = 0; i < t.length(); i++){
char c = t.charAt(i);
switch(c){
case '<': sb.append("&lt;"); break;
case '>': sb.append("&gt;"); break;
case '\"': sb.append("&quot;"); break;
case '&': sb.append("&amp;"); break;
case '\'': sb.append("&apos;"); break;
default:
if(c>0x7e) {
sb.append("&#"+((int)c)+";");
}else
sb.append(c);
}
}
return sb.toString();
String xmlEscapeText(final String t) {
if (t == null) {
return "";
}
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < t.length(); i++) {
final char c = t.charAt(i);
switch (c) {
case '<':
sb.append("&lt;");
break;
case '>':
sb.append("&gt;");
break;
case '\"':
sb.append("&quot;");
break;
case '&':
sb.append("&amp;");
break;
case '\'':
sb.append("&apos;");
break;
default:
if (c > 0x7e) {
sb.append("&#" + ((int) c) + ";");
} else {
sb.append(c);
}
}
}
return sb.toString();
}
}

0 comments on commit 40c69c4

Please sign in to comment.