]> source.dussan.org Git - aspectj.git/commitdiff
Fix for Bugzilla Bug 57666
authoraclement <aclement>
Mon, 2 Aug 2004 15:47:02 +0000 (15:47 +0000)
committeraclement <aclement>
Mon, 2 Aug 2004 15:47:02 +0000 (15:47 +0000)
   duplicate manifests cause resource-copying to gack
(Contributed by Matthew Webster)

13 files changed:
ajde/testdata/DuplicateManifestTest/META-INF/MANIFEST.MF [new file with mode: 0644]
ajde/testdata/DuplicateManifestTest/META-INF/test.xml [new file with mode: 0644]
ajde/testdata/DuplicateManifestTest/aspectjar.jar [new file with mode: 0644]
ajde/testdata/DuplicateManifestTest/build.ajsym [new file with mode: 0644]
ajde/testdata/DuplicateManifestTest/build.lst [new file with mode: 0644]
ajde/testdata/DuplicateManifestTest/injar.jar [new file with mode: 0644]
ajde/testdata/DuplicateManifestTest/outjar.jar [new file with mode: 0644]
ajde/testdata/DuplicateManifestTest/update-injar.xml [new file with mode: 0644]
ajde/testsrc/org/aspectj/ajde/AjdeTests.java
ajde/testsrc/org/aspectj/ajde/DuplicateManifestTest.java [new file with mode: 0644]
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java
org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/BcweaverJarMaker.java
weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java

diff --git a/ajde/testdata/DuplicateManifestTest/META-INF/MANIFEST.MF b/ajde/testdata/DuplicateManifestTest/META-INF/MANIFEST.MF
new file mode 100644 (file)
index 0000000..fde8895
--- /dev/null
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0\r
+Created-By: DuplicateManifestTest\r
+\r
diff --git a/ajde/testdata/DuplicateManifestTest/META-INF/test.xml b/ajde/testdata/DuplicateManifestTest/META-INF/test.xml
new file mode 100644 (file)
index 0000000..f9efa1f
--- /dev/null
@@ -0,0 +1,4 @@
+<?xml version="1.0" ?>
+<jar name="input1.jar">
+</jar>
+
diff --git a/ajde/testdata/DuplicateManifestTest/aspectjar.jar b/ajde/testdata/DuplicateManifestTest/aspectjar.jar
new file mode 100644 (file)
index 0000000..6cc196c
Binary files /dev/null and b/ajde/testdata/DuplicateManifestTest/aspectjar.jar differ
diff --git a/ajde/testdata/DuplicateManifestTest/build.ajsym b/ajde/testdata/DuplicateManifestTest/build.ajsym
new file mode 100644 (file)
index 0000000..898f8be
Binary files /dev/null and b/ajde/testdata/DuplicateManifestTest/build.ajsym differ
diff --git a/ajde/testdata/DuplicateManifestTest/build.lst b/ajde/testdata/DuplicateManifestTest/build.lst
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/ajde/testdata/DuplicateManifestTest/injar.jar b/ajde/testdata/DuplicateManifestTest/injar.jar
new file mode 100644 (file)
index 0000000..8613c36
Binary files /dev/null and b/ajde/testdata/DuplicateManifestTest/injar.jar differ
diff --git a/ajde/testdata/DuplicateManifestTest/outjar.jar b/ajde/testdata/DuplicateManifestTest/outjar.jar
new file mode 100644 (file)
index 0000000..ee50007
Binary files /dev/null and b/ajde/testdata/DuplicateManifestTest/outjar.jar differ
diff --git a/ajde/testdata/DuplicateManifestTest/update-injar.xml b/ajde/testdata/DuplicateManifestTest/update-injar.xml
new file mode 100644 (file)
index 0000000..7ce4c14
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" ?>
+<project name="DuplicateManifestTest" default="all" basedir=".">
+
+       <property name="injar" value="${basedir}/injar.jar"/>
+       <property name="tempdir" value="${basedir}/temp"/>
+
+       <target name="update">
+
+               <delete dir="${tempdir}"/>
+
+               <unzip
+                       dest="${tempdir}"
+                       src="${injar}"
+               />
+
+               <copy todir="${tempdir}" overwrite="true">
+                       <fileset dir="${basedir}">                      
+                               <include name="META-INF/*"/>
+                       </fileset>
+               </copy>
+
+               <zip
+                       destfile="${injar}"
+               >
+                       <fileset dir="${basedir}/temp"/>
+               
+               </zip>  
+
+               <delete dir="${tempdir}"/>
+       </target>
+       
+       <target name="all" depends="update"/>
+</project>
index b66c019edfaaf097fefce205f361730526cf5eff..e70619504cffce35089792e1f458335d826990b0 100644 (file)
@@ -37,6 +37,7 @@ public class AjdeTests extends TestCase {
                suite.addTestSuite(SavedModelConsistencyTest. class);
                suite.addTestSuite(BuildCancellingTest.class);
                suite.addTestSuite(JarManifestTest.class);
+               suite.addTestSuite(DuplicateManifestTest.class);
                
         //$JUnit-END$
         return suite;
diff --git a/ajde/testsrc/org/aspectj/ajde/DuplicateManifestTest.java b/ajde/testsrc/org/aspectj/ajde/DuplicateManifestTest.java
new file mode 100644 (file)
index 0000000..38c82bb
--- /dev/null
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials 
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ * 
+ * Contributors:
+ *     Matthew Webster - initial implementation
+ *******************************************************************************/
+package org.aspectj.ajde;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+public class DuplicateManifestTest extends AjdeTestCase {
+
+
+       public static final String PROJECT_DIR = "DuplicateManifestTest";
+
+       public static final String injarName  = "injar.jar";
+       public static final String aspectjarName  = "aspectjar.jar";
+       public static final String outjarName = "outjar.jar";
+
+
+       /*
+        * Ensure the output directpry in clean
+        */
+       protected void setUp() throws Exception {
+               super.setUp(PROJECT_DIR);
+       }
+       
+       public void testWeave () {
+               Set injars = new HashSet();
+               injars.add(openFile(injarName));
+               ideManager.getProjectProperties().setInJars(injars);
+               Set aspectpath = new HashSet();
+               aspectpath.add(openFile(aspectjarName));
+               ideManager.getProjectProperties().setAspectPath(aspectpath);
+               File outjar = openFile(outjarName);
+               ideManager.getProjectProperties().setOutJar(outjar.getAbsolutePath());
+               assertTrue("Build failed", doSynchronousBuild("build.lst"));
+               assertTrue(
+                       "Build warnings",
+                       ideManager.getCompilationSourceLineTasks().isEmpty());
+               compareManifests(openFile(injarName),openFile(outjarName));
+       }
+       
+       private void compareManifests (File inFile, File outFile) {
+
+               try {
+                       JarFile inJar = new JarFile(inFile);
+                       Manifest inManifest = inJar.getManifest();
+                       inJar.close();
+                       JarFile outJar = new JarFile(outFile);
+                       Manifest outManifest = outJar.getManifest();
+                       outJar.close();
+                       assertTrue("The manifests in '" + inFile.getCanonicalPath() + "' and '" + outFile.getCanonicalPath() + "' sould be the same",inManifest.equals(outManifest));
+               }
+               catch (IOException ex) {
+                       fail(ex.toString());
+               }
+       }
+
+}
index 096bb88556701d113601c88c056ad708bce879ee..ab428758ad22a429699f1da4366e93bf88974ab1 100644 (file)
@@ -290,6 +290,7 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc
                                if (entry == null) break;
                        
                                String filename = entry.getName();
+//                             System.out.println("? copyResourcesFromJarFile() filename='" + filename +"'");
        
                                if (!entry.isDirectory() && acceptResource(filename)) {
                                        byte[] bytes = FileUtil.readAsByteArray(inStream);
@@ -380,7 +381,8 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc
                                (resourceName.startsWith("CVS/")) ||
                                (resourceName.indexOf("/CVS/") != -1) ||
                                (resourceName.endsWith("/CVS")) ||
-                               (resourceName.endsWith(".class")) 
+                               (resourceName.endsWith(".class")) ||
+                               (resourceName.toUpperCase().equals(MANIFEST_NAME))
                    )
                {
                        return false;
index 40e81eedac998e9ae6560997d948b65362c99f97..96a5021ae384d5efd14e3a1744c687b6681a8ee3 100644 (file)
@@ -38,6 +38,8 @@ public class BcweaverJarMaker {
                makeTestJars();
 
                makeURLWeavingClassLoaderJars();
+               
+               makeDuplicateManifestTestJars();
        }
        
        public static void makeJar0() throws IOException {
@@ -294,5 +296,33 @@ public class BcweaverJarMaker {
                args.add(AjdtAjcTests.TESTDATA_PATH + "/src1/LTWPerthis.aj");
                CommandTestCase.runCompiler(args, CommandTestCase.NO_ERRORS);
        }       
+
        
+       public static void makeDuplicateManifestTestJars() throws IOException {
+               List args = new ArrayList();
+
+               /*
+                * injar
+                */
+               args.add("-classpath"); 
+               args.add("../lib/test/aspectjrt.jar;../lib/test/testing-client.jar" +
+                  File.pathSeparator + System.getProperty("aspectjrt.path"));
+               args.add("-outjar");
+               args.add("../ajde/testdata/DuplicateManifestTest/injar.jar");
+               args.add(AjdtAjcTests.TESTDATA_PATH + "/src1/Hello.java");
+               CommandTestCase.runCompiler(args, CommandTestCase.NO_ERRORS);
+
+               /*
+                * aspectjar
+                */
+               args = new ArrayList();
+               args.add("-classpath"); 
+               args.add("../lib/test/aspectjrt.jar;../lib/test/testing-client.jar" +
+                  File.pathSeparator + System.getProperty("aspectjrt.path"));
+               args.add("-outjar");
+               args.add("../ajde/testdata/DuplicateManifestTest/aspectjar.jar");
+               args.add(AjdtAjcTests.TESTDATA_PATH + "/src1/Trace.java");
+               args.add(AjdtAjcTests.TESTDATA_PATH + "/src1/TraceHello.java");
+               CommandTestCase.runCompiler(args, CommandTestCase.NO_ERRORS);
+       }       
 }
index 6fd891ca685878e131bfaadecf44aac5fdaf5c4d..19beb0f6237e42b5f6b9cd3b9b7ff63be77ce19e 100644 (file)
@@ -20,17 +20,21 @@ import java.io.FileFilter;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 import java.util.jar.Attributes;
 import java.util.jar.Attributes.Name;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
 import java.util.jar.JarInputStream;
 import java.util.jar.Manifest;
 import java.util.zip.ZipEntry;
@@ -181,7 +185,7 @@ public class BcelWeaver implements IWeaver {
 //             System.err.println("? addJarFile(" + inFile + ", " + outDir + ")");
                List addedClassFiles = new ArrayList();
                needToReweaveWorld = true;
-               JarInputStream inStream = null;
+               JarFile inJar = null;
                
                try {
                        // Is this a directory we are looking at?
@@ -189,15 +193,17 @@ public class BcelWeaver implements IWeaver {
                                addedClassFiles.addAll(addDirectoryContents(inFile,outDir));
                        } else {
                        
-                               inStream = new JarInputStream(new FileInputStream(inFile)); //??? buffered
-                               addManifest(inStream.getManifest());
+                               inJar = new JarFile(inFile);
+                               addManifest(inJar.getManifest());
+                               Enumeration entries = inJar.entries();
                        
-                               while (true) {
-                                       ZipEntry entry = inStream.getNextEntry();
-                                       if (entry == null) break;
-                               
+                               while (entries.hasMoreElements()) {
+                                       JarEntry entry = (JarEntry)entries.nextElement();
+                                       InputStream inStream = inJar.getInputStream(entry);
+                                       
                                        byte[] bytes = FileUtil.readAsByteArray(inStream);
                                        String filename = entry.getName();
+//                                     System.out.println("? addJarFile() filename='" + filename + "'");
                                        UnwovenClassFile classFile = new UnwovenClassFile(new File(outDir, filename).getAbsolutePath(), bytes);
 
                                        if (filename.endsWith(".class")) {
@@ -210,9 +216,9 @@ public class BcelWeaver implements IWeaver {
 //                                             addResource(filename,classFile);
 //                                     }
 
-                                       inStream.closeEntry();
+                                       inStream.close();
                                }
-                               inStream.close();
+                               inJar.close();
                        }
                } catch (FileNotFoundException ex) {
                        IMessage message = new Message(
@@ -227,8 +233,8 @@ public class BcelWeaver implements IWeaver {
                                        true);
                        world.getMessageHandler().handleMessage(message);
                } finally {
-                       if (inStream != null) {
-                               try {inStream.close();}
+                       if (inJar != null) {
+                               try {inJar.close();}
                                catch (IOException ex) {
                                        IMessage message = new Message(
                                                        "Could not close input jar file " + inFile.getPath() + "(" + ex.getMessage() + ")",
@@ -391,11 +397,14 @@ public class BcelWeaver implements IWeaver {
 //    }
     
        public void addManifest (Manifest newManifest) {
+//             System.out.println("? addManifest() newManifest=" + newManifest);
                if (manifest == null) {
                        manifest = newManifest;
                }
        }
        
+       public static final String MANIFEST_NAME = "META-INF/MANIFEST.MF";
+       
        private static final String WEAVER_MANIFEST_VERSION = "1.0";
        private static final Attributes.Name CREATED_BY = new Name("Created-By");
        private static final String WEAVER_CREATED_BY = "AspectJ Compiler";