@@ -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