Author: bentmann
Date: Sun Sep 20 17:51:11 2009
New Revision: 817065

URL: http://svn.apache.org/viewvc?rev=817065&view=rev
Log:
[MJARSIGNER-8] Allow to exclude specific attachments from signing/verification

Added:
    maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/
    
maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/excluded.jar
   (with props)
    
maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/pom.xml  
 (with props)
    maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/src/
    
maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/src/main/
    
maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/src/main/resources/
    
maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/src/main/resources/test.properties
   (with props)
    
maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/verify.bsh
   (with props)
Modified:
    maven/plugins/trunk/maven-jarsigner-plugin/src/it/type-detection/pom.xml
    
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/attachment-selection/excluded.jar
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/excluded.jar?rev=817065&view=auto
==============================================================================
Binary file - no diff available.

Propchange: 
maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/excluded.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: 
maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/pom.xml?rev=817065&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/pom.xml 
(added)
+++ 
maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/pom.xml 
Sun Sep 20 17:51:11 2009
@@ -0,0 +1,112 @@
+<?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 selection of specific attachments.
+  </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.codehaus.mojo</groupId>
+        <artifactId>build-helper-maven-plugin</artifactId>
+        <version>1.2</version>
+        <executions>
+          <execution>
+            <id>attach-artifacts</id>
+            <goals>
+              <goal>attach-artifact</goal>
+            </goals>
+            <configuration>
+              <artifacts>
+                <artifact>
+                  <file>excluded.jar</file>
+                  <type>jar</type>
+                  <classifier>unsigned</classifier>
+                </artifact>
+              </artifacts>
+            </configuration>
+          </execution>
+        </executions>
+      </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>
+          <excludeClassifiers>
+            <excludeClassifier>unsigned</excludeClassifier>
+          </excludeClassifiers>
+        </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/attachment-selection/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: 
maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/src/main/resources/test.properties
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/src/main/resources/test.properties?rev=817065&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/src/main/resources/test.properties
 (added)
+++ 
maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/src/main/resources/test.properties
 Sun Sep 20 17:51:11 2009
@@ -0,0 +1 @@
+key = value
\ No newline at end of file

Propchange: 
maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/src/main/resources/test.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/src/main/resources/test.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/verify.bsh
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/verify.bsh?rev=817065&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/verify.bsh
 (added)
+++ 
maven/plugins/trunk/maven-jarsigner-plugin/src/it/attachment-selection/verify.bsh
 Sun Sep 20 17:51:11 2009
@@ -0,0 +1,24 @@
+import java.io.*;
+import java.util.zip.*;
+
+File attachedJarFile = new File( basedir, "excluded.jar" );
+System.out.println( "Checking for existence of " + attachedJarFile );
+if ( !attachedJarFile.isFile() )
+{
+    throw new Exception( "missing " + attachedJarFile );
+}
+
+ZipFile attachedJar = new ZipFile( attachedJarFile );
+System.out.println( "Checking for absence of " + attachedJarFile.getName() + 
"!/META-INF/TESTING.SF" );
+if ( attachedJar.getEntry( "META-INF/TESTING.SF" ) != null )
+{
+    throw new Exception( "present " + attachedJarFile.getName() + 
"!/META-INF/TESTING.SF" );
+}
+System.out.println( "Checking for absence of " + attachedJarFile.getName() + 
"!/META-INF/TESTING.DSA" );
+if ( attachedJar.getEntry( "META-INF/TESTING.DSA" ) != null )
+{
+    throw new Exception( "present " + attachedJarFile.getName() + 
"!/META-INF/TESTING.DSA" );
+}
+attachedJar.close();
+
+return true;

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

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

Modified: 
maven/plugins/trunk/maven-jarsigner-plugin/src/it/type-detection/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jarsigner-plugin/src/it/type-detection/pom.xml?rev=817065&r1=817064&r2=817065&view=diff
==============================================================================
--- maven/plugins/trunk/maven-jarsigner-plugin/src/it/type-detection/pom.xml 
(original)
+++ maven/plugins/trunk/maven-jarsigner-plugin/src/it/type-detection/pom.xml 
Sun Sep 20 17:51:11 2009
@@ -28,7 +28,7 @@
   <packaging>jar</packaging>
 
   <description>
-    Tests the detection of JAR files (we don't want to sign/verify other file 
formats).
+    Tests the detection of JAR/ZIP files (we don't want to sign/verify other 
file formats).
   </description>
 
   <properties>

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=817065&r1=817064&r2=817065&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 Sep 20 17:51:11 2009
@@ -24,6 +24,9 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.text.MessageFormat;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Properties;
@@ -142,6 +145,24 @@
     private Boolean attachments;
 
     /**
+     * A set of artifact classifiers describing the project attachments that 
should be processed. This parameter is only
+     * relevant if {...@link #processAttachedArtifacts} is <code>true</code>. 
If empty, all attachments are included.
+     * 
+     * @parameter
+     * @since 1.2
+     */
+    private String[] includeClassifiers;
+
+    /**
+     * A set of artifact classifiers describing the project attachments that 
should not be processed. This parameter is
+     * only relevant if {...@link #processAttachedArtifacts} is 
<code>true</code>. If empty, no attachments are excluded.
+     * 
+     * @parameter
+     * @since 1.2
+     */
+    private String[] excludeClassifiers;
+
+    /**
      * The Maven project.
      *
      * @parameter default-value="${project}"
@@ -178,10 +199,32 @@
 
                 if ( processAttachedArtifacts && !Boolean.FALSE.equals( 
attachments ) )
                 {
+                    Collection includes = new HashSet();
+                    if ( includeClassifiers != null )
+                    {
+                        includes.addAll( Arrays.asList( includeClassifiers ) );
+                    }
+
+                    Collection excludes = new HashSet();
+                    if ( excludeClassifiers != null )
+                    {
+                        excludes.addAll( Arrays.asList( excludeClassifiers ) );
+                    }
+
                     for ( Iterator it = 
this.project.getAttachedArtifacts().iterator(); it.hasNext(); )
                     {
                         final Artifact artifact = (Artifact) it.next();
 
+                        if ( !includes.isEmpty() && !includes.contains( 
artifact.getClassifier() ) )
+                        {
+                            continue;
+                        }
+
+                        if ( excludes.contains( artifact.getClassifier() ) )
+                        {
+                            continue;
+                        }
+
                         processed += processArtifact( artifact ) ? 1 : 0;
                     }
                 }


Reply via email to