package org.aspectj.weaver;
+import java.io.File;
+
+import org.aspectj.util.FileUtil;
+
import junit.framework.*;
public class BcweaverTests extends TestCase {
public static final String TESTDATA_PATH = "../weaver/testdata";
+ public static final String OUTDIR_PATH = "../weaver/out";
+
+ /** @return File outDir (writable) or null if unable to write */
+ public static File getOutdir() {
+ File result = new File(OUTDIR_PATH);
+ if (result.mkdirs()
+ || (result.canWrite() && result.isDirectory())) {
+ return result;
+ }
+ return null;
+ }
+
+ /** best efforts to delete the output directory and any contents */
+ public static void removeOutDir() {
+ File outDir = getOutdir();
+ if (null != outDir) {
+ FileUtil.deleteContents(outDir);
+ outDir.delete();
+ }
+ }
+
public static Test suite() {
TestSuite suite = new TestSuite(BcweaverTests.class.getName());
// abstract
import java.lang.reflect.Modifier;
import java.util.*;
+import org.aspectj.util.FileUtil;
import org.aspectj.weaver.*;
public class MegaZipTestCase extends WeaveTestCase {
+ private File outDir;
+
public MegaZipTestCase(String arg0) {
super(arg0);
}
+ public void setUp() {
+ outDir = BcweaverTests.getOutdir();
+ }
+
+ public void tearDown() {
+ BcweaverTests.removeOutDir();
+ outDir = null;
+ }
+
private BcelAdvice makeAroundMunger(final boolean matchOnlyPrintln) {
BcelWorld world = new BcelWorld();
public void zipTest(String fileName) throws IOException {
long startTime = System.currentTimeMillis();
- File inFile = new File("testdata", fileName);
- File outFile = new File("out", fileName);
+ File inFile = new File(BcweaverTests.TESTDATA_PATH, fileName);
+ File outFile = new File(outDir, fileName);
outFile.delete();
world = new BcelWorld("c:/apps/java-1.3.1_04/lib/tools.jar");
world = new BcelWorld(getTraceJar());
BcelWeaver weaver = new BcelWeaver(world);
weaver.addLibraryAspect("MyTrace");
-
- UnwovenClassFile classFile = makeUnwovenClassFile(classDir, "DynamicHelloWorld", outDir);
+ UnwovenClassFile classFile
+ = makeUnwovenClassFile(classDir, "DynamicHelloWorld", outDirPath);
weaver.addClassFile(classFile);
weaver.prepareForWeave();
public boolean regenerate = false;
public boolean runTests = true;
-
+
+ File outDir;
+ String outDirPath;
+
public BcelWorld world = new BcelWorld();
public WeaveTestCase(String name) {
super(name);
}
+ public void setUp() {
+ outDir = BcweaverTests.getOutdir();
+ outDirPath = outDir.getAbsolutePath();
+ }
+ public void tearDown() {
+ BcweaverTests.removeOutDir();
+ outDir = null;
+ outDirPath = null;
+ }
+
public static InstructionList getAdviceTag(BcelShadow shadow, String where) {
String methodName =
"ajc_" + where + "_" + shadow.getKind().toLegalJavaIdentifier();
}
static String classDir = "../weaver/bin";
- static String outDir = "out";
public void weaveTest(String name, String outName, List planners) throws IOException {
BcelWeaver weaver = new BcelWeaver(world);
- UnwovenClassFile classFile = makeUnwovenClassFile(classDir, name, outDir);
+ UnwovenClassFile classFile = makeUnwovenClassFile(classDir, name, outDirPath);
weaver.addClassFile(classFile);
weaver.setShadowMungers(planners);
gen = classType.getLazyClassGen(); //new LazyClassGen(classType);
}
try {
- checkClass(gen, outDir, outName + ".txt");
+ checkClass(gen, outDirPath, outName + ".txt");
if (runTests) {
System.out.println(
"*******RUNNING: " + outName + " " + name + " *******");
- TestUtil.runMain(makeClassPath(outDir), name);
+ TestUtil.runMain(makeClassPath(outDirPath), name);
}
} catch (Error e) {
gen.print(System.err);
if (regenerate) genClass(gen, outDir, expectedFile);
else realCheckClass(gen, outDir, expectedFile);
}
- static final File TESTDATA_DIR = new File("../weaver/testdata");
+ static final File TESTDATA_DIR = new File(BcweaverTests.TESTDATA_PATH);
void genClass(LazyClassGen gen, String outDir, String expectedFile) throws IOException {
//ClassGen b = getJavaClass(outDir, className);
FileOutputStream out = new FileOutputStream(new File(TESTDATA_DIR, expectedFile));
super(name);
}
- private final BcelWorld world = new BcelWorld("testdata/tracing.jar");
+ private final BcelWorld world
+ = new BcelWorld(BcweaverTests.TESTDATA_PATH + "/tracing.jar");
protected World getWorld() {
return world;
public class ZipTestCase extends TestCase {
+ File outDir;
+
/**
* Constructor for ZipTestCase.
* @param arg0
public ZipTestCase(String arg0) {
super(arg0);
}
+
+ public void setUp() {
+ outDir = BcweaverTests.getOutdir();
+ }
+
+ public void tearDown() {
+ BcweaverTests.removeOutDir();
+ outDir = null;
+ }
public void zipTest(String fileName, String aspectjar) throws IOException {
public void zipTest(String fileName, String aspectjar, boolean isInJar) throws IOException {
File inFile = new File(fileName);
- File outFile = new File("out", inFile.getName());
+ File outFile = new File(outDir, inFile.getName());
BcelWorld world = new BcelWorld();