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

Convert to Guice constructor injection #236

Merged
merged 1 commit into from
Dec 15, 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 @@ -28,7 +28,6 @@
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings;
Expand Down Expand Up @@ -59,11 +58,6 @@ public abstract class AbstractReleaseMojo extends AbstractMojo {
@Parameter(defaultValue = "${project}", readonly = true, required = true)
protected MavenProject project;

/**
*/
@Component
protected ReleaseManager releaseManager;

/**
* Additional arguments to pass to the Maven executions, separated by spaces.
*/
Expand Down Expand Up @@ -130,6 +124,12 @@ public abstract class AbstractReleaseMojo extends AbstractMojo {
@Parameter(defaultValue = "default", property = "releaseStrategyId")
private String releaseStrategyId;

protected ReleaseManager releaseManager;

protected AbstractReleaseMojo(ReleaseManager releaseManager) {
this.releaseManager = releaseManager;
}

/**
* Gets the environment settings configured for this release.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@
*/
package org.apache.maven.plugins.release;

import javax.inject.Inject;

import java.util.Map;

import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.model.Scm;
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.scm.manager.ScmManager;
import org.apache.maven.shared.release.ReleaseManager;
import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder;

/**
Expand Down Expand Up @@ -123,8 +125,13 @@ public abstract class AbstractScmReleaseMojo extends AbstractReleaseMojo {
/**
* The SCM manager.
*/
@Component
private ScmManager scmManager;
private final ScmManager scmManager;

@Inject
protected AbstractScmReleaseMojo(ReleaseManager releaseManager, ScmManager scmManager) {
super(releaseManager);
this.scmManager = scmManager;
}

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@
*/
package org.apache.maven.plugins.release;

import javax.inject.Inject;

import java.util.Arrays;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.scm.manager.ScmManager;
import org.apache.maven.shared.release.DefaultReleaseManagerListener;
import org.apache.maven.shared.release.ReleaseBranchRequest;
import org.apache.maven.shared.release.ReleaseExecutionException;
import org.apache.maven.shared.release.ReleaseFailureException;
import org.apache.maven.shared.release.ReleaseManager;
import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder;
import org.codehaus.plexus.configuration.PlexusConfiguration;

Expand Down Expand Up @@ -244,6 +248,11 @@ public class BranchReleaseMojo extends AbstractScmReleaseMojo {
@Parameter(defaultValue = "false", property = "pinExternals")
private boolean pinExternals;

@Inject
public BranchReleaseMojo(ReleaseManager releaseManager, ScmManager scmManager) {
super(releaseManager, scmManager);
}

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
super.execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
*/
package org.apache.maven.plugins.release;

import javax.inject.Inject;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.shared.release.DefaultReleaseManagerListener;
import org.apache.maven.shared.release.ReleaseCleanRequest;
import org.apache.maven.shared.release.ReleaseFailureException;
import org.apache.maven.shared.release.ReleaseManager;
import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder;

/**
Expand All @@ -37,6 +40,12 @@
*/
@Mojo(name = "clean", aggregator = true)
public class CleanReleaseMojo extends AbstractReleaseMojo {

@Inject
public CleanReleaseMojo(ReleaseManager releaseManager) {
super(releaseManager);
}

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
ReleaseDescriptorBuilder releaseDescriptor = new ReleaseDescriptorBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@
*/
package org.apache.maven.plugins.release;

import javax.inject.Inject;

import java.io.File;
import java.util.Map;

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.scm.manager.ScmManager;
import org.apache.maven.shared.release.DefaultReleaseManagerListener;
import org.apache.maven.shared.release.ReleaseExecutionException;
import org.apache.maven.shared.release.ReleaseFailureException;
import org.apache.maven.shared.release.ReleaseManager;
import org.apache.maven.shared.release.ReleasePerformRequest;
import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder;
import org.codehaus.plexus.util.StringUtils;
Expand Down Expand Up @@ -136,8 +138,13 @@ public class PerformReleaseMojo extends AbstractReleaseMojo {
/**
* The SCM manager.
*/
@Component
private ScmManager scmManager;
private final ScmManager scmManager;

@Inject
public PerformReleaseMojo(ReleaseManager releaseManager, ScmManager scmManager) {
super(releaseManager);
this.scmManager = scmManager;
}

@Override
protected String getAdditionalProfiles() {
Expand All @@ -154,7 +161,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
}

// goals may be splitted into multiple line in configuration.
// goals may be split into multiple lines in configuration.
// Let's build a single line command
if (goals != null) {
goals = StringUtils.join(StringUtils.split(goals), " ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.maven.plugins.release;

import javax.inject.Inject;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -28,9 +30,11 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.scm.manager.ScmManager;
import org.apache.maven.shared.release.DefaultReleaseManagerListener;
import org.apache.maven.shared.release.ReleaseExecutionException;
import org.apache.maven.shared.release.ReleaseFailureException;
import org.apache.maven.shared.release.ReleaseManager;
import org.apache.maven.shared.release.ReleasePrepareRequest;
import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder;
import org.codehaus.plexus.configuration.PlexusConfiguration;
Expand Down Expand Up @@ -330,6 +334,11 @@ public class PrepareReleaseMojo extends AbstractScmReleaseMojo {
@Parameter(defaultValue = "false", property = "pinExternals")
private boolean pinExternals;

@Inject
public PrepareReleaseMojo(ReleaseManager releaseManager, ScmManager scmManager) {
super(releaseManager, scmManager);
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@
*/
package org.apache.maven.plugins.release;

import javax.inject.Inject;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.scm.manager.ScmManager;
import org.apache.maven.shared.release.ReleaseManager;

/**
* Prepare for a release in SCM, fully resolving dependencies for the purpose of producing a "release POM".
Expand All @@ -38,6 +42,11 @@ public class PrepareWithPomReleaseMojo extends PrepareReleaseMojo {
@Parameter(defaultValue = "true", property = "generateReleasePoms")
private boolean generateReleasePoms;

@Inject
public PrepareWithPomReleaseMojo(ReleaseManager releaseManager, ScmManager scmManager) {
super(releaseManager, scmManager);
}

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
prepareRelease(generateReleasePoms);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
*/
package org.apache.maven.plugins.release;

import javax.inject.Inject;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.scm.manager.ScmManager;
import org.apache.maven.shared.release.DefaultReleaseManagerListener;
import org.apache.maven.shared.release.ReleaseExecutionException;
import org.apache.maven.shared.release.ReleaseFailureException;
import org.apache.maven.shared.release.ReleaseManager;
import org.apache.maven.shared.release.ReleaseRollbackRequest;
import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder;

Expand Down Expand Up @@ -61,6 +65,11 @@ public class RollbackReleaseMojo extends AbstractScmReleaseMojo {
property = "scmRollbackCommitComment")
private String scmRollbackCommitComment = "@{prefix} rollback the release of @{releaseLabel}";

@Inject
public RollbackReleaseMojo(ReleaseManager releaseManager, ScmManager scmManager) {
super(releaseManager, scmManager);
}

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
super.execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
*/
package org.apache.maven.plugins.release;

import javax.inject.Inject;

import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.scm.manager.ScmManager;
import org.apache.maven.shared.release.ReleaseManager;

/**
* Perform a release from SCM to a staging repository.
Expand All @@ -43,6 +47,11 @@ public class StageReleaseMojo extends PerformReleaseMojo {
@Parameter(property = "stagingRepository", required = true)
private String stagingRepository;

@Inject
public StageReleaseMojo(ReleaseManager releaseManager, ScmManager scmManager) {
super(releaseManager, scmManager);
}

@Override
void createGoals() {
if (goals == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.maven.plugins.release;

import javax.inject.Inject;

import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
Expand All @@ -26,6 +28,7 @@
import org.apache.maven.shared.release.DefaultReleaseManagerListener;
import org.apache.maven.shared.release.ReleaseExecutionException;
import org.apache.maven.shared.release.ReleaseFailureException;
import org.apache.maven.shared.release.ReleaseManager;
import org.apache.maven.shared.release.ReleaseUpdateVersionsRequest;
import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder;
import org.codehaus.plexus.configuration.PlexusConfiguration;
Expand Down Expand Up @@ -99,6 +102,11 @@ public class UpdateVersionsMojo extends AbstractReleaseMojo {
@Parameter(property = "projectVersionPolicyConfig")
private PlexusConfiguration projectVersionPolicyConfig;

@Inject
public UpdateVersionsMojo(ReleaseManager releaseManager) {
super(releaseManager);
}

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
final ReleaseDescriptorBuilder config = createReleaseDescriptor();
Expand Down
Loading