ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From umag...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Jar.java Zip.java
Date Thu, 21 Nov 2002 21:47:53 GMT
umagesh     2002/11/21 13:47:53

  Modified:    .        WHATSNEW
               docs/manual/CoreTasks jar.html
               src/main/org/apache/tools/ant/taskdefs Jar.java Zip.java
  Log:
  The filesetmanifest attribute of <jar> has been reenabled.
  
  PR: 13296
  Submitted by: bdeitte@macromedia.com (Brian Deitte)
  
  Revision  Changes    Path
  1.326     +2 -0      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.325
  retrieving revision 1.326
  diff -u -r1.325 -r1.326
  --- WHATSNEW	21 Nov 2002 21:35:40 -0000	1.325
  +++ WHATSNEW	21 Nov 2002 21:47:52 -0000	1.326
  @@ -61,6 +61,8 @@
   
   Other changes:
   --------------
  +* The filesetmanifest attribute of <jar> has been reenabled.
  +
   * The start and end tokens for <translate> may now be longer than a 
     single character.
   
  
  
  
  1.20      +6 -0      jakarta-ant/docs/manual/CoreTasks/jar.html
  
  Index: jar.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTasks/jar.html,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- jar.html	9 Jul 2002 21:05:51 -0000	1.19
  +++ jar.html	21 Nov 2002 21:47:52 -0000	1.20
  @@ -120,6 +120,12 @@
       <td valign="top" align="center">No</td>
     </tr>
     <tr>
  +    <td valign="top">filesetmanifest</td>
  +    <td valign="top">behavior when a Manifest is found in a zipfileset or zipgroupfileset
file is found.  Valid values are &quot;skip&quot;, &quot;merge&quot;, and
&quot;mergewithoutmain&quot;.  &quot;merge&quot; will merge all of the manifests
together, and merge this into any other specified manifests.  &quot;mergewithoutmain&quot;
merges everything but the Main section of the manifests.  Default value is &quot;skip&quot;.
  +    </td>
  +    <td valign="top" align="center">No</td>
  +  </tr>
  +  <tr>
       <td valign="top">update</td>
       <td valign="top">indicates whether to update or overwrite
         the destination file if it already exists.</td>
  
  
  
  1.57      +22 -20    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Jar.java
  
  Index: Jar.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Jar.java,v
  retrieving revision 1.56
  retrieving revision 1.57
  diff -u -r1.56 -r1.57
  --- Jar.java	23 Oct 2002 09:34:05 -0000	1.56
  +++ Jar.java	21 Nov 2002 21:47:52 -0000	1.57
  @@ -103,11 +103,6 @@
       private FilesetManifestConfig filesetManifestConfig;
   
       /**
  -     *  Whether to create manifest file on finalizeOutputStream?
  -     */
  -    private boolean manifestOnFinalize = true;
  -
  -    /**
        * whether to merge the main section of fileset manifests;
        * value is true if filesetmanifest is 'merge'
        */
  @@ -243,12 +238,16 @@
        *
        * @param config setting for found manifest behavior.
        */
  -    /*
       public void setFilesetmanifest(FilesetManifestConfig config) {
           filesetManifestConfig = config;
           mergeManifestsMain = "merge".equals(config.getValue());
  +
  +        if (filesetManifestConfig != null
  +            && ! filesetManifestConfig.getValue().equals("skip")) {
  +
  +            doubleFilePass = true;
  +        }
       }
  -    */
   
       /**
        * Adds a zipfileset to include in the META-INF directory.
  @@ -263,16 +262,15 @@
   
       protected void initZipOutputStream(ZipOutputStream zOut)
           throws IOException, BuildException {
  -        if (filesetManifestConfig == null
  -            || filesetManifestConfig.getValue().equals("skip")) {
  -            manifestOnFinalize = false;
  +
  +        if (! skipWriting) {
               Manifest jarManifest = createManifest();
               writeManifest(zOut, jarManifest);
           }
       }
   
       private Manifest createManifest()
  -        throws IOException, BuildException {
  +        throws BuildException {
           try {
               Manifest finalManifest = Manifest.getDefaultManifest();
   
  @@ -332,10 +330,6 @@
   
       protected void finalizeZipOutputStream(ZipOutputStream zOut)
               throws IOException, BuildException {
  -        if (manifestOnFinalize) {
  -            Manifest jarManifest = createManifest();
  -            writeManifest(zOut, jarManifest);
  -        }
   
           if (index) {
               createIndexList(zOut);
  @@ -402,7 +396,9 @@
       protected void zipFile(File file, ZipOutputStream zOut, String vPath)
           throws IOException {
           if ("META-INF/MANIFEST.MF".equalsIgnoreCase(vPath))  {
  -            filesetManifest(file, null);
  +           if (! doubleFilePass || (doubleFilePass && skipWriting)) {
  +               filesetManifest(file, null);
  +           }
           } else {
               super.zipFile(file, zOut, vPath);
           }
  @@ -415,7 +411,9 @@
                              long lastModified, File file)
           throws IOException {
           if ("META-INF/MANIFEST.MF".equalsIgnoreCase(vPath))  {
  -            filesetManifest(file, is);
  +           if (! doubleFilePass || (doubleFilePass && skipWriting)) {
  +               filesetManifest(file, is);
  +           }
           } else {
               super.zipFile(is, zOut, vPath, lastModified, null);
           }
  @@ -539,9 +537,13 @@
       protected void cleanUp() {
           super.cleanUp();
   
  -        manifest = null;
  -        configuredManifest = savedConfiguredManifest;
  -        filesetManifest = null;
  +        // we want to save this info if we are going to make another pass
  +        if (! doubleFilePass || (doubleFilePass && ! skipWriting))
  +        {
  +            manifest = null;
  +            configuredManifest = savedConfiguredManifest;
  +            filesetManifest = null;
  +        }
       }
   
       /**
  
  
  
  1.84      +89 -67    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Zip.java
  
  Index: Zip.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Zip.java,v
  retrieving revision 1.83
  retrieving revision 1.84
  diff -u -r1.83 -r1.84
  --- Zip.java	25 Jul 2002 15:21:06 -0000	1.83
  +++ Zip.java	21 Nov 2002 21:47:53 -0000	1.84
  @@ -115,6 +115,10 @@
       protected Hashtable addedDirs = new Hashtable();
       private Vector addedFiles = new Vector();
   
  +    protected boolean doubleFilePass = false;
  +    protected boolean skipWriting = false;
  +
  +
       /**
        * true when we are adding new files into the Zip file, as opposed
        * to adding back the unchanged files
  @@ -272,6 +276,20 @@
        * validate and build
        */
       public void execute() throws BuildException {
  +
  +        if (doubleFilePass) {
  +            skipWriting = true;
  +            executeMain();
  +            skipWriting = false;
  +            executeMain();
  +        }
  +        else {
  +            executeMain();
  +        }
  +    }
  +
  +    public void executeMain() throws BuildException {
  +
           if (baseDir == null && filesets.size() == 0
               && groupfilesets.size() == 0 && "zip".equals(archiveType))
{
               throw new BuildException("basedir attribute must be set, "
  @@ -690,21 +708,23 @@
           log("adding directory " + vPath, Project.MSG_VERBOSE);
           addedDirs.put(vPath, vPath);
   
  -        ZipEntry ze = new ZipEntry (vPath);
  -        if (dir != null && dir.exists()) {
  -            ze.setTime(dir.lastModified());
  -        } else {
  -            ze.setTime(System.currentTimeMillis());
  -        }
  -        ze.setSize (0);
  -        ze.setMethod (ZipEntry.STORED);
  -        // This is faintly ridiculous:
  -        ze.setCrc (EMPTY_CRC);
  +        if (! skipWriting) {
  +            ZipEntry ze = new ZipEntry (vPath);
  +            if (dir != null && dir.exists()) {
  +                ze.setTime(dir.lastModified());
  +            } else {
  +                ze.setTime(System.currentTimeMillis());
  +            }
  +            ze.setSize (0);
  +            ze.setMethod (ZipEntry.STORED);
  +            // This is faintly ridiculous:
  +            ze.setCrc (EMPTY_CRC);
   
  -        // this is 040775 | MS-DOS directory flag in reverse byte order
  -        ze.setExternalAttributes(0x41FD0010L);
  +            // this is 040775 | MS-DOS directory flag in reverse byte order
  +            ze.setExternalAttributes(0x41FD0010L);
   
  -        zOut.putNextEntry (ze);
  +            zOut.putNextEntry (ze);
  +        }
       }
   
       protected void zipFile(InputStream in, ZipOutputStream zOut, String vPath,
  @@ -730,61 +750,63 @@
   
           entries.put(vPath, vPath);
   
  -        ZipEntry ze = new ZipEntry(vPath);
  -        ze.setTime(lastModified);
  +        if (! skipWriting) {
  +            ZipEntry ze = new ZipEntry(vPath);
  +            ze.setTime(lastModified);
  +
  +            /*
  +            * XXX ZipOutputStream.putEntry expects the ZipEntry to know its
  +            * size and the CRC sum before you start writing the data when using
  +            * STORED mode.
  +            *
  +            * This forces us to process the data twice.
  +            *
  +            * I couldn't find any documentation on this, just found out by try
  +            * and error.
  +            */
  +            if (!doCompress) {
  +                long size = 0;
  +                CRC32 cal = new CRC32();
  +                if (!in.markSupported()) {
  +                    // Store data into a byte[]
  +                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
  +
  +                    byte[] buffer = new byte[8 * 1024];
  +                    int count = 0;
  +                    do {
  +                        size += count;
  +                        cal.update(buffer, 0, count);
  +                        bos.write(buffer, 0, count);
  +                        count = in.read(buffer, 0, buffer.length);
  +                    } while (count != -1);
  +                    in = new ByteArrayInputStream(bos.toByteArray());
   
  -        /*
  -         * XXX ZipOutputStream.putEntry expects the ZipEntry to know its
  -         * size and the CRC sum before you start writing the data when using
  -         * STORED mode.
  -         *
  -         * This forces us to process the data twice.
  -         *
  -         * I couldn't find any documentation on this, just found out by try
  -         * and error.
  -         */
  -        if (!doCompress) {
  -            long size = 0;
  -            CRC32 cal = new CRC32();
  -            if (!in.markSupported()) {
  -                // Store data into a byte[]
  -                ByteArrayOutputStream bos = new ByteArrayOutputStream();
  -
  -                byte[] buffer = new byte[8 * 1024];
  -                int count = 0;
  -                do {
  -                    size += count;
  -                    cal.update(buffer, 0, count);
  -                    bos.write(buffer, 0, count);
  -                    count = in.read(buffer, 0, buffer.length);
  -                } while (count != -1);
  -                in = new ByteArrayInputStream(bos.toByteArray());
  -
  -            } else {
  -                in.mark(Integer.MAX_VALUE);
  -                byte[] buffer = new byte[8 * 1024];
  -                int count = 0;
  -                do {
  -                    size += count;
  -                    cal.update(buffer, 0, count);
  -                    count = in.read(buffer, 0, buffer.length);
  -                } while (count != -1);
  -                in.reset();
  -            }
  -            ze.setSize(size);
  -            ze.setCrc(cal.getValue());
  -        }
  -
  -        zOut.putNextEntry(ze);
  -
  -        byte[] buffer = new byte[8 * 1024];
  -        int count = 0;
  -        do {
  -            if (count != 0) {
  -                zOut.write(buffer, 0, count);
  -            }
  -            count = in.read(buffer, 0, buffer.length);
  -        } while (count != -1);
  +                } else {
  +                    in.mark(Integer.MAX_VALUE);
  +                    byte[] buffer = new byte[8 * 1024];
  +                    int count = 0;
  +                    do {
  +                        size += count;
  +                        cal.update(buffer, 0, count);
  +                        count = in.read(buffer, 0, buffer.length);
  +                    } while (count != -1);
  +                    in.reset();
  +                }
  +                ze.setSize(size);
  +                ze.setCrc(cal.getValue());
  +            }
  +
  +            zOut.putNextEntry(ze);
  +
  +            byte[] buffer = new byte[8 * 1024];
  +            int count = 0;
  +            do {
  +                if (count != 0) {
  +                    zOut.write(buffer, 0, count);
  +                }
  +                count = in.read(buffer, 0, buffer.length);
  +            } while (count != -1);
  +        }
           addedFiles.addElement(vPath);
       }
   
  
  
  

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


Mime
View raw message