Skip to content

Commit bb426bf

Browse files
authored
Revert "Update SonarModule to receive a list of sonar hotspot files (… (#374)
#368)" This reverts commit 4214e4e.
1 parent 4214e4e commit bb426bf

File tree

19 files changed

+96
-167
lines changed

19 files changed

+96
-167
lines changed

core-codemods/src/test/java/io/codemodder/codemods/AddMissingI18nCodemodTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ private CodemodLoader createLoader(final Class<? extends CodeChanger> codemodTyp
254254
Files.list(dir).toList(),
255255
Map.of(),
256256
List.of(),
257-
List.of(),
258257
null,
259258
null,
260259
null);

core-codemods/src/test/java/io/codemodder/codemods/JSPScriptletXSSCodemodTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ void it_fixes_jsp(
5050
List.of(jsp),
5151
Map.of(),
5252
List.of(),
53-
List.of(),
5453
null,
5554
null,
5655
null);

core-codemods/src/test/java/io/codemodder/codemods/VerbTamperingCodemodTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ void it_removes_verb_tampering(
6060
List.of(webxml),
6161
Map.of(),
6262
List.of(),
63-
List.of(),
6463
null,
6564
null,
6665
null);

framework/codemodder-base/src/main/java/io/codemodder/CLI.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ final class CLI implements Callable<Integer> {
133133
description =
134134
"comma-separated set of path(s) to file(s) containing the result of a call to the Sonar Web API Hotspots endpoint",
135135
split = ",")
136-
private List<String> sonarHotspotsJsonFilePaths;
136+
private List<Path> sonarHotspotsJsonFilePaths;
137137

138138
@CommandLine.Option(
139139
names = {"--contrast-vulnerabilities-xml"},
@@ -382,7 +382,6 @@ public Integer call() throws IOException {
382382
CodeDirectory codeDirectory = new DefaultCodeDirectory(projectPath);
383383
List<Path> sarifFiles = convertToPaths(sarifs);
384384
List<Path> sonarIssuesJsonFiles = convertToPaths(sonarIssuesJsonFilePaths);
385-
List<Path> sonarHotspotJsonFiles = convertToPaths(sonarHotspotsJsonFilePaths);
386385
Map<String, List<RuleSarif>> pathSarifMap =
387386
SarifParser.create().parseIntoMap(sarifFiles, codeDirectory);
388387
List<ParameterArgument> codemodParameters =
@@ -398,7 +397,6 @@ public Integer call() throws IOException {
398397
pathSarifMap,
399398
codemodParameters,
400399
sonarIssuesJsonFiles,
401-
sonarHotspotJsonFiles,
402400
defectDojoFindingsJsonFilePath,
403401
contrastVulnerabilitiesXmlFilePath);
404402
List<CodemodIdPair> codemods = loader.getCodemods();

framework/codemodder-base/src/main/java/io/codemodder/CodemodLoader.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public CodemodLoader(
2929
final Map<String, List<RuleSarif>> ruleSarifByTool,
3030
final List<ParameterArgument> codemodParameters,
3131
final List<Path> sonarIssuesJsonFiles,
32-
final List<Path> sonarHotspotsJsonFiles,
3332
final Path defectDojoFindingsJsonFile,
3433
final Path contrastVulnerabilitiesXmlFilePath) {
3534

@@ -102,7 +101,6 @@ public CodemodLoader(
102101
orderedCodemodTypes,
103102
allWantedSarifs,
104103
sonarIssuesJsonFiles,
105-
sonarHotspotsJsonFiles,
106104
defectDojoFindingsJsonFile,
107105
contrastVulnerabilitiesXmlFilePath);
108106
allModules.addAll(modules);

framework/codemodder-base/src/main/java/io/codemodder/CodemodProvider.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ Set<AbstractModule> getModules(
3636
List<Class<? extends CodeChanger>> codemodTypes,
3737
List<RuleSarif> sarifs,
3838
List<Path> sonarIssuesJsonPaths,
39-
List<Path> sonarHotspotsJsonPaths,
4039
Path defectDojoFindingsJsonPath,
4140
Path contrastFindingsJsonPath);
4241

framework/codemodder-base/src/test/java/io/codemodder/CodemodLoaderTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ private CodemodLoader createLoader(final Class<? extends CodeChanger> codemodTyp
409409
Files.list(dir).toList(),
410410
Map.of(),
411411
List.of(),
412-
List.of(),
413412
null,
414413
null,
415414
null);
@@ -426,7 +425,6 @@ private CodemodLoader createLoader(
426425
Files.list(dir).toList(),
427426
Map.of(),
428427
List.of(),
429-
List.of(),
430428
null,
431429
null,
432430
null);
@@ -448,7 +446,6 @@ private CodemodLoader createLoader(
448446
params,
449447
null,
450448
null,
451-
null,
452449
null);
453450
}
454451
}

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

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ default Stream<DynamicTest> generateTestCases(@TempDir final Path tmpDir) throws
7878
metadata.doRetransformTest(),
7979
metadata.expectingFixesAtLines(),
8080
metadata.expectingFailedFixesAtLines(),
81-
metadata.sonarIssuesJsonFiles(),
82-
metadata.sonarHotspotsJsonFiles());
81+
metadata.sonarIssuesJsonFiles());
8382

8483
return DynamicTest.stream(inputStream, displayNameGenerator, testExecutor);
8584
}
@@ -95,8 +94,7 @@ private void verifyCodemod(
9594
final boolean doRetransformTest,
9695
final int[] expectedFixLines,
9796
final int[] expectingFailedFixesAtLines,
98-
final String[] sonarIssuesJsonFiles,
99-
final String[] sonarHotspotsJsonFiles)
97+
final String[] sonarIssuesJsonFiles)
10098
throws IOException {
10199

102100
// create a copy of the test file in the temp directory to serve as our "repository"
@@ -116,10 +114,21 @@ private void verifyCodemod(
116114
pathToJavaFile = newPathToJavaFile;
117115
}
118116

119-
final List<Path> sonarIssuesJsonsPaths =
120-
buildSonarJsonPaths(testResourceDir, sonarIssuesJsonFiles, "sonar-issues.json");
121-
final List<Path> sonarHotspotsJsonPaths =
122-
buildSonarJsonPaths(testResourceDir, sonarHotspotsJsonFiles, "sonar-hotspots.json");
117+
final List<String> sonarJsons =
118+
sonarIssuesJsonFiles != null ? Arrays.asList(sonarIssuesJsonFiles) : new ArrayList<>();
119+
120+
final List<Path> sonarJsonsPaths =
121+
sonarJsons.stream()
122+
.map(testResourceDir::resolve)
123+
.filter(Files::exists)
124+
.collect(Collectors.toList());
125+
126+
if (sonarJsonsPaths.isEmpty()) {
127+
Path defaultPath = testResourceDir.resolve("sonar-issues.json");
128+
if (Files.exists(defaultPath)) {
129+
sonarJsonsPaths.add(defaultPath);
130+
}
131+
}
123132

124133
// Check for any sarif files and build the RuleSarif map
125134
CodeDirectory codeDir = CodeDirectory.from(tmpDir);
@@ -146,8 +155,7 @@ private void verifyCodemod(
146155
List.of(pathToJavaFile),
147156
map,
148157
List.of(),
149-
sonarIssuesJsonsPaths,
150-
sonarHotspotsJsonPaths,
158+
sonarJsonsPaths,
151159
Files.exists(defectDojo) ? defectDojo : null,
152160
Files.exists(contrastXml) ? contrastXml : null);
153161

@@ -235,7 +243,6 @@ private void verifyCodemod(
235243
List.of(),
236244
null,
237245
null,
238-
null,
239246
null);
240247
CodemodIdPair codemod2 = loader2.getCodemods().get(0);
241248
CodemodExecutor executor2 =
@@ -263,29 +270,6 @@ private void verifyCodemod(
263270
assertThat(codeAfterFirstTransform, equalTo(codeAfterSecondTransform));
264271
}
265272

266-
private List<Path> buildSonarJsonPaths(
267-
final Path testResourceDir,
268-
final String[] sonarJsonFiles,
269-
final String defaultSonarFilename) {
270-
final List<String> sonarJsons =
271-
sonarJsonFiles != null ? Arrays.asList(sonarJsonFiles) : new ArrayList<>();
272-
273-
final List<Path> sonarIssuesJsonsPaths =
274-
sonarJsons.stream()
275-
.map(testResourceDir::resolve)
276-
.filter(Files::exists)
277-
.collect(Collectors.toList());
278-
279-
if (sonarIssuesJsonsPaths.isEmpty()) {
280-
Path defaultPath = testResourceDir.resolve(defaultSonarFilename);
281-
if (Files.exists(defaultPath)) {
282-
sonarIssuesJsonsPaths.add(defaultPath);
283-
}
284-
}
285-
286-
return sonarIssuesJsonsPaths;
287-
}
288-
289273
/**
290274
* A hook for verifying the before and after files. By default, this method will compare the
291275
* contents of the two files for exact equality.

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,4 @@
5151

5252
/** Sonar issues file names for testing multiple json files */
5353
String[] sonarIssuesJsonFiles() default {};
54-
55-
String[] sonarHotspotsJsonFiles() default {};
5654
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ private void verifySingleCase(
7171
List.of(),
7272
null,
7373
null,
74-
null,
7574
null);
7675
List<CodemodIdPair> codemods = loader.getCodemods();
7776
assertThat("Only expecting 1 codemod per test", codemods.size(), equalTo(1));

0 commit comments

Comments
 (0)