Added Issue description in RevapiParser
package edu.hm.hafner.analysis.parser;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+
import org.json.JSONArray;
@@ -26,36 +29,39 @@ public class RevApiParser extends JsonIssueParser {
}
}
-
private Issue convertToIssue(final JSONObject jsonIssue, final IssueBuilder builder) {
builder.setCategory(jsonIssue.getString("code"));
- builder.setSeverity(evaluteSeverity(jsonIssue.getJSONArray("classification")));
+ builder.setSeverity(evaluateSeverity(jsonIssue.getJSONArray("classification")));
builder.setDescription(getDescription(jsonIssue));
addAttachments(jsonIssue.getJSONArray("attachments"), builder);
return builder.build();
}
private void addAttachments(final JSONArray attachments, final IssueBuilder builder) {
- String packageName = attachments.getString(0);
- String classQualifiedName = attachments.getString(1);
- String classSimpleName = attachments.getString(2);
- String elementKind = attachments.getString(3);
+ String packageName = attachments.getJSONObject(0).getString("value");
+ String classQualifiedName = attachments.getJSONObject(1).getString("value");
+ String classSimpleName = attachments.getJSONObject(2).getString("value");
+ String elementKind = attachments.getJSONObject(3).getString("value");
builder.setFileName(classSimpleName);
builder.setPackageName(packageName);
builder.setType(elementKind);
}
- private Severity evaluteSeverity(final JSONArray classification){
- String a = classification.getString(0);
- String b = classification.getString(1);
- return toSeverity(b);
+ private Severity evaluateSeverity(final JSONArray classification) {
+ ArrayList<Severity> allSeverities = new ArrayList<>();
+ for (Object severity : classification) {
+ if (severity instanceof JSONObject) {
+ allSeverities.add(toSeverity(((JSONObject) severity).getString("severity")));
}
-
- private String getDescription(final JSONObject jsonIssue) {
- return jsonIssue.getString("description");
}
-
+ if (allSeverities.contains(Severity.WARNING_HIGH)) {
+ return Severity.WARNING_HIGH;
+ } else if (allSeverities.contains(Severity.WARNING_LOW)){
+ return Severity.WARNING_LOW;
+ }
+ return Severity.WARNING_NORMAL;
+ }
private Severity toSeverity(final String level) {
switch (level) {
@@ -67,4 +73,25 @@ public class RevApiParser extends JsonIssueParser {
return Severity.WARNING_NORMAL;
}
}
+
+
+ private String getDescription(final JSONObject jsonIssue) {
+ StringBuilder severityDescription = new StringBuilder();
+ for (Object severity : jsonIssue.getJSONArray("classification")) {
+ if (severity instanceof JSONObject) {
+ severityDescription.append("<p>Compatibility: ")
+ .append(((JSONObject) severity).getString("compatibility"))
+ .append(" Severity: ")
+ .append(((JSONObject) severity).getString("severity"))
+ .append("</p>");
+ }
+ }
+
+ return MessageFormat.format(
+ "<p><div><b>File</b>: {0}</div><div><b>Description:</b> {1}</div><div><b>Change type:</b> {2}",
+ jsonIssue.getJSONArray("attachments").getJSONObject(1).getString("value"),
+ jsonIssue.getString("description"),
+ jsonIssue.getString("code")) + severityDescription;
+
+ }
}
