You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2011/10/28 15:43:29 UTC
svn commit: r1190315 - in /maven/shared/trunk: ./ maven-jarsigner/
maven-jarsigner/src/ maven-jarsigner/src/main/
maven-jarsigner/src/main/java/ maven-jarsigner/src/main/java/org/
maven-jarsigner/src/main/java/org/apache/ maven-jarsigner/src/main/java/...
Author: olamy
Date: Fri Oct 28 13:43:28 2011
New Revision: 1190315
URL: http://svn.apache.org/viewvc?rev=1190315&view=rev
Log:
[MJARSIGNER-19] Make mojo code reusable from another mojo + customize the working directory.
create maven-jarsigner shared component
Added:
maven/shared/trunk/maven-jarsigner/
maven/shared/trunk/maven-jarsigner/pom.xml (with props)
maven/shared/trunk/maven-jarsigner/src/
maven/shared/trunk/maven-jarsigner/src/main/
maven/shared/trunk/maven-jarsigner/src/main/java/
maven/shared/trunk/maven-jarsigner/src/main/java/org/
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/AbstractJarSignerRequest.java (with props)
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/CommandLineConfigurationException.java (with props)
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSigner.java (with props)
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSignerResult.java (with props)
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSigner.java (with props)
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerCommandLineBuilder.java (with props)
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerException.java (with props)
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerRequest.java (with props)
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerResult.java (with props)
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerSignRequest.java (with props)
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java (with props)
maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerVerifyRequest.java (with props)
Modified:
maven/shared/trunk/pom.xml
Added: maven/shared/trunk/maven-jarsigner/pom.xml
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-jarsigner/pom.xml?rev=1190315&view=auto
==============================================================================
--- maven/shared/trunk/maven-jarsigner/pom.xml (added)
+++ maven/shared/trunk/maven-jarsigner/pom.xml Fri Oct 28 13:43:28 2011
@@ -0,0 +1,103 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-shared-components</artifactId>
+ <version>16</version>
+ <relativePath>../maven-shared-components/pom.xml</relativePath>
+ </parent>
+ <artifactId>maven-jarsigner</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <name>Maven Jarsigner</name>
+
+ <description>A component to assist in signing jars.</description>
+
+ <prerequisites>
+ <maven>2.0.6</maven>
+ </prerequisites>
+
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/maven/shared/trunk/maven-jarsigner</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/maven/shared/trunk/maven-jarsigner</developerConnection>
+ <url>http://svn.apache.org/viewvc/maven/shared/trunk/maven-jarsigner</url>
+ </scm>
+ <issueManagement>
+ <system>jira</system>
+ <url>https://jira.codehaus.org/browse/MSHARED/component/15255</url>
+ </issueManagement>
+
+ <properties>
+ <mavenVersion>2.0.6</mavenVersion>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ <version>1.0-alpha-9-stable-1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>2.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.9</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-maven-plugin</artifactId>
+ <version>1.3.8</version>
+ <executions>
+ <execution>
+ <id>create-component-descriptor</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>descriptor</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Propchange: maven/shared/trunk/maven-jarsigner/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-jarsigner/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: 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=1190315&view=auto
==============================================================================
--- maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/AbstractJarSignerRequest.java (added)
+++ maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/AbstractJarSignerRequest.java Fri Oct 28 13:43:28 2011
@@ -0,0 +1,109 @@
+package org.apache.maven.shared.jarsigner;
+
+/*
+ * 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;
+
+/**
+ * Specifies the commons parameters used to control a jar signer invocation.
+ *
+ * @author tchemit <ch...@codelutin.com>
+ * @version $Id$
+ * @since 1.0
+ */
+public abstract class AbstractJarSignerRequest
+ implements JarSignerRequest
+{
+ /**
+ * See <a href="http://java.sun.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options">options</a>.
+ */
+ private boolean verbose;
+
+ /**
+ * The maximum memory available to the JAR signer, e.g. <code>256M</code>. See <a
+ * href="http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html#Xms">-Xmx</a> for more details.
+ */
+ private String maxMemory;
+
+ /**
+ * List of additional arguments to append to the jarsigner command line.
+ */
+ private String[] arguments;
+
+ /**
+ * Location of the working directory.
+ */
+ private File workingDirectory;
+
+ /**
+ * Archive to treat.
+ */
+ private File archive;
+
+ public boolean isVerbose()
+ {
+ return verbose;
+ }
+
+ public String getMaxMemory()
+ {
+ return maxMemory;
+ }
+
+ public String[] getArguments()
+ {
+ return arguments;
+ }
+
+ public File getWorkingDirectory()
+ {
+ return workingDirectory;
+ }
+
+ public File getArchive()
+ {
+ return archive;
+ }
+
+ public void setVerbose( boolean verbose )
+ {
+ this.verbose = verbose;
+ }
+
+ public void setMaxMemory( String maxMemory )
+ {
+ this.maxMemory = maxMemory;
+ }
+
+ public void setArguments( String[] arguments )
+ {
+ this.arguments = arguments;
+ }
+
+ public void setWorkingDirectory( File workingDirectory )
+ {
+ this.workingDirectory = workingDirectory;
+ }
+
+ public void setArchive( File archive )
+ {
+ this.archive = archive;
+ }
+}
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/AbstractJarSignerRequest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/AbstractJarSignerRequest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/CommandLineConfigurationException.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/CommandLineConfigurationException.java?rev=1190315&view=auto
==============================================================================
--- maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/CommandLineConfigurationException.java (added)
+++ maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/CommandLineConfigurationException.java Fri Oct 28 13:43:28 2011
@@ -0,0 +1,57 @@
+package org.apache.maven.shared.jarsigner;
+
+/*
+ * 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.
+ */
+
+/**
+ * Signals an error during the construction of the command line used to invoke jar signer.
+ *
+ * @author tchemit <ch...@codelutin.com>
+ * @version $Id$
+ * @since 1.0
+ */
+public class CommandLineConfigurationException
+ extends Exception
+{
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Creates a new exception using the specified detail message and cause.
+ *
+ * @param message The detail message for this exception, may be <code>null</code>.
+ * @param cause The nested exception, may be <code>null</code>.
+ */
+ public CommandLineConfigurationException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+
+ /**
+ * Creates a new exception using the specified detail message.
+ *
+ * @param message The detail message for this exception, may be <code>null</code>.
+ */
+ public CommandLineConfigurationException( String message )
+ {
+ super( message );
+ }
+
+}
+
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/CommandLineConfigurationException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/CommandLineConfigurationException.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: 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=1190315&view=auto
==============================================================================
--- maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSigner.java (added)
+++ maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSigner.java Fri Oct 28 13:43:28 2011
@@ -0,0 +1,226 @@
+package org.apache.maven.shared.jarsigner;
+
+/*
+ * 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 org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.util.Os;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+import org.codehaus.plexus.util.cli.StreamConsumer;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+/**
+ * Default implementation of component {@link JarSigner}.
+ *
+ * @author tchemit <ch...@codelutin.com>
+ * @version $Id$
+ * @plexus.component role="org.apache.maven.shared.jarsigner.JarSigner" role-hint="default"
+ * @since 1.0
+ */
+public class DefaultJarSigner
+ extends AbstractLogEnabled
+ implements JarSigner
+{
+
+ /**
+ * The location of the jarSigner executable file.
+ */
+ protected String jarSignerFile;
+
+ public JarSignerResult execute( JarSignerRequest request )
+ throws JarSignerException
+ {
+
+ 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 );
+ }
+
+ protected Commandline createCommandLine( JarSignerRequest request )
+ throws JarSignerException
+ {
+ JarSignerCommandLineBuilder cliBuilder = new JarSignerCommandLineBuilder();
+ cliBuilder.setLogger( getLogger() );
+ cliBuilder.setJarSignerFile( jarSignerFile );
+ Commandline cli;
+ try
+ {
+ cli = cliBuilder.build( request );
+ }
+ catch ( CommandLineConfigurationException e )
+ {
+ throw new JarSignerException( "Error configuring command-line. Reason: " + e.getMessage(), e );
+ }
+ return cli;
+ }
+
+ protected JarSignerResult executeCommandLine( Commandline cli, JarSignerRequest request )
+ {
+ if ( getLogger().isDebugEnabled() )
+ {
+ getLogger().debug( "Executing: " + cli );
+ }
+
+ final boolean verbose = request.isVerbose();
+
+ InputStream systemIn = new InputStream()
+ {
+
+ public int read()
+ {
+ return -1;
+ }
+
+ };
+ StreamConsumer systemOut = new StreamConsumer()
+ {
+
+ public void consumeLine( final String line )
+ {
+ if ( verbose )
+ {
+ getLogger().info( line );
+ }
+ else
+ {
+ getLogger().debug( line );
+ }
+ }
+
+ };
+
+ StreamConsumer systemErr = new StreamConsumer()
+ {
+
+ public void consumeLine( final String line )
+ {
+ getLogger().warn( line );
+ }
+
+ };
+
+ DefaultJarSignerResult result = new DefaultJarSignerResult();
+ result.setCommandline( cli );
+
+ 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" ), new String[]{ "../bin", "bin", "../sh" } );
+
+ if ( executable == null )
+ {
+ try
+ {
+ Properties env = CommandLineUtils.getSystemEnvVars();
+
+ String[] variables = { "JDK_HOME", "JAVA_HOME" };
+
+ for ( int i = 0; i < variables.length && executable == null; i++ )
+ {
+ executable =
+ findExecutable( command, env.getProperty( variables[i] ), new String[]{ "bin", "sh" } );
+ }
+ }
+ catch ( IOException e )
+ {
+ if ( getLogger().isDebugEnabled() )
+ {
+ getLogger().warn( "Failed to retrieve environment variables, cannot search for " + command, e );
+ }
+ else
+ {
+ getLogger().warn( "Failed to retrieve environment variables, cannot search for " + command );
+ }
+ }
+ }
+
+ if ( executable == null )
+ {
+ executable = command;
+ }
+
+ return executable;
+ }
+
+ /**
+ * 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 )
+ {
+ if ( StringUtils.isNotEmpty( homeDir ) )
+ {
+ for ( int i = 0; i < subDirs.length; i++ )
+ {
+ File file = new File( new File( homeDir, subDirs[i] ), command );
+
+ if ( file.isFile() )
+ {
+ return file.getAbsolutePath();
+ }
+ }
+ }
+
+ return null;
+ }
+}
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSigner.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSigner.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: 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=1190315&view=auto
==============================================================================
--- maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSignerResult.java (added)
+++ maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSignerResult.java Fri Oct 28 13:43:28 2011
@@ -0,0 +1,96 @@
+package org.apache.maven.shared.jarsigner;
+
+/*
+ * 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 org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.Commandline;
+
+/**
+ * Describes the result of a JarSigner invocation.
+ *
+ * @author tchemit <ch...@codelutin.com>
+ * @version $Id$
+ * @since 1.0
+ */
+public class DefaultJarSignerResult
+ 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
+ }
+
+ public int getExitCode()
+ {
+ return exitCode;
+ }
+
+ public Commandline getCommandline()
+ {
+ return commandline;
+ }
+
+ 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;
+ }
+}
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSignerResult.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSignerResult.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: 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=1190315&view=auto
==============================================================================
--- maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSigner.java (added)
+++ maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSigner.java Fri Oct 28 13:43:28 2011
@@ -0,0 +1,42 @@
+package org.apache.maven.shared.jarsigner;
+
+/*
+ * 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.
+ */
+
+/**
+ * Provides a facade to invoke JarSigner tool.
+ *
+ * @author tchemit <ch...@codelutin.com>
+ * @version $Id$
+ * @since 1.0
+ */
+public interface JarSigner
+{
+
+ /**
+ * 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;
+
+}
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSigner.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSigner.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerCommandLineBuilder.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerCommandLineBuilder.java?rev=1190315&view=auto
==============================================================================
--- maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerCommandLineBuilder.java (added)
+++ maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerCommandLineBuilder.java Fri Oct 28 13:43:28 2011
@@ -0,0 +1,196 @@
+package org.apache.maven.shared.jarsigner;
+
+/*
+ * 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 org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.logging.console.ConsoleLogger;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+
+import java.io.IOException;
+
+/**
+ * To build the command line for a given {@link JarSignerRequest}.
+ *
+ * @author tchemit <ch...@codelutin.com>
+ * @version $Id$
+ * @since 1.0
+ */
+public class JarSignerCommandLineBuilder
+{
+ private static final Logger DEFAULT_LOGGER = new ConsoleLogger( 0, JarSignerCommandLineBuilder.class.getName() );
+
+ private Logger logger = DEFAULT_LOGGER;
+
+ private String jarSignerFile;
+
+ public Commandline build( JarSignerRequest request )
+ throws CommandLineConfigurationException
+ {
+ try
+ {
+ checkRequiredState();
+ }
+ catch ( IOException e )
+ {
+ throw new CommandLineConfigurationException( e.getMessage(), e );
+ }
+
+ Commandline cli = new Commandline();
+
+ cli.setExecutable( jarSignerFile );
+
+ cli.setWorkingDirectory( request.getWorkingDirectory() );
+
+ if ( request.isVerbose() )
+ {
+ cli.createArg().setValue( "-verbose" );
+ }
+
+ String maxMemory = request.getMaxMemory();
+ if ( StringUtils.isNotEmpty( maxMemory ) )
+ {
+ cli.createArg().setValue( "-J-Xmx" + maxMemory );
+ }
+
+ String[] arguments = request.getArguments();
+ if ( arguments != null )
+ {
+ cli.addArguments( arguments );
+ }
+
+ if ( request instanceof JarSignerSignRequest )
+ {
+ build( (JarSignerSignRequest) request, cli );
+ }
+
+ if ( request instanceof JarSignerVerifyRequest )
+ {
+ build( (JarSignerVerifyRequest) request, cli );
+ }
+
+ return cli;
+ }
+
+ public void setLogger( Logger logger )
+ {
+ this.logger = logger;
+ }
+
+ public void setJarSignerFile( String jarSignerFile )
+ {
+ this.jarSignerFile = jarSignerFile;
+ }
+
+ protected void checkRequiredState()
+ throws IOException
+ {
+ if ( logger == null )
+ {
+ throw new IllegalStateException( "A logger instance is required." );
+ }
+
+ if ( jarSignerFile == null )
+ {
+ throw new IllegalStateException( "A jarSigner file is required." );
+ }
+ }
+
+ protected void build( JarSignerSignRequest request, Commandline cli )
+ {
+ String keystore = request.getKeystore();
+ if ( !StringUtils.isEmpty( keystore ) )
+ {
+ cli.createArg().setValue( "-keystore" );
+ cli.createArg().setValue( keystore );
+ }
+
+ String storepass = request.getStorepass();
+ if ( !StringUtils.isEmpty( storepass ) )
+ {
+ cli.createArg().setValue( "-storepass" );
+ cli.createArg().setValue( storepass );
+ }
+
+ String keypass = request.getKeypass();
+ if ( !StringUtils.isEmpty( keypass ) )
+ {
+ cli.createArg().setValue( "-keypass" );
+ cli.createArg().setValue( keypass );
+ }
+
+ String storetype = request.getStoretype();
+ if ( !StringUtils.isEmpty( storetype ) )
+ {
+ cli.createArg().setValue( "-storetype" );
+ cli.createArg().setValue( storetype );
+ }
+
+ String providerName = request.getProviderName();
+ if ( !StringUtils.isEmpty( providerName ) )
+ {
+ cli.createArg().setValue( "-providerName" );
+ cli.createArg().setValue( providerName );
+ }
+
+ String providerClass = request.getProviderClass();
+ if ( !StringUtils.isEmpty( providerClass ) )
+ {
+ cli.createArg().setValue( "-providerClass" );
+ cli.createArg().setValue( providerClass );
+ }
+
+ String providerArg = request.getProviderArg();
+ if ( !StringUtils.isEmpty( providerArg ) )
+ {
+ cli.createArg().setValue( "-providerArg" );
+ cli.createArg().setValue( providerArg );
+ }
+
+ String sigfile = request.getSigfile();
+ if ( !StringUtils.isEmpty( sigfile ) )
+ {
+ cli.createArg().setValue( "-sigfile" );
+ cli.createArg().setValue( sigfile );
+ }
+
+ cli.createArg().setFile( request.getArchive() );
+
+ String alias = request.getAlias();
+ if ( !StringUtils.isEmpty( alias ) )
+ {
+ cli.createArg().setValue( alias );
+ }
+ }
+
+ protected Commandline build( JarSignerVerifyRequest request, Commandline cli )
+ throws CommandLineConfigurationException
+ {
+ cli.createArg( true ).setValue( "-verify" );
+
+ if ( request.isCerts() )
+ {
+ cli.createArg().setValue( "-certs" );
+ }
+
+ cli.createArg().setFile( request.getArchive() );
+ return cli;
+ }
+}
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerCommandLineBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerCommandLineBuilder.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerException.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerException.java?rev=1190315&view=auto
==============================================================================
--- maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerException.java (added)
+++ maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerException.java Fri Oct 28 13:43:28 2011
@@ -0,0 +1,59 @@
+package org.apache.maven.shared.jarsigner;
+
+/*
+ * 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.
+ */
+
+/**
+ * Signals an error during the construction of the command line used to invoke jar signer, e.g. illegal invocation arguments.
+ * This should not be confused with a failure of the invoked JarSigner build itself which will be reported by means of a
+ * non-zero exit code.
+ *
+ * @author tchemit <ch...@codelutin.com>
+ * @version $Id$
+ * @see JarSignerResult#getExitCode()
+ * @since 1.0
+ */
+public class JarSignerException
+ extends Exception
+{
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Creates a new exception using the specified detail message and cause.
+ *
+ * @param message The detail message for this exception, may be <code>null</code>.
+ * @param cause The nested exception, may be <code>null</code>.
+ */
+ public JarSignerException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+
+ /**
+ * Creates a new exception using the specified detail message.
+ *
+ * @param message The detail message for this exception, may be <code>null</code>.
+ */
+ public JarSignerException( String message )
+ {
+ super( message );
+ }
+
+}
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerException.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: 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=1190315&view=auto
==============================================================================
--- maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerRequest.java (added)
+++ maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerRequest.java Fri Oct 28 13:43:28 2011
@@ -0,0 +1,52 @@
+package org.apache.maven.shared.jarsigner;
+
+/*
+ * 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;
+
+/**
+ * Specifies the common parameters used to control a JarSigner tool invocation.
+ *
+ * @author tchemit <ch...@codelutin.com>
+ * @version $Id$
+ * @since 1.0
+ */
+public interface JarSignerRequest
+{
+ boolean isVerbose();
+
+ String getMaxMemory();
+
+ String[] getArguments();
+
+ File getWorkingDirectory();
+
+ File getArchive();
+
+ void setVerbose( boolean verbose );
+
+ void setMaxMemory( String maxMemory );
+
+ void setArguments( String[] arguments );
+
+ void setWorkingDirectory( File workingDirectory );
+
+ void setArchive( File archive );
+}
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerRequest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerRequest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: 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=1190315&view=auto
==============================================================================
--- maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerResult.java (added)
+++ maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerResult.java Fri Oct 28 13:43:28 2011
@@ -0,0 +1,57 @@
+package org.apache.maven.shared.jarsigner;
+
+/*
+ * 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 org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.Commandline;
+
+/**
+ * Describes the result of a JarSigner invocation.
+ *
+ * @author tchemit <ch...@codelutin.com>
+ * @version $Id$
+ * @since 1.0
+ */
+public interface JarSignerResult
+{
+
+ /**
+ * 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();
+}
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerResult.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerResult.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerSignRequest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerSignRequest.java?rev=1190315&view=auto
==============================================================================
--- maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerSignRequest.java (added)
+++ maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerSignRequest.java Fri Oct 28 13:43:28 2011
@@ -0,0 +1,166 @@
+package org.apache.maven.shared.jarsigner;
+
+/*
+ * 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.
+ */
+
+/**
+ * Specifies the parameters used to control a jar signer sign operation invocation.
+ *
+ * @author tchemit <ch...@codelutin.com>
+ * @version $Id$
+ * @since 1.0
+ */
+public class JarSignerSignRequest
+ extends AbstractJarSignerRequest
+{
+ /**
+ * See <a href="http://java.sun.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options">options</a>.
+ */
+ private String keystore;
+
+ /**
+ * See <a href="http://java.sun.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options">options</a>.
+ */
+ private String storepass;
+
+ /**
+ * See <a href="http://java.sun.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options">options</a>.
+ */
+ private String keypass;
+
+ /**
+ * See <a href="http://java.sun.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options">options</a>.
+ */
+ private String sigfile;
+
+ /**
+ * See <a href="http://java.sun.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options">options</a>.
+ */
+ private String storetype;
+
+ /**
+ * See <a href="http://java.sun.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options">options</a>.
+ */
+ private String providerName;
+
+ /**
+ * See <a href="http://java.sun.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options">options</a>.
+ */
+ private String providerClass;
+
+ /**
+ * See <a href="http://java.sun.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options">options</a>.
+ */
+ private String providerArg;
+
+ /**
+ * See <a href="http://java.sun.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options">options</a>.
+ */
+ private String alias;
+
+ public String getKeystore()
+ {
+ return keystore;
+ }
+
+ public String getStorepass()
+ {
+ return storepass;
+ }
+
+ public String getKeypass()
+ {
+ return keypass;
+ }
+
+ public String getSigfile()
+ {
+ return sigfile;
+ }
+
+ public String getStoretype()
+ {
+ return storetype;
+ }
+
+ public String getProviderName()
+ {
+ return providerName;
+ }
+
+ public String getProviderClass()
+ {
+ return providerClass;
+ }
+
+ public String getProviderArg()
+ {
+ return providerArg;
+ }
+
+ public String getAlias()
+ {
+ return alias;
+ }
+
+ public void setKeystore( String keystore )
+ {
+ this.keystore = keystore;
+ }
+
+ public void setStorepass( String storepass )
+ {
+ this.storepass = storepass;
+ }
+
+ public void setKeypass( String keypass )
+ {
+ this.keypass = keypass;
+ }
+
+ public void setSigfile( String sigfile )
+ {
+ this.sigfile = sigfile;
+ }
+
+ public void setStoretype( String storetype )
+ {
+ this.storetype = storetype;
+ }
+
+ public void setProviderName( String providerName )
+ {
+ this.providerName = providerName;
+ }
+
+ public void setProviderClass( String providerClass )
+ {
+ this.providerClass = providerClass;
+ }
+
+ public void setProviderArg( String providerArg )
+ {
+ this.providerArg = providerArg;
+ }
+
+ public void setAlias( String alias )
+ {
+ this.alias = alias;
+ }
+}
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerSignRequest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerSignRequest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java?rev=1190315&view=auto
==============================================================================
--- maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java (added)
+++ maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java Fri Oct 28 13:43:28 2011
@@ -0,0 +1,149 @@
+package org.apache.maven.shared.jarsigner;
+
+/*
+ * 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 org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
+
+import java.io.*;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
+
+/**
+ * Usuful methods.
+ *
+ * @author tchemit <ch...@codelutin.com>
+ * @version $Id$
+ * @since 1.0
+ */
+public class JarSignerUtil
+{
+
+ private JarSignerUtil()
+ {
+ // static class
+ }
+
+ /**
+ * Checks whether the specified file is a JAR file. For our purposes, a ZIP file is a ZIP stream with at least one
+ * entry.
+ *
+ * @param file The file to check, must not be <code>null</code>.
+ * @return <code>true</code> if the file looks like a ZIP file, <code>false</code> otherwise.
+ */
+ public static boolean isZipFile( final File file )
+ {
+ try
+ {
+ ZipInputStream zis = new ZipInputStream( new FileInputStream( file ) );
+ try
+ {
+ return zis.getNextEntry() != null;
+ }
+ finally
+ {
+ zis.close();
+ }
+ }
+ catch ( Exception e )
+ {
+ // ignore, will fail below
+ }
+
+ return false;
+ }
+
+ /**
+ * Removes any existing signatures from the specified JAR file. We will stream from the input JAR directly to the
+ * output JAR to retain as much metadata from the original JAR as possible.
+ *
+ * @param jarFile The JAR file to unsign, must not be <code>null</code>.
+ * @throws java.io.IOException
+ */
+ public static void unsignArchive( File jarFile )
+ throws IOException
+ {
+
+ File unsignedFile = new File( jarFile.getAbsolutePath() + ".unsigned" );
+
+ ZipInputStream zis = null;
+ ZipOutputStream zos = null;
+ try
+ {
+ zis = new ZipInputStream( new BufferedInputStream( new FileInputStream( jarFile ) ) );
+ zos = new ZipOutputStream( new BufferedOutputStream( new FileOutputStream( unsignedFile ) ) );
+
+ for ( ZipEntry ze = zis.getNextEntry(); ze != null; ze = zis.getNextEntry() )
+ {
+ if ( isSignatureFile( ze.getName() ) )
+ {
+
+ continue;
+ }
+
+ zos.putNextEntry( ze );
+
+ IOUtil.copy( zis, zos );
+ }
+
+ }
+ finally
+ {
+ IOUtil.close( zis );
+ IOUtil.close( zos );
+ }
+
+ FileUtils.rename( unsignedFile, jarFile );
+
+ }
+
+ /**
+ * Checks whether the specified JAR file entry denotes a signature-related file, i.e. matches
+ * <code>META-INF/*.SF</code>, <code>META-INF/*.DSA</code> or <code>META-INF/*.RSA</code>.
+ *
+ * @param entryName The name of the JAR file entry to check, must not be <code>null</code>.
+ * @return <code>true</code> if the entry is related to a signature, <code>false</code> otherwise.
+ */
+ private static boolean isSignatureFile( String entryName )
+ {
+ if ( entryName.regionMatches( true, 0, "META-INF", 0, 8 ) )
+ {
+ entryName = entryName.replace( '\\', '/' );
+
+ if ( entryName.indexOf( '/' ) == 8 && entryName.lastIndexOf( '/' ) == 8 )
+ {
+ if ( entryName.regionMatches( true, entryName.length() - 3, ".SF", 0, 3 ) )
+ {
+ return true;
+ }
+ if ( entryName.regionMatches( true, entryName.length() - 4, ".DSA", 0, 4 ) )
+ {
+ return true;
+ }
+ if ( entryName.regionMatches( true, entryName.length() - 4, ".RSA", 0, 4 ) )
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+}
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerVerifyRequest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerVerifyRequest.java?rev=1190315&view=auto
==============================================================================
--- maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerVerifyRequest.java (added)
+++ maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerVerifyRequest.java Fri Oct 28 13:43:28 2011
@@ -0,0 +1,46 @@
+package org.apache.maven.shared.jarsigner;
+
+/*
+ * 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.
+ */
+
+/**
+ * Specifies the parameters used to control a jar signer verify operation invocation.
+ *
+ * @author tchemit <ch...@codelutin.com>
+ * @version $Id$
+ * @since 1.0
+ */
+public class JarSignerVerifyRequest
+ extends AbstractJarSignerRequest
+{
+ /**
+ * See <a href="http://java.sun.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options">options</a>.
+ */
+ private boolean certs;
+
+ public boolean isCerts()
+ {
+ return certs;
+ }
+
+ public void setCerts( boolean certs )
+ {
+ this.certs = certs;
+ }
+}
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerVerifyRequest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/JarSignerVerifyRequest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: maven/shared/trunk/pom.xml
URL: http://svn.apache.org/viewvc/maven/shared/trunk/pom.xml?rev=1190315&r1=1190314&r2=1190315&view=diff
==============================================================================
--- maven/shared/trunk/pom.xml (original)
+++ maven/shared/trunk/pom.xml Fri Oct 28 13:43:28 2011
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
-
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -17,9 +16,7 @@ software distributed under the License i
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
--->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@@ -63,6 +60,7 @@ under the License.
<module>maven-shared-monitor</module>
<module>maven-shared-resources</module>
<module>maven-verifier</module>
+ <module>maven-jarsigner</module>
</modules>
<profiles>
@@ -88,4 +86,4 @@ under the License.
</modules>
</profile>
</profiles>
-</project>
+</project>
\ No newline at end of file