From 2b8fa314f21eddf8551715fdd571da2b611411d0 Mon Sep 17 00:00:00 2001 From: aclement Date: Mon, 2 Aug 2004 15:47:02 +0000 Subject: [PATCH] Fix for Bugzilla Bug 57666 duplicate manifests cause resource-copying to gack (Contributed by Matthew Webster) --- .../META-INF/MANIFEST.MF | 3 + .../DuplicateManifestTest/META-INF/test.xml | 4 + .../DuplicateManifestTest/aspectjar.jar | Bin 0 -> 2544 bytes .../DuplicateManifestTest/build.ajsym | Bin 0 -> 1270 bytes ajde/testdata/DuplicateManifestTest/build.lst | 0 ajde/testdata/DuplicateManifestTest/injar.jar | Bin 0 -> 927 bytes .../testdata/DuplicateManifestTest/outjar.jar | Bin 0 -> 1273 bytes .../DuplicateManifestTest/update-injar.xml | 33 +++++++++ ajde/testsrc/org/aspectj/ajde/AjdeTests.java | 1 + .../aspectj/ajde/DuplicateManifestTest.java | 69 ++++++++++++++++++ .../internal/core/builder/AjBuildManager.java | 4 +- .../compiler/batch/BcweaverJarMaker.java | 30 ++++++++ .../org/aspectj/weaver/bcel/BcelWeaver.java | 31 +++++--- 13 files changed, 163 insertions(+), 12 deletions(-) create mode 100644 ajde/testdata/DuplicateManifestTest/META-INF/MANIFEST.MF create mode 100644 ajde/testdata/DuplicateManifestTest/META-INF/test.xml create mode 100644 ajde/testdata/DuplicateManifestTest/aspectjar.jar create mode 100644 ajde/testdata/DuplicateManifestTest/build.ajsym create mode 100644 ajde/testdata/DuplicateManifestTest/build.lst create mode 100644 ajde/testdata/DuplicateManifestTest/injar.jar create mode 100644 ajde/testdata/DuplicateManifestTest/outjar.jar create mode 100644 ajde/testdata/DuplicateManifestTest/update-injar.xml create mode 100644 ajde/testsrc/org/aspectj/ajde/DuplicateManifestTest.java diff --git a/ajde/testdata/DuplicateManifestTest/META-INF/MANIFEST.MF b/ajde/testdata/DuplicateManifestTest/META-INF/MANIFEST.MF new file mode 100644 index 000000000..fde889593 --- /dev/null +++ b/ajde/testdata/DuplicateManifestTest/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Created-By: DuplicateManifestTest + diff --git a/ajde/testdata/DuplicateManifestTest/META-INF/test.xml b/ajde/testdata/DuplicateManifestTest/META-INF/test.xml new file mode 100644 index 000000000..f9efa1f1f --- /dev/null +++ b/ajde/testdata/DuplicateManifestTest/META-INF/test.xml @@ -0,0 +1,4 @@ + + + + diff --git a/ajde/testdata/DuplicateManifestTest/aspectjar.jar b/ajde/testdata/DuplicateManifestTest/aspectjar.jar new file mode 100644 index 0000000000000000000000000000000000000000..6cc196c3eca337d748f14a7095ef2925a6f400d2 GIT binary patch literal 2544 zcmaKucTf{Z7r-L|2FOW=NRe_%E|DTdDFF%6OK8##LLg$4h)4;75{jS~LX;v3oD_jj zl!O*g0-O{DgNo7-r6?iNAynz*@GEnEH*?>6v$H$1^Y-ojvA_A*TOZ^W0|58)b|{xR z;D-3r%o~0EoLrE+!vpUh; z*^R2iPQR#li792MJ(VVI0bG>+NWYA^mzG2+6BclhcayKK7=ZvL5+I=iHu;KXdQoeU z!(p7-HG_?<#>U;l2#GeXE^PlvEa+^m-*Ao3S1K_Q&Ujj>iWE0?%VpoidQ6ufbPU2h zlboERV!EpG!mkJv9t5Z1dyk*q*R=7(NStnil zRuFwrWCd5ZReueeQDCCdf(DxPCb+Hl@+@DA;OD?>qUYkR4ngUj$B%7oC2Gb{b+1q2 zqkh+AU{3fMk1HcPPg84k1K1IL#o8!cxKs#Yk|N&f#}#RZ*Z<fP zq?FzQTd(|rVXVXW@RPm*Phqg2)vHGzGoy+p!OUlIqFg~^S`*yiJ%q48|HF`P1AH-g zk=(_#iBRnEcuUZ6p|dfgZ7SAXaduIGJ&t~QvCx>S;dR(q7m~uZq`^ZS*UAeb0v<&r z&^G!EoQFmCLgTZMp1tZ>!eAim^|x+Mk5Wsl`oo74hI&NC3hO7A{>7E8EgDDgxO&_& zUsiL3y#ta{=g`m9z24YXLI~q4T+Y`!6mSSz^}ZnWeOSels*N&4G~#sRCDZY|uUe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{07W$V!^XRl|sKN;UCvT6&NSL%=1LFLn_d0z6itU^^y>qSl`{0N;1YM--)E_ zDJFY<$_|u+xk32KQYYHcH{r!mA50Ra5%S9#4O8kly-tqFJ|#Ob7eDfj0Km UJo`@o01obF{r)Vw&np1nPfd7rg#Z8m literal 0 HcmV?d00001 diff --git a/ajde/testdata/DuplicateManifestTest/build.ajsym b/ajde/testdata/DuplicateManifestTest/build.ajsym new file mode 100644 index 0000000000000000000000000000000000000000..898f8bee075b4e9333f76b56ae299ba8713d650b GIT binary patch literal 1270 zcmah}&rcIU6n>PJ(()S;^+JM4qaMswIpP5cLZ~ik0tZ7j(bwJSc3^g9ot@IwgNc8J z2ajHeiT{C#;o!xK9{n5Cizc2(e6!s`K@3gW*}h-s!I?(wH@hFq(OmoR;CBuRE|h&G8$4X+f*F`~cX1!90%cg; zGMdZqjtj*G`8F{&Fx7Ln3>Q^0kgwE48KmCl@Dg$^BhEhn%SZ9Pga+_HDB;JVcz2HMUQ3AS(&HpWYNRjfO(G7I}J-rfCjyLtypj$ z4V9C;LDp^hdi53;fg=(_B+Xc0j_uspz@$m9Efl|fJiPSm%P{2Dp)3>z>*yP$Yfv&x z&61`PK__0m3-&YK9;M%D``Afr!z1T8G+h7hEKb9}arFMc`}6sG4leJ&7?0xKh?L%e zlGuy7%DXp&}`7^W1D7})hY(eAQve;RC=PJbcAA6MOJ)S z%t%i!*}wcAmw|z67eaYJaaJ)AF@PZnb^cUJo#+Z#wYJ%FQ)DSp0dJ7t({9E{m+}Pk zSd9K2l^Nh+GDgxSqrI`le$t86!t7f|C^kbhOmEUmpy5jP-DS;)M>#;uWTINyXRacJ zQlNp#x!rG_iXsqGy}Z+->BOYLIF3ovb0?Z!(HgsUIGtBt=U;!qH^VSggM7kYurvYM zc}gpH4CPw#XKjAvtXR+NXvNb0cHz;|ujQLRbC9b+QR#rw%`(VmTEAf6O1f?fz3Zf< dQ>Y8}>WEWj(%m`kqIA5Q1m)j=zU{m%`wQ>mn7jZ0 literal 0 HcmV?d00001 diff --git a/ajde/testdata/DuplicateManifestTest/build.lst b/ajde/testdata/DuplicateManifestTest/build.lst new file mode 100644 index 000000000..e69de29bb diff --git a/ajde/testdata/DuplicateManifestTest/injar.jar b/ajde/testdata/DuplicateManifestTest/injar.jar new file mode 100644 index 0000000000000000000000000000000000000000..8613c3686dd034e5f27251256972282d468a7ed3 GIT binary patch literal 927 zcmWIWW@h1H0D+2fCPOd-N^k;cU)K;vT~9wZ{Q#gc5e5z*Y$-!k#tl^Fk(!f}ua}&Y zSX`VNVC&E1C{TO&df{_Tj;8xuVHpRfib+TdCl>|^^YmV2l8z{ne`aCwPe<2e;|KO1 zi+eV6bBg5{>VGavyEpsi&%eLeE*#@jtXFPU*yhmk$;F0SU*O`2-LL(hC~TdeDxw#% zrC(CSza4z z7GFt%+>*}BuRT;}e4p=llVT-n-@82xg>x?+ zWAo~MR&3m}v;2zIZF!3rz5uQ}lbAEG>!4=~NPmA=te04m1 zFP5&_5>%k6d*Y-ITT$)8Ea!$9)4Qj0gYCU=w&95x&{P{B#%-@4vb`m##U*+bxjCCR zu0L@$Py=dXsL>VUfS?WAA3xo6(n}}kg!dWWt)ZvRXlv*iUSa0aXjJ*q$fI!fG%MKF zD~Fyom;=qU2HVQWB*K6@WdfA|fdIo_M-YvaPC?obDHS;YK`9jh)PYQ-bQ|D}&*`(P_14uocjo-&AcHH$51tn3dHL#i`d%zuwI!%PQ}@J4AGV^}g;~xGGp2V>=Vl1- zX6LwYw&95x&=wmY4!~(QH&E6iH76%uFF7Z%xVSeY+h5pG#5TE6*Sqotmz@KnW&qc2 z){rUfKO6!RD^*lid~BB7=6rM4UDex~9)CiUm|TSG8|+V2q(@hpweVZ_@BTio`rTaP z&(GhVzt7;a#^B0+(RHu06L@l2_Z>FY`~GR>)ZV5IOWQb{5BEH_ESjb`Nh&IR#q7_; zN^MmpFIG5DS$MU`W@C(AUPnT2{*ETayq{*}*DD{asJ$AYzI~2Rb6V@qWhVok^c}x2 z@mI>+CudI``1t9v)NV~AP&T_-i zJ&R9WJ#6Ir^w@Nqq}W?C)p|ZOdP&?H2vK|C86Wh29rBFEFr4{_@++lIm~eI+63pGViuCHrtoV zzsZ!iG|{a~G3sN?&6EsJ-pFjm?XIp2hCK%s*v*|`l2X!hDCI@q-&+E+>l7xb|DT+E z^6VXp`4aNW&C24hb$+;V?4!d$+ms#d^U|(fz9U-W&hqScL6EF);1{>4e@stpKhs@O z@po%W!6}pHpMpBIW*iZD`F~FA;hw(b3XVKi8g@1;T5;|1%vaZog=zy&=-Q`utUsjZ zef;~PijxU`Qm-~iBue*m{qSi`3=3S&qk2a3@Qsgi=LjCvZcAG_bE$yt>nD7CK(Q`GP!(_liROou+9yw`V+AF5cdpqjrV%NHzL34Cj>6t?BQ&@P1?@! z#nRUS?)>75wLP~thY3bq4t81Wwwvc{&$C}&6s7iGek3(3qbIb-#QgG_%hv^>UL-AI zU3>KbYg6BaJ5%Fsx!WfzyGv~AGcc=ZaQ~grf8XZ7-OV#NyY{!g(^}?NFVu2j8Z>ojy@zYHw zy>x<3c%Sjz8hYxCwuY|Z6=p7tMwKs(JPKz|vw}0~l|xS(%zXasnpnu6>vP=-f<8XyxX`=e__b{fdr2(X?ROCSVzv$BDdFazN}Agu~^ FFaZC6_~ifq literal 0 HcmV?d00001 diff --git a/ajde/testdata/DuplicateManifestTest/update-injar.xml b/ajde/testdata/DuplicateManifestTest/update-injar.xml new file mode 100644 index 000000000..7ce4c1452 --- /dev/null +++ b/ajde/testdata/DuplicateManifestTest/update-injar.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ajde/testsrc/org/aspectj/ajde/AjdeTests.java b/ajde/testsrc/org/aspectj/ajde/AjdeTests.java index b66c019ed..e70619504 100644 --- a/ajde/testsrc/org/aspectj/ajde/AjdeTests.java +++ b/ajde/testsrc/org/aspectj/ajde/AjdeTests.java @@ -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 index 000000000..38c82bb42 --- /dev/null +++ b/ajde/testsrc/org/aspectj/ajde/DuplicateManifestTest.java @@ -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()); + } + } + +} diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java index 096bb8855..ab428758a 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java @@ -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; diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/BcweaverJarMaker.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/BcweaverJarMaker.java index 40e81eeda..96a5021ae 100644 --- a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/BcweaverJarMaker.java +++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/BcweaverJarMaker.java @@ -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); + } } diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java index 6fd891ca6..19beb0f62 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java @@ -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"; -- 2.39.5