Skip to content

Commit

Permalink
Fix #18
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarsotovalero committed Nov 16, 2020
1 parent e9dacba commit 1ea2b5a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,15 @@
import java.nio.file.Paths;
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
* This Maven mojo is the main class of DepClean.
Expand Down Expand Up @@ -285,16 +288,16 @@ public void execute() throws MojoExecutionException, MojoFailureException {
System.out.println(SEPARATOR);

System.out.println("Used direct dependencies" + " [" + usedDeclaredArtifactsCoordinates.size() + "]" + ": ");
usedDeclaredArtifactsCoordinates.stream().forEach(s -> System.out.println("\t" + s + " (" + getSize(s, sizeOfDependencies) + ")"));
printDependencies(sizeOfDependencies, usedDeclaredArtifactsCoordinates);

System.out.println("Used transitive dependencies" + " [" + usedUndeclaredArtifactsCoordinates.size() + "]" + ": ");
usedUndeclaredArtifactsCoordinates.stream().forEach(s -> System.out.println("\t" + s + " (" + getSize(s, sizeOfDependencies) + ")"));
printDependencies(sizeOfDependencies, usedUndeclaredArtifactsCoordinates);

System.out.println("Potentially unused direct dependencies" + " [" + unusedDeclaredArtifactsCoordinates.size() + "]" + ": ");
unusedDeclaredArtifactsCoordinates.stream().forEach(s -> System.out.println("\t" + s + " (" + getSize(s, sizeOfDependencies) + ")"));
printDependencies(sizeOfDependencies, unusedDeclaredArtifactsCoordinates);

System.out.println("Potentially unused transitive dependencies" + " [" + unusedUndeclaredArtifactsCoordinates.size() + "]" + ": ");
unusedUndeclaredArtifactsCoordinates.stream().forEach(s -> System.out.println("\t" + s + " (" + getSize(s, sizeOfDependencies) + ")"));
printDependencies(sizeOfDependencies, unusedUndeclaredArtifactsCoordinates);

if (!ignoreDependencies.isEmpty()) {
System.out.println(SEPARATOR);
Expand Down Expand Up @@ -400,6 +403,22 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
}

/**
* Print the status of the depenencies to the standard output.
* The format is: "[coordinates][scope] [(size)]"
*
* @param sizeOfDependencies A map with the size of the dependencies.
* @param dependencies The set dependencies to print.
*/
private void printDependencies(Map<String, Long> sizeOfDependencies, Set<String> dependencies) {
dependencies
.stream()
.sorted(Comparator.comparing(o -> sizeOfDependencies.get(o.split(":")[1] + "-" + o.split(":")[2] + ".jar")))
.collect(Collectors.toCollection(LinkedList::new))
.descendingIterator()
.forEachRemaining(s -> System.out.println("\t" + s + " (" + getSize(s, sizeOfDependencies) + ")"));
}

/**
* Get the size of the dependency in humnan readable format.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private static void decompressJarFile(String destDirectory, String jarFilePath)
JarEntry entry = jarIn.getNextJarEntry();
// iterates over all the entries in the jar file
while (entry != null) {
String filePath = destDirectory + "/" + entry.getName();
String filePath = destDirectory + File.separator + entry.getName();
if (!entry.isDirectory()) {
new File(filePath).getParentFile().mkdirs();
// if the entry is a file, extracts it
Expand Down

0 comments on commit 1ea2b5a

Please sign in to comment.