You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2009/08/09 23:10:34 UTC

svn commit: r802605 - in /maven/plugins/trunk/maven-jarsigner-plugin/src: it/archive-dir/ it/archive-dir/src/ it/archive-dir/src/main/ it/archive-dir/src/main/resources/ it/archive-dir/src/main/resources/jars/ main/java/org/apache/maven/plugins/jarsigner/

Author: bentmann
Date: Sun Aug  9 21:10:34 2009
New Revision: 802605

URL: http://svn.apache.org/viewvc?rev=802605&view=rev
Log:
[MJARSIGNER-6] Allow batch signing of multiple JARs

Added:
    maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/
    maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/pom.xml   (with props)
    maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/src/
    maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/src/main/
    maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/src/main/resources/
    maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/src/main/resources/jars/
    maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/src/main/resources/jars/excluded.jar   (with props)
    maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/src/main/resources/jars/included.jar   (with props)
    maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/verify.bsh   (with props)
Modified:
    maven/plugins/trunk/maven-jarsigner-plugin/src/main/java/org/apache/maven/plugins/jarsigner/AbstractJarsignerMojo.java

Added: maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/pom.xml?rev=802605&view=auto
==============================================================================
--- maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/pom.xml (added)
+++ maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/pom.xml Sun Aug  9 21:10:34 2009
@@ -0,0 +1,92 @@
+<?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>
+
+  <groupId>org.apache.maven.its.jarsigner</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0</version>
+  <packaging>jar</packaging>
+
+  <description>
+    Tests the signing of multiple JARs within a directory selected by includes/excludes.
+  </description>
+
+  <properties>
+    <maven.test.skip>true</maven.test.skip>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.0.2</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <version>2.1</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-resources-plugin</artifactId>
+        <version>2.2</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.3.1</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jarsigner-plugin</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <alias>test-01</alias>
+          <keypass>key-passwd</keypass>
+          <sigfile>TESTING</sigfile>
+          <processMainArtifact>false</processMainArtifact>
+          <archiveDirectory>target/classes/jars</archiveDirectory>
+          <excludes>
+            <exclude>excluded.jar</exclude>
+          </excludes>
+        </configuration>
+        <executions>
+          <execution>
+            <id>sign-jars</id>
+            <goals>
+              <goal>sign</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>verify-jars</id>
+            <goals>
+              <goal>verify</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Propchange: maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/src/main/resources/jars/excluded.jar
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/src/main/resources/jars/excluded.jar?rev=802605&view=auto
==============================================================================
Binary file - no diff available.

Propchange: maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/src/main/resources/jars/excluded.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/src/main/resources/jars/included.jar
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/src/main/resources/jars/included.jar?rev=802605&view=auto
==============================================================================
Binary file - no diff available.

Propchange: maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/src/main/resources/jars/included.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/verify.bsh?rev=802605&view=auto
==============================================================================
--- maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/verify.bsh (added)
+++ maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/verify.bsh Sun Aug  9 21:10:34 2009
@@ -0,0 +1,46 @@
+import java.io.*;
+import java.util.jar.*;
+
+File jarDir = new File( basedir, "target/classes/jars" );
+
+File includedJarFile = new File( jarDir, "included.jar" );
+System.out.println( "Checking for existence of " + includedJarFile );
+if ( !includedJarFile.isFile() )
+{
+    throw new Exception( "missing " + includedJarFile );
+}
+
+JarFile includedJar = new JarFile( includedJarFile );
+System.out.println( "Checking for existence of " + includedJarFile.getName() + "!/META-INF/TESTING.SF" );
+if ( includedJar.getEntry( "META-INF/TESTING.SF" ) == null )
+{
+    throw new Exception( "missing " + includedJarFile.getName() + "!/META-INF/TESTING.SF" );
+}
+System.out.println( "Checking for existence of " + includedJarFile.getName() + "!/META-INF/TESTING.DSA" );
+if ( includedJar.getEntry( "META-INF/TESTING.DSA" ) == null )
+{
+    throw new Exception( "missing " + includedJarFile.getName() + "!/META-INF/TESTING.DSA" );
+}
+includedJar.close();
+
+File excludedJarFile = new File( jarDir, "excluded.jar" );
+System.out.println( "Checking for existence of " + excludedJarFile );
+if ( !excludedJarFile.isFile() )
+{
+    throw new Exception( "missing " + excludedJarFile );
+}
+
+JarFile excludedJar = new JarFile( excludedJarFile );
+System.out.println( "Checking for absence of " + excludedJarFile.getName() + "!/META-INF/TESTING.SF" );
+if ( excludedJar.getEntry( "META-INF/TESTING.SF" ) != null )
+{
+    throw new Exception( "present " + excludedJarFile.getName() + "!/META-INF/TESTING.SF" );
+}
+System.out.println( "Checking for absence of " + excludedJarFile.getName() + "!/META-INF/TESTING.DSA" );
+if ( excludedJar.getEntry( "META-INF/TESTING.DSA" ) != null )
+{
+    throw new Exception( "present " + excludedJarFile.getName() + "!/META-INF/TESTING.DSA" );
+}
+excludedJar.close();
+
+return true;

Propchange: maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/verify.bsh
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-jarsigner-plugin/src/it/archive-dir/verify.bsh
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/plugins/trunk/maven-jarsigner-plugin/src/main/java/org/apache/maven/plugins/jarsigner/AbstractJarsignerMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jarsigner-plugin/src/main/java/org/apache/maven/plugins/jarsigner/AbstractJarsignerMojo.java?rev=802605&r1=802604&r2=802605&view=diff
==============================================================================
--- maven/plugins/trunk/maven-jarsigner-plugin/src/main/java/org/apache/maven/plugins/jarsigner/AbstractJarsignerMojo.java (original)
+++ maven/plugins/trunk/maven-jarsigner-plugin/src/main/java/org/apache/maven/plugins/jarsigner/AbstractJarsignerMojo.java Sun Aug  9 21:10:34 2009
@@ -25,6 +25,7 @@
 import java.io.InputStream;
 import java.text.MessageFormat;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Properties;
 import java.util.ResourceBundle;
 import java.util.zip.ZipEntry;
@@ -35,6 +36,7 @@
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
 
+import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.Os;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.cli.CommandLineException;
@@ -68,18 +70,43 @@
     private String maxMemory;
 
     /**
-     * Archive to process. If set, neither the project artifact nor any attachments are processed.
+     * Archive to process. If set, neither the project artifact nor any attachments or archive sets are processed.
      *
      * @parameter expression="${jarsigner.archive}"
-     * @optional
      */
     private File archive;
 
     /**
+     * The base directory to scan for JAR files using Ant-like inclusion/exclusion patterns.
+     * 
+     * @parameter expression="${jarsigner.archiveDirectory}"
+     * @since 1.1
+     */
+    private File archiveDirectory;
+
+    /**
+     * The Ant-like inclusion patterns used to select JAR files to process. The patterns must be relative to the
+     * directory given by the parameter {@link #archiveDirectory}. By default, the pattern
+     * <code>&#42;&#42;/&#42;.?ar</code> is used.
+     * 
+     * @parameter
+     * @since 1.1
+     */
+    private String[] includes = { "**/*.?ar" };
+
+    /**
+     * The Ant-like exclusion patterns used to exclude JAR files from processing. The patterns must be relative to the
+     * directory given by the parameter {@link #archiveDirectory}.
+     * 
+     * @parameter
+     * @since 1.1
+     */
+    private String[] excludes = {};
+
+    /**
      * List of additional arguments to append to the jarsigner command line.
      *
      * @parameter expression="${jarsigner.arguments}"
-     * @optional
      */
     private String[] arguments;
 
@@ -91,11 +118,29 @@
     private boolean skip;
 
     /**
+     * Controls processing of the main artifact produced by the project.
+     * 
+     * @parameter expression="${jarsigner.processMainArtifact}" default-value="true"
+     * @since 1.1
+     */
+    private boolean processMainArtifact;
+
+    /**
+     * Controls processing of project attachments. If enabled, attached artifacts that are no JARs will be automatically
+     * excluded from processing.
+     * 
+     * @parameter expression="${jarsigner.processAttachedArtifacts}" default-value="true"
+     * @since 1.1
+     */
+    private boolean processAttachedArtifacts;
+
+    /**
      * Controls processing of project attachments.
-     *
-     * @parameter expression="${jarsigner.attachments}" default-value="true"
+     * 
+     * @parameter expression="${jarsigner.attachments}"
+     * @deprecated As of version 1.1 in favor of the new parameter <code>processAttachedArtifacts</code>.
      */
-    private boolean attachments;
+    private Boolean attachments;
 
     /**
      * The Maven project.
@@ -127,9 +172,12 @@
             }
             else
             {
-                processed += processArtifact( this.project.getArtifact() ) ? 1 : 0;
+                if ( processMainArtifact )
+                {
+                    processed += processArtifact( this.project.getArtifact() ) ? 1 : 0;
+                }
 
-                if ( attachments )
+                if ( processAttachedArtifacts && !Boolean.FALSE.equals( attachments ) )
                 {
                     for ( Iterator it = this.project.getAttachedArtifacts().iterator(); it.hasNext(); )
                     {
@@ -149,6 +197,31 @@
                         getLog().debug( getMessage( "ignoringAttachments" ) );
                     }
                 }
+
+                if ( archiveDirectory != null )
+                {
+                    String includeList = ( includes != null ) ? StringUtils.join( includes, "," ) : null;
+                    String excludeList = ( excludes != null ) ? StringUtils.join( excludes, "," ) : null;
+
+                    List jarFiles;
+                    try
+                    {
+                        jarFiles = FileUtils.getFiles( archiveDirectory, includeList, excludeList );
+                    }
+                    catch ( IOException e )
+                    {
+                        throw new MojoExecutionException( "Failed to scan archive directory for JARs: "
+                            + e.getMessage(), e );
+                    }
+
+                    for ( Iterator it = jarFiles.iterator(); it.hasNext(); )
+                    {
+                        File jarFile = (File) it.next();
+
+                        processArchive( jarFile );
+                        processed++;
+                    }
+                }
             }
 
             getLog().info( getMessage( "processed", new Integer( processed ) ) );
@@ -262,15 +335,6 @@
 
         if ( isJarFile( artifact ) )
         {
-            if ( this.verbose )
-            {
-                getLog().info( getMessage( "processing", artifact ) );
-            }
-            else if ( getLog().isDebugEnabled() )
-            {
-                getLog().debug( getMessage( "processing", artifact ) );
-            }
-
             processArchive( artifact.getFile() );
 
             processed = true;
@@ -319,6 +383,15 @@
 
         preProcessArchive( archive );
 
+        if ( this.verbose )
+        {
+            getLog().info( getMessage( "processing", archive ) );
+        }
+        else if ( getLog().isDebugEnabled() )
+        {
+            getLog().debug( getMessage( "processing", archive ) );
+        }
+
         Commandline commandLine = new Commandline();
 
         commandLine.setExecutable( this.executable );