Skip to content

Commit 6b78b32

Browse files
committed
create basics
1 parent cc9483a commit 6b78b32

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

framework/codemodder-testutils/src/main/java/io/codemodder/testutils/CodemodTestMixin.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import io.codemodder.javaparser.JavaParserFacade;
1414
import io.codemodder.javaparser.JavaParserFactory;
1515
import java.io.IOException;
16+
import java.io.UncheckedIOException;
1617
import java.nio.file.Files;
1718
import java.nio.file.Path;
1819
import java.nio.file.StandardCopyOption;
@@ -153,7 +154,7 @@ private void verifyCodemod(
153154
try {
154155
return factory.create(List.of(dir));
155156
} catch (IOException e) {
156-
throw new RuntimeException(e);
157+
throw new UncheckedIOException(e);
157158
}
158159
}),
159160
EncodingDetector.create());
@@ -210,8 +211,8 @@ private void verifyCodemod(
210211
List.of(pathToJavaFile),
211212
map,
212213
List.of(),
213-
Files.exists(sonarJson) ? sonarJson : null,
214-
Files.exists(defectDojo) ? defectDojo : null);
214+
null,
215+
null);
215216
CodemodIdPair codemod2 = loader2.getCodemods().get(0);
216217
CodemodExecutor executor2 =
217218
CodemodExecutorFactory.from(

plugins/codemodder-plugin-defectdojo/src/main/java/io/codemodder/providers/defectdojo/DefectDojoModule.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,21 @@ final class DefectDojoModule extends AbstractModule {
3131

3232
@Override
3333
protected void configure() {
34-
if (defectDojoFindingsJsonFile == null) {
35-
return;
36-
}
3734

3835
Findings findings;
39-
try {
40-
findings =
41-
new ObjectMapper()
42-
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
43-
.readValue(defectDojoFindingsJsonFile.toFile(), Findings.class);
44-
} catch (IOException e) {
45-
throw new UncheckedIOException("can't read defectdojo JSON", e);
36+
37+
// if there was no file, we still have to bind an empty result
38+
if (defectDojoFindingsJsonFile == null) {
39+
findings = new Findings(List.of());
40+
} else {
41+
try {
42+
findings =
43+
new ObjectMapper()
44+
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
45+
.readValue(defectDojoFindingsJsonFile.toFile(), Findings.class);
46+
} catch (IOException e) {
47+
throw new UncheckedIOException("can't read defectdojo JSON", e);
48+
}
4649
}
4750

4851
// create a RuleFindings instance for every rule id we come across in the findings object

plugins/codemodder-plugin-defectdojo/src/main/java/io/codemodder/providers/defectdojo/Findings.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import java.util.List;
5+
import java.util.Objects;
56

67
/** Represents the top level object in a DefectDojo findings API response. */
78
public class Findings {
89

10+
public Findings() {
11+
// needed for deserialization
12+
}
13+
14+
public Findings(final List<Finding> results) {
15+
this.results = Objects.requireNonNull(results);
16+
}
17+
918
@JsonProperty("results")
1019
private List<Finding> results;
1120

0 commit comments

Comments
 (0)