ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Gainty <mgai...@hotmail.com>
Subject RE: Problem with GPG plugin from Ant task
Date Thu, 31 Jan 2013 20:49:58 GMT

Antoine

can we take the Mojo source and re-factor to ANT taskdef class?
package org.apache.maven.plugin.gpg; /* * 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. */

import java.io.File;import java.io.IOException;import java.util.ArrayList;import java.util.Iterator;import
java.util.List;import org.apache.maven.artifact.Artifact;import org.apache.maven.plugin.MojoExecutionException;import
org.apache.maven.plugin.MojoFailureException;import org.apache.maven.project.MavenProject;import
org.apache.maven.project.MavenProjectHelper;import org.codehaus.plexus.util.FileUtils;import
org.codehaus.plexus.util.SelectorUtils;


/*
 * 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.
 */

import java.io.File;
import java.io.IOException;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;

/**
 * @author Benjamin Bentmann
*
 * old definition extends Mojo AbstractMojo which will be replaced by org.apache.tools.ant.Task
 public abstract class AbstractGpgMojo extends AbstractMojo
*/


public abstract class AbstractGpgMojo extends extends org.apache.tools.ant.Task 
{
    
/**
     * The directory from which gpg will load keyrings. If not specified, gpg will use the
value configured for its
     * installation, e.g. <code>~/.gnupg</code> or <code>%APPDATA%/gnupg</code>.
     * 
     * @parameter expression="${gpg.homedir}"
     * @since 1.0
     */
    private File homedir;

    /**
     * The passphrase to use when signing.
     * 
     * @parameter expression="${gpg.passphrase}"
     */
    private String passphrase;

    
/**
     * The "name" of the key to sign with. Passed to gpg as <code>--local-user</code>.
     * 
     * @parameter expression="${gpg.keyname}"
     */
    private String keyname;

    /**
     * Passes <code>--use-agent</code> or <code>--no-use-agent</code>
to gpg. If using an agent, the passphrase is
     * optional as the agent will provide it.
     * For gpg2, specify true as --no-use-agent was removed in gpg2 and doesn't ask for a
passphrase anymore.
     * 
     * @parameter expression="${gpg.useagent}" default-value="false"
     */
    private boolean useAgent;

    /**
     * @parameter default-value="${settings.interactiveMode}"
     * @readonly
     */
    private boolean interactive;

    /**
     * The path to the GnuPG executable to use for artifact signing. Defaults to either "gpg"
or "gpg.exe" depending on
     * the operating system.
     * 
     * @parameter expression="${gpg.executable}"
     * @since 1.1
     */
    private String executable;

    /**
     * Whether to add the default keyrings from gpg's home directory to the list of used keyrings.
     * 
     * @parameter expression="${gpg.defaultKeyring}" default-value="true"
     * @since 1.2
     */
    private boolean defaultKeyring;

    /**
     * The path to a secret keyring to add to the list of keyrings. By default, only the {@code
secring.gpg} from gpg's
     * home directory is considered. Use this option (in combination with {@link #publicKeyring}
and
     * {@link #defaultKeyring} if required) to use a different secret key. <em>Note:</em>
Relative paths are resolved
     * against gpg's home directory, not the project base directory.
     ** @parameter expression="${gpg.secretKeyring}"
     * @since 1.2
     */
    private String secretKeyring;

    /**
     * The path to a public keyring to add to the list of keyrings. By default, only the {@code
pubring.gpg} from gpg's
     * home directory is considered. Use this option (and {@link #defaultKeyring} if required)
to use a different public
     * key. <em>Note:</em> Relative paths are resolved against gpg's home directory,
not the project base directory.
     * 
     * @parameter expression="${gpg.publicKeyring}"
     * @since 1.2
     */
    private String publicKeyring;

     GpgSigner newSigner( MavenProject project )
        throws MojoExecutionException, MojoFailureException
    {
        GpgSigner signer = new GpgSigner();

        signer.setExecutable( executable );
        signer.setInteractive( interactive );
        signer.setKeyName( keyname );
        signer.setUseAgent( useAgent );
        signer.setHomeDirectory( homedir );
        signer.setDefaultKeyring( defaultKeyring );
        signer.setSecretKeyring( secretKeyring );
        signer.setPublicKeyring( publicKeyring );

        signer.setPassPhrase( passphrase );
        if ( null == passphrase && !useAgent )
        {
              if ( !interactive )
            {
                throw new MojoFailureException( "Cannot obtain passphrase in batch mode" );
            }
              try
              {
                     signer.setPassPhrase( signer.getPassphrase( project ) );
              }
              catch ( IOException e )
              {
                   throw new MojoExecutionException( "Exception reading passphrase", e );
              }
        }

        return signer;
    }

//override this in concrete class!public void execute { ; } throws org.apache.tools.ant.BuildException}

http://maven.apache.org/plugins/maven-gpg-plugin/project-info.html

Martin Gainty 
______________________________________________ 
Jogi és Bizalmassági kinyilatkoztatás/Verzicht und Vertraulichkeitanmerkung/Note de déni
et de confidentialité
 Ez az
üzenet bizalmas.  Ha nem ön az akinek szánva volt, akkor kérjük, hogy
jelentse azt nekünk vissza. Semmiféle továbbítása vagy másolatának
készítése nem megengedett.  Ez az üzenet csak ismeret cserét szolgál és
semmiféle jogi alkalmazhatósága sincs.  Mivel az electronikus üzenetek
könnyen megváltoztathatóak, ezért minket semmi felelöség nem terhelhet
ezen üzenet tartalma miatt.

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten
wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist
unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet
keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen
wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire
prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe
quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information
seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les
email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune
responsabilité pour le contenu fourni.

 > Date: Wed, 30 Jan 2013 19:08:33 -0800
> Subject: Re: Problem with GPG plugin from Ant task
> From: lewis.mcgibbney@gmail.com
> To: user@ant.apache.org
> 
> Hi Antoine,
> Thank you very much for your suggestion. I need to be honest with you
> though and say that we ended up changing the entire build to Maven to fix
> the problem and now everything works fine. It was sapping hours of my time
> looking for an answer so we made the decision to shift :0(
> Thank you for the feedback, hopefully now that this thread exists others
> can benefit.
> Best
> Lewis
> 
> On Wed, Jan 30, 2013 at 6:22 PM, Antoine Levy Lambert <antoine@gmx.de>wrote:
> 
> > Hello Lewis,
> >
> > there is a project in the commons sandbox at Apache with which you can PGP
> > sign artifacts in an Ant build
> >
> > The source code is there [1]
> >
> > There is an example of usage of this here [2]
> >
> > We use that when producing releases of Ant.
> >
> > Maybe this can help you ?
> >
> > Regards,
> >
> > Antoine
> >
> > [1]  http://svn.apache.org/repos/asf/commons/sandbox/openpgp/trunk/
> > [2] http://svn.apache.org/repos/asf/ant/core/trunk/release/signit.xml
> >
> >
> >
> > On Jan 29, 2013, at 6:47 PM, Lewis John Mcgibbney wrote:
> >
> > > Hi,
> > > Having looked high and low for a resolution, I've been unable to find
> > one.
> > > I'm in the process of pushing a release on a small project which uses ant
> > > tasks + maven for the build lifecycle.
> > > I am attempting to deploy to sonatype staging repository with the
> > following
> > > configuration
> > >
> > > ...
> > >     <!-- defined maven snapshots and staging repository id and url -->
> > >     <property name="maven-snapshots-repository-id"
> > > value="sonatype-nexus-snapshots" />
> > >     <property name="maven-snapshots-repository-url"
> > >         value="https://oss.sonatype.org/content/repositories/snapshots/
> > ";
> > > />
> > >     <property name="maven-staging-repository-id"
> > > value="sonatype-nexus-staging" />
> > >     <property name="maven-staging-repository-url"
> > >         value="
> > > https://oss.sonatype.org/service/local/staging/deploy/maven2/";
> > > />
> > > ...
> > >     <target name="stage" depends="dist"
> > >         description="--> deploy release version to Maven staging
> > > repository"
> > >         xmlns:artifact="urn:maven-artifact-ant">
> > >         <!-- sign and deploy the main artifact -->
> > >         <artifact:mvn>
> > >             <arg
> > >
> > >
> > value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file"
> > > />
> > >             <arg value="-Durl=${maven-staging-repository-url}" />
> > >             <arg value="-DrepositoryId=${maven-staging-repository-id}" />
> > >             <arg value="-DpomFile=pom.xml" />
> > >             <arg value="-Dfile=${maven-jar}" />
> > >             <arg value="-Pgpg" />
> > >         </artifact:mvn>
> > >
> > >         <!-- sign and deploy the sources artifact -->
> > >         <artifact:mvn>
> > >             <arg
> > >
> > >
> > value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file"
> > > />
> > >             <arg value="-Durl=${maven-staging-repository-url}" />
> > >             <arg value="-DrepositoryId=${maven-staging-repository-id}" />
> > >             <arg value="-DpomFile=pom.xml" />
> > >             <arg value="-Dfile=${maven-sources-jar}" />
> > >             <arg value="-Dclassifier=sources" />
> > >             <arg value="-Pgpg" />
> > >         </artifact:mvn>
> > >
> > >         <!-- sign and deploy the javadoc artifact -->
> > >         <artifact:mvn>
> > >             <arg
> > >
> > >
> > value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file"
> > > />
> > >             <arg value="-Durl=${maven-staging-repository-url}" />
> > >             <arg value="-DrepositoryId=${maven-staging-repository-id}" />
> > >             <arg value="-DpomFile=pom.xml" />
> > >             <arg value="-Dfile=${maven-javadoc-jar}" />
> > >             <arg value="-Dclassifier=javadoc" />
> > >             <arg value="-Pgpg" />
> > >         </artifact:mvn>
> > >     </target>
> > >
> > > However when I run the stage target, I get the following
> > >
> > > [artifact:mvn] [INFO]    task-segment:
> > > [org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file]
> > > (aggregator-style)
> > > [artifact:mvn] [INFO]
> > > ------------------------------------------------------------------------
> > > [artifact:mvn] [INFO] [gpg:sign-and-deploy-file]
> > > [artifact:mvn] [INFO]
> > > ------------------------------------------------------------------------
> > > [artifact:mvn] [ERROR] BUILD FAILURE
> > > [artifact:mvn] [INFO]
> > > ------------------------------------------------------------------------
> > > [artifact:mvn] [INFO] Cannot obtain passphrase in batch mode
> > > [artifact:mvn] [INFO]
> > > ------------------------------------------------------------------------
> > > [artifact:mvn] [INFO] For more information, run Maven with the -e switch
> > > [artifact:mvn] [INFO]
> > > ------------------------------------------------------------------------
> > > [artifact:mvn] [INFO] Total time: 2 seconds
> > > [artifact:mvn] [INFO] Finished at: Sun Jan 27 21:37:35 PST 2013
> > > [artifact:mvn] [INFO] Final Memory: 16M/40M
> > > [artifact:mvn] [INFO]
> > > ------------------------------------------------------------------------
> > > [artifact:mvn] Java Result: 1
> > >
> > > There is very little on the dreaded "Cannot obtain passphrase in batch
> > > mode".
> > > Even when I use overrides on the command line e.g. ant stage
> > > -Dpassphrase=${passphrase}, I still get the above.
> > >
> > > Does anyone have a suggestion on how I can run Maven (from an Ant
> > > task) to operate in interactive (non-batch) mode?
> > >
> > > Any ideas? Thanks very much in advance
> > >
> > > Lewis
> > >
> > >
> > >
> > > --
> > > *Lewis*
> >
> >
> 
> 
> -- 
> *Lewis*
 		 	   		  
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message