From 35cde06f2c21bfc529d088b33f89c3eeb79f6e4f Mon Sep 17 00:00:00 2001
From: aclement
- * The expected usage of Ajc is through the TestCase superclass,
- * AjcTestCase, which provides helper methods that conveniently
- * drive the base functions exposed by this class.
+ * The expected usage of Ajc is through the TestCase superclass, AjcTestCase, which provides helper methods that conveniently drive
+ * the base functions exposed by this class.
* The compilation happens in a sandbox (C:\temp\ajcSandbox\ajTestxxx.tmp or
- * /tmp/ajcSandbox/ajcTestxxx.tmp depending on platform). Compiler arguments are
- * adapted to the sandbox as follows. For every file or directory listed in an argument (source file, or component
- * of inpath, aspectpath, sourceroots, classpath,...), if the file is specified
- * using an absolute path then it is left unchanged, but if the file is specified
- * using a relative path, and a base directory (see setBaseDir) has been provided,
- * then files/directories are copied from the base directory to the sandbox, and the
- * compiler arguments adjusted to reflect their new location.
+ * Call the compiler with the given arguments (args are exactly the same as you would pass to ajc on the command-line). The
+ * results of the compile are returned in a
+ * The compilation happens in a sandbox (C:\temp\ajcSandbox\ajTestxxx.tmp or /tmp/ajcSandbox/ajcTestxxx.tmp depending on
+ * platform). Compiler arguments are adapted to the sandbox as follows.
* For example, given a baseDir of "tests/pr12345" and a compile command:
- * "ajc src/A.java src/B.java", the files in
+ *
+ * For every file or directory listed in an argument (source file, or component of inpath, aspectpath, sourceroots,
+ * classpath,...), if the file is specified using an absolute path then it is left unchanged, but if the file is specified using
+ * a relative path, and a base directory (see setBaseDir) has been provided, then files/directories are copied from the base
+ * directory to the sandbox, and the compiler arguments adjusted to reflect their new location.
+ *
+ * For example, given a baseDir of "tests/pr12345" and a compile command: "ajc src/A.java src/B.java", the files in
+ *
*
- * If no classpath is specified (no -classpath in the arguments) the classpath will
- * be set to include the sandbox directory, testing-client/bin (for the Tester class),
- * and runtime/bin (for the AspectJ runtime). If a classpath is specified,
- * then any relative directories in it will be made relative to the sandbox, and
- * the testing-client and runtime bin directories are also added.
+ * If no classpath is specified (no -classpath in the arguments) the classpath will be set to include the sandbox directory,
+ * testing-client/bin (for the Tester class), and runtime/bin (for the AspectJ runtime). If a classpath is specified,
+ * then any relative directories in it will be made relative to the sandbox, and the testing-client and runtime bin directories
+ * are also added.
*
- * If no output directory is specified (no -d in the arguments), the output directory
- * is set to the sandbox. If a directory is specified, and the path is relative, it
- * will be made relative to the sandbox.
+ * If no output directory is specified (no -d in the arguments), the output directory is set to the sandbox. If a directory is
+ * specified, and the path is relative, it will be made relative to the sandbox.
* compile
creates a new
- * sandbox (C:\temp\ajcSandbox\ajtTestxxx.tmp, or /tmp/ajcSandbox/ajcTestxxx.tmp
- * depending on your platform). To write a test that performs multiple
- * (non-incremental) compiles, building on the results of previous
- * compilations, set 'should empty sandbox' to false after the first
- * compile, which will cause subsequent compiles in the test to use the
- * same directory and contents.
+ * By default, each call to compile
creates a new sandbox (C:\temp\ajcSandbox\ajtTestxxx.tmp, or
+ * /tmp/ajcSandbox/ajcTestxxx.tmp depending on your platform). To write a test that performs multiple (non-incremental)
+ * compiles, building on the results of previous compilations, set 'should empty sandbox' to false after the first compile,
+ * which will cause subsequent compiles in the test to use the same directory and contents.
*/
public void setShouldEmptySandbox(boolean empty) {
this.shouldEmptySandbox = empty;
}
-
+
/**
- * Call the compiler with the given arguments (args are exactly the same
- * as you would pass to ajc on the command-line). The results of the
- * compile are returned in a CompilationResult
, which
- * provides for easy testing of results.
- * CompilationResult
, which provides for easy testing of results.
+ *
* tests/pr12345/
* src/
* A.java
* B.java
*
+ *
* are copied to:
+ *
*
* ajcSandbox/ajcTestxxx.tmp/
* src/
@@ -142,34 +142,31 @@ public class Ajc {
* B.java
*
*
*
*
- * Throws an IllegalStateException if you try and call this method without first doing a compile - * that specified the -incremental option. + * Throws an IllegalStateException if you try and call this method without first doing a compile that specified the -incremental + * option. *
+ * * @return A CompilationResult giving the results of the most recent increment. * @throws IOException */ public CompilationResult doIncrementalCompile() throws IOException { if ((ajcArgs == null) || !isIncremental(ajcArgs)) { - throw new IllegalStateException("Can't do incremental compile unless -incremental specified and first compile has taken place"); + throw new IllegalStateException( + "Can't do incremental compile unless -incremental specified and first compile has taken place"); } incrementalStage += 10; - return compile(ajcArgs,true); + return compile(ajcArgs, true); } - + /** - * Return the result of the last compile or incremental compile. This is the same as the - * return value from the compile() or doIncrementalCompile() methods. + * Return the result of the last compile or incremental compile. This is the same as the return value from the compile() or + * doIncrementalCompile() methods. */ - public CompilationResult getLastCompilationResult() { + public CompilationResult getLastCompilationResult() { return result; } - + /** * Get the sandbox directory used for the compilation. */ public File getSandboxDirectory() { - if (sandbox == null) {sandbox = createEmptySandbox();} + if (sandbox == null) { + sandbox = createEmptySandbox(); + } return sandbox; } - + /** - * Set the base directory relative to which all relative paths specified in the arguments to a compile will be - * interpreted. + * Set the base directory relative to which all relative paths specified in the arguments to a compile will be interpreted. */ public void setBaseDir(File dir) { - if ((dir != null) && !dir.isDirectory()) throw new IllegalArgumentException(dir.getPath() + " is not a directory"); + if ((dir != null) && !dir.isDirectory()) + throw new IllegalArgumentException(dir.getPath() + " is not a directory"); baseDir = dir; } - + private void addMessagesTo(List aList, IMessage[] messages) { for (int i = 0; i < messages.length; i++) { aList.add(messages[i]); } } - + private boolean isIncremental(String[] args) { for (int i = 0; i < args.length; i++) { - if (args[i].trim().equals("-incremental")) return true; + if (args[i].trim().equals("-incremental")) + return true; } return false; } public static File createEmptySandbox() { File sandbox; - + String os = System.getProperty("os.name"); File tempDir = null; // AMC - I did this rather than use the JDK default as I hate having to go look // in c:\documents and settings\......... for the results of a failed test. if (os.startsWith("Windows")) { tempDir = new File("C:\\temp"); - if (!tempDir.exists()) {tempDir.mkdir();} + if (!tempDir.exists()) { + tempDir.mkdir(); + } } else { - tempDir = new File("/tmp"); + tempDir = new File("/tmp"); } - File sandboxRoot = new File(tempDir,SANDBOX_NAME); + File sandboxRoot = new File(tempDir, SANDBOX_NAME); if (!sandboxRoot.exists()) { sandboxRoot.mkdir(); } - - + try { File workspace = new File(".." + File.separator); String workspaceName = workspace.getCanonicalPath(); int index = workspaceName.lastIndexOf(File.separator); - workspaceName = workspaceName.substring(index+1); - - File workspaceRoot = new File(sandboxRoot,workspaceName); + workspaceName = workspaceName.substring(index + 1); + + File workspaceRoot = new File(sandboxRoot, workspaceName); if (!workspaceRoot.exists()) { workspaceRoot.mkdir(); } - + FileUtil.deleteContents(workspaceRoot); - - sandbox = File.createTempFile("ajcTest",".tmp",workspaceRoot); + + sandbox = File.createTempFile("ajcTest", ".tmp", workspaceRoot); sandbox.delete(); sandbox.mkdir(); - + } catch (IOException ioEx) { throw new AssertionFailedError("Unable to create sandbox directory for test"); } - + return sandbox; } /** - * Make every relative file name and dir be absolute under sandbox - * Add TESTER_PATH to classpath + * Make every relative file name and dir be absolute under sandbox Add TESTER_PATH to classpath */ - private String[] adjustToSandbox(String[] args,boolean doCopy) throws IOException { + private String[] adjustToSandbox(String[] args, boolean doCopy) throws IOException { String[] newArgs = new String[args.length]; boolean hasClasspath = false; boolean hasOutdir = false; @@ -343,118 +350,114 @@ public class Ajc { newArgs[i] = args[i]; if (FileUtil.hasSourceSuffix(args[i])) { File f = new File(args[i]); - //newArgs[i] = new File(baseDir,args[i]).getAbsolutePath(); // might be quicker? - newArgs[i] = adjustFileOrDir(f,doCopy).getAbsolutePath(); + // newArgs[i] = new File(baseDir,args[i]).getAbsolutePath(); // might be quicker? + newArgs[i] = adjustFileOrDir(f, doCopy).getAbsolutePath(); } else { - if ((args[i].equals("-aspectpath") || - args[i].equals("-inpath") || - args[i].equals("-injars") || - args[i].equals("-outjar") || - args[i].equals("-classpath") || - args[i].equals("-sourceroots") || - args[i].equals("-Xlintfile") || - args[i].equals("-extdirs") || - args[i].equals("-d")) && - args.length > (i+1)) { + if ((args[i].equals("-aspectpath") || args[i].equals("-inpath") || args[i].equals("-injars") + || args[i].equals("-outjar") || args[i].equals("-classpath") || args[i].equals("-sourceroots") + || args[i].equals("-Xlintfile") || args[i].equals("-extdirs") || args[i].equals("-d")) + && args.length > (i + 1)) { newArgs[i] = args[i]; StringBuffer buff = new StringBuffer(); boolean copyThisTime = doCopy; - if (args[i].equals("-d")) { + if (args[i].equals("-d")) { copyThisTime = false; hasOutdir = true; } - StringTokenizer strTok = new StringTokenizer(args[++i],File.pathSeparator); - while (strTok.hasMoreTokens()) { - File f = new File(strTok.nextToken()); - buff.append(adjustFileOrDir(f,copyThisTime).getAbsolutePath()); - if (strTok.hasMoreTokens()) buff.append(File.pathSeparator); - } - newArgs[i] = buff.toString(); - if (args[i-1].equals("-classpath")) { - hasClasspath = true; - newArgs[i] = newArgs[i] + File.pathSeparator + TESTER_PATH + File.pathSeparator + getSandboxDirectory().getAbsolutePath(); - } + StringTokenizer strTok = new StringTokenizer(args[++i], File.pathSeparator); + while (strTok.hasMoreTokens()) { + File f = new File(strTok.nextToken()); + buff.append(adjustFileOrDir(f, copyThisTime).getAbsolutePath()); + if (strTok.hasMoreTokens()) + buff.append(File.pathSeparator); + } + newArgs[i] = buff.toString(); + if (args[i - 1].equals("-classpath")) { + hasClasspath = true; + newArgs[i] = newArgs[i] + File.pathSeparator + TESTER_PATH + File.pathSeparator + + getSandboxDirectory().getAbsolutePath(); + } } else { // could be resource file File f = new File(args[i]); if (f.exists()) { - newArgs[i] = adjustFileOrDir(f,doCopy).getAbsolutePath(); + newArgs[i] = adjustFileOrDir(f, doCopy).getAbsolutePath(); } } - } + } } if (!hasClasspath) { String[] oldArgs = newArgs; newArgs = new String[oldArgs.length + 2]; - System.arraycopy(oldArgs,0,newArgs,0,oldArgs.length); + System.arraycopy(oldArgs, 0, newArgs, 0, oldArgs.length); newArgs[oldArgs.length] = "-classpath"; newArgs[oldArgs.length + 1] = TESTER_PATH + File.pathSeparator + getSandboxDirectory().getAbsolutePath(); } if (!hasOutdir) { String[] oldArgs = newArgs; newArgs = new String[oldArgs.length + 2]; - System.arraycopy(oldArgs,0,newArgs,0,oldArgs.length); + System.arraycopy(oldArgs, 0, newArgs, 0, oldArgs.length); newArgs[oldArgs.length] = "-d"; - newArgs[oldArgs.length + 1] = getSandboxDirectory().getPath(); + newArgs[oldArgs.length + 1] = getSandboxDirectory().getPath(); } return newArgs; } - - private File adjustFileOrDir(File from,boolean doCopy) throws IOException { + + private File adjustFileOrDir(File from, boolean doCopy) throws IOException { File to = from; File ret = from; if (!from.isAbsolute()) { - ret = new File(sandbox,from.getPath()); + ret = new File(sandbox, from.getPath()); File fromParent = from.getParentFile(); String relativeToPath = (fromParent != null) ? (fromParent.getPath() + File.separator) : ""; if (baseDir != null) { - from = new File(baseDir,from.getPath()); + from = new File(baseDir, from.getPath()); } - if (!from.exists()) return ret; + if (!from.exists()) + return ret; if (doCopy) { // harness requires that any files with the same name, and a different extension, // get copied too (e.g. .out, .err, .event files) if (from.isFile()) { - final String prefix = from.getName().substring(0,from.getName().lastIndexOf('.')); + final String prefix = from.getName().substring(0, from.getName().lastIndexOf('.')); String[] toCopy = from.getParentFile().list(new FilenameFilter() { public boolean accept(File dir, String name) { - if (name.indexOf('.') == -1) return false; - String toMatch = name.substring(0,name.lastIndexOf('.')); + if (name.indexOf('.') == -1) + return false; + String toMatch = name.substring(0, name.lastIndexOf('.')); return (toMatch.equals(prefix)); } - }); + }); for (int i = 0; i < toCopy.length; i++) { String toPath = relativeToPath + toCopy[i]; - to = new File(sandbox,toPath); - FileUtil.copyFile(new File(from.getParentFile(),toCopy[i]), - to); + to = new File(sandbox, toPath); + FileUtil.copyFile(new File(from.getParentFile(), toCopy[i]), to); } } else { - FileUtil.copyFile(from,ret); + FileUtil.copyFile(from, ret); } } } return ret; } - - public static void dumpAJDEStructureModel(String prefix) { - dumpAJDEStructureModel(prefix, false); + + public static void dumpAJDEStructureModel(AsmManager model, String prefix) { + dumpAJDEStructureModel(model, prefix, false); } - - public static void dumpAJDEStructureModel(String prefix, boolean useHandles) { + + public static void dumpAJDEStructureModel(AsmManager model, String prefix, boolean useHandles) { System.out.println("======================================");//$NON-NLS-1$ - System.out.println("start of AJDE structure model:"+prefix); //$NON-NLS-1$ + System.out.println("start of AJDE structure model:" + prefix); //$NON-NLS-1$ - IRelationshipMap asmRelMap = AsmManager.getDefault().getRelationshipMap(); + IRelationshipMap asmRelMap = model.getRelationshipMap(); for (Iterator iter = asmRelMap.getEntries().iterator(); iter.hasNext();) { String sourceOfRelationship = (String) iter.next(); - System.err.println("Examining source relationship handle: "+sourceOfRelationship); + System.err.println("Examining source relationship handle: " + sourceOfRelationship); List relationships = null; if (useHandles) { relationships = asmRelMap.get(sourceOfRelationship); } else { - IProgramElement ipe = AsmManager.getDefault().getHierarchy() - .findElementForHandle(sourceOfRelationship); + IProgramElement ipe = model.getHierarchy().findElementForHandle(sourceOfRelationship); relationships = asmRelMap.get(ipe); } if (relationships != null) { @@ -463,14 +466,14 @@ public class Ajc { List targets = rel.getTargets(); for (Iterator iterator2 = targets.iterator(); iterator2.hasNext();) { String t = (String) iterator2.next(); - IProgramElement link = AsmManager.getDefault().getHierarchy().findElementForHandle(t); + IProgramElement link = model.getHierarchy().findElementForHandle(t); System.out.println(""); //$NON-NLS-1$ System.out.println(" sourceOfRelationship " + sourceOfRelationship); //$NON-NLS-1$ System.out.println(" relationship " + rel.getName()); //$NON-NLS-1$ System.out.println(" target " + link.getName()); //$NON-NLS-1$ } } - + } } System.out.println("End of AJDE structure model"); //$NON-NLS-1$ @@ -479,30 +482,34 @@ public class Ajc { } /* - * So that we can drive incremental compilation easily from a unit - * test. + * So that we can drive incremental compilation easily from a unit test. */ class AjcCommandController extends Main.CommandController { - + private ICommand command; - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.aspectj.tools.ajc.Main.CommandController#doRepeatCommand() */ boolean doRepeatCommand(ICommand command) { this.command = command; - return false; // ensure that control returns to caller + return false; // ensure that control returns to caller } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.aspectj.tools.ajc.Main.CommandController#running() */ public boolean running() { - return false; // so that we can come back for more... + return false; // so that we can come back for more... } - + public void doIncremental(IMessageHandler handler) { - if (command == null) throw new IllegalArgumentException("Can't repeat command until it has executed at least once!"); + if (command == null) + throw new IllegalArgumentException("Can't repeat command until it has executed at least once!"); command.repeatCommand(handler); } } @@ -517,13 +524,14 @@ class AbortInterceptor implements IMessageHandler { if (message.getThrown() != null) { System.err.println("caused by " + message.getThrown().toString()); } - - } // allow message to accumulate... + + } // allow message to accumulate... return false; } public boolean isIgnoring(Kind kind) { - if (kind != IMessage.ABORT) return true; + if (kind != IMessage.ABORT) + return true; return false; } diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java index 2abb07d85..1a8da2974 100644 --- a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java +++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java @@ -34,17 +34,16 @@ import org.aspectj.bridge.ISourceLocation; import org.aspectj.testing.util.TestUtil; /** - * A TestCase class that acts as the superclass for all test cases wishing - * to drive the ajc compiler. + * A TestCase class that acts as the superclass for all test cases wishing to drive the ajc compiler. *- * This class provides a number of utility methods that make programmatic - * testing of the compiler easy. See AjcTestCaseTest for a couple of simple - * tests written using this class. + * This class provides a number of utility methods that make programmatic testing of the compiler easy. See AjcTestCaseTest for a + * couple of simple tests written using this class. *
*- * See the XMLBasedAjcTestCase subclass for TestCase class that can be - * used to drive compiler tests based on an ajcTests.xml format test - * specification file.
+ * See the XMLBasedAjcTestCase subclass for TestCase class that can be used to drive compiler tests based on an ajcTests.xml format + * test specification file. + * + * * @see org.aspectj.tools.ajc.AjcTestCase.Message * @see org.aspectj.tools.ajc.AjcTestCase.MessageSpec * @see org.aspectj.tools.ajc.AjcTestCase.RunResult @@ -52,51 +51,56 @@ import org.aspectj.testing.util.TestUtil; * @see org.aspectj.testing.XMLBasedAjcTestCase */ public class AjcTestCase extends TestCase { - + private RunResult lastRunResult; - + /** - * The Ajc (compiler) instance used for thet test. Created afresh - * during the test setup. + * The Ajc (compiler) instance used for the test. Created afresh during the test setup. */ protected Ajc ajc; - - public static final String DEFAULT_CLASSPATH_ENTRIES = - File.pathSeparator + ".." + File.separator + "bridge" + File.separator + "bin" - + File.pathSeparator + ".." + File.separator + "util" + File.separator + "bin" - + File.pathSeparator+ ".."+File.separator+"loadtime"+File.separator+"bin" - + File.pathSeparator+ ".."+File.separator+"weaver"+File.separator+"bin" - + File.pathSeparator+ ".."+File.separator+"weaver5"+File.separator+"bin" - + File.pathSeparator+ ".."+File.separator+"asm"+File.separator+"bin" - + File.pathSeparator + ".." + File.separator + "testing-client" + File.separator + "bin" - + File.pathSeparator + ".." + File.separator + "runtime" + File.separator + "bin" - + File.pathSeparator + ".." + File.separator + "aspectj5rt" + File.separator + "bin" - + File.pathSeparator+ ".."+File.separator+"lib"+File.separator+"junit"+File.separator+"junit.jar" - + File.pathSeparator+ ".."+File.separator+"lib"+File.separator+"bcel"+File.separator+"bcel.jar" - + File.pathSeparator+ ".."+File.separator+"lib"+File.separator+"bcel"+File.separator+"bcel-verifier.jar" - - // When the build machine executes the tests, it is using code built into jars rather than code build into - // bin directories. This means for the necessary types to be found we have to put these jars on the classpath: - + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"bridge.jar" - + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"util.jar" - + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"loadtime.jar" - + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"weaver.jar" - + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"weaver5.jar" - + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"asm.jar" - + File.pathSeparator+".."+File.separator+"lib" +File.separator+"test"+File.separator+"testing-client.jar" - // hmmm, this next one should perhaps point to an aj-build jar... - + File.pathSeparator+".."+File.separator+"lib" +File.separator+"test"+File.separator+"aspectjrt.jar" - ; - - public static final String JAVA5_CLASSPATH_ENTRIES = - File.pathSeparator + ".." + File.separator + "aspectj5rt" + File.separator + "bin" - + File.pathSeparator+ ".."+File.separator+"loadtime5"+File.separator+"bin" - + File.pathSeparator+ ".."+File.separator+"weaver5"+File.separator+"bin" - - + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"aspectj5rt.jar" - + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"loadtime5.jar" - + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"weaver5.jar"; - + + public static final String DEFAULT_CLASSPATH_ENTRIES = File.pathSeparator + ".." + File.separator + "bridge" + File.separator + + "bin" + File.pathSeparator + ".." + File.separator + "util" + File.separator + "bin" + File.pathSeparator + ".." + + File.separator + "loadtime" + File.separator + "bin" + File.pathSeparator + ".." + File.separator + "weaver" + + File.separator + "bin" + File.pathSeparator + ".." + File.separator + "weaver5" + File.separator + "bin" + + File.pathSeparator + ".." + File.separator + "asm" + File.separator + "bin" + File.pathSeparator + ".." + + File.separator + "testing-client" + File.separator + "bin" + File.pathSeparator + ".." + File.separator + "runtime" + + File.separator + "bin" + File.pathSeparator + ".." + File.separator + "aspectj5rt" + File.separator + "bin" + + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "junit" + File.separator + "junit.jar" + + File.pathSeparator + ".." + File.separator + "lib" + + File.separator + + "bcel" + + File.separator + + "bcel.jar" + + File.pathSeparator + + ".." + + File.separator + + "lib" + + File.separator + + "bcel" + + File.separator + + "bcel-verifier.jar" + + // When the build machine executes the tests, it is using code built into jars rather than code build into + // bin directories. This means for the necessary types to be found we have to put these jars on the classpath: + + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "bridge.jar" + + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "util.jar" + + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "loadtime.jar" + + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "weaver.jar" + + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "weaver5.jar" + + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "asm.jar" + + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "test" + File.separator + "testing-client.jar" + // hmmm, this next one should perhaps point to an aj-build jar... + + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "test" + File.separator + "aspectjrt.jar"; + + public static final String JAVA5_CLASSPATH_ENTRIES = File.pathSeparator + ".." + File.separator + "aspectj5rt" + File.separator + + "bin" + File.pathSeparator + ".." + File.separator + "loadtime5" + File.separator + "bin" + File.pathSeparator + ".." + + File.separator + "weaver5" + File.separator + "bin" + + + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "aspectj5rt.jar" + + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "loadtime5.jar" + + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "weaver5.jar"; + /* * Save reference to real stderr and stdout before starting redirection */ @@ -104,16 +108,16 @@ public class AjcTestCase extends TestCase { public final static PrintStream out = System.out; private final static DelegatingOutputStream delegatingErr; private final static DelegatingOutputStream delegatingOut; - public final static boolean DEFAULT_VERBOSE = getBoolean("org.aspectj.tools.ajc.AjcTestCase.verbose",true); - public final static boolean DEFAULT_ERR_VERBOSE = getBoolean("org.aspectj.tools.ajc.AjcTestCase.verbose.err",DEFAULT_VERBOSE); - public final static boolean DEFAULT_OUT_VERBOSE = getBoolean("org.aspectj.tools.ajc.AjcTestCase.verbose.out",DEFAULT_VERBOSE); + public final static boolean DEFAULT_VERBOSE = getBoolean("org.aspectj.tools.ajc.AjcTestCase.verbose", true); + public final static boolean DEFAULT_ERR_VERBOSE = getBoolean("org.aspectj.tools.ajc.AjcTestCase.verbose.err", DEFAULT_VERBOSE); + public final static boolean DEFAULT_OUT_VERBOSE = getBoolean("org.aspectj.tools.ajc.AjcTestCase.verbose.out", DEFAULT_VERBOSE); /** - * Helper class that represents the specification of an individual - * message expected to be produced during a compilation run. + * Helper class that represents the specification of an individual message expected to be produced during a compilation run. *- * Message objects are combined in a MessageSpec which can then be - * passed to the various assertMessage methods.
+ * Message objects are combined in a MessageSpec which can then be passed to the various assertMessage methods. + * + * * @see org.aspectj.tools.ajc.AjcTestCase.MessageSpec */ public static class Message { @@ -121,34 +125,32 @@ public class AjcTestCase extends TestCase { private String text; private String sourceFileName; private ISourceLocation[] seeAlsos; - + /** - * Create a message that will match any compiler message on - * the given line. + * Create a message that will match any compiler message on the given line. */ public Message(int line) { this.line = line; } - + /** - * Create a message that will match any compiler message on - * the given line, where the message text containstext
.
+ * Create a message that will match any compiler message on the given line, where the message text contains
+ * text
.
*/
public Message(int line, String text) {
this.line = line;
this.text = text;
}
-
+
/**
- * Create a message that will match any compiler message on
- * the given line, where the message text contains text
.
+ * Create a message that will match any compiler message on the given line, where the message text contains
+ * text
.
*
- * If srcFile is non-null, the source file location of the message must
- * end with srcFile
.
+ * If srcFile is non-null, the source file location of the message must end with srcFile
.
*
- * If seeAlso
is non-null, each source location in seeAlso
- * must be matched by an extraSourceLocation in the message.
+ * If seeAlso
is non-null, each source location in seeAlso must be matched by an extraSourceLocation in the
+ * message.
*
text
.
+ * Create a message spec that will match any compiler message where the message text includes text
.
*/
public Message(String text) {
this.text = text;
@@ -206,22 +207,22 @@ public class AjcTestCase extends TestCase {
return false;
}
for (int i = 0; i < seeAlsos.length; i++) {
- if (!hasAMatch(extraLocations,seeAlsos[i])) {
+ if (!hasAMatch(extraLocations, seeAlsos[i])) {
return false;
}
}
}
return true;
}
-
- private boolean hasAMatch(List srcLocations,ISourceLocation sLoc) {
+
+ private boolean hasAMatch(List srcLocations, ISourceLocation sLoc) {
for (Iterator iter = srcLocations.iterator(); iter.hasNext();) {
ISourceLocation thisLoc = (ISourceLocation) iter.next();
if (thisLoc.getLine() == sLoc.getLine()) {
if (thisLoc.getSourceFile().getPath().equals(sLoc.getSourceFile().getPath())) {
return true;
}
- }
+ }
}
return false;
}
@@ -259,60 +260,49 @@ public class AjcTestCase extends TestCase {
return buff.toString();
}
}
-
+
/**
- * Helper class that represents the specification of a set of
- * messages expected to be produced from a compiler run.
+ * Helper class that represents the specification of a set of messages expected to be produced from a compiler run.
*
- * Instances of MessageSpec are passed to the assertMessage methods
- * to validate CompilationResult
s.
+ * Instances of MessageSpec are passed to the assertMessage methods to validate CompilationResult
s.
*/
public static class MessageSpec {
-
+
/**
- * Convenience constant that matches a CompilationResult with
- * any number of information messages, but no others.
+ * Convenience constant that matches a CompilationResult with any number of information messages, but no others.
*/
- public static final MessageSpec EMPTY_MESSAGE_SET =
- new MessageSpec(
- null,
- Collections.EMPTY_LIST,
- Collections.EMPTY_LIST,
- Collections.EMPTY_LIST,
- Collections.EMPTY_LIST);
-
+ public static final MessageSpec EMPTY_MESSAGE_SET = new MessageSpec(null, Collections.EMPTY_LIST, Collections.EMPTY_LIST,
+ Collections.EMPTY_LIST, Collections.EMPTY_LIST);
+
boolean ignoreInfos = true;
public List fails;
public List infos;
public List warnings;
public List errors;
public List weaves;
-
+
/**
- * Set to true to enable or disable comparison of information messages.
+ * Set to true to enable or disable comparison of information messages.
*/
public void setInfoComparison(boolean enabled) {
this.ignoreInfos = !enabled;
}
-
+
/**
- * True if information messages are not being included in matching.
+ * True if information messages are not being included in matching.
*/
public boolean isIgnoringInfoMessages() {
return ignoreInfos;
}
-
+
/**
- * Create a message specification to test a CompilationResult for a
- * given set of info, warning, error, and fail messages.
- * @param infos The set of info messages to test for. Specifying a non-null value
- * for this parameter enables info message comparison.
- * @param warnings The set of warning messages to test for - can pass null to indicate
- * empty set.
- * @param errors The set of error messages to test for - can pass null to indicate
- * empty set.
- * @param fails The set of fail or abort messages to test for - can pass null to indicate
- * empty set.
+ * Create a message specification to test a CompilationResult for a given set of info, warning, error, and fail messages.
+ *
+ * @param infos The set of info messages to test for. Specifying a non-null value for this parameter enables info message
+ * comparison.
+ * @param warnings The set of warning messages to test for - can pass null to indicate empty set.
+ * @param errors The set of error messages to test for - can pass null to indicate empty set.
+ * @param fails The set of fail or abort messages to test for - can pass null to indicate empty set.
*/
public MessageSpec(List infos, List warnings, List errors, List fails, List weaves) {
if (infos != null) {
@@ -326,96 +316,101 @@ public class AjcTestCase extends TestCase {
this.fails = ((fails == null) ? Collections.EMPTY_LIST : fails);
this.weaves = ((weaves == null) ? Collections.EMPTY_LIST : weaves);
}
-
+
/**
- * Create a message specification to test a CompilationResult for a given
- * set of info, warning, and error messages. The presence of any fail or
- * abort messages in a CompilationResult will be a test failure.
+ * Create a message specification to test a CompilationResult for a given set of info, warning, and error messages. The
+ * presence of any fail or abort messages in a CompilationResult will be a test failure.
*/
public MessageSpec(List infos, List warnings, List errors) {
- this(infos,warnings,errors,null,null);
+ this(infos, warnings, errors, null, null);
}
/**
- * Create a message specification to test a CompilationResult for a given
- * set of warning, and error messages. The presence of any fail or
- * abort messages in a CompilationResult will be a test failure. Informational
- * messages will be ignored.
+ * Create a message specification to test a CompilationResult for a given set of warning, and error messages. The presence
+ * of any fail or abort messages in a CompilationResult will be a test failure. Informational messages will be ignored.
*/
public MessageSpec(List warnings, List errors) {
- this(null,warnings,errors,null,null);
+ this(null, warnings, errors, null, null);
}
}
-
+
public static class EmptyMessageSpec extends MessageSpec {
public EmptyMessageSpec() {
- super(null,null);
+ super(null, null);
}
}
-
+
/**
- * Helper class representing the results of running a test program built
- * by the compiler. Provides access to the standard out and error of the
- * program, and the actual command that was executed.
+ * Helper class representing the results of running a test program built by the compiler. Provides access to the standard out
+ * and error of the program, and the actual command that was executed.
*/
public static class RunResult {
- private String command;
- private String stdOut;
- private String stdErr;
-
+ private final String command;
+ private final String stdOut;
+ private final String stdErr;
+
protected RunResult(String command, String stdOut, String stdErr) {
this.command = command;
this.stdOut = stdOut;
this.stdErr = stdErr;
}
-
+
/**
* Return the command that was executed, e.g. "java Driver".
*/
- public String getCommand() { return command; }
+ public String getCommand() {
+ return command;
+ }
+
/**
* The standard output from the run.
*/
- public String getStdOut() {return stdOut;}
+ public String getStdOut() {
+ return stdOut;
+ }
+
/**
* The standard error from the run.
*/
- public String getStdErr() {return stdErr;}
-
+ public String getStdErr() {
+ return stdErr;
+ }
+
/**
* Returns the command that was executed to produce this result.
*/
- public String toString() { return command; }
+ public String toString() {
+ return command;
+ }
}
-
+
/**
* Assert that no (non-informational) messages where produced during a compiler run.
*/
public void assertNoMessages(CompilationResult result) {
- assertNoMessages(result,"Not expecting any compiler messages to be produced");
+ assertNoMessages(result, "Not expecting any compiler messages to be produced");
}
-
+
/**
* Assert that no (non-informational) messages where produced during a compiler run.
*/
public void assertNoMessages(CompilationResult result, String message) {
- assertMessages(result, message,MessageSpec.EMPTY_MESSAGE_SET);
+ assertMessages(result, message, MessageSpec.EMPTY_MESSAGE_SET);
}
/**
- * Assert that messages in accordance with the expected
message specification
- * where produced during a compiler run.
+ * Assert that messages in accordance with the expected
message specification where produced during a compiler run.
*/
public void assertMessages(CompilationResult result, MessageSpec expected) {
- assertMessages(result, "Compilation results did not meet expected messages specification",expected);
+ assertMessages(result, "Compilation results did not meet expected messages specification", expected);
}
-
+
/**
- * Assert that messages in accordance with the expected
message specification
- * where produced during a compiler run.
+ * Assert that messages in accordance with the expected
message specification where produced during a compiler run.
*/
public void assertMessages(CompilationResult result, String message, MessageSpec expected) {
- if (result == null) fail("Attempt to compare null compilation results against expected.");
+ if (result == null)
+ fail("Attempt to compare null compilation results against expected.");
List missingFails = copyAll(expected.fails);
List missingInfos = copyAll(expected.infos);
List missingWarnings = copyAll(expected.warnings);
@@ -426,33 +421,33 @@ public class AjcTestCase extends TestCase {
List extraWarnings = copyAll(result.getWarningMessages());
List extraErrors = copyAll(result.getErrorMessages());
List extraWeaves = copyAll(result.getWeaveMessages());
- compare(expected.fails,result.getFailMessages(),missingFails,extraFails);
- compare(expected.warnings,result.getWarningMessages(),missingWarnings,extraWarnings);
- compare(expected.errors,result.getErrorMessages(),missingErrors,extraErrors);
+ compare(expected.fails, result.getFailMessages(), missingFails, extraFails);
+ compare(expected.warnings, result.getWarningMessages(), missingWarnings, extraWarnings);
+ compare(expected.errors, result.getErrorMessages(), missingErrors, extraErrors);
if (!expected.isIgnoringInfoMessages()) {
- compare(expected.infos,result.getInfoMessages(),missingInfos,extraInfos);
+ compare(expected.infos, result.getInfoMessages(), missingInfos, extraInfos);
}
- compare(expected.weaves,result.getWeaveMessages(),missingWeaves,extraWeaves);
+ compare(expected.weaves, result.getWeaveMessages(), missingWeaves, extraWeaves);
- boolean infosEmpty = expected.isIgnoringInfoMessages() ? true: (missingInfos.isEmpty() && extraInfos.isEmpty());
- if ( !(missingFails.isEmpty() && missingWarnings.isEmpty() && missingErrors.isEmpty() && missingWeaves.isEmpty() &&
- extraFails.isEmpty() && extraWarnings.isEmpty() && extraErrors.isEmpty() && extraWeaves.isEmpty() && infosEmpty)) {
+ boolean infosEmpty = expected.isIgnoringInfoMessages() ? true : (missingInfos.isEmpty() && extraInfos.isEmpty());
+ if (!(missingFails.isEmpty() && missingWarnings.isEmpty() && missingErrors.isEmpty() && missingWeaves.isEmpty()
+ && extraFails.isEmpty() && extraWarnings.isEmpty() && extraErrors.isEmpty() && extraWeaves.isEmpty() && infosEmpty)) {
StringBuffer failureReport = new StringBuffer(message);
failureReport.append("\n");
if (!expected.isIgnoringInfoMessages()) {
- addMissing(failureReport,"info",missingInfos);
+ addMissing(failureReport, "info", missingInfos);
}
- addMissing(failureReport,"warning",missingWarnings);
- addMissing(failureReport,"error",missingErrors);
- addMissing(failureReport,"fail",missingFails);
- addMissing(failureReport,"weaveInfo",missingWeaves);
+ addMissing(failureReport, "warning", missingWarnings);
+ addMissing(failureReport, "error", missingErrors);
+ addMissing(failureReport, "fail", missingFails);
+ addMissing(failureReport, "weaveInfo", missingWeaves);
if (!expected.isIgnoringInfoMessages()) {
- addExtra(failureReport,"info",extraInfos);
+ addExtra(failureReport, "info", extraInfos);
}
- addExtra(failureReport,"warning",extraWarnings);
- addExtra(failureReport,"error",extraErrors);
- addExtra(failureReport,"fail",extraFails);
- addExtra(failureReport,"weaveInfo",extraWeaves);
+ addExtra(failureReport, "warning", extraWarnings);
+ addExtra(failureReport, "error", extraErrors);
+ addExtra(failureReport, "fail", extraFails);
+ addExtra(failureReport, "weaveInfo", extraWeaves);
failureReport.append("\ncommand was: ajc");
String[] args = result.getArgs();
for (int i = 0; i < args.length; i++) {
@@ -473,7 +468,7 @@ public class AjcTestCase extends TestCase {
ret.add(m1);
return ret;
}
-
+
/**
* Helper method to build a new message list for passing to a MessageSpec.
*/
@@ -481,9 +476,9 @@ public class AjcTestCase extends TestCase {
List ret = new ArrayList();
ret.add(m1);
ret.add(m2);
- return ret;
+ return ret;
}
-
+
/**
* Helper method to build a new message list for passing to a MessageSpec.
*/
@@ -492,9 +487,9 @@ public class AjcTestCase extends TestCase {
ret.add(m1);
ret.add(m2);
ret.add(m3);
- return ret;
+ return ret;
}
-
+
/**
* Helper method to build a new message list for passing to a MessageSpec.
*/
@@ -508,30 +503,30 @@ public class AjcTestCase extends TestCase {
/**
* Perform a compilation and return the result.
- * @param baseDir the base directory relative to which all relative paths and
- * directories in the arguments will be interpreted.
- * @param args the compiler arguments, as you would specify on the command-line.
- * See the Ajc class for a description of the argument processing done in
- * order to run the compilation in a sandbox.
- * @see org.aspectj.tools.ajc.Ajc
+ *
+ * @param baseDir the base directory relative to which all relative paths and directories in the arguments will be interpreted.
+ * @param args the compiler arguments, as you would specify on the command-line. See the Ajc class for a description of the
+ * argument processing done in order to run the compilation in a sandbox.
+ * @see org.aspectj.tools.ajc.Ajc
*/
public CompilationResult ajc(File baseDir, String[] args) {
try {
ajc.setBaseDir(baseDir);
- args = fixupArgs(args);
+ args = fixupArgs(args);
return ajc.compile(args);
- } catch(IOException ioEx ) {
+ } catch (IOException ioEx) {
fail("IOException thrown during compilation: " + ioEx);
}
return null;
}
-
+
public File getSandboxDirectory() {
return ajc.getSandboxDirectory();
}
-
+
/**
* Indicate whether or not the sandbox should be emptied before the next compile.
+ *
* @see org.aspectj.tools.ajc.Ajc#setShouldEmptySandbox(boolean)
*/
public void setShouldEmptySandbox(boolean empty) {
@@ -541,37 +536,37 @@ public class AjcTestCase extends TestCase {
public RunResult getLastRunResult() {
return lastRunResult;
}
- public void testNothingForAntJUnit() {}
-
+
+ public void testNothingForAntJUnit() {
+ }
+
/**
- * Run the given class (main method), and return the result in a RunResult. The program runs with
- * a classpath containing the sandbox directory, runtime, testing-client, bridge, and
- * util projects (all used by the Tester class), and any jars in the sandbox.
+ * Run the given class (main method), and return the result in a RunResult. The program runs with a classpath containing the
+ * sandbox directory, runtime, testing-client, bridge, and util projects (all used by the Tester class), and any jars in the
+ * sandbox.
*/
- public RunResult run(String className){
- return run(className,new String[0],null);
+ public RunResult run(String className) {
+ return run(className, new String[0], null);
}
- public RunResult run(String className, String[] args, String classpath) {
- return run(className,args,null,false);
+ public RunResult run(String className, String[] args, String classpath) {
+ return run(className, args, null, false);
}
-
/**
- * Run the given class, and return the result in a RunResult. The program runs with
- * a classpath containing the sandbox directory, runtime, testing-client, bridge, and
- * util projects (all used by the Tester class), and any jars in the sandbox.
+ * Run the given class, and return the result in a RunResult. The program runs with a classpath containing the sandbox
+ * directory, runtime, testing-client, bridge, and util projects (all used by the Tester class), and any jars in the sandbox.
+ *
* @param args the arguments to pass to the program.
- * @param classpath the execution classpath, the sandbox directory, runtime, testing-client,
- * bridge, and util projects will all be appended to the classpath, as will any jars in
- * the sandbox.
+ * @param classpath the execution classpath, the sandbox directory, runtime, testing-client, bridge, and util projects will all
+ * be appended to the classpath, as will any jars in the sandbox.
*/
- public RunResult run(String className, String[] args, final String classpath, boolean useLTW) {
- if (args != null) {
- for (int i = 0; i < args.length; i++) {
- args[i] = substituteSandbox(args[i]);
- }
- }
+ public RunResult run(String className, String[] args, final String classpath, boolean useLTW) {
+ if (args != null) {
+ for (int i = 0; i < args.length; i++) {
+ args[i] = substituteSandbox(args[i]);
+ }
+ }
lastRunResult = null;
StringBuffer cp = new StringBuffer();
if (classpath != null) {
@@ -580,36 +575,35 @@ public class AjcTestCase extends TestCase {
cp.append(File.pathSeparator);
}
cp.append(ajc.getSandboxDirectory().getAbsolutePath());
- getAnyJars(ajc.getSandboxDirectory(),cp);
-
+ getAnyJars(ajc.getSandboxDirectory(), cp);
+
URLClassLoader sandboxLoader;
- URLClassLoader testLoader = (URLClassLoader)getClass().getClassLoader();
+ URLClassLoader testLoader = (URLClassLoader) getClass().getClassLoader();
ClassLoader parentLoader = testLoader.getParent();
-
+
/* Sandbox -> AspectJ -> Extension -> Bootstrap */
if (useLTW) {
-
+
/*
- * Create a new AspectJ class loader using the existing test CLASSPATH
- * and any missing Java 5 projects
+ * Create a new AspectJ class loader using the existing test CLASSPATH and any missing Java 5 projects
*/
URL[] testUrls = testLoader.getURLs();
URL[] java5Urls = getURLs(JAVA5_CLASSPATH_ENTRIES);
URL[] urls = new URL[testUrls.length + java5Urls.length];
- System.arraycopy(testUrls,0,urls,0,testUrls.length);
- System.arraycopy(java5Urls,0,urls,testUrls.length,java5Urls.length);
-// ClassLoader aspectjLoader = new URLClassLoader(getURLs(DEFAULT_CLASSPATH_ENTRIES),parent);
- ClassLoader aspectjLoader = new URLClassLoader(urls,parentLoader);
+ System.arraycopy(testUrls, 0, urls, 0, testUrls.length);
+ System.arraycopy(java5Urls, 0, urls, testUrls.length, java5Urls.length);
+ // ClassLoader aspectjLoader = new URLClassLoader(getURLs(DEFAULT_CLASSPATH_ENTRIES),parent);
+ ClassLoader aspectjLoader = new URLClassLoader(urls, parentLoader);
URL[] sandboxUrls = getURLs(cp.toString());
- sandboxLoader = createWeavingClassLoader(sandboxUrls,aspectjLoader);
-// sandboxLoader = createWeavingClassLoader(sandboxUrls,testLoader);
+ sandboxLoader = createWeavingClassLoader(sandboxUrls, aspectjLoader);
+ // sandboxLoader = createWeavingClassLoader(sandboxUrls,testLoader);
}
/* Sandbox + AspectJ -> Extension -> Bootstrap */
else {
cp.append(DEFAULT_CLASSPATH_ENTRIES);
URL[] urls = getURLs(cp.toString());
- sandboxLoader = new URLClassLoader(urls,parentLoader);
+ sandboxLoader = new URLClassLoader(urls, parentLoader);
}
StringBuffer command = new StringBuffer("java -classpath ");
@@ -627,67 +621,64 @@ public class AjcTestCase extends TestCase {
try {
try {
Class testerClass = sandboxLoader.loadClass("org.aspectj.testing.Tester");
- Method setBaseDir = testerClass.getDeclaredMethod("setBASEDIR",new Class[] {File.class});
- setBaseDir.invoke(null,new Object[] {ajc.getSandboxDirectory()});
+ Method setBaseDir = testerClass.getDeclaredMethod("setBASEDIR", new Class[] { File.class });
+ setBaseDir.invoke(null, new Object[] { ajc.getSandboxDirectory() });
} catch (InvocationTargetException itEx) {
- fail ("Unable to prepare org.aspectj.testing.Tester for test run: " + itEx.getTargetException());
+ fail("Unable to prepare org.aspectj.testing.Tester for test run: " + itEx.getTargetException());
} catch (Exception ex) {
- fail ("Unable to prepare org.aspectj.testing.Tester for test run: " + ex);
+ fail("Unable to prepare org.aspectj.testing.Tester for test run: " + ex);
}
- startCapture(baosErr,baosOut);
-
+ startCapture(baosErr, baosOut);
+
/* Frameworks like XML use context class loader for dynamic loading */
Thread.currentThread().setContextClassLoader(sandboxLoader);
-
+
Class toRun = sandboxLoader.loadClass(className);
- Method mainMethod = toRun.getMethod("main",new Class[] {String[].class});
- mainMethod.invoke(null,new Object[] {args});
- } catch(ClassNotFoundException cnf) {
+ Method mainMethod = toRun.getMethod("main", new Class[] { String[].class });
+ mainMethod.invoke(null, new Object[] { args });
+ } catch (ClassNotFoundException cnf) {
fail("Can't find class: " + className);
- } catch(NoSuchMethodException nsm) {
+ } catch (NoSuchMethodException nsm) {
fail(className + " does not have a main method");
} catch (IllegalAccessException illEx) {
fail("main method in class " + className + " is not public");
} catch (InvocationTargetException invTgt) {
// the main method threw an exception...
- fail("Exception thrown by " + className + ".main(String[]) :" + invTgt.getTargetException());
+ fail("Exception thrown by " + className + ".main(String[]) :" + invTgt.getTargetException());
} finally {
Thread.currentThread().setContextClassLoader(contexClassLoader);
- stopCapture(baosErr,baosOut);
- lastRunResult = new RunResult(command.toString(),new String(baosOut.toByteArray()),new String(baosErr.toByteArray()));
+ stopCapture(baosErr, baosOut);
+ lastRunResult = new RunResult(command.toString(), new String(baosOut.toByteArray()), new String(baosErr.toByteArray()));
}
return lastRunResult;
}
-
- /* Must create weaving class loader reflectively using new parent so we
- * don't have a reference to a World loaded from CLASSPATH which won't
- * be able to resolve Java 5 specific extensions and may cause
- * ClassCastExceptions
- */
- private URLClassLoader createWeavingClassLoader (URL[] urls, ClassLoader parent) {
+
+ /*
+ * Must create weaving class loader reflectively using new parent so we don't have a reference to a World loaded from CLASSPATH
+ * which won't be able to resolve Java 5 specific extensions and may cause ClassCastExceptions
+ */
+ private URLClassLoader createWeavingClassLoader(URL[] urls, ClassLoader parent) {
URLClassLoader loader = null;
-
+
try {
- Class loaderClazz = Class.forName("org.aspectj.weaver.loadtime.WeavingURLClassLoader",false,parent);
+ Class loaderClazz = Class.forName("org.aspectj.weaver.loadtime.WeavingURLClassLoader", false, parent);
Class[] parameterTypes = new Class[] { urls.getClass(), ClassLoader.class };
Object[] parameters = new Object[] { urls, parent };
Constructor constructor = loaderClazz.getConstructor(parameterTypes);
- loader = (URLClassLoader)constructor.newInstance(parameters);
- }
- catch (InvocationTargetException ex) {
+ loader = (URLClassLoader) constructor.newInstance(parameters);
+ } catch (InvocationTargetException ex) {
ex.printStackTrace();
fail("Cannot create weaving class loader: " + ex.getTargetException());
- }
- catch (Exception ex) {
+ } catch (Exception ex) {
ex.printStackTrace();
fail("Cannot create weaving class loader: " + ex.toString());
}
-
+
return loader;
}
-
- private URL[] getURLs (String classpath) {
- StringTokenizer strTok = new StringTokenizer(classpath,File.pathSeparator);
+
+ private URL[] getURLs(String classpath) {
+ StringTokenizer strTok = new StringTokenizer(classpath, File.pathSeparator);
URL[] urls = new URL[strTok.countTokens()];
try {
for (int i = 0; i < urls.length; i++) {
@@ -696,84 +687,82 @@ public class AjcTestCase extends TestCase {
} catch (Exception malEx) {
fail("Bad classpath specification: " + classpath);
}
-
+
return urls;
}
private String substituteSandbox(String classpath) {
// the longhand form of the non 1.3 API: classpath.replace("$sandbox", ajc.getSandboxDirectory().getAbsolutePath());
- while (classpath.indexOf("$sandbox")!=-1) {
+ while (classpath.indexOf("$sandbox") != -1) {
int pos = classpath.indexOf("$sandbox");
- String firstbit = classpath.substring(0,pos);
- String endbit = classpath.substring(pos+8);
- classpath = firstbit+ ajc.getSandboxDirectory().getAbsolutePath()+endbit;
+ String firstbit = classpath.substring(0, pos);
+ String endbit = classpath.substring(pos + 8);
+ classpath = firstbit + ajc.getSandboxDirectory().getAbsolutePath() + endbit;
}
return classpath;
}
-
- /**
- * Any central pre-processing of args.
- * This supplies aspectjrt.jar if available and classpath not set.
- * @param args the String[] args to fix up
- * @return the String[] args to use
- */
+
+ /**
+ * Any central pre-processing of args. This supplies aspectjrt.jar if available and classpath not set.
+ *
+ * @param args the String[] args to fix up
+ * @return the String[] args to use
+ */
protected String[] fixupArgs(String[] args) {
- if (null == args) {
- return null;
- }
- int cpIndex = -1;
- boolean hasruntime = false;
- for (int i = 0; i < args.length-1; i++) {
- args[i] = adaptToPlatform(args[i]);
- if ("-classpath".equals(args[i])) {
- cpIndex = i;
- args[i+1] = substituteSandbox(args[i+1]);
- String next = args[i+1];
- hasruntime = ((null != next)
- && (-1 != next.indexOf("aspectjrt.jar")));
- }
- }
- if (-1 == cpIndex) {
- String[] newargs = new String[args.length + 2];
- newargs[0] = "-classpath";
- newargs[1] = TestUtil.aspectjrtPath().getPath();
- System.arraycopy(args, 0, newargs, 2, args.length);
- args = newargs;
- } else {
- if (!hasruntime) {
- cpIndex++;
- String[] newargs = new String[args.length];
- System.arraycopy(args, 0, newargs, 0, args.length);
- newargs[cpIndex] = args[cpIndex] + File.pathSeparator
- + TestUtil.aspectjrtPath().getPath();
- args = newargs;
- }
- }
- return args;
- }
-
+ if (null == args) {
+ return null;
+ }
+ int cpIndex = -1;
+ boolean hasruntime = false;
+ for (int i = 0; i < args.length - 1; i++) {
+ args[i] = adaptToPlatform(args[i]);
+ if ("-classpath".equals(args[i])) {
+ cpIndex = i;
+ args[i + 1] = substituteSandbox(args[i + 1]);
+ String next = args[i + 1];
+ hasruntime = ((null != next) && (-1 != next.indexOf("aspectjrt.jar")));
+ }
+ }
+ if (-1 == cpIndex) {
+ String[] newargs = new String[args.length + 2];
+ newargs[0] = "-classpath";
+ newargs[1] = TestUtil.aspectjrtPath().getPath();
+ System.arraycopy(args, 0, newargs, 2, args.length);
+ args = newargs;
+ } else {
+ if (!hasruntime) {
+ cpIndex++;
+ String[] newargs = new String[args.length];
+ System.arraycopy(args, 0, newargs, 0, args.length);
+ newargs[cpIndex] = args[cpIndex] + File.pathSeparator + TestUtil.aspectjrtPath().getPath();
+ args = newargs;
+ }
+ }
+ return args;
+ }
+
private String adaptToPlatform(String s) {
- String ret = s.replace(';',File.pathSeparatorChar);
- //ret = ret.replace(':',File.pathSeparatorChar);
+ String ret = s.replace(';', File.pathSeparatorChar);
+ // ret = ret.replace(':',File.pathSeparatorChar);
return ret;
}
-
+
private List copyAll(List in) {
- if (in == Collections.EMPTY_LIST) return in;
-
+ if (in == Collections.EMPTY_LIST)
+ return in;
+
List out = new ArrayList();
for (Iterator iter = in.iterator(); iter.hasNext();) {
- out.add(iter.next());
+ out.add(iter.next());
}
return out;
}
-
+
/**
- * Compare the set of expected messages against the set of actual messages,
- * leaving in missingElements the set of messages that were expected but did not
- * occur, and in extraElements the set of messages that occured but were not
- * excpected
- * @param expected the expected messages
+ * Compare the set of expected messages against the set of actual messages, leaving in missingElements the set of messages that
+ * were expected but did not occur, and in extraElements the set of messages that occured but were not excpected
+ *
+ * @param expected the expected messages
* @param actual the actual messages
* @param missingElements the missing messages, when passed in must contain all of the expected messages
* @param extraElements the additional messages, when passed in must contain all of the actual messages
@@ -791,7 +780,7 @@ public class AjcTestCase extends TestCase {
}
}
- private void addMissing(StringBuffer buff,String type, List messages) {
+ private void addMissing(StringBuffer buff, String type, List messages) {
if (!messages.isEmpty()) {
buff.append("Missing expected ");
buff.append(type);
@@ -803,7 +792,7 @@ public class AjcTestCase extends TestCase {
}
}
}
-
+
private void addExtra(StringBuffer buff, String type, List messages) {
if (!messages.isEmpty()) {
buff.append("Unexpected ");
@@ -814,61 +803,66 @@ public class AjcTestCase extends TestCase {
buff.append(iter.next().toString());
buff.append("\n");
}
- }
+ }
}
-
+
// add any jars in the directory to the classpath
- private void getAnyJars(File dir,StringBuffer buff) {
+ private void getAnyJars(File dir, StringBuffer buff) {
File[] files = dir.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].getName().endsWith(".jar")) {
buff.append(File.pathSeparator);
buff.append(files[i].getAbsolutePath());
} else if (files[i].isDirectory()) {
- getAnyJars(files[i],buff);
+ getAnyJars(files[i], buff);
}
}
}
-
- private static void startCapture (OutputStream errOS, OutputStream outOS) {
+
+ private static void startCapture(OutputStream errOS, OutputStream outOS) {
delegatingErr.add(errOS);
delegatingOut.add(outOS);
delegatingErr.setVerbose(DEFAULT_ERR_VERBOSE);
delegatingOut.setVerbose(DEFAULT_OUT_VERBOSE);
}
-
- private static void stopCapture (OutputStream errOS, OutputStream outOS) {
+
+ private static void stopCapture(OutputStream errOS, OutputStream outOS) {
delegatingErr.setVerbose(true);
delegatingOut.setVerbose(true);
delegatingErr.remove(errOS);
delegatingOut.remove(outOS);
}
-
- private static boolean getBoolean (String name, boolean def) {
+
+ private static boolean getBoolean(String name, boolean def) {
String defaultValue = String.valueOf(def);
- String value = System.getProperty(name,defaultValue);
+ String value = System.getProperty(name, defaultValue);
return Boolean.valueOf(value).booleanValue();
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
ajc = new Ajc();
}
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see junit.framework.TestCase#tearDown()
*/
protected void tearDown() throws Exception {
super.tearDown();
- //ajc = null;
+ // ajc = null;
}
-
+
static {
-// new RuntimeException("*** AjcTestCase.