Skip to content
Permalink
Browse files
COMMONSSITE-123: introduce configuration parameter to perfom distribu…
…tion checkin using Maven settings server credentials
  • Loading branch information
mbenson committed Aug 30, 2018
1 parent c315ce0 commit 462dffabe3c0c01a99fea2dffdc59067059cea02
Showing 2 changed files with 42 additions and 2 deletions.
@@ -25,6 +25,7 @@
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.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.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
@@ -142,6 +150,13 @@ public class CommonsDistributionStagingMojo extends AbstractMojo {
@Parameter(property = "commons.rc.version")
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.
*/
@@ -154,6 +169,18 @@ public class CommonsDistributionStagingMojo extends AbstractMojo {
@Parameter(property = "user.password")
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,
@@ -183,8 +210,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
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 @@ private List<File> copyHeaderAndReadmeToSubdirectories(File headerFile, File rea
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));
}
}
@@ -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>

0 comments on commit 462dffa

Please sign in to comment.