From 39ab69234cb4e891d47334bd23cad4cf472e0cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Soto=20Valero?= Date: Sun, 4 Apr 2021 10:45:40 +0200 Subject: [PATCH] Just added new method for reducing redundant code (#69) Co-authored-by: Dhruvil --- .../java/se/kth/depclean/DepCleanMojo.java | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 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 c271a5f1..e815d069 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 @@ -194,6 +194,18 @@ private void printDependencies(Map sizeOfDependencies, Set .forEachRemaining(s -> printString("\t" + s + " (" + getSize(s, sizeOfDependencies) + ")")); } + /** + * Util function to print the information of the analyzed artifacts. + * + * @param info The usage status (used or unused) and type (direct, transitive, inherited) of artifacts. + * @param sizeOfDependencies The size of the JAR file of the artifact. + * @param dependencies The GAV of the artifact. + */ + private void printInfoOfDependencies(String info, Map sizeOfDependencies, Set dependencies) { + printString(info.toUpperCase() + " [" + dependencies.size() + "]" + ": "); + printDependencies(sizeOfDependencies, dependencies); + } + /** * Utility method to obtain the size of a dependency from a map of dependency -> size. If the size of the dependency * cannot be obtained form the map (no key with the name of the dependency exists), then it returns 0. @@ -535,30 +547,15 @@ public void execute() throws MojoExecutionException, MojoFailureException { printString(SEPARATOR); 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); - - printString("Used direct dependencies".toUpperCase() - + " [" + usedDirectArtifactsCoordinates.size() + "]" + ": "); - printDependencies(sizeOfDependencies, usedDirectArtifactsCoordinates); - - printString("Used inherited dependencies".toUpperCase() - + " [" + usedInheritedArtifactsCoordinates.size() + "]" + ": "); - printDependencies(sizeOfDependencies, usedInheritedArtifactsCoordinates); - - printString("Used transitive dependencies".toUpperCase() - + " [" + usedTransitiveArtifactsCoordinates.size() + "]" + ": "); - printDependencies(sizeOfDependencies, usedTransitiveArtifactsCoordinates); - - printString("Potentially unused direct dependencies".toUpperCase() - + " [" + unusedDirectArtifactsCoordinates.size() + "]" + ": "); - printDependencies(sizeOfDependencies, unusedDirectArtifactsCoordinates); - - printString("Potentially unused inherited dependencies".toUpperCase() - + " [" + unusedInheritedArtifactsCoordinates.size() + "]" + ": "); - printDependencies(sizeOfDependencies, unusedInheritedArtifactsCoordinates); - - printString("Potentially unused transitive dependencies".toUpperCase() - + " [" + unusedTransitiveArtifactsCoordinates.size() + "]" + ": "); - printDependencies(sizeOfDependencies, unusedTransitiveArtifactsCoordinates); + printInfoOfDependencies("Used direct dependencies", sizeOfDependencies, usedDirectArtifactsCoordinates); + printInfoOfDependencies("Used inherited dependencies", sizeOfDependencies, usedInheritedArtifactsCoordinates); + printInfoOfDependencies("Used transitive dependencies", sizeOfDependencies, usedTransitiveArtifactsCoordinates); + printInfoOfDependencies("Potentially unused direct dependencies", sizeOfDependencies, + unusedDirectArtifactsCoordinates); + printInfoOfDependencies("Potentially unused inherited dependencies", sizeOfDependencies, + unusedInheritedArtifactsCoordinates); + printInfoOfDependencies("Potentially unused transitive dependencies", sizeOfDependencies, + unusedTransitiveArtifactsCoordinates); if (!ignoreDependencies.isEmpty()) { printString(SEPARATOR);