From 0303e5a727cbe62fa47fc7b26e401f270bfd88ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Soto=20Valero?= Date: Tue, 13 Apr 2021 01:47:25 +0200 Subject: [PATCH] Add IT for depclean-results.json creation (#83) --- .../depclean/core/analysis/ArtifactTypes.java | 12 +-- .../DefaultProjectDependencyAnalyzer.java | 81 ++++++++++++------- .../java/se/kth/depclean/DepCleanMojo.java | 53 +++++++----- .../kth/depclean/util/json/NodeAdapter.java | 69 ++++++---------- .../util/json/ParsedDependencies.java | 45 +++-------- .../java/se/kth/depclean/DepCleanMojoIT.java | 48 +++++++---- .../json_should_be_correct/pom.xml | 36 --------- 7 files changed, 153 insertions(+), 191 deletions(-) delete mode 100644 depclean-maven-plugin/src/test/resources-its/se/kth/depclean/DepCleanMojoIT/json_should_be_correct/pom.xml diff --git a/depclean-core/src/main/java/se/kth/depclean/core/analysis/ArtifactTypes.java b/depclean-core/src/main/java/se/kth/depclean/core/analysis/ArtifactTypes.java index 2d0b6b17..dbc24312 100644 --- a/depclean-core/src/main/java/se/kth/depclean/core/analysis/ArtifactTypes.java +++ b/depclean-core/src/main/java/se/kth/depclean/core/analysis/ArtifactTypes.java @@ -1,12 +1,14 @@ package se.kth.depclean.core.analysis; import java.util.Set; +import lombok.AllArgsConstructor; import lombok.Data; /** * POJO containing the types in an artifact. */ @Data +@AllArgsConstructor public class ArtifactTypes { /** @@ -19,14 +21,4 @@ public class ArtifactTypes { */ private Set usedTypes; - /** - * Ctor. - * - * @param allTypes All types in the artifact. - * @param usedTypes Thew used types in the artifact. - */ - public ArtifactTypes(Set allTypes, Set usedTypes) { - this.allTypes = allTypes; - this.usedTypes = usedTypes; - } } diff --git a/depclean-core/src/main/java/se/kth/depclean/core/analysis/DefaultProjectDependencyAnalyzer.java b/depclean-core/src/main/java/se/kth/depclean/core/analysis/DefaultProjectDependencyAnalyzer.java index 1548ac67..21104c92 100644 --- a/depclean-core/src/main/java/se/kth/depclean/core/analysis/DefaultProjectDependencyAnalyzer.java +++ b/depclean-core/src/main/java/se/kth/depclean/core/analysis/DefaultProjectDependencyAnalyzer.java @@ -41,23 +41,31 @@ import se.kth.depclean.core.analysis.graph.DefaultCallGraph; /** - * The principal class that perform the dependency analysis in a Maven project. + * This is principal class that perform the dependency analysis in a Maven project. */ @Slf4j @Component(role = ProjectDependencyAnalyzer.class) public class DefaultProjectDependencyAnalyzer implements ProjectDependencyAnalyzer { - /** - * If true, the project's classes in target/test-classes are not going to be analyzed. - */ - private final boolean isIgnoredTest; - @Requirement private final ClassAnalyzer classAnalyzer = new DefaultClassAnalyzer(); @Requirement private final DependencyAnalyzer dependencyAnalyzer = new ASMDependencyAnalyzer(); + /** + * If true, the project's classes in target/test-classes are not going to be analyzed. + */ + private final boolean isIgnoredTest; + + /** + * A map [artifact] -> [allTypes]. + */ + private Map> artifactClassesMap; + + /** + * A map [artifact] -> [usedTypes]. + */ private final Map> artifactUsedClassesMap = new HashMap<>(); /** @@ -67,11 +75,6 @@ public DefaultProjectDependencyAnalyzer(boolean isIgnoredTest) { this.isIgnoredTest = isIgnoredTest; } - /** - * A map [dependency] -> [dependency classes]. - */ - private Map> artifactClassesMap; - /** * Analyze the dependencies in a project. * @@ -108,7 +111,6 @@ public ProjectDependencyAnalysis analyze(MavenProject project) throws ProjectDep ); Set usedArtifacts = collectUsedArtifactsFromProcessors(project, artifactClassesMap); - /* ******************** results as statically used at the bytecode *********************** */ // for the used dependencies, get the ones that are declared @@ -127,12 +129,12 @@ public ProjectDependencyAnalysis analyze(MavenProject project) throws ProjectDep } catch (IOException exception) { throw new ProjectDependencyAnalyzerException("Cannot analyze dependencies", exception); } + } /** * Maven processors are defined like this. - *
-   * {@code
+   * 
{@code
    *       
    *         org.bsc.maven
    *         maven-processor-plugin
@@ -148,8 +150,7 @@ public ProjectDependencyAnalysis analyze(MavenProject project) throws ProjectDep
    *           
    *         
    *       
-   * }
-   * 
+ * }
* * @param project the maven project * @param artifactClassesMap previously built artifacts map @@ -167,6 +168,7 @@ private Set collectUsedArtifactsFromProcessors(MavenProject project, .forEach(processor -> findArtifactForClassName(artifactClassesMap, processor.getValue()) .ifPresent(artifact -> artifactUsedClassesMap.putIfAbsent(artifact, new HashSet<>())) ); + return artifactUsedClassesMap.keySet(); } @@ -222,16 +224,31 @@ private void buildDependenciesDependencyClasses(MavenProject project) throws IOE collectDependencyClasses(dependenciesDirectory); } - private Set collectUsedArtifacts(Map> artifactClassMap, + /** + * Determine the artifacts that are used. + * + * @param artifactClassMap A map of [artifact] -> [classes in the artifact]. + * @param referencedClasses A set of classes that are detected as used. + * @return The set of used artifacts. + */ + private Set collectUsedArtifacts( + Map> artifactClassMap, Set referencedClasses) { - // find for used members in each class in the dependency classes + Set usedArtifacts = new HashSet<>(); for (String clazz : referencedClasses) { - findArtifactForClassName(artifactClassMap, clazz) - .ifPresent(artifact -> artifactUsedClassesMap.putIfAbsent(artifact, new HashSet<>())); + Optional artifact = findArtifactForClassName(artifactClassMap, clazz); + if (artifact.isPresent()) { + if (!artifactUsedClassesMap.containsKey(artifact.get())) { + artifactUsedClassesMap.put(artifact.get(), new HashSet<>()); + } + artifactUsedClassesMap.get(artifact.get()).add(clazz); + usedArtifacts.add(artifact.get()); + } } - return artifactUsedClassesMap.keySet(); + return usedArtifacts; } + private Optional findArtifactForClassName(Map> artifactClassMap, String className) { for (Map.Entry> entry : artifactClassMap.entrySet()) { if (entry.getValue().contains(className)) { @@ -272,24 +289,26 @@ private Set collectDependencyClasses(String path) throws IOException { } /** - * Computes a map of artifacts and their types. + * Computes a map of [artifact] -> [allTypes, usedTypes]. * - * @return A map of artifact -> classes + * @return A map of [artifact] -> [allTypes, usedTypes] */ public Map getArtifactClassesMap() { Map output = new HashMap<>(); for (Map.Entry> entry : artifactClassesMap.entrySet()) { Artifact key = entry.getKey(); if (artifactUsedClassesMap.containsKey(key)) { - output.put(key.toString(), new ArtifactTypes( - artifactClassesMap.get(key), // get all the types - artifactUsedClassesMap.get(key) // get used types - )); + output.put(key.toString(), + new ArtifactTypes( + artifactClassesMap.get(key), // get all the types + artifactUsedClassesMap.get(key) // get used types + )); } else { - output.put(key.toString(), new ArtifactTypes( - artifactClassesMap.get(key), // get all the types - new HashSet<>() // get used types - )); + output.put(key.toString(), + new ArtifactTypes( + artifactClassesMap.get(key), // get all the types + new HashSet<>() // get used types + )); } } return output; 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 e815d069..ad196ee9 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 @@ -104,11 +104,19 @@ public class DepCleanMojo extends AbstractMojo { /** * If this is true, DepClean creates a JSON file with the result of the analysis. The file is called - * "debloat-result.json" and it is located in the root of the project. + * "debloat-result.json" and it is located in /target. */ @Parameter(property = "createResultJson", defaultValue = "false") private boolean createResultJson; + + /** + * If this is true, DepClean creates a CSV file with the result of the analysis with the columns: + * OriginClass,TargetClass,Dependency. The file is called "class-usage.csv" and it is located in /target. + */ + @Parameter(property = "createClassUsageCsv", defaultValue = "false") + private boolean createClassUsageCsv; + /** * Add a list of dependencies, identified by their coordinates, to be ignored by DepClean during the analysis and * considered as used dependencies. Useful to override incomplete result caused by bytecode-level analysis Dependency @@ -167,6 +175,7 @@ public class DepCleanMojo extends AbstractMojo { @Component(hint = "default") private DependencyGraphBuilder dependencyGraphBuilder; + /** * Write pom file to the filesystem. * @@ -392,7 +401,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { Iterator iterator = FileUtils.iterateFiles( new File( project.getBuild().getDirectory() + File.separator - + DIRECTORY_TO_COPY_DEPENDENCIES), new String[]{"jar"}, true); + + DIRECTORY_TO_COPY_DEPENDENCIES), new String[] {"jar"}, true); while (iterator.hasNext()) { File file = iterator.next(); sizeOfDependencies.put(file.getName(), FileUtils.sizeOf(file)); @@ -411,8 +420,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { /* Analyze dependencies usage status */ ProjectDependencyAnalysis projectDependencyAnalysis; - DefaultProjectDependencyAnalyzer dependencyAnalyzer = new DefaultProjectDependencyAnalyzer( - ignoreTests); + DefaultProjectDependencyAnalyzer dependencyAnalyzer = new DefaultProjectDependencyAnalyzer(ignoreTests); try { projectDependencyAnalysis = dependencyAnalyzer.analyze(project); } catch (ProjectDependencyAnalyzerException e) { @@ -543,7 +551,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { } } - /* Printing the results to the console */ + /* Printing the results to the terminal */ 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); @@ -652,7 +660,6 @@ public void execute() throws MojoExecutionException, MojoFailureException { } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } - getLog().info("POM debloated successfully"); getLog().info("pom-debloated.xml file created in: " + pathToDebloatedPom); } @@ -661,10 +668,9 @@ public void execute() throws MojoExecutionException, MojoFailureException { /* Writing the JSON file with the debloat results */ if (createResultJson) { printString("Creating depclean-results.json, please wait..."); - String pathToJsonFile = - project.getBasedir().getAbsolutePath() + File.separator + "depclean-results.json"; - String treeFile = project.getBuild().getDirectory() + File.separator + "tree.txt"; - /* Copy direct dependencies locally */ + final File jsonFile = new File(project.getBuild().getDirectory() + File.separator + "depclean-results.json"); + final File treeFile = new File(project.getBuild().getDirectory() + File.separator + "tree.txt"); + final File classUsageFile = new File(project.getBuild().getDirectory() + File.separator + "class-usage.csv"); try { MavenInvoker.runCommand("mvn dependency:tree -DoutputFile=" + treeFile + " -Dverbose=true"); } catch (IOException | InterruptedException e) { @@ -673,13 +679,13 @@ public void execute() throws MojoExecutionException, MojoFailureException { Thread.currentThread().interrupt(); return; } - File classUsageFile = new File( - project.getBasedir().getAbsolutePath() + File.separator + "class-usage.csv"); - try { - FileUtils.write(classUsageFile, "OriginClass,TargetClass,Dependency\n", - Charset.defaultCharset()); - } catch (IOException e) { - getLog().error("Error writing the CSV header."); + if (createClassUsageCsv) { + printString("Creating class-usage.csv, please wait..."); + try { + FileUtils.write(classUsageFile, "OriginClass,TargetClass,Dependency\n", Charset.defaultCharset()); + } catch (IOException e) { + getLog().error("Error writing the CSV header."); + } } ParsedDependencies parsedDependencies = new ParsedDependencies( treeFile, @@ -691,15 +697,20 @@ public void execute() throws MojoExecutionException, MojoFailureException { unusedDirectArtifactsCoordinates, unusedInheritedArtifactsCoordinates, unusedTransitiveArtifactsCoordinates, - classUsageFile + classUsageFile, + createClassUsageCsv ); try { - FileUtils.write(new File(pathToJsonFile), parsedDependencies.parseTreeToJson(), - Charset.defaultCharset()); - getLog().info("depclean-results.json file created in: " + pathToJsonFile); + FileUtils.write(jsonFile, parsedDependencies.parseTreeToJson(), Charset.defaultCharset()); } catch (ParseException | IOException e) { getLog().error("Unable to generate JSON file."); } + if (jsonFile.exists()) { + getLog().info("depclean-results.json file created in: " + jsonFile.getAbsolutePath()); + } + if (classUsageFile.exists()) { + getLog().info("class-usage.csv file created in: " + classUsageFile.getAbsolutePath()); + } } } } diff --git a/depclean-maven-plugin/src/main/java/se/kth/depclean/util/json/NodeAdapter.java b/depclean-maven-plugin/src/main/java/se/kth/depclean/util/json/NodeAdapter.java index 2951d350..da989875 100644 --- a/depclean-maven-plugin/src/main/java/se/kth/depclean/util/json/NodeAdapter.java +++ b/depclean-maven-plugin/src/main/java/se/kth/depclean/util/json/NodeAdapter.java @@ -9,13 +9,15 @@ import java.nio.charset.Charset; import java.util.Map; import java.util.Set; +import lombok.AllArgsConstructor; import org.apache.commons.io.FileUtils; import se.kth.depclean.core.analysis.DefaultProjectDependencyAnalyzer; import se.kth.depclean.core.analysis.graph.DefaultCallGraph; /** - * Custom custom Gson type adapter to write a JSON file with information of the dependencies. + * Custom Gson type adapter to write a JSON file with information of the dependencies. */ +@AllArgsConstructor public class NodeAdapter extends TypeAdapter { private final Set usedDirectArtifactsCoordinates; @@ -24,55 +26,21 @@ public class NodeAdapter extends TypeAdapter { private final Set unusedDirectArtifactsCoordinates; private final Set unusedInheritedArtifactsCoordinates; private final Set unusedTransitiveArtifactsCoordinates; + private final Map sizeOfDependencies; private final DefaultProjectDependencyAnalyzer dependencyAnalyzer; private final File classUsageFile; - private final Map sizeOfDependencies; - - /** - * Ctor. - */ - public NodeAdapter(Set usedDirectArtifactsCoordinates, - Set usedInheritedArtifactsCoordinates, - Set usedTransitiveArtifactsCoordinates, - Set unusedDirectArtifactsCoordinates, - Set unusedInheritedArtifactsCoordinates, - Set unusedTransitiveArtifactsCoordinates, - Map sizeOfDependencies, - DefaultProjectDependencyAnalyzer dependencyAnalyzer, - File classUsageFile) { - this.usedDirectArtifactsCoordinates = usedDirectArtifactsCoordinates; - this.usedInheritedArtifactsCoordinates = usedInheritedArtifactsCoordinates; - this.usedTransitiveArtifactsCoordinates = usedTransitiveArtifactsCoordinates; - this.unusedDirectArtifactsCoordinates = unusedDirectArtifactsCoordinates; - this.unusedInheritedArtifactsCoordinates = unusedInheritedArtifactsCoordinates; - this.unusedTransitiveArtifactsCoordinates = unusedTransitiveArtifactsCoordinates; - this.sizeOfDependencies = sizeOfDependencies; - this.dependencyAnalyzer = dependencyAnalyzer; - this.classUsageFile = classUsageFile; - } + private boolean createClassUsageCsv; @Override public void write(JsonWriter jsonWriter, Node node) throws IOException { - String coordinates = - node.getGroupId() + ":" + node.getArtifactId() + ":" + node.getVersion() + ":" + node.getScope(); - String canonical = - node.getGroupId() + ":" + node.getArtifactId() + ":" + node.getPackaging() + ":" + node.getVersion() - + ":" + node.getScope(); + String ga = node.getGroupId() + ":" + node.getArtifactId(); + String vs = node.getVersion() + ":" + node.getScope(); + String coordinates = ga + ":" + vs; + String canonical = ga + ":" + node.getPackaging() + ":" + vs; String dependencyJar = node.getArtifactId() + "-" + node.getVersion() + ".jar"; - // Write to the class-usage.csv file - DefaultCallGraph defaultCallGraph = new DefaultCallGraph(); - for (Map.Entry> usagePerClassMap : defaultCallGraph.getUsagesPerClass().entrySet()) { - String key = usagePerClassMap.getKey(); - Set value = usagePerClassMap.getValue(); - for (String s : value) { - if (dependencyAnalyzer.getArtifactClassesMap().containsKey(canonical) && dependencyAnalyzer - .getArtifactClassesMap().get(canonical).getAllTypes().contains(s)) { - // System.out.println(key + " uses " + s + " from " + canonical); - String triplet = key + "," + s + "," + canonical + "\n"; - FileUtils.write(classUsageFile, triplet, Charset.defaultCharset(), true); - } - } + if (createClassUsageCsv) { + writeClassUsageCsv(canonical); } JsonWriter localWriter = jsonWriter.beginObject() @@ -157,6 +125,21 @@ public void write(JsonWriter jsonWriter, Node node) throws IOException { .endObject(); } + private void writeClassUsageCsv(String canonical) throws IOException { + DefaultCallGraph defaultCallGraph = new DefaultCallGraph(); + for (Map.Entry> usagePerClassMap : defaultCallGraph.getUsagesPerClass().entrySet()) { + String key = usagePerClassMap.getKey(); + Set value = usagePerClassMap.getValue(); + for (String s : value) { + if (dependencyAnalyzer.getArtifactClassesMap().containsKey(canonical) && dependencyAnalyzer + .getArtifactClassesMap().get(canonical).getAllTypes().contains(s)) { + String triplet = key + "," + s + "," + canonical + "\n"; + FileUtils.write(classUsageFile, triplet, Charset.defaultCharset(), true); + } + } + } + } + @Override public Node read(JsonReader jsonReader) { throw new UnsupportedOperationException(); diff --git a/depclean-maven-plugin/src/main/java/se/kth/depclean/util/json/ParsedDependencies.java b/depclean-maven-plugin/src/main/java/se/kth/depclean/util/json/ParsedDependencies.java index 767bfbbb..3f634f3b 100644 --- a/depclean-maven-plugin/src/main/java/se/kth/depclean/util/json/ParsedDependencies.java +++ b/depclean-maven-plugin/src/main/java/se/kth/depclean/util/json/ParsedDependencies.java @@ -15,6 +15,7 @@ import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.Set; +import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import se.kth.depclean.core.analysis.DefaultProjectDependencyAnalyzer; @@ -23,9 +24,11 @@ * the structure of the dependency tree enriched with metadata of the usage or not of each dependency. */ @Slf4j +@AllArgsConstructor public class ParsedDependencies { - private final String treeTextFilePath; + private final File treeFile; + private final Map sizeOfDependencies; private final DefaultProjectDependencyAnalyzer dependencyAnalyzer; private final Set usedDirectArtifactsCoordinates; private final Set usedInheritedArtifactsCoordinates; @@ -33,47 +36,21 @@ public class ParsedDependencies { private final Set unusedDirectArtifactsCoordinates; private final Set unusedInheritedArtifactsCoordinates; private final Set unusedTransitiveArtifactsCoordinates; - private final Map sizeOfDependencies; private final File classUsageFile; - - /** - * Ctor. - */ - public ParsedDependencies(String treeTextFilePath, - Map sizeOfDependencies, - DefaultProjectDependencyAnalyzer dependencyAnalyzer, - Set usedDirectArtifactsCoordinates, - Set usedInheritedArtifactsCoordinates, - Set usedUndeclaredArtifactsCoordinates, - Set unusedDirectArtifactsCoordinates, - Set unusedInheritedArtifactsCoordinates, - Set unusedUndeclaredArtifactsCoordinates, - File classUsageFile) { - this.treeTextFilePath = treeTextFilePath; - this.sizeOfDependencies = sizeOfDependencies; - this.dependencyAnalyzer = dependencyAnalyzer; - this.usedDirectArtifactsCoordinates = usedDirectArtifactsCoordinates; - this.usedInheritedArtifactsCoordinates = usedInheritedArtifactsCoordinates; - this.usedTransitiveArtifactsCoordinates = usedUndeclaredArtifactsCoordinates; - this.unusedDirectArtifactsCoordinates = unusedDirectArtifactsCoordinates; - this.unusedInheritedArtifactsCoordinates = unusedInheritedArtifactsCoordinates; - this.unusedTransitiveArtifactsCoordinates = unusedUndeclaredArtifactsCoordinates; - this.classUsageFile = classUsageFile; - } + private final boolean createClassUsageCsv; /** * Creates string with the JSON representation of the enriched dependency tree of the Maven project. * - * @return The JSON representation of the dependency tree of the project with additional metadata of the used/unused - * dependencies. + * @return The JSON representation of the dependency tree of the project with additional metadata of the + * used/unused dependencies. + * * @throws ParseException if there are parsing errors. * @throws IOException if the JSON file cannot be written. */ public String parseTreeToJson() throws ParseException, IOException { InputType type = InputType.TEXT; - Reader r = new BufferedReader(new InputStreamReader( - new FileInputStream(treeTextFilePath), StandardCharsets.UTF_8 - )); + Reader r = new BufferedReader(new InputStreamReader(new FileInputStream(treeFile), StandardCharsets.UTF_8)); Parser parser = type.newParser(); Node tree = parser.parse(r); NodeAdapter nodeAdapter = new NodeAdapter( @@ -85,13 +62,13 @@ public String parseTreeToJson() throws ParseException, IOException { unusedTransitiveArtifactsCoordinates, sizeOfDependencies, dependencyAnalyzer, - classUsageFile + classUsageFile, + createClassUsageCsv ); GsonBuilder gsonBuilder = new GsonBuilder() .setPrettyPrinting() .registerTypeAdapter(Node.class, nodeAdapter); Gson gson = gsonBuilder.create(); - return gson.toJson(tree); } } diff --git a/depclean-maven-plugin/src/test/java/se/kth/depclean/DepCleanMojoIT.java b/depclean-maven-plugin/src/test/java/se/kth/depclean/DepCleanMojoIT.java index b47b97f2..8f47d047 100644 --- a/depclean-maven-plugin/src/test/java/se/kth/depclean/DepCleanMojoIT.java +++ b/depclean-maven-plugin/src/test/java/se/kth/depclean/DepCleanMojoIT.java @@ -1,17 +1,19 @@ package se.kth.depclean; +import static com.soebes.itf.extension.assertj.MavenITAssertions.assertThat; + import com.soebes.itf.jupiter.extension.MavenJupiterExtension; import com.soebes.itf.jupiter.extension.MavenTest; import com.soebes.itf.jupiter.maven.MavenExecutionResult; +import java.io.File; import org.junit.jupiter.api.DisplayName; -import static com.soebes.itf.extension.assertj.MavenITAssertions.assertThat; - /** * This class executes integration tests against the DepCleanMojo. The projects used for testing are in * src/test/resources-its/se/kth/depclean/DepCleanMojoIT. The results of the DepClean executions for each project are in * target/maven-it/se/kth/depclean/DepCleanMojoIT. *

+ * * @see */ @MavenJupiterExtension @@ -27,22 +29,36 @@ void empty_project(MavenExecutionResult result) { @DisplayName("Test that DepClean runs in a Maven project with processors") void processor_used(MavenExecutionResult result) { assertThat(result).isSuccessful().out() - .plain().contains( - "-------------------------------------------------------", - " D E P C L E A N A N A L Y S I S R E S U L T S", - "-------------------------------------------------------", - "USED DIRECT DEPENDENCIES [1]: ", - " org.mapstruct:mapstruct-processor:1.4.2.Final:provided (1 MB)", - "USED INHERITED DEPENDENCIES [0]: ", - "USED TRANSITIVE DEPENDENCIES [1]: ", - " com.fasterxml.jackson.core:jackson-core:2.12.2:compile (356 KB)", - "POTENTIALLY UNUSED DIRECT DEPENDENCIES [1]: ", - " com.fasterxml.jackson.core:jackson-databind:2.12.2:compile (1 MB)", - "POTENTIALLY UNUSED INHERITED DEPENDENCIES [0]: ", - "POTENTIALLY UNUSED TRANSITIVE DEPENDENCIES [1]: ", - " com.fasterxml.jackson.core:jackson-annotations:2.12.2:compile (73 KB)" + .plain().contains( + "-------------------------------------------------------", + " D E P C L E A N A N A L Y S I S R E S U L T S", + "-------------------------------------------------------", + "USED DIRECT DEPENDENCIES [1]: ", + " org.mapstruct:mapstruct-processor:1.4.2.Final:provided (1 MB)", + "USED INHERITED DEPENDENCIES [0]: ", + "USED TRANSITIVE DEPENDENCIES [1]: ", + " com.fasterxml.jackson.core:jackson-core:2.12.2:compile (356 KB)", + "POTENTIALLY UNUSED DIRECT DEPENDENCIES [1]: ", + " com.fasterxml.jackson.core:jackson-databind:2.12.2:compile (1 MB)", + "POTENTIALLY UNUSED INHERITED DEPENDENCIES [0]: ", + "POTENTIALLY UNUSED TRANSITIVE DEPENDENCIES [1]: ", + " com.fasterxml.jackson.core:jackson-annotations:2.12.2:compile (73 KB)" ); } + @MavenTest + @DisplayName("Test that DepClean creates a proper depclean-results.json file") + void json_should_be_correct(MavenExecutionResult result) { + File producedJson = + new File("target/maven-it/se/kth/depclean/DepCleanMojoIT/json_should_be_correct/project/depclean-results.json"); + File expectedJson = + new File("src/test/resources/depclean-results.json"); + assertThat(result).isSuccessful() + .out() + .plain().contains( + "Creating depclean-results.json, please wait...", + "[INFO] depclean-results.json file created in: " + producedJson.getAbsolutePath()); + assertThat(expectedJson).hasSameTextualContentAs(producedJson); + } } diff --git a/depclean-maven-plugin/src/test/resources-its/se/kth/depclean/DepCleanMojoIT/json_should_be_correct/pom.xml b/depclean-maven-plugin/src/test/resources-its/se/kth/depclean/DepCleanMojoIT/json_should_be_correct/pom.xml deleted file mode 100644 index 03c1fbb5..00000000 --- a/depclean-maven-plugin/src/test/resources-its/se/kth/depclean/DepCleanMojoIT/json_should_be_correct/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - 4.0.0 - - org.foo.bar - foobar - 1.0.0-SNAPSHOT - jar - foobar - - - UTF-8 - UTF-8 - 11 - 11 - - - - - - se.kth.castor - depclean-maven-plugin - 2.0.1 - - - - depclean - - - - - - - -