Author: tchemit
Date: Wed Nov 13 20:50:12 2013
New Revision: 1541704

URL: http://svn.apache.org/r1541704
Log:
MSHARED-305 - Use maven-shared-utils javatool API

Removed:
    
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerException.java
Modified:
    maven/shared/trunk/maven-jarsigner/pom.xml
    
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/AbstractJarSignerRequest.java
    
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSigner.java
    
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSignerResult.java
    
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSigner.java
    
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerRequest.java
    
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerResult.java

Modified: maven/shared/trunk/maven-jarsigner/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-jarsigner/pom.xml?rev=1541704&r1=1541703&r2=1541704&view=diff
==============================================================================
--- maven/shared/trunk/maven-jarsigner/pom.xml (original)
+++ maven/shared/trunk/maven-jarsigner/pom.xml Wed Nov 13 20:50:12 2013
@@ -54,7 +54,7 @@
   </distributionManagement>
 
   <properties>
-    <mavenVersion>2.0.6</mavenVersion>
+    <mavenVersion>2.1.0</mavenVersion>
     
<maven.site.path>shared-archives/${project.artifactId}-LATEST</maven.site.path>
   </properties>
 
@@ -62,7 +62,7 @@
     <dependency>
       <groupId>org.apache.maven.shared</groupId>
       <artifactId>maven-shared-utils</artifactId>
-      <version>0.3</version>
+      <version>0.5-SNAPSHOT</version>
     </dependency>
 
     <dependency>
@@ -76,6 +76,11 @@
       <artifactId>plexus-container-default</artifactId>
       <version>1.0-alpha-9-stable-1</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-toolchain</artifactId>
+      <version>${mavenVersion}</version>
+    </dependency>
 
     <dependency>
       <groupId>junit</groupId>

Modified: 
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/AbstractJarSignerRequest.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/AbstractJarSignerRequest.java?rev=1541704&r1=1541703&r2=1541704&view=diff
==============================================================================
--- 
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/AbstractJarSignerRequest.java
 (original)
+++ 
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/AbstractJarSignerRequest.java
 Wed Nov 13 20:50:12 2013
@@ -19,7 +19,7 @@ package org.apache.maven.shared.jarsigne
  * under the License.
  */
 
-import org.apache.maven.shared.utils.cli.StreamConsumer;
+import org.apache.maven.shared.utils.cli.javatool.AbstractJavaToolRequest;
 
 import java.io.File;
 
@@ -31,6 +31,7 @@ import java.io.File;
  * @since 1.0
  */
 public abstract class AbstractJarSignerRequest
+    extends AbstractJavaToolRequest
     implements JarSignerRequest
 {
     /**
@@ -60,16 +61,6 @@ public abstract class AbstractJarSignerR
     private File archive;
 
     /**
-     * Optional system out stream consumer used by the commandline execution.
-     */
-    private StreamConsumer systemOutStreamConsumer;
-
-    /**
-     * Optional system error stream consumer used by the commandline execution.
-     */
-    private StreamConsumer systemErrorStreamConsumer;
-
-    /**
      * See <a 
href="http://java.sun.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options";>options</a>.
      */
     protected boolean protectedAuthenticationPath;
@@ -117,25 +108,9 @@ public abstract class AbstractJarSignerR
     /**
      * {@inheritDoc}
      */
-    public StreamConsumer getSystemOutStreamConsumer()
-    {
-        return systemOutStreamConsumer;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public StreamConsumer getSystemErrorStreamConsumer()
-    {
-        return systemErrorStreamConsumer;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
     public boolean isProtectedAuthenticationPath()
     {
-      return protectedAuthenticationPath;
+        return protectedAuthenticationPath;
     }
 
     /**
@@ -181,24 +156,8 @@ public abstract class AbstractJarSignerR
     /**
      * {@inheritDoc}
      */
-    public void setSystemOutStreamConsumer( StreamConsumer 
systemOutStreamConsumer )
-    {
-        this.systemOutStreamConsumer = systemOutStreamConsumer;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void setSystemErrorStreamConsumer( StreamConsumer 
systemErrorStreamConsumer )
-    {
-        this.systemErrorStreamConsumer = systemErrorStreamConsumer;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void setProtectedAuthenticationPath(boolean protect)
+    public void setProtectedAuthenticationPath( boolean protect )
     {
-      this.protectedAuthenticationPath = protect;
+        this.protectedAuthenticationPath = protect;
     }
 }

Modified: 
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSigner.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSigner.java?rev=1541704&r1=1541703&r2=1541704&view=diff
==============================================================================
--- 
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSigner.java
 (original)
+++ 
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSigner.java
 Wed Nov 13 20:50:12 2013
@@ -19,19 +19,11 @@ package org.apache.maven.shared.jarsigne
  * under the License.
  */
 
-import org.apache.maven.shared.utils.Os;
-import org.apache.maven.shared.utils.StringUtils;
-import org.apache.maven.shared.utils.cli.CommandLineException;
-import org.apache.maven.shared.utils.cli.CommandLineUtils;
 import org.apache.maven.shared.utils.cli.Commandline;
 import org.apache.maven.shared.utils.cli.StreamConsumer;
+import org.apache.maven.shared.utils.cli.javatool.AbstractJavaTool;
+import org.apache.maven.shared.utils.cli.javatool.JavaToolException;
 import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Map;
 
 /**
  * Default implementation of component {@link JarSigner}.
@@ -42,84 +34,56 @@ import java.util.Map;
  */
 @Component( role = JarSigner.class, hint = "default" )
 public class DefaultJarSigner
-    extends AbstractLogEnabled
+    extends AbstractJavaTool<JarSignerRequest, JarSignerResult>
     implements JarSigner
 {
 
-    /**
-     * The location of the jarSigner executable file.
-     */
-    protected String jarSignerFile;
-
-    /**
-     * {@inheritDoc}
-     */
-    public JarSignerResult execute( JarSignerRequest request )
-        throws JarSignerException
+    public DefaultJarSigner()
     {
+        super( "jarsigner" );
+    }
 
-        if ( jarSignerFile == null )
-        {
-
-            // find the jar singer to use
-            try
-            {
-                jarSignerFile = findJarSignerExecutable();
-            }
-            catch ( IOException e )
-            {
-                throw new JarSignerException( "Error finding jar signer 
executable. Reason: " + e.getMessage(), e );
-            }
-        }
-
-        // creates the command line
-        Commandline cli = createCommandLine( request );
-
-        // execute it
-        return executeCommandLine( cli, request );
+    @Override
+    protected JarSignerResult createResult()
+    {
+        return new DefaultJarSignerResult();
     }
 
-    protected Commandline createCommandLine( JarSignerRequest request )
-        throws JarSignerException
+    @Override
+    protected Commandline createCommandLine( JarSignerRequest request, String 
javaToolFile )
+        throws JavaToolException
     {
         JarSignerCommandLineBuilder cliBuilder = new 
JarSignerCommandLineBuilder();
         cliBuilder.setLogger( getLogger() );
-        cliBuilder.setJarSignerFile( jarSignerFile );
+        cliBuilder.setJarSignerFile( javaToolFile );
         try
         {
-            return cliBuilder.build( request );
+            Commandline cli = cliBuilder.build( request );
+            if ( request.isVerbose() )
+            {
+                getLogger().info( cli.toString() );
+            }
+            else
+            {
+                getLogger().debug( cli.toString() );
+            }
+            return cli;
         }
         catch ( CommandLineConfigurationException e )
         {
-            throw new JarSignerException( "Error configuring command-line. 
Reason: " + e.getMessage(), e );
+            throw new JavaToolException( "Error configuring command-line. 
Reason: " + e.getMessage(), e );
         }
     }
 
-    protected JarSignerResult executeCommandLine( Commandline cli, 
JarSignerRequest request )
+    protected StreamConsumer createSystemOutStreamConsumer( JarSignerRequest 
request )
     {
-        if ( getLogger().isDebugEnabled() )
-        {
-            getLogger().debug( "Executing: " + cli );
-        }
-
-        final boolean verbose = request.isVerbose();
-
-        InputStream systemIn = new InputStream()
-        {
-
-            /**
-             * {@inheritDoc}
-             */
-            public int read()
-            {
-                return -1;
-            }
-
-        };
         StreamConsumer systemOut = request.getSystemOutStreamConsumer();
 
         if ( systemOut == null )
         {
+
+            final boolean verbose = request.isVerbose();
+
             systemOut = new StreamConsumer()
             {
 
@@ -140,109 +104,7 @@ public class DefaultJarSigner
 
             };
         }
-
-        StreamConsumer systemErr = request.getSystemErrorStreamConsumer();
-
-        if ( systemErr == null )
-        {
-            systemErr = new StreamConsumer()
-            {
-
-                /**
-                 * {@inheritDoc}
-                 */
-                public void consumeLine( final String line )
-                {
-                    getLogger().warn( line );
-                }
-
-            };
-        }
-
-        DefaultJarSignerResult result = new DefaultJarSignerResult();
-        result.setCommandline( cli );
-
-        if ( verbose )
-        {
-            getLogger().info( cli.toString() );
-        }
-        else
-        {
-            getLogger().debug( cli.toString() );
-        }
-
-        try
-        {
-            int resultCode = CommandLineUtils.executeCommandLine( cli, 
systemIn, systemOut, systemErr );
-
-            result.setExitCode( resultCode );
-        }
-        catch ( CommandLineException e )
-        {
-            result.setExecutionException( e );
-        }
-
-        return result;
-    }
-
-    protected String findJarSignerExecutable()
-        throws IOException
-    {
-        String command = "jarsigner" + ( Os.isFamily( Os.FAMILY_WINDOWS ) ? 
".exe" : "" );
-
-        String executable = findExecutable( command, System.getProperty( 
"java.home" ), "../bin", "bin", "../sh" );
-
-        if ( executable == null )
-        {
-
-            Map<String, String> env = System.getenv();
-
-            String[] variables = { "JDK_HOME", "JAVA_HOME" };
-
-            for ( String variable : variables )
-            {
-                executable = findExecutable( command, env.get( variable ), 
"bin", "sh" );
-                if ( executable != null )
-                {
-                    break;
-                }
-            }
-
-        }
-
-        if ( executable == null )
-        {
-            executable = command;
-        }
-
-        return executable;
+        return systemOut;
     }
 
-    /**
-     * Finds the specified command in any of the given sub directories of the 
specified JDK/JRE home directory.
-     *
-     * @param command The command to find, must not be <code>null</code>.
-     * @param homeDir The home directory to search in, may be 
<code>null</code>.
-     * @param subDirs The sub directories of the home directory to search in, 
must not be <code>null</code>.
-     * @return The (absolute) path to the command if found, <code>null</code> 
otherwise.
-     */
-    protected String findExecutable( String command, String homeDir, String... 
subDirs )
-    {
-        String result = null;
-        if ( StringUtils.isNotEmpty( homeDir ) )
-        {
-            for ( String subDir : subDirs )
-            {
-                File file = new File( new File( homeDir, subDir ), command );
-
-                if ( file.isFile() )
-                {
-                    result = file.getAbsolutePath();
-                    break;
-                }
-            }
-        }
-
-        return result;
-    }
 }

Modified: 
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSignerResult.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSignerResult.java?rev=1541704&r1=1541703&r2=1541704&view=diff
==============================================================================
--- 
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSignerResult.java
 (original)
+++ 
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSignerResult.java
 Wed Nov 13 20:50:12 2013
@@ -19,8 +19,7 @@ package org.apache.maven.shared.jarsigne
  * under the License.
  */
 
-import org.apache.maven.shared.utils.cli.CommandLineException;
-import org.apache.maven.shared.utils.cli.Commandline;
+import org.apache.maven.shared.utils.cli.javatool.AbstractJavaToolResult;
 
 /**
  * Describes the result of a JarSigner invocation.
@@ -30,76 +29,15 @@ import org.apache.maven.shared.utils.cli
  * @since 1.0
  */
 public class DefaultJarSignerResult
+    extends AbstractJavaToolResult
     implements JarSignerResult
 {
 
     /**
-     * The exception that prevented to execute the command line, will be 
<code>null</code> if jarSigner could be
-     * successfully started.
-     */
-    private CommandLineException executionException;
-
-    /**
-     * The exit code reported by the Maven invocation.
-     */
-    private int exitCode = Integer.MIN_VALUE;
-
-    private Commandline commandline;
-
-    /**
      * Creates a new invocation result
      */
     DefaultJarSignerResult()
     {
         // hide constructor
     }
-
-    /**
-     * {@inheritDoc}
-     */
-    public int getExitCode()
-    {
-        return exitCode;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Commandline getCommandline()
-    {
-        return commandline;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public CommandLineException getExecutionException()
-    {
-        return executionException;
-    }
-
-    /**
-     * Sets the exit code reported by the Jarsigner invocation.
-     *
-     * @param exitCode The exit code reported by the JarSigner invocation.
-     */
-    void setExitCode( int exitCode )
-    {
-        this.exitCode = exitCode;
-    }
-
-    /**
-     * Sets the exception that prevented to execute the command line.
-     *
-     * @param executionException The exception that prevented to execute the 
command line, may be <code>null</code>.
-     */
-    void setExecutionException( CommandLineException executionException )
-    {
-        this.executionException = executionException;
-    }
-
-    void setCommandline( Commandline commandline )
-    {
-        this.commandline = commandline;
-    }
 }

Modified: 
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSigner.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSigner.java?rev=1541704&r1=1541703&r2=1541704&view=diff
==============================================================================
--- 
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSigner.java
 (original)
+++ 
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSigner.java
 Wed Nov 13 20:50:12 2013
@@ -19,6 +19,8 @@ package org.apache.maven.shared.jarsigne
  * under the License.
  */
 
+import org.apache.maven.shared.utils.cli.javatool.JavaTool;
+
 /**
  * Provides a facade to invoke JarSigner tool.
  *
@@ -27,16 +29,7 @@ package org.apache.maven.shared.jarsigne
  * @since 1.0
  */
 public interface JarSigner
+    extends JavaTool<JarSignerRequest, JarSignerResult>
 {
 
-    /**
-     * Executes JarSigner tool using the parameters specified by the given 
invocation request.
-     *
-     * @param request The invocation request to execute, must not be 
<code>null</code>.
-     * @return The result of the JarSigner invocation, never <code>null</code>.
-     * @throws JarSignerException if something fails while init the command
-     */
-    JarSignerResult execute( JarSignerRequest request )
-        throws JarSignerException;
-
 }

Modified: 
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerRequest.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerRequest.java?rev=1541704&r1=1541703&r2=1541704&view=diff
==============================================================================
--- 
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerRequest.java
 (original)
+++ 
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerRequest.java
 Wed Nov 13 20:50:12 2013
@@ -19,7 +19,7 @@ package org.apache.maven.shared.jarsigne
  * under the License.
  */
 
-import org.apache.maven.shared.utils.cli.StreamConsumer;
+import org.apache.maven.shared.utils.cli.javatool.JavaToolRequest;
 
 import java.io.File;
 
@@ -31,6 +31,7 @@ import java.io.File;
  * @since 1.0
  */
 public interface JarSignerRequest
+    extends JavaToolRequest
 {
 
     /**
@@ -72,29 +73,10 @@ public interface JarSignerRequest
     File getArchive();
 
     /**
-     * Gets the value of the {@code systemOutStreamConsumer} field.
-     * <p/>
-     * This option field if filled is used by the commandline tool to consume 
system ouput stream of the jarsigner
-     * command.
-     *
-     * @return the value of the {@code systemOutStreamConsumer} field.
-     */
-    StreamConsumer getSystemOutStreamConsumer();
-
-    /**
-     * Gets the value of the {@code systemErrorStreamConsumer} field.
-     * <p/>
-     * This option field if filled is used by the commandline tool to consume 
system error stream of the jarsigner
-     * command.
-     *
-     * @return the value of the {@code systemErrorStreamConsumer} field.
-     */
-    StreamConsumer getSystemErrorStreamConsumer();
-
-    /**
      * Gets the value of the command line tool parameter <pre>protected</pre>
+     *
      * @return true iff the password must be given via a protected
-     * authentication path such as a dedicated PIN reader
+     *         authentication path such as a dedicated PIN reader
      */
     boolean isProtectedAuthenticationPath();
 
@@ -134,24 +116,11 @@ public interface JarSignerRequest
     void setArchive( File archive );
 
     /**
-     * Sets the new given value to the field {@code systemOutStreamConsumer} 
of the request.
-     *
-     * @param systemOutStreamConsumer the new value of the field {@code 
systemOutStreamConsumer}.
-     */
-    void setSystemOutStreamConsumer( StreamConsumer systemOutStreamConsumer );
-
-    /**
-     * Sets the new given value to the field {@code systemErrorStreamConsumer} 
of the request.
-     *
-     * @param systemErrorStreamConsumer the new value of the field {@code 
systemErrorStreamConsumer}.
-     */
-    void setSystemErrorStreamConsumer( StreamConsumer 
systemErrorStreamConsumer );
-
-    /**
      * Sets the value of the command line tool parameter <pre>protected</pre>
+     *
      * @param protectedAuthenticationPath iff the password must be given via a 
protected
-     * authentication path such as a dedicated PIN reader
+     *                                    authentication path such as a 
dedicated PIN reader
      */
-    void setProtectedAuthenticationPath(boolean protectedAuthenticationPath);
+    void setProtectedAuthenticationPath( boolean protectedAuthenticationPath );
 
 }

Modified: 
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerResult.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerResult.java?rev=1541704&r1=1541703&r2=1541704&view=diff
==============================================================================
--- 
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerResult.java
 (original)
+++ 
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerResult.java
 Wed Nov 13 20:50:12 2013
@@ -19,8 +19,7 @@ package org.apache.maven.shared.jarsigne
  * under the License.
  */
 
-import org.apache.maven.shared.utils.cli.CommandLineException;
-import org.apache.maven.shared.utils.cli.Commandline;
+import org.apache.maven.shared.utils.cli.javatool.JavaToolResult;
 
 /**
  * Describes the result of a JarSigner invocation.
@@ -30,28 +29,7 @@ import org.apache.maven.shared.utils.cli
  * @since 1.0
  */
 public interface JarSignerResult
+    extends JavaToolResult
 {
 
-    /**
-     * Gets the command line used.
-     *
-     * @return The command line used
-     */
-    Commandline getCommandline();
-
-    /**
-     * Gets the exception that possibly occurred during the execution of the 
command line.
-     *
-     * @return The exception that prevented to invoke Jarsigner or 
<code>null</code> if the command line was successfully
-     *         processed by the operating system.
-     */
-    CommandLineException getExecutionException();
-
-    /**
-     * Gets the exit code from the JarSigner invocation. A non-zero value 
indicates a build failure. <strong>Note:</strong>
-     * This value is undefined if {@link #getExecutionException()} reports an 
exception.
-     *
-     * @return The exit code from the Jarsigner invocation.
-     */
-    int getExitCode();
 }


Reply via email to