diff options
author | acolyer <acolyer> | 2004-03-16 11:55:54 +0000 |
---|---|---|
committer | acolyer <acolyer> | 2004-03-16 11:55:54 +0000 |
commit | 9fca6d2c418cf886f060fb0eaff1c64fc647a8cf (patch) | |
tree | a5e1c137005072d40b3fca88ab5a145c233b4ed3 /weaver/src | |
parent | 45b84e93b81522852b6034a2e922b9f3990ff48d (diff) | |
download | aspectj-9fca6d2c418cf886f060fb0eaff1c64fc647a8cf.tar.gz aspectj-9fca6d2c418cf886f060fb0eaff1c64fc647a8cf.zip |
fix for Bugzilla Bug 43714
weaving from an input jar into that same jar.
Diffstat (limited to 'weaver/src')
-rw-r--r-- | weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java | 80 |
1 files changed, 55 insertions, 25 deletions
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; |