Skip to content

Commit 283e0e6

Browse files
committed
spotless
1 parent 32933c4 commit 283e0e6

File tree

3 files changed

+47
-47
lines changed

3 files changed

+47
-47
lines changed
Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package org.owasp.benchmark.report.sonarqube;
22

3+
import static java.lang.String.join;
4+
import static java.nio.charset.Charset.defaultCharset;
5+
import static org.apache.commons.io.FileUtils.writeStringToFile;
6+
import static org.apache.commons.io.IOUtils.readLines;
7+
38
import com.fasterxml.jackson.core.JsonProcessingException;
49
import com.fasterxml.jackson.databind.ObjectMapper;
5-
import org.owasp.benchmark.report.sonarqube.dto.SonarQubeResult;
6-
7-
import javax.xml.parsers.DocumentBuilderFactory;
810
import java.io.File;
911
import java.io.IOException;
1012
import java.net.HttpURLConnection;
@@ -15,11 +17,8 @@
1517
import java.util.List;
1618
import java.util.Set;
1719
import java.util.function.Consumer;
18-
19-
import static java.lang.String.join;
20-
import static java.nio.charset.Charset.defaultCharset;
21-
import static org.apache.commons.io.FileUtils.writeStringToFile;
22-
import static org.apache.commons.io.IOUtils.readLines;
20+
import javax.xml.parsers.DocumentBuilderFactory;
21+
import org.owasp.benchmark.report.sonarqube.dto.SonarQubeResult;
2322

2423
public class SonarReport {
2524
private static final String SONAR_USER = "admin";
@@ -30,9 +29,8 @@ public class SonarReport {
3029

3130
private static final int PAGE_SIZE = 500;
3231

33-
private static final String sonarAuth = Base64.getEncoder()
34-
.encodeToString((SONAR_USER + ":" + SONAR_PASSWORD)
35-
.getBytes());
32+
private static final String sonarAuth =
33+
Base64.getEncoder().encodeToString((SONAR_USER + ":" + SONAR_PASSWORD).getBytes());
3634

3735
private static final ObjectMapper objectMapper = new ObjectMapper();
3836

@@ -42,55 +40,56 @@ public static void main(String[] args) throws Exception {
4240
List<String> hotspots = new ArrayList<>();
4341

4442
forAllPagesAt(
45-
"issues/search?componentKeys=" + SONAR_PROJECT + "&types=VULNERABILITY&&rules=" + allJavaRules,
46-
(result -> issues.addAll(result.issues))
47-
);
43+
"issues/search?componentKeys="
44+
+ SONAR_PROJECT
45+
+ "&types=VULNERABILITY&&rules="
46+
+ allJavaRules,
47+
(result -> issues.addAll(result.issues)));
4848
forAllPagesAt(
49-
"hotspots/search?projectKey=" + SONAR_PROJECT,
50-
(result -> hotspots.addAll(result.hotspots))
51-
);
49+
"hotspots/search?projectKey=" + SONAR_PROJECT,
50+
(result -> hotspots.addAll(result.hotspots)));
5251

5352
writeStringToFile(
54-
new File("results/" + resultFilename() + ".json"),
55-
formattedJson(issues, hotspots),
56-
defaultCharset()
57-
);
53+
new File("results/" + resultFilename() + ".json"),
54+
formattedJson(issues, hotspots),
55+
defaultCharset());
5856
}
5957

6058
private static String resultFilename() throws Exception {
6159
return "Benchmark_" + benchmarkVersion() + "-sonarqube-v" + apiCall("server/version");
6260
}
6361

6462
private static String benchmarkVersion() throws Exception {
65-
return DocumentBuilderFactory
66-
.newInstance()
67-
.newDocumentBuilder()
68-
.parse(new File("pom.xml"))
69-
.getElementsByTagName("version")
70-
.item(0)
71-
.getTextContent();
63+
return DocumentBuilderFactory.newInstance()
64+
.newDocumentBuilder()
65+
.parse(new File("pom.xml"))
66+
.getElementsByTagName("version")
67+
.item(0)
68+
.getTextContent();
7269
}
7370

7471
private static Set<String> allJavaRules() throws IOException {
7572
Set<String> javaRuleIds = new HashSet<>();
7673

77-
forAllPagesAt("rules/search", (result) -> result
78-
.rules
79-
.stream().filter(rule -> rule.ruleId.startsWith("java:"))
80-
.forEach(rule -> javaRuleIds.add(rule.ruleId)));
74+
forAllPagesAt(
75+
"rules/search",
76+
(result) ->
77+
result.rules.stream()
78+
.filter(rule -> rule.ruleId.startsWith("java:"))
79+
.forEach(rule -> javaRuleIds.add(rule.ruleId)));
8180

8281
return javaRuleIds;
8382
}
8483

85-
private static void forAllPagesAt(String apiPath, Consumer<SonarQubeResult> pageHandlerCallback) throws IOException {
84+
private static void forAllPagesAt(String apiPath, Consumer<SonarQubeResult> pageHandlerCallback)
85+
throws IOException {
8686
int pages;
8787
int page = 1;
8888

8989
do {
90-
SonarQubeResult result = objectMapper.readValue(
91-
apiCall(apiPath + pagingSuffix(page, apiPath)),
92-
SonarQubeResult.class
93-
);
90+
SonarQubeResult result =
91+
objectMapper.readValue(
92+
apiCall(apiPath + pagingSuffix(page, apiPath)), SonarQubeResult.class);
9493

9594
pages = (result.paging.resultCount / PAGE_SIZE) + 1;
9695

@@ -114,11 +113,17 @@ private static String apiCall(String apiPath) throws IOException {
114113
return join("\n", readLines(connection.getInputStream(), defaultCharset()));
115114
}
116115

117-
private static String formattedJson(List<String> issues, List<String> hotspots) throws JsonProcessingException {
118-
String sb = "{\"issues\":[" + join(",", issues) + "],\"hotspots\":[" + join(",", hotspots) + "]}";
116+
private static String formattedJson(List<String> issues, List<String> hotspots)
117+
throws JsonProcessingException {
118+
String sb =
119+
"{\"issues\":["
120+
+ join(",", issues)
121+
+ "],\"hotspots\":["
122+
+ join(",", hotspots)
123+
+ "]}";
119124

120125
return objectMapper
121-
.writerWithDefaultPrettyPrinter()
122-
.writeValueAsString(objectMapper.readValue(sb, Object.class));
126+
.writerWithDefaultPrettyPrinter()
127+
.writeValueAsString(objectMapper.readValue(sb, Object.class));
123128
}
124129
}

src/main/java/org/owasp/benchmark/report/sonarqube/dto/KeepAsJsonDeserializer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@
55
import com.fasterxml.jackson.core.TreeNode;
66
import com.fasterxml.jackson.databind.DeserializationContext;
77
import com.fasterxml.jackson.databind.JsonDeserializer;
8-
98
import java.io.IOException;
109
import java.util.ArrayList;
1110
import java.util.List;
1211

13-
/**
14-
* <a href="https://stackoverflow.com/a/24085100">Credits to Roy Truelove</a>
15-
*/
12+
/** <a href="https://stackoverflow.com/a/24085100">Credits to Roy Truelove</a> */
1613
public class KeepAsJsonDeserializer extends JsonDeserializer<List<String>> {
1714

1815
@Override

src/main/java/org/owasp/benchmark/report/sonarqube/dto/SonarQubeResult.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.fasterxml.jackson.annotation.JsonAlias;
44
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
55
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
6-
76
import java.util.List;
87

98
@JsonIgnoreProperties(ignoreUnknown = true)
@@ -31,6 +30,5 @@ public static class Rule {
3130

3231
@JsonAlias("key")
3332
public String ruleId;
34-
3533
}
3634
}

0 commit comments

Comments
 (0)