summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoracolyer <acolyer>2004-03-16 11:55:54 +0000
committeracolyer <acolyer>2004-03-16 11:55:54 +0000
commit9fca6d2c418cf886f060fb0eaff1c64fc647a8cf (patch)
treea5e1c137005072d40b3fca88ab5a145c233b4ed3
parent45b84e93b81522852b6034a2e922b9f3990ff48d (diff)
downloadaspectj-9fca6d2c418cf886f060fb0eaff1c64fc647a8cf.tar.gz
aspectj-9fca6d2c418cf886f060fb0eaff1c64fc647a8cf.zip
fix for Bugzilla Bug 43714
weaving from an input jar into that same jar.
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java49
-rw-r--r--tests/ajcTests.xml23
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java80
3 files changed, 115 insertions, 37 deletions
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 4b128b17c..94ed3a627 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
@@ -94,7 +94,7 @@ public class AjBuildManager implements IOutputClassFileNameProvider,ICompilerAda
AjBuildConfig buildConfig,
IMessageHandler baseHandler,
boolean batch) throws IOException, AbortException {
-
+ boolean ret = true;
batchCompile = batch;
try {
@@ -134,8 +134,7 @@ public class AjBuildManager implements IOutputClassFileNameProvider,ICompilerAda
}
if (buildConfig.getOutputJar() != null) {
- OutputStream os = FileUtil.makeOutputStream(buildConfig.getOutputJar());
- zos = new ZipOutputStream(os);
+ if (!openOutputStream(buildConfig.getOutputJar())) return false;
}
if (batch) {
@@ -183,16 +182,52 @@ public class AjBuildManager implements IOutputClassFileNameProvider,ICompilerAda
if (buildConfig.isGenerateModelMode()) {
AsmManager.getDefault().fireModelUpdated();
}
- return !handler.hasErrors();
} finally {
if (zos != null) {
- zos.close();
+ closeOutputStream();
}
- handler = null;
+ ret = !handler.hasErrors();
+ handler = null;
}
+ return ret;
}
- private void copyResourcesToDestination() throws IOException {
+
+ private boolean openOutputStream(File outJar) {
+ try {
+ OutputStream os = FileUtil.makeOutputStream(buildConfig.getOutputJar());
+ zos = new ZipOutputStream(os);
+ } catch (IOException ex) {
+ IMessage message =
+ new Message("Unable to open outjar "
+ + outJar.getPath()
+ + "(" + ex.getMessage()
+ + ")",
+ new SourceLocation(outJar,0),
+ true);
+ handler.handleMessage(message);
+ return false;
+ }
+ return true;
+ }
+
+ private void closeOutputStream() {
+ try {
+ if (zos != null) zos.close();
+ } catch (IOException ex) {
+ IMessage message =
+ new Message("Unable to write outjar "
+ + buildConfig.getOutputJar().getPath()
+ + "(" + ex.getMessage()
+ + ")",
+ new SourceLocation(buildConfig.getOutputJar(),0),
+ true);
+ handler.handleMessage(message);
+ }
+ }
+
+
+ private void copyResourcesToDestination() throws IOException {
if (buildConfig.getOutputJar() != null) {
bcelWeaver.dumpResourcesToOutJar(zos);
} else {
diff --git a/tests/ajcTests.xml b/tests/ajcTests.xml
index a3050d48b..3a6699227 100644
--- a/tests/ajcTests.xml
+++ b/tests/ajcTests.xml
@@ -7236,7 +7236,7 @@
</compile>
</ajc-test>
-
+
<ajc-test dir="bugs/serialVersionUID"
title="SUID: Before execution advice" pr="41181">
<compile files="Test.java, Util.java"/>
@@ -7430,8 +7430,8 @@
title="fail in compiling aspect with overriding method introduction with different throws clause ">
<compile files="IntertypeDifferentThrows.java" />
</ajc-test>
-
- <ajc-test dir="new"
+
+ <ajc-test dir="new"
comment="in ajc 1.1.1, VerifyError Illegal use of nonvirtual function call"
title="super call in anonymous class created in around advice">
<compile files="SuperClosure.java" />
@@ -7466,11 +7466,24 @@
<message kind="error" line="6"/>
</compile>
</ajc-test>
-
- <ajc-test dir="bugs" pr="51322"
+
+ <ajc-test dir="bugs" pr="51322"
title="Introduce Unknown Type to class causes Null pointer exception" >
<compile files="Pr51322.java">
<message kind="error" line="5"/>
</compile>
</ajc-test>
+
+ <ajc-test dir="bugs" pr="43714"
+ title="weaving from an input jar into that same jar.." >
+ <compile files="notAJar.jar" outjar="notAJar.jar">
+ <message kind="error" line="0"/>
+ </compile>
+ </ajc-test>
+
+ <ajc-test dir="bugs" pr="43714"
+ title="weaving from an input jar into that same jar.." >
+ <compile files="WeaveLocal.java" aspectpath="notAJar.jar" outjar="notAJar.jar" >
+ </compile>
+ </ajc-test>
</suite>
diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java
index e71707cae..222295e95 100644
--- a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java
+++ b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java
@@ -18,6 +18,7 @@ import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
@@ -38,6 +39,8 @@ import org.apache.bcel.classfile.ClassParser;
import org.apache.bcel.classfile.JavaClass;
import org.aspectj.bridge.IMessage;
import org.aspectj.bridge.IProgressListener;
+import org.aspectj.bridge.Message;
+import org.aspectj.bridge.SourceLocation;
import org.aspectj.util.FileUtil;
import org.aspectj.weaver.ConcreteTypeMunger;
import org.aspectj.weaver.CrosscuttingMembersSet;
@@ -53,6 +56,7 @@ import org.aspectj.weaver.WeaverStateInfo;
import org.aspectj.weaver.patterns.DeclareParents;
import org.aspectj.weaver.patterns.FastMatchInfo;
+
public class BcelWeaver implements IWeaver {
private BcelWorld world;
private CrosscuttingMembersSet xcutSet;
@@ -105,7 +109,7 @@ public class BcelWeaver implements IWeaver {
- public void addLibraryJarFile(File inFile) throws IOException {
+ public void addLibraryJarFile(File inFile) throws IOException {
ZipInputStream inStream = new ZipInputStream(new FileInputStream(inFile)); //??? buffered
List addedAspects = new ArrayList();
@@ -189,39 +193,65 @@ public class BcelWeaver implements IWeaver {
/** Adds all class files in the jar
*/
- public List addJarFile(File inFile, File outDir, boolean canBeDirectory) throws IOException {
+ public List addJarFile(File inFile, File outDir, boolean canBeDirectory){
// System.err.println("? addJarFile(" + inFile + ", " + outDir + ")");
List addedClassFiles = new ArrayList();
needToReweaveWorld = true;
+ ZipInputStream inStream = null;
- // Is this a directory we are looking at?
- if (inFile.isDirectory() && canBeDirectory) {
- addedClassFiles.addAll(addDirectoryContents(inFile,outDir));
- } else {
-
- ZipInputStream inStream = new ZipInputStream(new FileInputStream(inFile)); //??? buffered
-
- while (true) {
- ZipEntry entry = inStream.getNextEntry();
- if (entry == null) break;
+ try {
+ // Is this a directory we are looking at?
+ if (inFile.isDirectory() && canBeDirectory) {
+ addedClassFiles.addAll(addDirectoryContents(inFile,outDir));
+ } else {
+
+ inStream = new ZipInputStream(new FileInputStream(inFile)); //??? buffered
- byte[] bytes = FileUtil.readAsByteArray(inStream);
- String filename = entry.getName();
- UnwovenClassFile classFile = new UnwovenClassFile(new File(outDir, filename).getAbsolutePath(), bytes);
+ while (true) {
+ ZipEntry entry = inStream.getNextEntry();
+ if (entry == null) break;
+
+ byte[] bytes = FileUtil.readAsByteArray(inStream);
+ String filename = entry.getName();
+ UnwovenClassFile classFile = new UnwovenClassFile(new File(outDir, filename).getAbsolutePath(), bytes);
+
+ if (filename.endsWith(".class")) {
+ this.addClassFile(classFile);
+ addedClassFiles.add(classFile);
+ }
+ else if (!entry.isDirectory()) {
- if (filename.endsWith(".class")) {
- this.addClassFile(classFile);
- addedClassFiles.add(classFile);
- }
- else if (!entry.isDirectory()) {
+ /* bug-44190 Copy meta-data */
+ addResource(filename,classFile);
+ }
- /* bug-44190 Copy meta-data */
- addResource(filename,classFile);
+ inStream.closeEntry();
+ }
+ inStream.close();
+ }
+ } catch (FileNotFoundException ex) {
+ IMessage message = new Message(
+ "Could not find input jar file " + inFile.getPath() + ", ignoring",
+ new SourceLocation(inFile,0),
+ false);
+ world.getMessageHandler().handleMessage(message);
+ } catch (IOException ex) {
+ IMessage message = new Message(
+ "Could not read input jar file " + inFile.getPath() + "(" + ex.getMessage() + ")",
+ new SourceLocation(inFile,0),
+ true);
+ world.getMessageHandler().handleMessage(message);
+ } finally {
+ if (inStream != null) {
+ try {inStream.close();}
+ catch (IOException ex) {
+ IMessage message = new Message(
+ "Could not close input jar file " + inFile.getPath() + "(" + ex.getMessage() + ")",
+ new SourceLocation(inFile,0),
+ true);
+ world.getMessageHandler().handleMessage(message);
}
-
- inStream.closeEntry();
}
- inStream.close();
}
return addedClassFiles;