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

Prefer Guice constructor injection #126

Merged
merged 1 commit into from
Dec 18, 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 @@ -18,12 +18,13 @@
*/
package org.apache.maven.plugins.gpg;

import javax.inject.Inject;

import java.io.File;
import java.util.List;

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.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
Expand Down Expand Up @@ -60,14 +61,18 @@ public class GpgSignAttachedMojo extends AbstractGpgMojo {
/**
* The maven project.
*/
@Component
protected MavenProject project;
protected final MavenProject project;

/**
* Maven ProjectHelper
*/
@Component
private MavenProjectHelper projectHelper;
private final MavenProjectHelper projectHelper;

@Inject
public GpgSignAttachedMojo(MavenProject project, MavenProjectHelper projectHelper) {
this.project = project;
this.projectHelper = projectHelper;
}

@Override
protected void doExecute() throws MojoExecutionException, MojoFailureException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.maven.plugins.gpg;

import javax.inject.Inject;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
Expand All @@ -41,7 +43,6 @@
import org.apache.maven.model.validation.ModelValidator;
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.project.MavenProject;
Expand Down Expand Up @@ -185,30 +186,36 @@ public class SignAndDeployFileMojo extends AbstractGpgMojo {
@Parameter(property = "files")
private String files;

/**
*/
@Component
private RepositorySystem repositorySystem;
private final RepositorySystem repositorySystem;

/**
* The component used to validate the user-supplied artifact coordinates.
*/
@Component
private ModelValidator modelValidator;
private final ModelValidator modelValidator;

/**
* The default Maven project created when building the plugin
*
* @since 1.3
*/
@Component
private MavenProject project;
private final MavenProject project;

/**
* @since 3.2.0
*/
@Component
private ArtifactHandlerManager artifactHandlerManager;
private final ArtifactHandlerManager artifactHandlerManager;

@Inject
public SignAndDeployFileMojo(
RepositorySystem repositorySystem,
ModelValidator modelValidator,
MavenProject project,
ArtifactHandlerManager artifactHandlerManager) {
this.repositorySystem = repositorySystem;
this.modelValidator = modelValidator;
this.project = project;
this.artifactHandlerManager = artifactHandlerManager;
}

private void initProperties() throws MojoExecutionException {
// Process the supplied POM (if there is one)
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/org/apache/maven/plugins/gpg/SignDeployedMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

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.codehaus.plexus.util.FileUtils;
Expand Down Expand Up @@ -106,11 +105,15 @@ public class SignDeployedMojo extends AbstractGpgMojo {
@Parameter(property = "artifacts")
private String artifacts;

@Component
private RepositorySystem repositorySystem;
private final RepositorySystem repositorySystem;

private final Map<String, ArtifactCollectorSPI> artifactCollectors;
slachiewicz marked this conversation as resolved.
Show resolved Hide resolved

@Inject
private Map<String, ArtifactCollectorSPI> artifactCollectors;
public SignDeployedMojo(RepositorySystem repositorySystem, Map<String, ArtifactCollectorSPI> artifactCollectors) {
this.repositorySystem = repositorySystem;
this.artifactCollectors = artifactCollectors;
}

@Override
protected void doExecute() throws MojoExecutionException, MojoFailureException {
Expand Down
Loading