Skip to content

Commit

Permalink
Convert AbstractAnalyzeMojo to Guice
Browse files Browse the repository at this point in the history
  • Loading branch information
elharo committed Nov 28, 2024
1 parent 969ed96 commit 69fe095
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,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.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter;
Expand All @@ -54,20 +53,6 @@
*/
public abstract class AbstractAnalyzeMojo extends AbstractMojo {
// fields -----------------------------------------------------------------

/**
* The plexusContainer to look-up the right {@link ProjectDependencyAnalyzer} implementation depending on the mojo
* configuration.
*/
@Component
private PlexusContainer plexusContainer;

/**
* The Maven project to analyze.
*/
@Component
private MavenProject project;

/**
* Specify the project dependency analyzer to use (plexus component role-hint). By default,
* <a href="/shared/maven-dependency-analyzer/">maven-dependency-analyzer</a> is used. To use this, you must declare
Expand Down Expand Up @@ -271,6 +256,22 @@ public abstract class AbstractAnalyzeMojo extends AbstractMojo {
@Parameter(property = "mdep.analyze.excludedClasses")
private Set<String> excludedClasses;

/**
* The plexusContainer to look-up the right {@link ProjectDependencyAnalyzer} implementation depending on the mojo
* configuration.
*/
private PlexusContainer plexusContainer;

/**
* The Maven project to analyze.
*/
private MavenProject project;

public AbstractAnalyzeMojo(PlexusContainer plexusContainer, MavenProject project) {
this.plexusContainer = plexusContainer;
this.project = project;
}

// Mojo methods -----------------------------------------------------------

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@
*/
package org.apache.maven.plugins.dependency.analyze;

import javax.inject.Inject;

import org.apache.maven.plugins.annotations.Execute;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.PlexusContainer;

/**
* Analyzes the dependencies of this project and determines which are: used and declared; used and undeclared; unused
* and declared. This goal is intended to be used standalone, thus it always executes the <code>test-compile</code>
* phase - use the <code>dependency:analyze-only</code> goal instead when participating in the build lifecycle.
* <p>
* By default, <a href="http://maven.apache.org/shared/maven-dependency-analyzer/">maven-dependency-analyzer</a> is used
* By default, <a href="https://maven.apache.org/shared/maven-dependency-analyzer/">maven-dependency-analyzer</a> is used
* to perform the analysis, with limitations due to the fact that it works at bytecode level, but any analyzer can be
* plugged in through <code>analyzer</code> parameter.
* </p>
Expand All @@ -41,4 +45,9 @@
@Execute(phase = LifecyclePhase.TEST_COMPILE)
public class AnalyzeMojo extends AbstractAnalyzeMojo {
// subclassed to provide annotations

@Inject
public AnalyzeMojo(PlexusContainer plexusContainer, MavenProject project) {
super(plexusContainer, project);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
*/
package org.apache.maven.plugins.dependency.analyze;

import javax.inject.Inject;

import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.PlexusContainer;

/**
* Analyzes the dependencies of this project and determines which are: used and declared; used and undeclared; unused
Expand All @@ -46,4 +50,9 @@
// @formatter:on
public class AnalyzeOnlyMojo extends AbstractAnalyzeMojo {
// subclassed to provide annotations

@Inject
public AnalyzeOnlyMojo(PlexusContainer plexusContainer, MavenProject project) {
super(plexusContainer, project);
}
}

0 comments on commit 69fe095

Please sign in to comment.