ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r349639 - in /ant/core/trunk: docs/manual/CoreTasks/ src/etc/testcases/taskdefs/ src/main/org/apache/tools/ant/taskdefs/ src/testcases/org/apache/tools/ant/taskdefs/
Date Tue, 29 Nov 2005 04:45:52 GMT
Author: bodewig
Date: Mon Nov 28 20:45:43 2005
New Revision: 349639

URL: http://svn.apache.org/viewcvs?rev=349639&view=rev
Log:
support for filesystem based resource collections in <signjar> and VerifyJar

Modified:
    ant/core/trunk/docs/manual/CoreTasks/signjar.html
    ant/core/trunk/src/etc/testcases/taskdefs/signjar.xml
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AbstractJarSignerTask.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SignJar.java
    ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/SignJarTest.java

Modified: ant/core/trunk/docs/manual/CoreTasks/signjar.html
URL: http://svn.apache.org/viewcvs/ant/core/trunk/docs/manual/CoreTasks/signjar.html?rev=349639&r1=349638&r2=349639&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/signjar.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/signjar.html Mon Nov 28 20:45:43 2005
@@ -12,7 +12,7 @@
 <h3>Description</h3>
 <p>Signs JAR files with the <tt>jarsigner</tt> command line tool. 
 It will take a named file in the <tt>jar</tt> attribute, and an optional
-<tt>destDir</tt> or <tt>signedJar</tt> attribute. Nested filesets
are also
+<tt>destDir</tt> or <tt>signedJar</tt> attribute. Nested paths are
also
 supported; here only an (optional) <tt>destDir</tt> is allowed. If a destination
 directory or explicit JAR file name is not provided, JARs are signed in place.
 </p>
@@ -39,7 +39,7 @@
   <tr>
     <td valign="top">jar</td>
     <td valign="top">the jar file to sign</td>
-    <td valign="top" align="center">Yes, unless nested filesets have
+    <td valign="top" align="center">Yes, unless nested paths have
       been used.</td>
   </tr>
   <tr>
@@ -135,6 +135,11 @@
     <td align="center" valign="top"><b>Required</b></td>
   </tr>
   <tr>
+    <td valign="top">path</td>
+    <td valign="top">path of JAR files to sign. <em>since Ant 1.7</em></td>
+    <td valign="top" align="center">No</td>
+  </tr>
+  <tr>
     <td valign="top">fileset</td>
     <td valign="top">fileset of JAR files to sign. </td>
     <td valign="top" align="center">No</td>
@@ -167,7 +172,9 @@
     alias="testonly" keystore="testkeystore"
     storepass="apacheant"
     preservelastmodified="true"&gt;
-  &lt;fileset dir="dist" includes="**/*.jar" /&gt;
+  &lt;path&gt;
+    &lt;fileset dir="dist" includes="**/*.jar" /&gt;
+  &lt;/path&gt;
   &lt;flattenmapper /&gt;
 &lt;/signjar&gt;
 </pre></blockquote>
@@ -183,7 +190,9 @@
     storepass="apacheant"
     lazy="true"
     &gt;
-  &lt;fileset dir="dist" includes="**/*.jar" /&gt;
+  &lt;path&gt;
+    &lt;fileset dir="dist" includes="**/*.jar" /&gt;
+  &lt;/path&gt;
 &lt;/signjar&gt;
 </pre></blockquote>
 <p>

Modified: ant/core/trunk/src/etc/testcases/taskdefs/signjar.xml
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/etc/testcases/taskdefs/signjar.xml?rev=349639&r1=349638&r2=349639&view=diff
==============================================================================
--- ant/core/trunk/src/etc/testcases/taskdefs/signjar.xml (original)
+++ ant/core/trunk/src/etc/testcases/taskdefs/signjar.xml Mon Nov 28 20:45:43 2005
@@ -118,6 +118,32 @@
     </sign-base>
   </target>
   
+  <target name="testPath" depends="jar">
+    <sign-base>
+      <path>
+        <fileset file="${test.jar}" />
+      </path>
+    </sign-base>
+    <assertSigned/>
+  </target>
+
+  <target name="testPathAndJar" depends="jar">
+    <sign-base jar="${test.jar}" lazy="true">
+      <path>
+        <fileset file="${test.jar}" />
+      </path>
+    </sign-base>
+    <assertSigned/>
+  </target>
+  
+  <target name="testPathAndSignedJar" depends="jar">
+    <sign-base signedjar="${sign.dir}/newfile.jar">
+      <path>
+        <fileset file="${test.jar}" />
+      </path>
+    </sign-base>
+  </target>
+  
   <target name="testSignedJar" depends="jar">
     <sign signedjar="${subdirtest.jar}"/>
     <assertSigned jar="${subdirtest.jar}"/>
@@ -139,6 +165,15 @@
     <assertSigned jar="${subdirtest.jar}"/>
   </target>
   
+  <target name="testDestDirPath" depends="jar">
+    <sign-base destDir="${subdir}">
+      <path>
+        <fileset file="${test.jar}" />
+      </path>
+    </sign-base>
+    <assertSigned jar="${subdirtest.jar}"/>
+  </target>
+  
   <target name="testMapperNoDest" depends="jar">
     <sign-base >
       <flattenmapper />
@@ -154,6 +189,16 @@
     <assertSigned jar="${subdirtest.jar}"/>
   </target>
 
+  <target name="testMapperPath" depends="jar">
+    <sign-base destDir="${subdir}">
+      <path>
+        <pathelement location="${test.jar}" />
+      </path>
+      <flattenmapper />
+    </sign-base>
+    <assertSigned jar="${subdirtest.jar}"/>
+  </target>
+
   <target name="testTwoMappers" depends="jar">
     <sign-base destDir="${subdir}">
       <fileset file="${test.jar}" />
@@ -208,6 +253,14 @@
   <target name="testVerifyFileset" depends="basic">
     <verify-base >
       <fileset file="${test.jar}" />
+    </verify-base>
+  </target>
+
+  <target name="testVerifyPath" depends="basic">
+    <verify-base >
+      <path>
+        <pathelement location="${test.jar}" />
+      </path>
     </verify-base>
   </target>
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AbstractJarSignerTask.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AbstractJarSignerTask.java?rev=349639&r1=349638&r2=349639&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AbstractJarSignerTask.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AbstractJarSignerTask.java Mon Nov
28 20:45:43 2005
@@ -21,6 +21,7 @@
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.util.JavaEnvUtils;
 import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.Path;
 import org.apache.tools.ant.types.RedirectorElement;
 import org.apache.tools.ant.types.Environment;
 
@@ -91,6 +92,13 @@
             + "or nested filesets";
 
     /**
+     * Path holding all non-filesets of filesystem resources we want to sign.
+     *
+     * @since Ant 1.7
+     */
+    private Path path = null;
+
+    /**
      * Set the maximum memory to be used by the jarsigner process
      *
      * @param max a string indicating the maximum memory according to the JVM
@@ -181,6 +189,20 @@
     public void addSysproperty(Environment.Variable sysp) {
         sysProperties.addVariable(sysp);
     }
+
+    /**
+     * Adds a path of files to sign.
+     *
+     * @param a path of files to sign.
+     * @since Ant 1.7
+     */
+    public Path createPath() {
+        if (path == null) {
+            path = new Path(getProject());
+        }
+        return path.createPath();
+    }
+
     /**
      * init processing logic; this is retained through our execution(s)
      */
@@ -306,11 +328,37 @@
             //this lets us combine our logic for handling output directories,
             //mapping etc.
             FileSet sourceJar = new FileSet();
+            sourceJar.setProject(getProject());
             sourceJar.setFile(jar);
             sourceJar.setDir(jar.getParentFile());
             sources.add(sourceJar);
         }
         return sources;
+    }
+
+    /**
+     * clone our path and add all explicitly specified FileSets as
+     * well, patch in the jar attribute as a new fileset if it is
+     * defined.
+     * @return a path that contains all files to sign
+     * @since Ant 1.7
+     */
+    protected Path createUnifiedSourcePath() {
+        Path p = path == null ? new Path(getProject()) : (Path) path.clone();
+        Vector s = createUnifiedSources();
+        Enumeration e = s.elements();
+        while (e.hasMoreElements()) {
+            p.add((FileSet) e.nextElement());
+        }
+        return p;
+    }
+
+    /**
+     * Has either a path or a fileset been specified?
+     * @since Ant 1.7
+     */
+    protected boolean hasResources() {
+        return path != null || filesets.size() > 0;
     }
 
     /**

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SignJar.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SignJar.java?rev=349639&r1=349638&r2=349639&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SignJar.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SignJar.java Mon Nov 28 20:45:43
2005
@@ -19,13 +19,14 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.util.Vector;
+import java.util.Iterator;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.DirectoryScanner;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.taskdefs.condition.IsSigned;
-import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.resources.FileResource;
 import org.apache.tools.ant.util.FileUtils;
 import org.apache.tools.ant.util.IdentityMapper;
 import org.apache.tools.ant.util.FileNameMapper;
@@ -80,7 +81,7 @@
     protected boolean lazy;
 
     /**
-     * the output directory when using filesets.
+     * the output directory when using paths.
      */
     protected File destDir;
 
@@ -111,7 +112,7 @@
     /**
      * error string for unit test verification {@value}
      */
-    public static final String ERROR_SIGNEDJAR_AND_FILESETS = "You cannot specify the signed
JAR when using filesets";
+    public static final String ERROR_SIGNEDJAR_AND_PATHS = "You cannot specify the signed
JAR when using paths or filesets";
     /**
      * error string for unit test verification: {@value}
      */
@@ -252,13 +253,12 @@
      */
     public void execute() throws BuildException {
         //validation logic
-        final boolean hasFileset = filesets.size() > 0;
         final boolean hasJar = jar != null;
         final boolean hasSignedJar = signedjar != null;
         final boolean hasDestDir = destDir != null;
         final boolean hasMapper = mapper != null;
 
-        if (!hasJar && !hasFileset) {
+        if (!hasJar && !hasResources()) {
             throw new BuildException(ERROR_NO_SOURCE);
         }
         if (null == alias) {
@@ -274,8 +274,8 @@
         }
 
 
-        if (hasFileset && hasSignedJar) {
-            throw new BuildException(ERROR_SIGNEDJAR_AND_FILESETS);
+        if (hasResources() && hasSignedJar) {
+            throw new BuildException(ERROR_SIGNEDJAR_AND_PATHS);
         }
 
         //this isnt strictly needed, but by being fussy now,
@@ -297,9 +297,9 @@
             }
 
             //the rest of the method treats single jar like
-            //a nested fileset with one file
+            //a nested path with one file
 
-            Vector sources = createUnifiedSources();
+            Path sources = createUnifiedSourcePath();
             //set up our mapping policy
             FileNameMapper destMapper;
             if (hasMapper) {
@@ -310,34 +310,26 @@
             }
 
 
-            //at this point the filesets are set up with lists of files,
+            //at this point the paths are set up with lists of files,
             //and the mapper is ready to map from source dirs to dest files
             //now we iterate through every JAR giving source and dest names
-            // deal with the filesets
-            for (int i = 0; i < sources.size(); i++) {
-                FileSet fs = (FileSet) sources.elementAt(i);
-                //get all included files in a fileset
-                DirectoryScanner ds = fs.getDirectoryScanner(getProject());
-                String[] jarFiles = ds.getIncludedFiles();
-                File baseDir = fs.getDir(getProject());
+            // deal with the paths
+            Iterator iter = sources.iterator();
+            while (iter.hasNext()) {
+                FileResource fr = (FileResource) iter.next();
 
                 //calculate our destination directory; it is either the destDir
                 //attribute, or the base dir of the fileset (for in situ updates)
-                File toDir = hasDestDir ? destDir : baseDir;
+                File toDir = hasDestDir ? destDir : fr.getBaseDir();
 
-                //loop through all jars in the fileset
-                for (int j = 0; j < jarFiles.length; j++) {
-                    String jarFile = jarFiles[j];
-                    //determine the destination filename via the mapper
-                    String[] destFilenames = destMapper.mapFileName(jarFile);
-                    if (destFilenames == null || destFilenames.length != 1) {
-                        //we only like simple mappers.
-                        throw new BuildException(ERROR_BAD_MAP + jarFile);
-                    }
-                    File destFile = new File(toDir, destFilenames[0]);
-                    File jarSource = new File(baseDir, jarFile);
-                    signOneJar(jarSource, destFile);
+                //determine the destination filename via the mapper
+                String[] destFilenames = destMapper.mapFileName(fr.getName());
+                if (destFilenames == null || destFilenames.length != 1) {
+                    //we only like simple mappers.
+                    throw new BuildException(ERROR_BAD_MAP + fr.getFile());
                 }
+                File destFile = new File(toDir, destFilenames[0]);
+                signOneJar(fr.getFile(), destFile);
             }
         } finally {
             endExecution();

Modified: ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/SignJarTest.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/SignJarTest.java?rev=349639&r1=349638&r2=349639&view=diff
==============================================================================
--- ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/SignJarTest.java (original)
+++ ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/SignJarTest.java Mon Nov 28
20:45:43 2005
@@ -86,7 +86,21 @@
     public void testFilesetAndSignedJar() {
         expectBuildExceptionContaining("testFilesetAndSignedJar",
                 "incompatible attributes",
-                SignJar.ERROR_SIGNEDJAR_AND_FILESETS);
+                SignJar.ERROR_SIGNEDJAR_AND_PATHS);
+    }
+
+    public void testPath() {
+        executeTarget("testPath");
+    }
+
+    public void testPathAndJar() {
+        executeTarget("testPathAndJar");
+    }
+
+    public void testPathAndSignedJar() {
+        expectBuildExceptionContaining("testPathAndSignedJar",
+                "incompatible attributes",
+                SignJar.ERROR_SIGNEDJAR_AND_PATHS);
     }
 
     public void testSignedJar() {
@@ -100,7 +114,13 @@
     public void testDestDirAndSignedJar() {
         expectBuildExceptionContaining("testFilesetAndSignedJar",
                 "incompatible attributes",
-                SignJar.ERROR_SIGNEDJAR_AND_FILESETS);
+                SignJar.ERROR_SIGNEDJAR_AND_PATHS);
+    }
+
+    public void testDestDirAndSignedJar2() {
+        expectBuildExceptionContaining("testPathAndSignedJar",
+                "incompatible attributes",
+                SignJar.ERROR_SIGNEDJAR_AND_PATHS);
     }
 
     public void testDestDirFileset() {
@@ -111,6 +131,14 @@
         executeTarget("testMapperFileset");
     }
 
+    public void testDestDirPath() {
+        executeTarget("testDestDirPath");
+    }
+
+    public void testMapperPath() {
+        executeTarget("testMapperPath");
+    }
+
     public void testMapperNoDest() {
         expectBuildExceptionContaining("testMapperNoDest",
                 "two mappers",
@@ -178,6 +206,10 @@
 
     public void testVerifyFileset() {
         executeTarget("testVerifyFileset");
+    }
+
+    public void testVerifyPath() {
+        executeTarget("testVerifyPath");
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message