ajc -outjar jarfile does not contain MANIFEST.MFtags/Root_ajdt_support
@@ -0,0 +1,3 @@ | |||
src/Main.java | |||
src/Logging.aj | |||
-noweave |
@@ -0,0 +1,13 @@ | |||
public aspect Logging { | |||
pointcut methods () : | |||
execution(* *..*(..)) && !within(Logging); | |||
before () : methods () { | |||
System.err.println("> " + thisJoinPoint.getSignature().toLongString()); | |||
} | |||
after () : methods () { | |||
System.err.println("< " + thisJoinPoint.getSignature().toLongString()); | |||
} | |||
} |
@@ -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(); | |||
} | |||
} |
@@ -0,0 +1,2 @@ | |||
src/Main.java | |||
src/Logging.aj |
@@ -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; |
@@ -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(); |
@@ -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()); | |||
} | |||
} | |||
} |
@@ -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(); |
@@ -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 ( |
@@ -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... |