You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ch...@apache.org on 2018/01/07 18:21:56 UTC
[12/26] commons-release-plugin git commit: Got svn repo provider
working
Got svn repo provider working
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/2a3a8823
Tree: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/tree/2a3a8823
Diff: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/diff/2a3a8823
Branch: refs/heads/master
Commit: 2a3a88238a95397331e35fb98670240575a4bea9
Parents: 7cc0bd9
Author: Rob Tompkins <ch...@apache.org>
Authored: Tue Jan 2 11:27:21 2018 -0500
Committer: Rob Tompkins <ch...@apache.org>
Committed: Tue Jan 2 11:28:55 2018 -0500
----------------------------------------------------------------------
pom.xml | 24 +++-
.../commons/release/plugin/SharedFunctions.java | 20 ++-
.../plugin/handler/DistributionScmHandler.java | 122 ++++++++++++++++++-
.../release/plugin/handler/package-info.java | 16 +++
.../CommonsDistributionDetatchmentMojo.java | 3 +-
.../mojos/CommonsDistributionStagingMojo.java | 70 ++++++++++-
.../mojos/CommonsSiteCompressionMojo.java | 18 ++-
7 files changed, 261 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/2a3a8823/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 1d8f463..c79db7c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -43,7 +43,8 @@
<scm>
<connection>scm:git:http://git-wip-us.apache.org/repos/asf/commons-release-plugin.git</connection>
- <developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/commons-release-plugin.git</developerConnection>
+ <developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/commons-release-plugin.git
+ </developerConnection>
<url>https://git-wip-us.apache.org/repos/asf?p=commons-release-plugin.git</url>
</scm>
@@ -97,9 +98,24 @@
<version>2.2.1</version>
</dependency>
<dependency>
- <groupId>org.apache.maven.wagon</groupId>
- <artifactId>wagon-provider-api</artifactId>
- <version>3.0.0</version>
+ <groupId>org.apache.maven.scm</groupId>
+ <artifactId>maven-scm-api</artifactId>
+ <version>1.9.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.scm</groupId>
+ <artifactId>maven-scm-provider-svnexe</artifactId>
+ <version>1.9.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.scm</groupId>
+ <artifactId>maven-scm-provider-svn-commons</artifactId>
+ <version>1.9.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.sonatype.plexus</groupId>
+ <artifactId>plexus-sec-dispatcher</artifactId>
+ <version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/2a3a8823/src/main/java/org/apache/commons/release/plugin/SharedFunctions.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/release/plugin/SharedFunctions.java b/src/main/java/org/apache/commons/release/plugin/SharedFunctions.java
index 238d58b..60f2db9 100644
--- a/src/main/java/org/apache/commons/release/plugin/SharedFunctions.java
+++ b/src/main/java/org/apache/commons/release/plugin/SharedFunctions.java
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.commons.release.plugin;
import org.apache.maven.plugin.MojoExecutionException;
@@ -26,13 +42,13 @@ public class SharedFunctions {
* @param log is the maven log for output logging, particularly in regards to error management.
* @param workingDirectory is a {@link File} that represents the directory to first attempt to delete then create.
*/
- public static void initWorkingDirectory(Log log, File workingDirectory) throws MojoExecutionException {
+ public static void initDirectory(Log log, File workingDirectory) throws MojoExecutionException {
if (workingDirectory.exists()) {
try {
FileUtils.deleteDirectory(workingDirectory);
} catch (IOException e) {
log.error(e.getMessage());
- throw new MojoExecutionException("Unable to remove working directory: " + e.getMessage(), e);
+ throw new MojoExecutionException("Unable to remove directory: " + e.getMessage(), e);
}
}
if (!workingDirectory.exists()) {
http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/2a3a8823/src/main/java/org/apache/commons/release/plugin/handler/DistributionScmHandler.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/release/plugin/handler/DistributionScmHandler.java b/src/main/java/org/apache/commons/release/plugin/handler/DistributionScmHandler.java
index 0a841f9..4762dae 100644
--- a/src/main/java/org/apache/commons/release/plugin/handler/DistributionScmHandler.java
+++ b/src/main/java/org/apache/commons/release/plugin/handler/DistributionScmHandler.java
@@ -1,11 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.commons.release.plugin.handler;
+import org.apache.maven.scm.manager.NoSuchScmProviderException;
+import org.apache.maven.scm.manager.ScmManager;
+import org.apache.maven.scm.provider.ScmProviderRepository;
+import org.apache.maven.scm.provider.ScmProviderRepositoryWithHost;
+import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
+import org.apache.maven.scm.repository.ScmRepository;
+import org.apache.maven.scm.repository.ScmRepositoryException;
+import org.apache.maven.settings.Server;
+import org.apache.maven.settings.Settings;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.util.StringUtils;
+import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;
+import org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException;
+
import java.io.File;
-public class DistributionScmHandler {
+@Component(role= DistributionScmHandler.class, instantiationStrategy = "singleton" )
+public class DistributionScmHandler extends AbstractLogEnabled {
+
+ /**
+ * The SCM manager.
+ */
+ @Requirement
+ private ScmManager scmManager;
+
+ /**
+ * When this plugin requires Maven 3.0 as minimum, this component can be removed and o.a.m.s.c.SettingsDecrypter be
+ * used instead.
+ */
+ @Requirement(hint = "mng-4384")
+ private SecDispatcher secDispatcher;
public void checkoutDirectory(String scmUrl, File checkoutRootDirectory) {
}
+ public ScmRepository getConfiguredRepository(String url,
+ String username,
+ String password,
+ String privateKey,
+ String passphrase,
+ Settings settings)
+ throws ScmRepositoryException, NoSuchScmProviderException {
+ ScmRepository repository = scmManager.makeScmRepository(url);
+ ScmProviderRepository scmRepo = repository.getProviderRepository();
+ //MRELEASE-76
+ scmRepo.setPersistCheckout(false);
+ if (settings != null) {
+ Server server = null;
+ if (server == null && repository.getProviderRepository() instanceof ScmProviderRepositoryWithHost) {
+ ScmProviderRepositoryWithHost repositoryWithHost =
+ (ScmProviderRepositoryWithHost) repository.getProviderRepository();
+ String host = repositoryWithHost.getHost();
+ int port = repositoryWithHost.getPort();
+ if (port > 0) {
+ host += ":" + port;
+ }
+ // TODO: this is a bit dodgy - id is not host, but since we don't have a <host> field we make an assumption
+ server = settings.getServer(host);
+ }
+
+ if (server != null) {
+ if (username == null) {
+ username = server.getUsername();
+ }
+ if (password == null) {
+ password = decrypt(server.getPassword(), server.getId());
+ }
+ if (privateKey == null) {
+ privateKey = server.getPrivateKey();
+ }
+ if (passphrase == null) {
+ passphrase = decrypt(server.getPassphrase(), server.getId());
+ }
+ }
+ }
+ if (!StringUtils.isEmpty(username)) {
+ scmRepo.setUser(username);
+ }
+ if (!StringUtils.isEmpty(password)) {
+ scmRepo.setPassword(password);
+ }
+ if (scmRepo instanceof ScmProviderRepositoryWithHost) {
+ ScmProviderRepositoryWithHost repositoryWithHost = (ScmProviderRepositoryWithHost) scmRepo;
+ if (!StringUtils.isEmpty(privateKey)) {
+ repositoryWithHost.setPrivateKey(privateKey);
+ }
+ if (!StringUtils.isEmpty(passphrase)) {
+ repositoryWithHost.setPassphrase(passphrase);
+ }
+ }
+ return repository;
+ }
+
+ private String decrypt(String str, String server) {
+ try {
+ return secDispatcher.decrypt(str);
+ } catch (SecDispatcherException e) {
+ String msg =
+ "Failed to decrypt password/passphrase for server " + server + ", using auth token as is: "
+ + e.getMessage();
+ if (getLogger().isDebugEnabled()) {
+ getLogger().warn(msg, e);
+ } else {
+ getLogger().warn(msg);
+ }
+ return str;
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/2a3a8823/src/main/java/org/apache/commons/release/plugin/handler/package-info.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/release/plugin/handler/package-info.java b/src/main/java/org/apache/commons/release/plugin/handler/package-info.java
index 064b55a..6f97164 100644
--- a/src/main/java/org/apache/commons/release/plugin/handler/package-info.java
+++ b/src/main/java/org/apache/commons/release/plugin/handler/package-info.java
@@ -1 +1,17 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.commons.release.plugin.handler;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/2a3a8823/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetatchmentMojo.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetatchmentMojo.java b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetatchmentMojo.java
index 1d6d54e..c8ed139 100644
--- a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetatchmentMojo.java
+++ b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetatchmentMojo.java
@@ -26,7 +26,6 @@ import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.AttachedArtifact;
-import org.codehaus.plexus.util.FileUtils;
import java.io.File;
import java.io.FileInputStream;
@@ -92,7 +91,7 @@ public class CommonsDistributionDetatchmentMojo extends AbstractMojo {
project.getAttachedArtifacts().remove(artifactToRemove);
}
if (!workingDirectory.exists()) {
- SharedFunctions.initWorkingDirectory(getLog(), workingDirectory);
+ SharedFunctions.initDirectory(getLog(), workingDirectory);
}
copyRemovedArtifactsToWorkingDirectory();
getLog().info("");
http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/2a3a8823/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 b4741f2..327d8c5 100644
--- a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionStagingMojo.java
+++ b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionStagingMojo.java
@@ -1,25 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.commons.release.plugin.mojos;
+import org.apache.commons.release.plugin.SharedFunctions;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.scm.manager.BasicScmManager;
+import org.apache.maven.scm.manager.NoSuchScmProviderException;
+import org.apache.maven.scm.manager.ScmManager;
+import org.apache.maven.scm.provider.svn.svnexe.SvnExeScmProvider;
+import org.apache.maven.scm.repository.ScmRepository;
+import org.apache.maven.scm.repository.ScmRepositoryException;
+import org.apache.maven.settings.Settings;
import java.io.File;
@Mojo( name = "stage-distributions", defaultPhase = LifecyclePhase.DEPLOY, threadSafe = true)
public class CommonsDistributionStagingMojo extends AbstractMojo {
+ /**
+ */
+ @Parameter( defaultValue = "${settings}", readonly = true, required = true )
+ private Settings settings;
+
+ /**
+ */
@Parameter( defaultValue = "${project.build.directory}/commons-release-plugin", alias = "outputDirectory" )
private File workingDirectory;
+ /**
+ */
+ @Parameter( defaultValue = "${project.build.directory}/commons-release-plugin/scm", alias = "outputDirectory" )
+ private File distCheckoutDirectory;
+
+ /**
+ */
@Parameter ( required = true )
- private String distScmStagingUrl;
+ private String distSvnStagingUrl;
+
+ /**
+ * The SCM username to use.
+ */
+ @Parameter( property = "username" )
+ private String username;
+
+ /**
+ * The SCM password to use.
+ */
+ @Parameter( property = "password" )
+ private String password;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
-
+ try {
+ ScmManager scmManager = new BasicScmManager();
+ scmManager.setScmProvider("svn", new SvnExeScmProvider());
+ ScmRepository repository = scmManager.makeScmRepository(distSvnStagingUrl);
+ if (!workingDirectory.exists()) {
+ SharedFunctions.initDirectory(getLog(), workingDirectory);
+ }
+ if (!distCheckoutDirectory.exists()) {
+ SharedFunctions.initDirectory(getLog(), distCheckoutDirectory);
+ }
+ } catch (ScmRepositoryException e) {
+ getLog().error("Failed getting scm repository: " + distSvnStagingUrl, e);
+ throw new MojoExecutionException("Failed getting scm repository: " + distSvnStagingUrl, e);
+ } catch (NoSuchScmProviderException e) {
+ getLog().error("No Scm Provider For: " + distSvnStagingUrl, e);
+ throw new MojoExecutionException("No Scm Provider For: " + distSvnStagingUrl, e);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/2a3a8823/src/main/java/org/apache/commons/release/plugin/mojos/CommonsSiteCompressionMojo.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsSiteCompressionMojo.java b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsSiteCompressionMojo.java
index 5812061..c030f90 100644
--- a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsSiteCompressionMojo.java
+++ b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsSiteCompressionMojo.java
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.commons.release.plugin.mojos;
import org.apache.commons.compress.archivers.zip.ParallelScatterZipCreator;
@@ -44,7 +60,7 @@ public class CommonsSiteCompressionMojo extends AbstractMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (!workingDirectory.exists()) {
- SharedFunctions.initWorkingDirectory(getLog(), workingDirectory);
+ SharedFunctions.initDirectory(getLog(), workingDirectory);
}
try {
filesToCompress = new ArrayList<>();