Skip to content

Commit

Permalink
[MDEP-966] Migrate AnalyzeDepMgt to Sisu (#473)
Browse files Browse the repository at this point in the history
* Migrate AnalyzeDepMgt to Sisu
  • Loading branch information
elharo authored Nov 18, 2024
1 parent 4eca443 commit 1011ebe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 31 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ under the License.
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.plexus</artifactId>
<version>0.9.0.M3</version>
<scope>provided</scope>
</dependency>

<!-- doxia -->
<dependency>
<groupId>org.apache.maven.doxia</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -52,10 +53,6 @@
public class AnalyzeDepMgt extends AbstractMojo {
// fields -----------------------------------------------------------------

/**
*
*/
@Component
private MavenProject project;

/**
Expand All @@ -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 -----------------------------------------------------------

/*
Expand All @@ -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 {
Expand Down Expand Up @@ -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<String, Exclusion> addExclusions(List<Exclusion> exclusionList) {
if (exclusionList != null) {
Expand All @@ -183,9 +185,9 @@ public Map<String, Exclusion> addExclusions(List<Exclusion> 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<Artifact> getExclusionErrors(Map<String, Exclusion> exclusions, Set<Artifact> allDependencyArtifacts) {
return allDependencyArtifacts.stream()
Expand All @@ -195,15 +197,15 @@ public List<Artifact> getExclusionErrors(Map<String, Exclusion> exclusions, Set<

/**
* @param artifact {@link Artifact}
* @return The resulting GA.
* @return the resulting GA
*/
public String getExclusionKey(Artifact artifact) {
return artifact.getGroupId() + ":" + artifact.getArtifactId();
}

/**
* @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();
Expand Down Expand Up @@ -236,9 +238,9 @@ public Map<Artifact, Dependency> 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 {
Expand Down Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Artifact> allArtifacts = stubFactory.getMixedArtifacts();
Set<Artifact> directArtifacts = stubFactory.getClassifiedArtifacts();

exclusionArtifact = stubFactory.getReleaseArtifact();
Artifact exclusionArtifact = stubFactory.getReleaseArtifact();
directArtifacts.add(exclusionArtifact);
ex = new Exclusion();
ex.setArtifactId(exclusionArtifact.getArtifactId());
Expand All @@ -87,8 +84,6 @@ protected void setUp() throws Exception {

project.setArtifacts(allArtifacts);
project.setDependencyArtifacts(directArtifacts);

mojo.setProject(project);
}

public void testGetManagementKey() throws IOException {
Expand Down

0 comments on commit 1011ebe

Please sign in to comment.