--- /dev/null
+src/Main.java\r
+src/Logging.aj\r
+-noweave
\ No newline at end of file
--- /dev/null
+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
--- /dev/null
+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();
+ }
+}
--- /dev/null
+src/Main.java\r
+src/Logging.aj\r
suite.addTestSuite(ResourceCopyTestCase.class);
suite.addTestSuite(ModelPerformanceTest.class);
suite.addTestSuite(SavedModelConsistencyTest. class);
+ suite.addTestSuite(JarManifestTest.class);
//$JUnit-END$
return suite;
import java.io.*;
import java.util.*;
+import java.util.jar.JarInputStream;
import java.util.zip.*;
import org.aspectj.util.FileUtil;
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);
// 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();
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();
--- /dev/null
+/*******************************************************************************
+ * 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());
+ }
+ }
+}
import java.io.*;
import java.util.*;
+import java.util.jar.JarInputStream;
import java.util.zip.*;
import org.aspectj.util.FileUtil;
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();
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;
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;
private int compiledCount;
private int sourceFileCount;
- private ZipOutputStream zos;
+ private JarOutputStream zos;
private boolean batchCompile = true;
private INameEnvironment environment;
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 "
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;
}
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 (
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;
// 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
}
- // 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;
/**
// 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?
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();
// 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...