From 1011ebe9acfe755dd8a9d1ec95740235ea1c19fc Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Mon, 18 Nov 2024 22:53:27 +0000 Subject: [PATCH] [MDEP-966] Migrate AnalyzeDepMgt to Sisu (#473) * Migrate AnalyzeDepMgt to Sisu --- pom.xml | 7 ++++ .../dependency/analyze/AnalyzeDepMgt.java | 41 ++++++++----------- .../dependency/analyze/TestAnalyzeDepMgt.java | 11 ++--- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/pom.xml b/pom.xml index b901e38d4..f72428a26 100644 --- a/pom.xml +++ b/pom.xml @@ -146,6 +146,13 @@ under the License. provided + + org.eclipse.sisu + org.eclipse.sisu.plexus + 0.9.0.M3 + provided + + org.apache.maven.doxia diff --git a/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDepMgt.java b/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDepMgt.java index a96b4f041..9cb79ece6 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDepMgt.java +++ b/src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDepMgt.java @@ -18,6 +18,8 @@ */ package org.apache.maven.plugins.dependency.analyze; +import javax.inject.Inject; + import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashSet; @@ -34,7 +36,6 @@ import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; @@ -52,10 +53,6 @@ public class AnalyzeDepMgt extends AbstractMojo { // fields ----------------------------------------------------------------- - /** - * - */ - @Component private MavenProject project; /** @@ -78,6 +75,11 @@ public class AnalyzeDepMgt extends AbstractMojo { @Parameter(property = "mdep.analyze.skip", defaultValue = "false") private boolean skip; + @Inject + public AnalyzeDepMgt(MavenProject project) { + this.project = project; + } + // Mojo methods ----------------------------------------------------------- /* @@ -104,7 +106,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { /** * Does the work of checking the DependencyManagement Section. * - * @return true if errors are found. + * @return true if errors are found * @throws MojoExecutionException */ private boolean checkDependencyManagement() throws MojoExecutionException { @@ -169,8 +171,8 @@ private boolean checkDependencyManagement() throws MojoExecutionException { /** * Returns a map of the exclusions using the Dependency ManagementKey as the keyset. * - * @param exclusionList to be added to the map. - * @return a map of the exclusions using the Dependency ManagementKey as the keyset. + * @param exclusionList to be added to the map + * @return a map of the exclusions using the Dependency ManagementKey as the keyset */ public Map addExclusions(List exclusionList) { if (exclusionList != null) { @@ -183,9 +185,9 @@ public Map addExclusions(List exclusionList) { * Returns a List of the artifacts that should have been excluded, but were found in the dependency tree. * * @param exclusions a map of the DependencyManagement exclusions, with the ManagementKey as the key and Dependency - * as the value. - * @param allDependencyArtifacts resolved artifacts to be compared. - * @return list of artifacts that should have been excluded. + * as the value + * @param allDependencyArtifacts resolved artifacts to be compared + * @return list of artifacts that should have been excluded */ public List getExclusionErrors(Map exclusions, Set allDependencyArtifacts) { return allDependencyArtifacts.stream() @@ -195,7 +197,7 @@ public List getExclusionErrors(Map exclusions, Set< /** * @param artifact {@link Artifact} - * @return The resulting GA. + * @return the resulting GA */ public String getExclusionKey(Artifact artifact) { return artifact.getGroupId() + ":" + artifact.getArtifactId(); @@ -203,7 +205,7 @@ public String getExclusionKey(Artifact artifact) { /** * @param ex The exclusion key. - * @return The resulting combination of groupId+artifactId. + * @return the resulting combination of groupId+artifactId */ public String getExclusionKey(Exclusion ex) { return ex.getGroupId() + ":" + ex.getArtifactId(); @@ -236,9 +238,9 @@ public Map getMismatch( * This function displays the log to the screen showing the versions and information about the artifacts that don't * match. * - * @param dependencyArtifact the artifact that was resolved. - * @param dependencyFromDepMgt the dependency listed in the DependencyManagement section. - * @throws MojoExecutionException in case of errors. + * @param dependencyArtifact the artifact that was resolved + * @param dependencyFromDepMgt the dependency listed in the DependencyManagement section + * @throws MojoExecutionException in case of errors */ public void logMismatch(Artifact dependencyArtifact, Dependency dependencyFromDepMgt) throws MojoExecutionException { @@ -284,13 +286,6 @@ protected final MavenProject getProject() { return this.project; } - /** - * @param theProject the project to set - */ - public void setProject(MavenProject theProject) { - this.project = theProject; - } - /** * @return the ignoreDirect */ diff --git a/src/test/java/org/apache/maven/plugins/dependency/analyze/TestAnalyzeDepMgt.java b/src/test/java/org/apache/maven/plugins/dependency/analyze/TestAnalyzeDepMgt.java index 44e32cbbe..32c0919c6 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/analyze/TestAnalyzeDepMgt.java +++ b/src/test/java/org/apache/maven/plugins/dependency/analyze/TestAnalyzeDepMgt.java @@ -49,23 +49,20 @@ public class TestAnalyzeDepMgt extends TestCase { Exclusion ex; - Artifact exclusionArtifact; - DependencyManagement depMgt; - DependencyManagement depMgtNoExclusions; - + @Override protected void setUp() throws Exception { - mojo = new AnalyzeDepMgt(); MavenProject project = new DependencyProjectStub(); + mojo = new AnalyzeDepMgt(project); stubFactory = new DependencyArtifactStubFactory(new File(""), false); Set allArtifacts = stubFactory.getMixedArtifacts(); Set directArtifacts = stubFactory.getClassifiedArtifacts(); - exclusionArtifact = stubFactory.getReleaseArtifact(); + Artifact exclusionArtifact = stubFactory.getReleaseArtifact(); directArtifacts.add(exclusionArtifact); ex = new Exclusion(); ex.setArtifactId(exclusionArtifact.getArtifactId()); @@ -87,8 +84,6 @@ protected void setUp() throws Exception { project.setArtifacts(allArtifacts); project.setDependencyArtifacts(directArtifacts); - - mojo.setProject(project); } public void testGetManagementKey() throws IOException {