From 97efae5f3f95c5864d6d758785e854dd35da4938 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Sun, 31 Jul 2022 00:01:40 +0200 Subject: [PATCH] Simplify PerformReleaseMojo --- .../plugins/release/PerformReleaseMojo.java | 54 +------------------ .../FlatMultiModuleMavenProjectStub.java | 31 +++++++---- 2 files changed, 23 insertions(+), 62 deletions(-) diff --git a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PerformReleaseMojo.java b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PerformReleaseMojo.java index 7994e2a65..f7d7bc2bc 100644 --- a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PerformReleaseMojo.java +++ b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PerformReleaseMojo.java @@ -20,14 +20,11 @@ */ 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; @@ -46,7 +43,7 @@ */ @Mojo( name = "perform", aggregator = true, requiresProject = false ) public class PerformReleaseMojo - extends AbstractReleaseMojo + extends AbstractScmReleaseMojo { /** * A space separated list of goals to execute on release perform. Default value is either deploy or @@ -88,18 +85,6 @@ public class PerformReleaseMojo @Parameter( defaultValue = "false", property = "localCheckout" ) private boolean localCheckout; - /** - * The SCM username to use. - */ - @Parameter( property = "username" ) - private String username; - - /** - * The SCM password to use. - */ - @Parameter( property = "password" ) - private String password; - /** * When cloning a repository if it should be a shallow clone or a full clone. */ @@ -125,23 +110,6 @@ public class PerformReleaseMojo @Parameter( defaultValue = "false", property = "dryRun" ) private boolean dryRun; - /** - * Add a new or overwrite the default implementation per provider. - * The key is the scm prefix and the value is the role hint of the - * {@link org.apache.maven.scm.provider.ScmProvider}. - * - * @since 2.5.3 - * @see ScmManager#setScmProviderImplementation(String, String) - */ - @Parameter - private Map providerImplementations; - - /** - * The SCM manager. - */ - @Component - private ScmManager scmManager; - @Override protected String getAdditionalProfiles() { @@ -152,15 +120,7 @@ protected String getAdditionalProfiles() public void execute() throws MojoExecutionException, MojoFailureException { - if ( providerImplementations != null ) - { - for ( Map.Entry providerEntry : providerImplementations.entrySet() ) - { - getLog().info( "Change the default '" + providerEntry.getKey() + "' provider implementation to '" - + providerEntry.getValue() + "'." ); - scmManager.setScmProviderImplementation( providerEntry.getKey(), providerEntry.getValue() ); - } - } + super.execute(); // goals may be splitted into multiple line in configuration. // Let's build a single line command @@ -179,16 +139,6 @@ public void execute() releaseDescriptor.setScmSourceUrl( connectionUrl ); } - if ( username != null ) - { - releaseDescriptor.setScmUsername( username ); - } - - if ( password != null ) - { - releaseDescriptor.setScmPassword( password ); - } - releaseDescriptor.setScmShallowClone( scmShallowClone ); releaseDescriptor.setLocalCheckout( localCheckout ); diff --git a/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/stubs/FlatMultiModuleMavenProjectStub.java b/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/stubs/FlatMultiModuleMavenProjectStub.java index 44ff46869..82ef5c1a9 100644 --- a/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/stubs/FlatMultiModuleMavenProjectStub.java +++ b/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/stubs/FlatMultiModuleMavenProjectStub.java @@ -29,7 +29,7 @@ /** *

Stub for a MavenProject with a flat structure.

- * + * *

TODO: shouldn't need to do this, but the "stub" in the harness just throws away values you set. * Just overriding the ones I need for this plugin.

* @@ -40,7 +40,7 @@ */ public class FlatMultiModuleMavenProjectStub extends org.apache.maven.plugin.testing.stubs.MavenProjectStub -{ +{ public void setDistributionManagement( DistributionManagement distributionManagement ) { getModel().setDistributionManagement( distributionManagement ); @@ -57,46 +57,57 @@ public Model getModel() return model; } + @Override + public Model getOriginalModel() { + Model originalModel = super.getOriginalModel(); + if ( originalModel == null ) + { + originalModel = new Model(); + setOriginalModel( originalModel ); + } + return originalModel; + } + public DistributionManagement getDistributionManagement() { return getModel().getDistributionManagement(); } - + public List getModules() { List modules = new ArrayList(); modules.add( "../core" ); modules.add( "../webapp" ); modules.add( "../commons" ); - + return modules; } - + public File getBasedir() { return new File( "/flat-multi-module/root-project" ).getAbsoluteFile(); } - + public Scm getScm() { Scm scm = new Scm(); scm.setConnection( "scm:svn:file://localhost/target/svnroot/flat-multi-module/trunk/root-project" ); - + return scm; } - + @Override public String getGroupId() { return "GROUPID"; } - + @Override public String getArtifactId() { return "ARTIFACTID"; } - + @Override public String getVersion() {