Return-Path: X-Original-To: apmail-maven-commits-archive@www.apache.org Delivered-To: apmail-maven-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F343A10CD4 for ; Wed, 13 Nov 2013 20:50:39 +0000 (UTC) Received: (qmail 48420 invoked by uid 500); 13 Nov 2013 20:50:39 -0000 Delivered-To: apmail-maven-commits-archive@maven.apache.org Received: (qmail 48367 invoked by uid 500); 13 Nov 2013 20:50:39 -0000 Mailing-List: contact commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@maven.apache.org Delivered-To: mailing list commits@maven.apache.org Received: (qmail 48360 invoked by uid 99); 13 Nov 2013 20:50:39 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Nov 2013 20:50:39 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Nov 2013 20:50:35 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 2265823889ED; Wed, 13 Nov 2013 20:50:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1541704 - in /maven/shared/trunk/maven-jarsigner: ./ src/main/java/org/apache/maven/shared/jarsigner/ Date: Wed, 13 Nov 2013 20:50:12 -0000 To: commits@maven.apache.org From: tchemit@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131113205013.2265823889ED@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ - 2.0.6 + 2.1.0 shared-archives/${project.artifactId}-LATEST @@ -62,7 +62,7 @@ org.apache.maven.shared maven-shared-utils - 0.3 + 0.5-SNAPSHOT @@ -76,6 +76,11 @@ plexus-container-default 1.0-alpha-9-stable-1 + + org.apache.maven + maven-toolchain + ${mavenVersion} + junit 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 options. */ 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 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 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 null. - * @param homeDir The home directory to search in, may be null. - * @param subDirs The sub directories of the home directory to search in, must not be null. - * @return The (absolute) path to the command if found, null 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 null 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 null. - */ - 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 { - /** - * Executes JarSigner tool using the parameters specified by the given invocation request. - * - * @param request The invocation request to execute, must not be null. - * @return The result of the JarSigner invocation, never null. - * @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. - *

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

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

protected
+ * * @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
protected
+ * * @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 null 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. Note: - * This value is undefined if {@link #getExecutionException()} reports an exception. - * - * @return The exit code from the Jarsigner invocation. - */ - int getExitCode(); }