ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/security GenerateKey.java SignJar.java
Date Sat, 12 Jan 2002 23:45:10 GMT
donaldp     02/01/12 15:45:10

  Modified:    proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/security
                        GenerateKey.java SignJar.java
  Log:
  Don't use ExecTask directly, instead use the ant adaptor objects and Execute2
  
  Revision  Changes    Path
  1.3       +51 -33    jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/security/GenerateKey.java
  
  Index: GenerateKey.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/security/GenerateKey.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- GenerateKey.java	4 Jan 2002 09:25:13 -0000	1.2
  +++ GenerateKey.java	12 Jan 2002 23:45:10 -0000	1.3
  @@ -7,17 +7,19 @@
    */
   package org.apache.tools.ant.taskdefs.security;
   
  +import org.apache.myrmidon.api.AbstractTask;
   import org.apache.myrmidon.api.TaskException;
  -import org.apache.tools.ant.Task;
  -import org.apache.tools.ant.taskdefs.exec.ExecTask;
  +import org.apache.tools.ant.taskdefs.exec.Execute2;
  +import org.apache.tools.ant.types.Commandline;
  +import java.io.IOException;
   
   /**
    * Generates a key.
    *
  - * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
  + * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    */
   public class GenerateKey
  -    extends Task
  +    extends AbstractTask
   {
       /**
        * The alias of signer.
  @@ -141,87 +143,103 @@
           final String message = "Generating Key for " + m_alias;
           getLogger().info( message );
   
  -        final ExecTask cmd = (ExecTask)getProject().createTask( "exec" );
  +        final Commandline cmd = createCommand();
  +        final Execute2 exe = new Execute2();
  +        exe.setWorkingDirectory( getBaseDirectory() );
  +        exe.setCommandline( cmd.getCommandline() );
  +        try
  +        {
  +            exe.execute();
  +        }
  +        catch( final IOException ioe )
  +        {
  +            throw new TaskException( ioe.getMessage(), ioe );
  +        }
  +    }
  +
  +    private Commandline createCommand()
  +    {
  +        final Commandline cmd = new Commandline();
           cmd.setExecutable( "keytool" );
   
  -        cmd.createArg().setValue( "-genkey " );
  +        cmd.createArgument().setValue( "-genkey " );
   
           if( m_verbose )
           {
  -            cmd.createArg().setValue( "-v " );
  +            cmd.createArgument().setValue( "-v " );
           }
   
  -        cmd.createArg().setValue( "-alias" );
  -        cmd.createArg().setValue( m_alias );
  +        cmd.createArgument().setValue( "-alias" );
  +        cmd.createArgument().setValue( m_alias );
   
           if( null != m_dname )
           {
  -            cmd.createArg().setValue( "-dname" );
  -            cmd.createArg().setValue( m_dname );
  +            cmd.createArgument().setValue( "-dname" );
  +            cmd.createArgument().setValue( m_dname );
           }
   
           if( null != m_expandedDname )
           {
  -            cmd.createArg().setValue( "-dname" );
  -            cmd.createArg().setValue( m_expandedDname.toString() );
  +            cmd.createArgument().setValue( "-dname" );
  +            cmd.createArgument().setValue( m_expandedDname.toString() );
           }
   
           if( null != m_keystore )
           {
  -            cmd.createArg().setValue( "-keystore" );
  -            cmd.createArg().setValue( m_keystore );
  +            cmd.createArgument().setValue( "-keystore" );
  +            cmd.createArgument().setValue( m_keystore );
           }
   
           if( null != m_storepass )
           {
  -            cmd.createArg().setValue( "-storepass" );
  -            cmd.createArg().setValue( m_storepass );
  +            cmd.createArgument().setValue( "-storepass" );
  +            cmd.createArgument().setValue( m_storepass );
           }
   
           if( null != m_storetype )
           {
  -            cmd.createArg().setValue( "-storetype" );
  -            cmd.createArg().setValue( m_storetype );
  +            cmd.createArgument().setValue( "-storetype" );
  +            cmd.createArgument().setValue( m_storetype );
           }
   
  -        cmd.createArg().setValue( "-keypass" );
  +        cmd.createArgument().setValue( "-keypass" );
           if( null != m_keypass )
           {
  -            cmd.createArg().setValue( m_keypass );
  +            cmd.createArgument().setValue( m_keypass );
           }
           else
           {
  -            cmd.createArg().setValue( m_storepass );
  +            cmd.createArgument().setValue( m_storepass );
           }
   
           if( null != m_sigalg )
           {
  -            cmd.createArg().setValue( "-sigalg" );
  -            cmd.createArg().setValue( m_sigalg );
  +            cmd.createArgument().setValue( "-sigalg" );
  +            cmd.createArgument().setValue( m_sigalg );
           }
   
           if( null != m_keyalg )
           {
  -            cmd.createArg().setValue( "-keyalg" );
  -            cmd.createArg().setValue( m_keyalg );
  +            cmd.createArgument().setValue( "-keyalg" );
  +            cmd.createArgument().setValue( m_keyalg );
           }
   
           if( 0 < m_keysize )
           {
  -            cmd.createArg().setValue( "-keysize" );
  -            cmd.createArg().setValue( "" + m_keysize );
  +            cmd.createArgument().setValue( "-keysize" );
  +            cmd.createArgument().setValue( "" + m_keysize );
           }
   
           if( 0 < m_validity )
           {
  -            cmd.createArg().setValue( "-validity" );
  -            cmd.createArg().setValue( "" + m_validity );
  +            cmd.createArgument().setValue( "-validity" );
  +            cmd.createArgument().setValue( "" + m_validity );
           }
  -
  -        cmd.execute();
  +        return cmd;
       }
   
  -    private void validate() throws TaskException
  +    private void validate()
  +        throws TaskException
       {
           if( null == m_alias )
           {
  
  
  
  1.4       +42 -26    jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/security/SignJar.java
  
  Index: SignJar.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/security/SignJar.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SignJar.java	1 Jan 2002 09:13:46 -0000	1.3
  +++ SignJar.java	12 Jan 2002 23:45:10 -0000	1.4
  @@ -15,15 +15,16 @@
   import java.util.zip.ZipFile;
   import org.apache.myrmidon.api.AbstractTask;
   import org.apache.myrmidon.api.TaskException;
  -import org.apache.tools.ant.DirectoryScanner;
  -import org.apache.tools.ant.taskdefs.exec.ExecTask;
  +import org.apache.tools.ant.types.DirectoryScanner;
  +import org.apache.tools.ant.taskdefs.exec.Execute2;
  +import org.apache.tools.ant.types.Commandline;
   import org.apache.tools.ant.types.FileSet;
   
   /**
    * Sign a archive.
    *
  - * @author Peter Donald <a href="mailto:donaldp@apache.org">donaldp@apache.org</a>
  - * @author Nick Fortescue <a href="mailto:nick@ox.compsoc.net">nick@ox.compsoc.net</a>
  + * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  + * @author <a href="mailto:nick@ox.compsoc.net">Nick Fortescue</a>
    */
   public class SignJar
       extends AbstractTask
  @@ -285,67 +286,82 @@
   
           final StringBuffer sb = new StringBuffer();
   
  -        final ExecTask cmd = null;//(ExecTask)getProject().createTask( "exec" );
  +        final String message = "Signing Jar : " + jarSource.getAbsolutePath();
  +        getLogger().info( message );
  +
  +        final Commandline cmd = buildCommand( jarTarget, jarSource );
  +        final Execute2 exe = new Execute2();
  +        setupLogger( exe );
  +        try
  +        {
  +            exe.execute();
  +        }
  +        catch( final IOException ioe )
  +        {
  +            throw new TaskException( ioe.getMessage(), ioe );
  +        }
  +    }
  +
  +    private Commandline buildCommand( final File jarTarget, final File jarSource )
  +    {
  +        final Commandline cmd = new Commandline();
           cmd.setExecutable( "jarsigner" );
   
           if( null != m_keystore )
           {
  -            cmd.createArg().setValue( "-keystore" );
  -            cmd.createArg().setValue( m_keystore.toString() );
  +            cmd.createArgument().setValue( "-keystore" );
  +            cmd.createArgument().setValue( m_keystore.toString() );
           }
   
           if( null != m_storepass )
           {
  -            cmd.createArg().setValue( "-storepass" );
  -            cmd.createArg().setValue( m_storepass );
  +            cmd.createArgument().setValue( "-storepass" );
  +            cmd.createArgument().setValue( m_storepass );
           }
   
           if( null != m_storetype )
           {
  -            cmd.createArg().setValue( "-storetype" );
  -            cmd.createArg().setValue( m_storetype );
  +            cmd.createArgument().setValue( "-storetype" );
  +            cmd.createArgument().setValue( m_storetype );
           }
   
           if( null != m_keypass )
           {
  -            cmd.createArg().setValue( "-keypass" );
  -            cmd.createArg().setValue( m_keypass );
  +            cmd.createArgument().setValue( "-keypass" );
  +            cmd.createArgument().setValue( m_keypass );
           }
   
           if( null != m_sigfile )
           {
  -            cmd.createArg().setValue( "-sigfile" );
  -            cmd.createArg().setValue( m_sigfile.toString() );
  +            cmd.createArgument().setValue( "-sigfile" );
  +            cmd.createArgument().setValue( m_sigfile.toString() );
           }
   
           if( null != jarTarget )
           {
  -            cmd.createArg().setValue( "-signedjar" );
  -            cmd.createArg().setValue( jarTarget.toString() );
  +            cmd.createArgument().setValue( "-signedjar" );
  +            cmd.createArgument().setValue( jarTarget.toString() );
           }
   
           if( m_verbose )
           {
  -            cmd.createArg().setValue( "-verbose" );
  +            cmd.createArgument().setValue( "-verbose" );
           }
   
           if( m_internalsf )
           {
  -            cmd.createArg().setValue( "-internalsf" );
  +            cmd.createArgument().setValue( "-internalsf" );
           }
   
           if( m_sectionsonly )
           {
  -            cmd.createArg().setValue( "-sectionsonly" );
  +            cmd.createArgument().setValue( "-sectionsonly" );
           }
   
  -        cmd.createArg().setValue( jarSource.toString() );
  +        cmd.createArgument().setValue( jarSource.toString() );
   
  -        cmd.createArg().setValue( m_alias );
  -
  -        final String message = "Signing Jar : " + jarSource.getAbsolutePath();
  -        getLogger().info( message );
  -        cmd.execute();
  +        cmd.createArgument().setValue( m_alias );
  +        return cmd;
       }
   }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message