Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MDEP-966] Convert Analyze Mojos to Guice constructor injection #499

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -55,19 +54,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 +257,22 @@ public abstract class AbstractAnalyzeMojo extends AbstractMojo {
@Parameter(property = "mdep.analyze.excludedClasses")
private Set<String> excludedClasses;

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

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

protected 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.
* 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,17 +18,21 @@
*/
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
* and declared. This goal is intended to be used in the build lifecycle, thus it assumes that the
* <code>test-compile</code> phase has been executed - use the <code>dependency:analyze</code> goal instead when running
* standalone.
* <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 @@ -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);
}
}
Loading