You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2006/08/29 03:53:04 UTC
svn commit: r437908 -
/geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/GpgSignAttachedMojo.java
Author: jdillon
Date: Mon Aug 28 18:53:04 2006
New Revision: 437908
URL: http://svn.apache.org/viewvc?rev=437908&view=rev
Log:
Adding a mojo to sign a projects attached artifacts with GnuPG
Added:
geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/GpgSignAttachedMojo.java (with props)
Added: geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/GpgSignAttachedMojo.java
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/GpgSignAttachedMojo.java?rev=437908&view=auto
==============================================================================
--- geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/GpgSignAttachedMojo.java (added)
+++ geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/GpgSignAttachedMojo.java Mon Aug 28 18:53:04 2006
@@ -0,0 +1,151 @@
+/*
+ * 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.geronimo.genesis.plugins.tools;
+
+import java.util.List;
+import java.util.Iterator;
+import java.util.ArrayList;
+
+import java.io.File;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.apache.geronimo.genesis.AntMojoSupport;
+
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectHelper;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.commons.lang.SystemUtils;
+
+import org.codehaus.plexus.util.cli.Commandline;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.DefaultConsumer;
+import org.codehaus.plexus.util.cli.CommandLineException;
+
+/**
+ * Sign project attached artifacts with GnuPG.
+ *
+ * @goal gpg-sign-attached
+ * @phase package
+ *
+ * @version $Rev$ $Date$
+ */
+public class GpgSignAttachedMojo
+ extends AntMojoSupport
+{
+ /**
+ * The passphrase to use when signing.
+ *
+ * @parameter expression="${passphrase}"
+ * @required
+ */
+ private String passphrase = null;
+
+ /**
+ * Maven ProjectHelper
+ *
+ * @component
+ * @readonly
+ */
+ private MavenProjectHelper projectHelper = null;
+
+ //
+ // MojoSupport Hooks
+ //
+
+ /**
+ * The maven project.
+ *
+ * @parameter expression="${project}"
+ * @required
+ * @readonly
+ */
+ protected MavenProject project = null;
+
+ protected MavenProject getProject() {
+ return project;
+ }
+
+ //
+ // Mojo
+ //
+
+ protected void doExecute() throws Exception {
+ List artifacts = new ArrayList();
+ artifacts.add(project.getArtifact());
+ artifacts.addAll(project.getAttachedArtifacts());
+
+ if (log.isDebugEnabled()) {
+ log.info("Artifacts to be signed: " + artifacts);
+ }
+
+ Iterator iter = artifacts.iterator();
+ while (iter.hasNext()) {
+ Artifact artifact = (Artifact)iter.next();
+ File signature = sign(artifact);
+ projectHelper.attachArtifact(project, artifact.getType() + ".asc", null, signature);
+ }
+ }
+
+ private File sign(final Artifact artifact) throws Exception {
+ assert artifact != null;
+
+ File file = artifact.getFile();
+ log.info("Signing artifact file: " + file);
+
+ File signature = new File(file.getCanonicalPath() + ".asc");
+ log.debug("Signature file: " + signature);
+
+ if (signature.exists()) {
+ log.debug("Signature file already exists, removing: " + signature);
+ signature.delete();
+ }
+
+ Commandline cmd = new Commandline();
+ cmd.setExecutable("gpg" + (SystemUtils.IS_OS_WINDOWS ? ".exe" : ""));
+
+ cmd.createArgument().setValue("--passphrase-fd");
+ cmd.createArgument().setValue("0");
+ cmd.createArgument().setValue("--armor");
+ cmd.createArgument().setValue("--detach-sign");
+ cmd.createArgument().setFile(file);
+
+ if (log.isDebugEnabled()) {
+ log.debug(Commandline.toString(cmd.getCommandline()));
+ }
+
+ // Prepare the input stream which will be used to pass the passphrase to the executable
+ InputStream in = new ByteArrayInputStream(passphrase.getBytes());
+
+ try {
+ int exitCode = CommandLineUtils.executeCommandLine(cmd, in, new DefaultConsumer(), new DefaultConsumer());
+
+ if (exitCode != 0) {
+ throw new MojoExecutionException("Exit code: " + exitCode);
+ }
+ }
+ catch (CommandLineException e) {
+ throw new MojoExecutionException("Unable to execute java command", e);
+ }
+
+ return signature;
+ }
+}
Propchange: geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/GpgSignAttachedMojo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/GpgSignAttachedMojo.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/GpgSignAttachedMojo.java
------------------------------------------------------------------------------
svn:mime-type = text/plain