ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs JarTest.java
Date Wed, 05 Feb 2003 15:31:33 GMT
bodewig     2003/02/05 07:31:33

  Modified:    src/main/org/apache/tools/ant/taskdefs Jar.java
               src/testcases/org/apache/tools/ant/taskdefs JarTest.java
  Log:
  fix the 'is the manifest up-to-date?' checks
  
  Revision  Changes    Path
  1.63      +50 -64    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.62
  retrieving revision 1.63
  diff -u -r1.62 -r1.63
  --- Jar.java	5 Feb 2003 10:43:08 -0000	1.62
  +++ Jar.java	5 Feb 2003 15:31:32 -0000	1.63
  @@ -92,6 +92,9 @@
       /** The index file name. */
       private static final String INDEX_NAME = "META-INF/INDEX.LIST";
   
  +    /** The mainfest file name. */
  +    private static final String MANIFEST_NAME = "META-INF/MANIFEST.MF";
  +
       /** merged manifests added through addConfiguredManifest */
       private Manifest configuredManifest;
       /** shadow of the above if upToDate check alters the value */
  @@ -163,35 +166,6 @@
        */
       public void setDestFile(File jarFile) {
           super.setDestFile(jarFile);
  -        if (jarFile.exists()) {
  -            ZipFile zf = null;
  -            try {
  -                zf = new ZipFile(jarFile);
  -
  -                // must not use getEntry as "well behaving" applications
  -                // must accept the manifest in any capitalization
  -                Enumeration enum = zf.entries();
  -                while (enum.hasMoreElements()) {
  -                    ZipEntry ze = (ZipEntry) enum.nextElement();
  -                    if (ze.getName().equalsIgnoreCase("META-INF/MANIFEST.MF")) {
  -                        originalManifest = 
  -                            getManifest(new InputStreamReader(zf
  -                                                              .getInputStream(ze)));
  -                    }
  -                }
  -            } catch (Throwable t) {
  -                log("error while reading original manifest: " + t.getMessage(),
  -                    Project.MSG_WARN);
  -            } finally {
  -                if (zf != null) {
  -                    try {
  -                        zf.close();
  -                    } catch (IOException e) {
  -                        // XXX - log an error?  throw an exception?
  -                    }
  -                }
  -            }
  -        }
       }
   
       /**
  @@ -258,6 +232,33 @@
           return newManifest;
       }
   
  +    private Manifest getManifestFromJar(File jarFile) throws IOException {
  +        ZipFile zf = null;
  +        try {
  +            zf = new ZipFile(jarFile);
  +            
  +            // must not use getEntry as "well behaving" applications
  +            // must accept the manifest in any capitalization
  +            Enumeration enum = zf.entries();
  +            while (enum.hasMoreElements()) {
  +                ZipEntry ze = (ZipEntry) enum.nextElement();
  +                if (ze.getName().equalsIgnoreCase(MANIFEST_NAME)) {
  +                    return getManifest(new InputStreamReader(zf
  +                                                             .getInputStream(ze)));
  +                }
  +            }
  +            return null;
  +        } finally {
  +            if (zf != null) {
  +                try {
  +                    zf.close();
  +                } catch (IOException e) {
  +                    // XXX - log an error?  throw an exception?
  +                }
  +            }
  +        }
  +    }
  +
       private Manifest getManifest(Reader r) {
   
           Manifest newManifest = null;
  @@ -321,10 +322,6 @@
       private Manifest createManifest()
           throws BuildException {
           try {
  -            if (!isInUpdateMode()) {
  -                originalManifest = null;
  -            }
  -
               Manifest finalManifest = Manifest.getDefaultManifest();
   
               if (manifest == null) {
  @@ -343,7 +340,9 @@
                * merge with null argument is a no-op
                */
   
  -            finalManifest.merge(originalManifest);
  +            if (isInUpdateMode()) {
  +                finalManifest.merge(originalManifest);
  +            }
               finalManifest.merge(filesetManifest);
               finalManifest.merge(configuredManifest);
               finalManifest.merge(manifest, !mergeManifestsMain);
  @@ -373,7 +372,7 @@
   
           ByteArrayInputStream bais =
               new ByteArrayInputStream(baos.toByteArray());
  -        super.zipFile(bais, zOut, "META-INF/MANIFEST.MF",
  +        super.zipFile(bais, zOut, MANIFEST_NAME,
                         System.currentTimeMillis(), null,
                         ZipFileSet.DEFAULT_FILE_MODE);
           super.initZipOutputStream(zOut);
  @@ -448,7 +447,7 @@
       protected void zipFile(InputStream is, ZipOutputStream zOut, String vPath,
                              long lastModified, File fromArchive, int mode)
           throws IOException {
  -        if ("META-INF/MANIFEST.MF".equalsIgnoreCase(vPath))  {
  +        if (MANIFEST_NAME.equalsIgnoreCase(vPath))  {
               if (! doubleFilePass || (doubleFilePass && skipWriting)) {
                   filesetManifest(fromArchive, is);
               }
  @@ -536,45 +535,32 @@
           throws BuildException {
   
           // need to handle manifest as a special check
  -        if (configuredManifest != null || manifestFile == null) {
  -            java.util.zip.ZipFile theZipFile = null;
  +        if (zipFile.exists()) {
  +            // if it doesn't exist, it will get created anyway, don't
  +            // bother with any up-to-date checks.
  +
               try {
  -                theZipFile = new java.util.zip.ZipFile(zipFile);
  -                java.util.zip.ZipEntry entry =
  -                    theZipFile.getEntry("META-INF/MANIFEST.MF");
  -                if (entry == null) {
  +                originalManifest = getManifestFromJar(zipFile);
  +                if (originalManifest == null) {
                       log("Updating jar since the current jar has no manifest",
                           Project.MSG_VERBOSE);
                       needsUpdate = true;
                   } else {
  -                    Manifest currentManifest =
  -                        new Manifest(new InputStreamReader(theZipFile
  -                                                           .getInputStream(entry)));
  -                    Manifest newManifest = createManifest();
  -                    if (!currentManifest.equals(newManifest)) {
  -                        log("Updating jar since jar manifest has changed",
  +                    Manifest mf = createManifest();
  +                    if (!mf.equals(originalManifest)) {
  +                        log("Updating jar since jar manifest has changed", 
                               Project.MSG_VERBOSE);
                           needsUpdate = true;
                       }
                   }
  -            } catch (Exception e) {
  -                // any problems and we will rebuild
  -                log("Updating jar since cannot read current jar manifest: "
  -                    + e.getClass().getName() + " - " + e.getMessage(),
  -                    Project.MSG_VERBOSE);
  +            } catch (Throwable t) {
  +                log("error while reading original manifest: " + t.getMessage(),
  +                    Project.MSG_WARN);
                   needsUpdate = true;
  -            } finally {
  -                if (theZipFile != null) {
  -                    try {
  -                        theZipFile.close();
  -                    } catch (IOException e) {
  -                        //ignore
  -                    }
  -                }
               }
  -        } else if (manifestFile.lastModified() > zipFile.lastModified()) {
  -            log("Updating jar since manifestFile is newer than the archive",
  -                Project.MSG_VERBOSE);
  +
  +        } else {
  +            // no existing archive
               needsUpdate = true;
           }
           
  
  
  
  1.15      +4 -0      jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/JarTest.java
  
  Index: JarTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/JarTest.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- JarTest.java	27 Jan 2003 13:29:03 -0000	1.14
  +++ JarTest.java	5 Feb 2003 15:31:33 -0000	1.15
  @@ -79,6 +79,10 @@
           executeTarget("cleanup");
       }
       
  +//    public static junit.framework.Test suite() {
  +//        return new JarTest("testNoRecreateWithoutUpdate");
  +//    }
  +
       public void test1() {
           expectBuildException("test1", "required argument not specified");
       }
  
  
  

Mime
View raw message