Skip to content

Commit

Permalink
Move depclean-results.json to the root of the project
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarsotovalero committed Nov 25, 2020
1 parent 0f1a295 commit 227ed39
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -256,7 +255,6 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}

// --- used dependencies

Set<String> usedDirectArtifactsCoordinates = new HashSet<>();
Set<String> usedInheritedArtifactsCoordinates = new HashSet<>();
Set<String> usedTransitiveArtifactsCoordinates = new HashSet<>();
Expand Down Expand Up @@ -284,7 +282,6 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}

// --- unused dependencies

Set<String> unusedDirectArtifactsCoordinates = new HashSet<>();
Set<String> unusedInheritedArtifactsCoordinates = new HashSet<>();
Set<String> unusedTransitiveArtifactsCoordinates = new HashSet<>();
Expand All @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -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(
Expand All @@ -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.");
}
Expand Down

0 comments on commit 227ed39

Please sign in to comment.