aboutsummaryrefslogtreecommitdiffstats
path: root/weaver
diff options
context:
space:
mode:
authoracolyer <acolyer>2003-11-11 13:09:14 +0000
committeracolyer <acolyer>2003-11-11 13:09:14 +0000
commit1c6db5d4f24f6ddaee4c48661503a8b7ea516744 (patch)
tree776e942fa9f0bd7ed54a717e7227f8e9a3716480 /weaver
parent8c70c5a515a383e0691eeb3a9bc1caa66a0398b5 (diff)
downloadaspectj-1c6db5d4f24f6ddaee4c48661503a8b7ea516744.tar.gz
aspectj-1c6db5d4f24f6ddaee4c48661503a8b7ea516744.zip
Andy Clement's patch for enh 46347: "-inpath"
Diffstat (limited to 'weaver')
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java114
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/ZipFileWeaver.java2
-rw-r--r--weaver/testsrc/org/aspectj/weaver/bcel/ZipTestCase.java4
3 files changed, 94 insertions, 26 deletions
diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java
index 51b5333ed..78ee0d576 100644
--- a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java
+++ b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java
@@ -13,18 +13,40 @@
package org.aspectj.weaver.bcel;
-import java.io.*;
-import java.util.*;
-import java.util.zip.*;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+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.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
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.util.FileUtil;
-import org.aspectj.weaver.*;
+import org.aspectj.weaver.ConcreteTypeMunger;
+import org.aspectj.weaver.CrosscuttingMembersSet;
+import org.aspectj.weaver.IWeaver;
+import org.aspectj.weaver.NewParentTypeMunger;
+import org.aspectj.weaver.ResolvedTypeMunger;
+import org.aspectj.weaver.ResolvedTypeX;
+import org.aspectj.weaver.ShadowMunger;
+import org.aspectj.weaver.TypeX;
import org.aspectj.weaver.patterns.DeclareParents;
-import org.aspectj.weaver.patterns.Pointcut;
public class BcelWeaver implements IWeaver {
private BcelWorld world;
@@ -109,34 +131,80 @@ public class BcelWeaver implements IWeaver {
}
+ /**
+ * Add any .class files in the directory to the outdir. Anything other than .class files in
+ * the directory (or its subdirectories) are considered resources and are also copied.
+ *
+ */
+ public void addDirectoryContents(File inFile,File outDir) throws IOException {
+
+ // Get a list of all files (i.e. everything that isnt a directory)
+ File[] files = FileUtil.listFiles(inFile,new FileFilter() {
+ public boolean accept(File f) {
+ boolean accept = !f.isDirectory();
+ return accept;
+ }
+ });
+
+ // For each file, add it either as a real .class file or as a resource
+ for (int i = 0; i < files.length; i++) {
+
+ FileInputStream fis = new FileInputStream(files[i]);
+ byte[] bytes = FileUtil.readAsByteArray(fis);
+ String relativePath = files[i].getPath();
+
+ // ASSERT: files[i].getAbsolutePath().startsWith(inFile.getAbsolutePath()
+ // or we are in trouble...
+ String filename = files[i].getAbsolutePath().substring(
+ inFile.getAbsolutePath().length()+1);
+ UnwovenClassFile classFile = new UnwovenClassFile(new File(outDir,filename).getAbsolutePath(),bytes);
+ if (filename.endsWith(".class")) {
+ // System.err.println("BCELWeaver: processing class from input directory "+classFile);
+ this.addClassFile(classFile);
+ } else {
+ // System.err.println("BCELWeaver: processing resource from input directory "+filename);
+ addResource(filename,classFile);
+ }
+ fis.close();
+ }
+
+ }
+
+
/** Adds all class files in the jar
*/
- public void addJarFile(File inFile, File outDir) throws IOException {
+ public void addJarFile(File inFile, File outDir, boolean canBeDirectory) throws IOException {
// System.err.println("? addJarFile(" + inFile + ", " + outDir + ")");
needToReweaveWorld = true;
- ZipInputStream inStream = new ZipInputStream(new FileInputStream(inFile)); //??? buffered
- while (true) {
- ZipEntry entry = inStream.getNextEntry();
- if (entry == null) break;
+ // Is this a directory we are looking at?
+ if (inFile.isDirectory() && canBeDirectory) {
+ addDirectoryContents(inFile,outDir);
+ } else {
+
+ ZipInputStream inStream = new ZipInputStream(new FileInputStream(inFile)); //??? buffered
+
+ 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);
+ 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);
- }
- else if (!entry.isDirectory()) {
+ if (filename.endsWith(".class")) {
+ this.addClassFile(classFile);
+ }
+ else if (!entry.isDirectory()) {
- /* bug-44190 Copy meta-data */
- addResource(filename,classFile);
- }
+ /* bug-44190 Copy meta-data */
+ addResource(filename,classFile);
+ }
- inStream.closeEntry();
+ inStream.closeEntry();
+ }
+ inStream.close();
}
-
- inStream.close();
}
public void addResource(String name, File inPath, File outDir) throws IOException {
diff --git a/weaver/src/org/aspectj/weaver/bcel/ZipFileWeaver.java b/weaver/src/org/aspectj/weaver/bcel/ZipFileWeaver.java
index 249f36325..7f0eb92db 100644
--- a/weaver/src/org/aspectj/weaver/bcel/ZipFileWeaver.java
+++ b/weaver/src/org/aspectj/weaver/bcel/ZipFileWeaver.java
@@ -28,7 +28,7 @@ public class ZipFileWeaver {
public void weave(BcelWeaver weaver, File outFile) throws IOException {
int count = 0;
long startTime = System.currentTimeMillis();
- weaver.addJarFile(inFile, new File("."));
+ weaver.addJarFile(inFile, new File("."),false);
weaver.weave(outFile);
long stopTime = System.currentTimeMillis();
diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/ZipTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/ZipTestCase.java
index 1aa65bcfb..5df1e2cfb 100644
--- a/weaver/testsrc/org/aspectj/weaver/bcel/ZipTestCase.java
+++ b/weaver/testsrc/org/aspectj/weaver/bcel/ZipTestCase.java
@@ -56,10 +56,10 @@ public class ZipTestCase extends TestCase {
BcelWeaver weaver = new BcelWeaver(world);
long startTime = System.currentTimeMillis();
- weaver.addJarFile(inFile, new File("."));
+ weaver.addJarFile(inFile, new File("."),false);
if (aspectjar != null) {
if (isInJar) {
- weaver.addJarFile(new File(aspectjar), new File("."));
+ weaver.addJarFile(new File(aspectjar), new File("."),false);
} else {
weaver.addLibraryJarFile(new File(aspectjar));
}