Skip to content

Commit 6e61316

Browse files
authored
Merge pull request #20 from hangga/devel-build-report
update : move report files
2 parents d3dc2b1 + ac36c6c commit 6e61316

File tree

3 files changed

+58
-9
lines changed

3 files changed

+58
-9
lines changed

src/main/java/io/github/hangga/delvelin/cwedetectors/GeneralScanner.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.IOException;
44
import java.nio.file.Path;
5+
import java.util.ArrayList;
56
import java.util.Arrays;
67
import java.util.List;
78

@@ -11,9 +12,23 @@
1112

1213
public class GeneralScanner {
1314

14-
private final List<BaseDetector> detectors = Arrays.asList(
15+
// private final List<BaseDetector> detectors = Arrays.asList(
16+
// new ThreadDetector(),
17+
// // new NonAtomicDetector(),
18+
// new HardCodedSecretDetector(),
19+
// new NonThreadSafeDetector(),
20+
// new XSSDetector(),
21+
// new SQLInjectionDetector(),
22+
// new CmdInjectionDetector(),
23+
// new WeakCryptographicDetector(),
24+
// new InsecureHttpDetector(),
25+
// new OsvDetector()
26+
// // add new detector here
27+
// );
28+
29+
private final List<BaseDetector> detectors = new ArrayList<>(Arrays.asList(
1530
new ThreadDetector(),
16-
// new NonAtomicDetector(),
31+
// new NonAtomicDetector(),
1732
new HardCodedSecretDetector(),
1833
new NonThreadSafeDetector(),
1934
new XSSDetector(),
@@ -23,7 +38,8 @@ public class GeneralScanner {
2338
new InsecureHttpDetector(),
2439
new OsvDetector()
2540
// add new detector here
26-
);
41+
));
42+
2743

2844
private boolean shouldSkipLine(String line) {
2945
return line.startsWith("import") || line.startsWith("public void") || line.startsWith("private void") || line.startsWith("protected void") ||

src/main/java/io/github/hangga/delvelin/properties/Config.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ public class Config {
99

1010
public static OutputFileFormat outputFileFormat = OutputFileFormat.LOG;
1111

12-
public static String VERSION = "0.2.0-beta";
12+
public static String VERSION = "0.2.1-beta";
1313
}

src/main/java/io/github/hangga/delvelin/utils/FileUtil.java

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,55 @@ public static String extract(Path path) throws IOException {
3535
return new String(Files.readAllBytes(path));
3636
}
3737

38+
// public static void saveOutputFile(String content, String extName) {
39+
// Path path = FileUtil.getBasePath();
40+
// Path outputPath = Paths.get(path.toString(), "vulnerability-report" + extName);
41+
// try {
42+
// Files.write(outputPath, content.getBytes());
43+
// if (Desktop.isDesktopSupported() && extName.equalsIgnoreCase(".html") && Config.isAutoLaunchBrowser) {
44+
// Desktop.getDesktop()
45+
// .browse(outputPath.toUri());
46+
// } else {
47+
// System.out.println("Report saved: file://" + outputPath.toAbsolutePath());
48+
// }
49+
// } catch (IOException e) {
50+
// throw new RuntimeException("Failed to save HTML report to file: " + path, e);
51+
// }
52+
// }
53+
3854
public static void saveOutputFile(String content, String extName) {
39-
Path path = FileUtil.getBasePath();
40-
Path outputPath = Paths.get(path.toString(), "vulnerability-report" + extName);
55+
Path basePath;
56+
57+
if (Files.exists(Paths.get("target", "surefire-reports"))) {
58+
basePath = Paths.get("target", "surefire-reports"); // Maven Surefire (Unit Test)
59+
} else if (Files.exists(Paths.get("target", "failsafe-reports"))) {
60+
basePath = Paths.get("target", "failsafe-reports"); // Maven Failsafe (Integration Test)
61+
} else if (Files.exists(Paths.get("build", "reports", "tests", "test"))) {
62+
basePath = Paths.get("build", "reports", "tests", "test"); // Gradle JUnit
63+
} else {
64+
basePath = FileUtil.getBasePath(); // Fallback jika tidak ditemukan
65+
}
66+
67+
saveFile(content, extName, basePath);
68+
}
69+
70+
private static void saveFile(String content, String extName, Path basePath) {
4171
try {
72+
Files.createDirectories(basePath);
73+
Path outputPath = basePath.resolve("vulnerability-report" + extName);
4274
Files.write(outputPath, content.getBytes());
75+
4376
if (Desktop.isDesktopSupported() && extName.equalsIgnoreCase(".html") && Config.isAutoLaunchBrowser) {
44-
Desktop.getDesktop()
45-
.browse(outputPath.toUri());
77+
Desktop.getDesktop().browse(outputPath.toUri());
4678
} else {
4779
System.out.println("Report saved: file://" + outputPath.toAbsolutePath());
4880
}
4981
} catch (IOException e) {
50-
throw new RuntimeException("Failed to save HTML report to file: " + path, e);
82+
throw new RuntimeException("Failed to save report to file: " + basePath, e);
5183
}
5284
}
5385

86+
5487
public static void saveOutputCustom(String content, String extName) {
5588
JFileChooser fileChooser = getJFileChooser(extName);
5689
// Show save dialog and get the user's choice

0 commit comments

Comments
 (0)