]> source.dussan.org Git - aspectj.git/commitdiff
Fix from Matthew Webster for copying first resource in jars and
authoracolyer <acolyer>
Tue, 4 Nov 2003 14:31:12 +0000 (14:31 +0000)
committeracolyer <acolyer>
Tue, 4 Nov 2003 14:31:12 +0000 (14:31 +0000)
for copying first Manifest.mf file

ajde/testdata/bug-36071a/input1.jar
ajde/testdata/bug-36071a/input2.jar
ajde/testsrc/org/aspectj/ajde/ResourceCopyTestCase.java
weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java

index 83abbbaa1b7965ef85196d73c3c52c13aa8eb908..cc7183fdd2f2eaba41c2a6424d6e906ecb2f9fbf 100644 (file)
Binary files a/ajde/testdata/bug-36071a/input1.jar and b/ajde/testdata/bug-36071a/input1.jar differ
index d55b84dfed40e93a1b9d60ec7e9cd4555f32d506..ff8b20a65f3c0eca46ab74a7945d3adffa644631 100644 (file)
Binary files a/ajde/testdata/bug-36071a/input2.jar and b/ajde/testdata/bug-36071a/input2.jar differ
index 016ebef92927aaa42d78306a352902c276de81a3..bd02c18db53f297cc4c162fdb3556efb3cb2036c 100644 (file)
@@ -61,9 +61,7 @@ public class ResourceCopyTestCase extends AjdeTestCase {
                File outjar = openFile(outjarName);
                ideManager.getProjectProperties().setOutJar(outjar.getAbsolutePath());
                assertTrue("Build failed",doSynchronousBuild("config2.lst"));
-               assertFalse("No build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
-               List msgs = NullIdeManager.getIdeManager().getCompilationSourceLineTasks();
-               assertTrue("Wrong message",((NullIdeTaskListManager.SourceLineTask)msgs.get(0)).message.getMessage().startsWith("manifest not copied: "));
+               assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
                compareJars(injar1,"src",outjar);
        }
        
@@ -76,10 +74,11 @@ public class ResourceCopyTestCase extends AjdeTestCase {
                ideManager.getProjectProperties().setInJars(injars);
                File outjar = openFile(outjarName);
                ideManager.getProjectProperties().setOutJar(outjar.getAbsolutePath());
-               assertFalse("Build should have failed",doSynchronousBuild("config2.lst"));
-               assertFalse("No build errors",ideManager.getCompilationSourceLineTasks().isEmpty());
+               assertTrue("Build should have suceeded",doSynchronousBuild("config2.lst"));
+               assertFalse("Build warnings for duplicate resource expected",ideManager.getCompilationSourceLineTasks().isEmpty());
                List msgs = NullIdeManager.getIdeManager().getCompilationSourceLineTasks();
-               assertTrue("Wrong message",((NullIdeTaskListManager.SourceLineTask)msgs.get(1)).message.getMessage().startsWith("duplicate resource: "));
+               assertTrue("Wrong message",((NullIdeTaskListManager.SourceLineTask)msgs.get(0)).message.getMessage().startsWith("duplicate resource: "));
+               compareJars(injar1,"src",outjar);
        }
        
        public void testSrcToOutjar () {
@@ -95,9 +94,7 @@ public class ResourceCopyTestCase extends AjdeTestCase {
                injars.add(injar1);
                ideManager.getProjectProperties().setInJars(injars);
                assertTrue("Build failed",doSynchronousBuild("config2.lst"));
-               assertFalse("No build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
-               List msgs = NullIdeManager.getIdeManager().getCompilationSourceLineTasks();
-               assertTrue("Wrong message",((NullIdeTaskListManager.SourceLineTask)msgs.get(0)).message.getMessage().startsWith("manifest not copied: "));
+               assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
                compareInjarsToBin(injar1,"src","bin");
        }
        
@@ -114,10 +111,10 @@ public class ResourceCopyTestCase extends AjdeTestCase {
                for (int i = 0; i < toResources.length; i++) {
                        String fileName = FileUtil.normalizedPath(toResources[i],binBase);
                        boolean b = resources.remove(fileName);
-                       assertTrue("Extraneous resoures:" + fileName,b);
+                       assertTrue("Extraneous resources: " + fileName,b);
                }
                
-               assertTrue("Missing resources:" + resources.toString(), resources.isEmpty());
+               assertTrue("Missing resources: " + resources.toString(), resources.isEmpty());
        }       
        
        /*
@@ -138,10 +135,10 @@ public class ResourceCopyTestCase extends AjdeTestCase {
                                String fileName = entry.getName();
                                if (!fileName.endsWith(".class")) {
                                        
-                                       /* Ensure we didn't copy any JAR manifests */
-                                       if (fileName.toLowerCase().startsWith("meta-inf")) {
+                                       /* Ensure we copied right JAR manifest */
+                                       if (fileName.equalsIgnoreCase("meta-inf/Manifest.mf")) {
                                                byte[] outManifest = FileUtil.readAsByteArray(outjar);
-                                               assertFalse("Manifest has been copied",Arrays.equals(inManifest,outManifest));
+                                               assertTrue("Wrong manifest has been copied",Arrays.equals(inManifest,outManifest));
                                        }
                                        
                                        boolean b = resources.remove(fileName);
@@ -179,7 +176,7 @@ public class ResourceCopyTestCase extends AjdeTestCase {
                        }
                        outjar.close();
 
-                       assertTrue("Missing resources:" + resources.toString(), resources.isEmpty());
+                       assertTrue("Missing resources: " + resources.toString(), resources.isEmpty());
                }
                catch (IOException ex) {
                        fail(ex.toString());
@@ -202,16 +199,16 @@ public class ResourceCopyTestCase extends AjdeTestCase {
                        for (int i = 0; i < toResources.length; i++) {
                                String fileName = FileUtil.normalizedPath(toResources[i],binBase);
 
-                               /* Ensure we didn't copy any JAR manifests */
-                               if (fileName.toLowerCase().startsWith("meta-inf")) {
+                               /* Ensure we copied the right JAR manifest */
+                               if (fileName.equalsIgnoreCase("meta-inf/Manifest.mf")) {
                                        byte[] outManifest = FileUtil.readAsByteArray(toResources[i]);
-                                       assertFalse("Manifest has been copied",Arrays.equals(inManifest,outManifest));
+                                       assertTrue("Wrong manifest has been copied",Arrays.equals(inManifest,outManifest));
                                }
                                boolean b = resources.remove(fileName);
-                               assertTrue("Extraneous resoures:" + fileName,b);
+                               assertTrue("Extraneous resources: " + fileName,b);
                        }
 
-                       assertTrue("Missing resources:" + resources.toString(), resources.isEmpty());
+                       assertTrue("Missing resources: " + resources.toString(), resources.isEmpty());
                }
                catch (IOException ex) {
                        fail(ex.toString());
@@ -237,15 +234,13 @@ public class ResourceCopyTestCase extends AjdeTestCase {
                        ZipEntry entry;
                        while (null != (entry = injar.getNextEntry())) {
                                String fileName = entry.getName();
-                               if (!fileName.endsWith(".class")) {
+                               if (!entry.isDirectory() && !fileName.endsWith(".class")) {
                                        
                                        /* JAR manifests shouldn't be copied */
-                                       if (fileName.toLowerCase().startsWith("meta-inf")) {
+                                       if (fileName.equalsIgnoreCase("meta-inf/Manifest.mf")) {
                                                manifest = FileUtil.readAsByteArray(injar);
                                        }
-                                       else {
-                                               resources.add(fileName);
-                                       }
+                                       resources.add(fileName);
                                }
                                injar.closeEntry();
                        }
index 9730bbdec28261cdefc728add3737d87326aa301..51b5333ed1a0576ad5392ff6267d01df1b2b2923 100644 (file)
@@ -128,16 +128,9 @@ public class BcelWeaver implements IWeaver {
                                this.addClassFile(classFile);
                        }
                        else if (!entry.isDirectory()) {
-//                             System.err.println("? addJarFile() filename='" + filename + "'");
-                               
-                               /* Don't copy JAR manifests */
-                               if (filename.toLowerCase().startsWith("meta-inf")) {
-                                       world.showMessage(IMessage.WARNING, "manifest not copied: '" + filename + 
-                                                                       "' in JAR '" + inFile + "'", null, null);
-                               }
-                               else {
-                                       addResource(filename,classFile);
-                               }
+
+                               /* bug-44190 Copy meta-data */
+                               addResource(filename,classFile);
                        }
 
                        inStream.closeEntry();
@@ -179,9 +172,12 @@ public class BcelWeaver implements IWeaver {
     }
 
        public void addResource (String name, UnwovenClassFile resourceFile) {
-               Object previous = resources.put(name, resourceFile);
-               if (null != previous) {
-                       world.showMessage(IMessage.ERROR, "duplicate resource: '" + name + "'",
+               /* bug-44190 Change error to warning and copy first resource */
+               if (!resources.containsKey(name)) {
+                       resources.put(name, resourceFile);
+               }
+               else {
+                       world.showMessage(IMessage.WARNING, "duplicate resource: '" + name + "'",
                                null, null);
                }
        }