You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mb...@apache.org on 2018/08/30 19:20:05 UTC
commons-release-plugin git commit: COMMONSSITE-123: introduce
configuration parameter to perfom distribution checkin using Maven settings
server credentials
Repository: commons-release-plugin
Updated Branches:
refs/heads/master c315ce0ce -> 462dffabe
COMMONSSITE-123: introduce configuration parameter to perfom distribution checkin using Maven settings server credentials
Project: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/commit/462dffab
Tree: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/tree/462dffab
Diff: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/diff/462dffab
Branch: refs/heads/master
Commit: 462dffabe3c0c01a99fea2dffdc59067059cea02
Parents: c315ce0
Author: Matt Benson <mb...@apache.org>
Authored: Thu Aug 30 14:19:44 2018 -0500
Committer: Matt Benson <mb...@apache.org>
Committed: Thu Aug 30 14:19:44 2018 -0500
----------------------------------------------------------------------
.../mojos/CommonsDistributionStagingMojo.java | 43 +++++++++++++++++++-
.../stage-distributions/stage-distributions.xml | 1 +
2 files changed, 42 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/462dffab/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionStagingMojo.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionStagingMojo.java b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionStagingMojo.java
index 6221c34..2846352 100755
--- a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionStagingMojo.java
+++ b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionStagingMojo.java
@@ -25,6 +25,7 @@ import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
+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;
@@ -37,9 +38,15 @@ import org.apache.maven.scm.command.checkout.CheckOutScmResult;
import org.apache.maven.scm.manager.BasicScmManager;
import org.apache.maven.scm.manager.ScmManager;
import org.apache.maven.scm.provider.ScmProvider;
+import org.apache.maven.scm.provider.ScmProviderRepository;
import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
import org.apache.maven.scm.provider.svn.svnexe.SvnExeScmProvider;
import org.apache.maven.scm.repository.ScmRepository;
+import org.apache.maven.settings.Server;
+import org.apache.maven.settings.Settings;
+import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest;
+import org.apache.maven.settings.crypto.SettingsDecrypter;
+import org.apache.maven.settings.crypto.SettingsDecryptionResult;
import java.io.File;
import java.io.FileOutputStream;
@@ -49,6 +56,7 @@ import java.io.Writer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.Optional;
/**
* This class checks out the dev distribution location, copies the distributions into that directory
@@ -143,6 +151,13 @@ public class CommonsDistributionStagingMojo extends AbstractMojo {
private String commonsRcVersion;
/**
+ * The ID of the server (specified in settings.xml) which should be used for dist authentication.
+ * This will be used in preference to {@link #username}/{@link #password}.
+ */
+ @Parameter(property = "commons.distServer")
+ private String distServer;
+
+ /**
* The username for the distribution subversion repository. This is typically your Apache id.
*/
@Parameter(property = "user.name")
@@ -155,6 +170,18 @@ public class CommonsDistributionStagingMojo extends AbstractMojo {
private String password;
/**
+ * Maven {@link Settings}.
+ */
+ @Parameter(defaultValue = "${settings}", readonly = true, required = true)
+ private Settings settings;
+
+ /**
+ * Maven {@link SettingsDecrypter} component.
+ */
+ @Component
+ private SettingsDecrypter settingsDecrypter;
+
+ /**
* A subdirectory of the dist directory into which we are going to stage the release candidate. We
* build this up in the {@link CommonsDistributionStagingMojo#execute()} method. And, for example,
* the directory should look like <code>https://https://dist.apache.org/repos/dist/dev/commons/text/1.4-RC1</code>.
@@ -183,8 +210,7 @@ public class CommonsDistributionStagingMojo extends AbstractMojo {
ScmRepository repository = scmManager.makeScmRepository(distSvnStagingUrl);
ScmProvider provider = scmManager.getProviderByRepository(repository);
SvnScmProviderRepository providerRepository = (SvnScmProviderRepository) repository.getProviderRepository();
- providerRepository.setUser(username);
- providerRepository.setPassword(password);
+ setAuthentication(providerRepository);
distVersionRcVersionDirectory =
new File(distCheckoutDirectory, commonsReleaseVersion + "-" + commonsRcVersion);
if (!distCheckoutDirectory.exists()) {
@@ -456,4 +482,17 @@ public class CommonsDistributionStagingMojo extends AbstractMojo {
protected void setBaseDir(File baseDir) {
this.baseDir = baseDir;
}
+
+ /**
+ * Set authentication information on the specified {@link ScmProviderRepository}.
+ * @param providerRepository target
+ */
+ private void setAuthentication(ScmProviderRepository providerRepository) {
+ Optional<Server> server =
+ Optional.ofNullable(distServer).map(settings::getServer).map(DefaultSettingsDecryptionRequest::new)
+ .map(settingsDecrypter::decrypt).map(SettingsDecryptionResult::getServer);
+
+ providerRepository.setUser(server.map(Server::getUsername).orElse(username));
+ providerRepository.setPassword(server.map(Server::getPassword).orElse(password));
+ }
}
http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/462dffab/src/test/resources/mojos/stage-distributions/stage-distributions.xml
----------------------------------------------------------------------
diff --git a/src/test/resources/mojos/stage-distributions/stage-distributions.xml b/src/test/resources/mojos/stage-distributions/stage-distributions.xml
index b8ad1ca..852bbf0 100755
--- a/src/test/resources/mojos/stage-distributions/stage-distributions.xml
+++ b/src/test/resources/mojos/stage-distributions/stage-distributions.xml
@@ -43,6 +43,7 @@
<artifactId>commons-release-plugin</artifactId>
<configuration>
<project implementation="org.apache.commons.release.plugin.stubs.DistributionDetachmentProjectStub" />
+ <settings implementation="org.apache.maven.settings.Settings" />
<workingDirectory>target/testing-commons-release-plugin</workingDirectory>
<distCheckoutDirectory>target/testing-commons-release-plugin/scm</distCheckoutDirectory>
<siteDirectory>${basedir}/target/test-classes/mojos/detach-distributions/target/site</siteDirectory>