From 227ed390f2511b220f18c952cad6a7c91e627d29 Mon Sep 17 00:00:00 2001 From: cesarsotovalero Date: Wed, 25 Nov 2020 13:49:52 +0100 Subject: [PATCH] Move depclean-results.json to the root of the project --- .../main/java/se/kth/depclean/DepCleanMojo.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/depclean-maven-plugin/src/main/java/se/kth/depclean/DepCleanMojo.java b/depclean-maven-plugin/src/main/java/se/kth/depclean/DepCleanMojo.java index 63586d4c..2664c4ec 100644 --- a/depclean-maven-plugin/src/main/java/se/kth/depclean/DepCleanMojo.java +++ b/depclean-maven-plugin/src/main/java/se/kth/depclean/DepCleanMojo.java @@ -177,7 +177,6 @@ public void execute() throws MojoExecutionException, MojoFailureException { return; } - String pathToDebloatedPom = project.getBasedir().getAbsolutePath() + File.separator + "pom-debloated.xml"; /* Build Maven model to manipulate the pom */ Model model; @@ -256,7 +255,6 @@ public void execute() throws MojoExecutionException, MojoFailureException { } // --- used dependencies - Set usedDirectArtifactsCoordinates = new HashSet<>(); Set usedInheritedArtifactsCoordinates = new HashSet<>(); Set usedTransitiveArtifactsCoordinates = new HashSet<>(); @@ -284,7 +282,6 @@ public void execute() throws MojoExecutionException, MojoFailureException { } // --- unused dependencies - Set unusedDirectArtifactsCoordinates = new HashSet<>(); Set unusedInheritedArtifactsCoordinates = new HashSet<>(); Set unusedTransitiveArtifactsCoordinates = new HashSet<>(); @@ -311,7 +308,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { } } - /* Ignoring dependencies from analysis */ + /* Ignoring dependencies from the analysis */ if (ignoreDependencies != null) { for (String ignoredDependency : ignoreDependencies) { // if the ignored dependency is an unused direct dependency then add it to the set of used direct @@ -348,7 +345,6 @@ public void execute() throws MojoExecutionException, MojoFailureException { } /* Printing the results to the console */ - printString(" D E P C L E A N A N A L Y S I S R E S U L T S"); printString(SEPARATOR); @@ -436,6 +432,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { } /* Write the debloated pom file */ + String pathToDebloatedPom = project.getBasedir().getAbsolutePath() + File.separator + "pom-debloated.xml"; try { Path path = Paths.get(pathToDebloatedPom); writePom(path, model); @@ -450,13 +447,13 @@ public void execute() throws MojoExecutionException, MojoFailureException { /* Writing the JSON file with the debloat results */ if (createResultJson) { - String jsonFile = project.getBuild().getDirectory() + File.separator + "depclean-results.json"; + String pathToJsonFile = project.getBasedir().getAbsolutePath() + File.separator + "depclean-results.json"; String treeFile = project.getBuild().getDirectory() + File.separator + "tree.txt"; /* Copy direct dependencies locally */ try { MavenInvoker.runCommand("mvn dependency:tree -DoutputFile=" + treeFile + " -Dverbose=true"); } catch (IOException e) { - getLog().error("Unable generate dependency tree."); + getLog().error("Unable to generate dependency tree."); return; } ParsedDependencies parsedDependencies = new ParsedDependencies( @@ -470,8 +467,8 @@ public void execute() throws MojoExecutionException, MojoFailureException { unusedTransitiveArtifactsCoordinates ); try { - FileUtils.write(new File(jsonFile), parsedDependencies.parseTreeToJSON(), Charset.defaultCharset()); - getLog().info("depclean-results.json file created in " + jsonFile); + FileUtils.write(new File(pathToJsonFile), parsedDependencies.parseTreeToJSON(), Charset.defaultCharset()); + getLog().info("depclean-results.json file created in: " + pathToJsonFile); } catch (ParseException | IOException e) { getLog().error("Unable to generate JSON file."); }