Skip to content

Commit

Permalink
Prefer Guice constructor injection
Browse files Browse the repository at this point in the history
  • Loading branch information
elharo committed Dec 12, 2024
1 parent 969027f commit 9717bd5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
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;

@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

0 comments on commit 9717bd5

Please sign in to comment.