]> source.dussan.org Git - aspectj.git/commitdiff
fix for Bugzilla Bug 47910
authoracolyer <acolyer>
Wed, 17 Mar 2004 12:25:49 +0000 (12:25 +0000)
committeracolyer <acolyer>
Wed, 17 Mar 2004 12:25:49 +0000 (12:25 +0000)
  ajc -outjar jarfile does not contain MANIFEST.MF

ajde/testdata/JarManifestTest/noweave.lst [new file with mode: 0644]
ajde/testdata/JarManifestTest/src/Logging.aj [new file with mode: 0644]
ajde/testdata/JarManifestTest/src/Main.java [new file with mode: 0644]
ajde/testdata/JarManifestTest/weave.lst [new file with mode: 0644]
ajde/testsrc/org/aspectj/ajde/AjdeTests.java
ajde/testsrc/org/aspectj/ajde/InpathTestcase.java
ajde/testsrc/org/aspectj/ajde/JarManifestTest.java [new file with mode: 0644]
ajde/testsrc/org/aspectj/ajde/ResourceCopyTestCase.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java
weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java

diff --git a/ajde/testdata/JarManifestTest/noweave.lst b/ajde/testdata/JarManifestTest/noweave.lst
new file mode 100644 (file)
index 0000000..814b7c8
--- /dev/null
@@ -0,0 +1,3 @@
+src/Main.java\r
+src/Logging.aj\r
+-noweave
\ No newline at end of file
diff --git a/ajde/testdata/JarManifestTest/src/Logging.aj b/ajde/testdata/JarManifestTest/src/Logging.aj
new file mode 100644 (file)
index 0000000..3ef6ef0
--- /dev/null
@@ -0,0 +1,13 @@
+public aspect Logging {\r
+       \r
+       pointcut methods () :\r
+               execution(* *..*(..)) && !within(Logging);\r
+       \r
+       before () : methods () {\r
+               System.err.println("> " + thisJoinPoint.getSignature().toLongString());\r
+       }\r
+       \r
+       after () : methods () {\r
+               System.err.println("< " + thisJoinPoint.getSignature().toLongString());\r
+       }\r
+}\r
diff --git a/ajde/testdata/JarManifestTest/src/Main.java b/ajde/testdata/JarManifestTest/src/Main.java
new file mode 100644 (file)
index 0000000..94369dd
--- /dev/null
@@ -0,0 +1,25 @@
+import java.io.IOException;
+
+/*
+ * Created on 30-Jul-03
+ *
+ * To change this generated comment go to 
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+
+/**
+ * @author websterm
+ *
+ * To change this generated comment go to 
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class Main {
+
+       public void println () {
+               System.out.println("Main.");
+       }
+
+       public static void main(String[] args) throws IOException {
+               new Main().println();
+       }
+}
diff --git a/ajde/testdata/JarManifestTest/weave.lst b/ajde/testdata/JarManifestTest/weave.lst
new file mode 100644 (file)
index 0000000..0ad7a8a
--- /dev/null
@@ -0,0 +1,2 @@
+src/Main.java\r
+src/Logging.aj\r
index 06ead0b2cae5148d827fb2eb3e02aabb18848c0e..ecd8471ce57ebf55d7714d5cd7e41268374676bd 100644 (file)
@@ -35,6 +35,7 @@ public class AjdeTests extends TestCase {
                suite.addTestSuite(ResourceCopyTestCase.class);
                suite.addTestSuite(ModelPerformanceTest.class);
                suite.addTestSuite(SavedModelConsistencyTest. class);
+               suite.addTestSuite(JarManifestTest.class);
                
         //$JUnit-END$
         return suite;
index ce7b3e5f38f029debf0243a4839bed208f1fb141..e65b2441dc7469cf80dec136aa84286c59f51698 100644 (file)
@@ -15,6 +15,7 @@ package org.aspectj.ajde;
 
 import java.io.*;
 import java.util.*;
+import java.util.jar.JarInputStream;
 import java.util.zip.*;
 
 import org.aspectj.util.FileUtil;
@@ -244,13 +245,13 @@ public class InpathTestcase extends AjdeTestCase {
        public int fetchFromJar(File outjarFile, String filename) {
                int ret = -1;
                try {
-                       ZipInputStream outjar;
+                       JarInputStream outjar;
 
                        outjar =
-                               new ZipInputStream(new java.io.FileInputStream(outjarFile));
+                               new JarInputStream(new java.io.FileInputStream(outjarFile));
 
                        ZipEntry entry;
-                       while (null != (entry = outjar.getNextEntry())) {
+                       while (null != (entry = (ZipEntry)outjar.getNextEntry())) {
                                String zipentryname = entry.getName();
                                if (zipentryname.equals(filename)) {
                                                byte[] filedata = FileUtil.readAsByteArray(outjar);
@@ -285,8 +286,8 @@ public class InpathTestcase extends AjdeTestCase {
                        // Go through the output jar file, for each element, remove it from
                        // the expectedOutputJarContents - when we finish, the expectedOutputJarContents
                        // set should be empty!
-                       ZipInputStream outjar =
-                               new ZipInputStream(new java.io.FileInputStream(outjarFile));
+                       JarInputStream outjar =
+                               new JarInputStream(new java.io.FileInputStream(outjarFile));
                        ZipEntry entry;
                        while (null != (entry = outjar.getNextEntry())) {
                                String fileName = entry.getName();
@@ -319,8 +320,8 @@ public class InpathTestcase extends AjdeTestCase {
 
                try {
 
-                       ZipInputStream outjar =
-                               new ZipInputStream(new java.io.FileInputStream(outjarFile));
+                       JarInputStream outjar =
+                               new JarInputStream(new java.io.FileInputStream(outjarFile));
                        ZipEntry entry;
                        while (null != (entry = outjar.getNextEntry())) {
                                String fileName = entry.getName();
diff --git a/ajde/testsrc/org/aspectj/ajde/JarManifestTest.java b/ajde/testsrc/org/aspectj/ajde/JarManifestTest.java
new file mode 100644 (file)
index 0000000..6583dae
--- /dev/null
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * 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:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+/*
+ * Created on 16-Mar-2004
+ *
+ * To change the template for this generated file go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+package org.aspectj.ajde;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.jar.JarInputStream;
+import java.util.jar.Manifest;
+
+import org.aspectj.util.FileUtil;
+
+/**
+ * @author websterm
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class JarManifestTest extends AjdeTestCase {
+       public static final String PROJECT_DIR = "JarManifestTest";   
+       public static final String srcDir = PROJECT_DIR + "/src"; 
+       public static final String binDir = "bin"; 
+
+       public static final String outjarName = "/bin/output.jar"; 
+
+       /**
+        * Constructor for JarResourceCopyTestCase.
+        * @param arg0
+        */
+       public JarManifestTest (String arg0) {
+               super(arg0);
+       }
+
+       /*
+        * Ensure the output directpry in clean
+        */     
+       protected void setUp() throws Exception {
+               super.setUp(PROJECT_DIR);
+               FileUtil.deleteContents(openFile(binDir));
+       }
+
+       public void testWeave () {
+               File outjar = openFile(outjarName);
+               ideManager.getProjectProperties().setOutJar(outjar.getAbsolutePath());
+               assertTrue("Build failed",doSynchronousBuild("weave.lst"));
+               assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
+               checkManifest(outjar);
+       }
+
+       public void testNoweave () {
+               File outjar = openFile(outjarName);
+               ideManager.getProjectProperties().setOutJar(outjar.getAbsolutePath());
+               assertTrue("Build failed",doSynchronousBuild("noweave.lst"));
+               assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
+               checkManifest(outjar);
+       }
+       
+       private void checkManifest (File outjarFile) {
+               Manifest manifest = null;
+
+               try {
+                       JarInputStream outjar = new JarInputStream(new FileInputStream(outjarFile));
+                       manifest = outjar.getManifest();
+                       outjar.close();
+                       assertNotNull("'" + outjarFile.getCanonicalPath() + "' should contain a manifest",manifest);
+               }
+               catch (IOException ex) {
+                       fail(ex.toString());
+               }
+       }
+}
index bd02c18db53f297cc4c162fdb3556efb3cb2036c..cb7ca236da237ab08517787e1a190793967bae0a 100644 (file)
@@ -14,6 +14,7 @@ package org.aspectj.ajde;
 
 import java.io.*;
 import java.util.*;
+import java.util.jar.JarInputStream;
 import java.util.zip.*;
 
 import org.aspectj.util.FileUtil;
@@ -164,7 +165,7 @@ public class ResourceCopyTestCase extends AjdeTestCase {
        
                try {   
 
-                       ZipInputStream outjar = new ZipInputStream(new java.io.FileInputStream(outjarFile));
+                       ZipInputStream outjar = new JarInputStream(new java.io.FileInputStream(outjarFile));
                        ZipEntry entry;
                        while (null != (entry = outjar.getNextEntry())) {
                                String fileName = entry.getName();
index 6a6e0aa8f44a662a6ce0bedd915b44ca5691027e..f49ea9e3c1aa16dea285d209f00272f6ccf5f4dd 100644 (file)
@@ -17,8 +17,6 @@ import java.io.*;
 import java.util.*;
 import java.util.jar.*;
 import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-import java.util.zip.ZipOutputStream;
 
 import org.aspectj.ajdt.internal.compiler.AjCompilerAdapter;
 import org.aspectj.ajdt.internal.compiler.IIntermediateResultsRequestor;
@@ -45,6 +43,7 @@ import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
 
 public class AjBuildManager implements IOutputClassFileNameProvider,ICompilerAdapterFactory {
        private static final String CANT_WRITE_RESULT = "unable to write compilation result";
+       private static final String MANIFEST_NAME = "META-INF/MANIFEST.MF";
        static final boolean COPY_INPATH_DIR_RESOURCES = false;
     static final boolean FAIL_IF_RUNTIME_NOT_FOUND = false;
        private IProgressListener progressListener = null;
@@ -52,7 +51,7 @@ public class AjBuildManager implements IOutputClassFileNameProvider,ICompilerAda
        private int compiledCount;
        private int sourceFileCount;
 
-       private ZipOutputStream zos;
+       private JarOutputStream zos;
        private boolean batchCompile = true;
        private INameEnvironment environment;
        
@@ -198,7 +197,7 @@ public class AjBuildManager implements IOutputClassFileNameProvider,ICompilerAda
        private boolean openOutputStream(File outJar)  {
                try {
                        OutputStream os = FileUtil.makeOutputStream(buildConfig.getOutputJar());
-                       zos = new ZipOutputStream(os);
+                       zos = new JarOutputStream(os,bcelWeaver.getManifest(true));
                } catch (IOException ex) {
                        IMessage message = 
                                new Message("Unable to open outjar " 
@@ -253,12 +252,14 @@ public class AjBuildManager implements IOutputClassFileNameProvider,ICompilerAda
                                copyResourcesFromFile(from,resource,from);
                        }
                }
+               
+               writeManifest();
     }
        
        private void copyResourcesFromJarFile(File jarFile) throws IOException {
-               ZipInputStream inStream = null;
+               JarInputStream inStream = null;
                try {
-                       inStream = new ZipInputStream(new FileInputStream(jarFile));
+                       inStream = new JarInputStream(new FileInputStream(jarFile));
                        while (true) {
                                ZipEntry entry = inStream.getNextEntry();
                                if (entry == null) break;
@@ -334,6 +335,20 @@ public class AjBuildManager implements IOutputClassFileNameProvider,ICompilerAda
                }
                state.resources.add(filename);
        }
+       
+       /*
+        * If we are writing to an output directory copy the manifest but only
+        * if we already have one
+        */    
+       private void writeManifest () throws IOException {
+               Manifest manifest = bcelWeaver.getManifest(false);
+               if (manifest != null && zos == null) {
+                       OutputStream fos = 
+                               FileUtil.makeOutputStream(new File(buildConfig.getOutputDir(),MANIFEST_NAME));
+                       manifest.write(fos);    
+                       fos.close();
+               }
+       }
 
        private boolean acceptResource(String resourceName) {
                if (  
index 7cc91555b98dc2c7941793c8e5b0fe9547d1c353..d900c2035bf649a422710afb1feac21d76407520 100644 (file)
@@ -25,12 +25,14 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
+import java.util.jar.Attributes;
+import java.util.jar.Attributes.Name;
+import java.util.jar.JarInputStream;
+import java.util.jar.Manifest;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 import java.util.zip.ZipOutputStream;
@@ -80,7 +82,8 @@ public class BcelWeaver implements IWeaver {
 //    private Map  sourceJavaClasses = new HashMap();   /* String -> UnwovenClassFile */
     private List addedClasses      = new ArrayList(); /* List<UnovenClassFile> */
     private List deletedTypenames  = new ArrayList(); /* List<String> */
-//    private Map  resources         = new HashMap(); /* String -> UnwovenClassFile */ 
+//     private Map  resources         = new HashMap(); /* String -> UnwovenClassFile */ 
+       private Manifest manifest = null;
     private boolean needToReweaveWorld = false;
 
     private List shadowMungerList = null; // setup by prepareForWeave
@@ -142,8 +145,8 @@ public class BcelWeaver implements IWeaver {
        }
 
 
-       // The ANT copy task should be used to copy resources across.
-       private final static boolean CopyResourcesFromInpathDirectoriesToOutput=false;
+//     // The ANT copy task should be used to copy resources across.
+//     private final static boolean CopyResourcesFromInpathDirectoriesToOutput=false;
        private Set alreadyConfirmedReweavableState;
        
        /**
@@ -197,7 +200,7 @@ public class BcelWeaver implements IWeaver {
 //             System.err.println("? addJarFile(" + inFile + ", " + outDir + ")");
                List addedClassFiles = new ArrayList();
                needToReweaveWorld = true;
-               ZipInputStream inStream = null;
+               JarInputStream inStream = null;
                
                try {
                        // Is this a directory we are looking at?
@@ -205,7 +208,8 @@ public class BcelWeaver implements IWeaver {
                                addedClassFiles.addAll(addDirectoryContents(inFile,outDir));
                        } else {
                        
-                               inStream = new ZipInputStream(new FileInputStream(inFile)); //??? buffered
+                               inStream = new JarInputStream(new FileInputStream(inFile)); //??? buffered
+                               addManifest(inStream.getManifest());
                        
                                while (true) {
                                        ZipEntry entry = inStream.getNextEntry();
@@ -387,6 +391,29 @@ public class BcelWeaver implements IWeaver {
 //     dumpResourcesToOutJar();
 //    }
     
+       public void addManifest (Manifest newManifest) {
+               if (manifest == null) {
+                       manifest = newManifest;
+               }
+       }
+       
+       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";
+    
+    public Manifest getManifest (boolean shouldCreate) {
+               
+               if (manifest == null && shouldCreate) {
+                       manifest = new Manifest();
+
+                       Attributes attributes = manifest.getMainAttributes();
+                       attributes.put(Name.MANIFEST_VERSION,WEAVER_MANIFEST_VERSION);
+                       attributes.put(CREATED_BY,WEAVER_CREATED_BY);
+               }
+               
+               return manifest;
+    }
+    
     // ---- weaving
 
     // Used by some test cases only...