Skip to content

Tweak JsonReport output #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 47 additions & 30 deletions src/main/java/org/sonarlint/cli/report/JsonReport.java
Original file line number Diff line number Diff line change
@@ -24,6 +24,8 @@
import java.io.PrintStream;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Arrays;
import java.util.function.Function;
import org.sonarlint.cli.util.Logger;
import org.sonarsource.sonarlint.core.client.api.common.RuleDetails;
@@ -33,7 +35,10 @@

public class JsonReport implements Reporter {

private static final Logger LOGGER = Logger.get();
private static final List<String> VALID_RULE_DETAIL_TYPES = Arrays.asList(
"BUG",
"VULNERABILITY"
);

JsonReport() {

@@ -45,45 +50,57 @@ public void execute(String projectName, Date date, Collection<Trackable> trackab
Issue issue = trackable.getIssue();
RuleDetails ruleDetails = ruleDescriptionProducer.apply(issue.getRuleKey());

JsonObject json = new JsonObject();
json.addProperty("type", "issue");
json.addProperty("check_name", issue.getRuleKey());
json.addProperty("severity", ruleDetails.getSeverity().toLowerCase());
if (VALID_RULE_DETAIL_TYPES.contains(ruleDetails.getType())) {
JsonObject json = new JsonObject();
json.addProperty("type", "issue");
json.addProperty("check_name", issue.getRuleKey());
json.addProperty("severity", ruleDetails.getSeverity().toLowerCase());
json.addProperty("description", issue.getMessage());

JsonArray categories = new JsonArray();
json.add("categories", categories);
categories.add("Bug Risk");
JsonObject content = new JsonObject();
json.add("content", content);
content.addProperty("body", ruleDetails.getHtmlDescription());
// // ruleDetails.getExtendedDescription();

json.addProperty("description", issue.getMessage());
JsonObject location = new JsonObject();
json.add("location", location);

JsonObject content = new JsonObject();
json.add("content", content);
content.addProperty("body", ruleDetails.getHtmlDescription());
// // ruleDetails.getExtendedDescription();
// Code Climate CLI expects relative path to file
location.addProperty("path", issue.getInputFile().getPath().replaceFirst("^/code-read-write/", ""));

JsonObject location = new JsonObject();
json.add("location", location);
JsonObject lines = new JsonObject();
location.add("lines", lines);

// Code Climate CLI expects relative path to file
location.addProperty("path", issue.getInputFile().getPath().replaceFirst("^/code-read-write/", ""));
if (issue.getStartLine() != null) {
lines.addProperty("begin", issue.getStartLine());

JsonObject lines = new JsonObject();
location.add("lines", lines);

if (issue.getStartLine() != null) {
lines.addProperty("begin", issue.getStartLine());

if (issue.getEndLine() != null) {
lines.addProperty("end", issue.getEndLine());
if (issue.getEndLine() != null) {
lines.addProperty("end", issue.getEndLine());
} else {
lines.addProperty("end", 1);
}
} else {
lines.addProperty("begin", 1);
lines.addProperty("end", 1);
}
} else {
lines.addProperty("begin", 1);
lines.addProperty("end", 1);
}

System.out.println(json.toString() + "\0");
String category;
switch (ruleDetails.getType()) {
case "VULNERABILITY": {
category = "Security";
break;
}
default: {
category = "Bug Risk";
break;
}
}
JsonArray categories = new JsonArray();
categories.add(category);
json.add("categories", categories);

System.out.println(json.toString() + "\0");
}
}
}
}