/* *******************************************************************
* Copyright (c) 2004 IBM Corporation
- * All rights reserved.
- * This program and the accompanying materials are made available
- * under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Adrian Colyer,
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Adrian Colyer,
* ******************************************************************/
package org.aspectj.tools.ajc;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
-import junit.framework.AssertionFailedError;
-
import org.aspectj.asm.AsmManager;
import org.aspectj.asm.IProgramElement;
import org.aspectj.asm.IRelationship;
import org.aspectj.bridge.AbortException;
import org.aspectj.bridge.ICommand;
import org.aspectj.bridge.IMessage;
+import org.aspectj.bridge.IMessage.Kind;
import org.aspectj.bridge.IMessageHandler;
import org.aspectj.bridge.MessageHandler;
-import org.aspectj.bridge.IMessage.Kind;
import org.aspectj.bridge.context.CompilationAndWeavingContext;
import org.aspectj.testing.util.TestUtil;
import org.aspectj.util.FileUtil;
* 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.
* </p>
- *
+ *
* @see org.aspectj.tools.ajc.AjcTestCase
*/
public class Ajc {
private static final String BUILD_OUTPUT_FOLDER = "target";
-
+
public static final String outputFolder(String module) {
return File.pathSeparator + ".." +File.separator + module + File.separator + "target" + File.separator + "classes";
}
}
return s.toString();
}
-
+
// ALSO SEE ANTSPEC AND AJCTESTCASE
- private static final String TESTER_PATH = outputFolder("testing-client") + outputFolder("runtime") + outputFolder("bcel-builder")
-// + File.pathSeparator + ".." + File.separator + "runtime" + File.separator + BUILD_OUTPUT_FOLDER //
-// + File.pathSeparator + ".." + File.separator + "aspectj5rt" + File.separator + BUILD_OUTPUT_FOLDER //
- + 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" +
-
- + outputFolder("bridge")
- + outputFolder("loadtime")
- + outputFolder("weaver")
- + outputFolder("org.aspectj.matcher")
- + outputFolder("bridge");
-// File.pathSeparator + ".." + File.separator + "bridge" + 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
-// + "org.aspectj.matcher"
-// + File.separator
-// + "bin"
-
- // 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
-// + "org.aspectj.matcher.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";
+ private static final String TESTER_PATH = outputFolder("testing-client") + outputFolder("runtime") + outputFolder("bcel-builder")
+ // + File.pathSeparator + ".." + File.separator + "runtime" + File.separator + BUILD_OUTPUT_FOLDER //
+ // + File.pathSeparator + ".." + File.separator + "aspectj5rt" + File.separator + BUILD_OUTPUT_FOLDER //
+ + 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" +
+
+ + outputFolder("bridge")
+ + outputFolder("loadtime")
+ + outputFolder("weaver")
+ + outputFolder("org.aspectj.matcher")
+ + outputFolder("bridge");
+ // File.pathSeparator + ".." + File.separator + "bridge" + 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
+ // + "org.aspectj.matcher"
+ // + File.separator
+ // + "bin"
+
+ // 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
+ // + "org.aspectj.matcher.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";
private CompilationResult result;
private File sandbox;
private int incrementalStage = 10;
private boolean shouldEmptySandbox = true;
private final AjcCommandController controller;
- private static boolean verbose = System.getProperty("org.aspectj.tools.ajc.Ajc.verbose", "true").equals("true");
+ public static boolean verbose = System.getProperty("org.aspectj.tools.ajc.Ajc.verbose", "true").equals("true");
/**
* Constructs a new Ajc instance, with a new AspectJ compiler inside.
* </p>
* <p>
* For example, given a baseDir of "tests/pr12345" and a compile command: "ajc src/A.java src/B.java", the files in
- *
+ *
* <pre>
* tests/pr12345/
* src/
* A.java
* B.java
* </pre>
- *
+ *
* are copied to:
- *
+ *
* <pre>
* ajcSandbox/ajcTestxxx.tmp/
* src/
* <ul>
* </ul>
* </p>
- *
+ *
* @param args The compiler arguments.
* @return a CompilationResult object with all the messages produced by the compiler, a description of the ajc command that was
* issued, and the standard output and error of the compile (excluding messages which are provided separately)
* Throws an IllegalStateException if you try and call this method without first doing a compile that specified the -incremental
* option.
* </p>
- *
+ *
* @return A CompilationResult giving the results of the most recent increment.
* @throws IOException
*/
String relativeToPath = (fromParent != null) ? (fromParent.getPath() + File.separator) : "";
if (baseDir != null) {
from = new File(baseDir, from.getPath());
-// if (ensureDirsExist) {
-// File toMkdir = (ret.getPath().endsWith(".jar") || ret.getPath().endsWith(".zip"))?ret.getParentFile():ret;
-// toMkdir.mkdirs();
-// }
+ // if (ensureDirsExist) {
+ // File toMkdir = (ret.getPath().endsWith(".jar") || ret.getPath().endsWith(".zip"))?ret.getParentFile():ret;
+ // toMkdir.mkdirs();
+ // }
}
if (!from.exists())
return ret;
if (from.isFile()) {
final String prefix = from.getName().substring(0, from.getName().lastIndexOf('.'));
String[] toCopy = from.getParentFile().list(new FilenameFilter() {
+ @Override
public boolean accept(File dir, String name) {
if (name.indexOf('.') == -1)
return false;
/*
* (non-Javadoc)
- *
+ *
* @see org.aspectj.tools.ajc.Main.CommandController#doRepeatCommand()
*/
+ @Override
boolean doRepeatCommand(ICommand command) {
this.command = command;
return false; // ensure that control returns to caller
/*
* (non-Javadoc)
- *
+ *
* @see org.aspectj.tools.ajc.Main.CommandController#running()
*/
+ @Override
public boolean running() {
return false; // so that we can come back for more...
}
class AbortInterceptor implements IMessageHandler {
+ @Override
public boolean handleMessage(IMessage message) throws AbortException {
if (message.getKind() == IMessage.ABORT) {
System.err.println("***** Abort Message Received ******");
return false;
}
+ @Override
public boolean isIgnoring(Kind kind) {
if (kind != IMessage.ABORT)
return true;
return false;
}
+ @Override
public void dontIgnore(Kind kind) {
}
+ @Override
public void ignore(Kind kind) {
}
}
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
cp.append(TestUtil.aspectjrtPath().getPath()).append(File.pathSeparator);
}
String command = LangUtil.getJavaExecutable().getAbsolutePath() + " " +vmargs+ (cp.length()==0?"":" -classpath " + cp) + " -p "+mp+" --module "+moduleName ;
- System.out.println("Command is "+command);
+ if (Ajc.verbose) {
+ System.out.println("Command is "+command);
+ }
// Command is executed using ProcessBuilder to allow setting CWD for ajc sandbox compliance
ProcessBuilder pb = new ProcessBuilder(tokenizeCommand(command));
pb.directory( new File(ajc.getSandboxDirectory().getAbsolutePath()));
cp.append(File.pathSeparator).append(TestUtil.aspectjrtPath().getPath());
}
String command = LangUtil.getJavaExecutable().getAbsolutePath() + " " +vmargs+ (cp.length()==0?"":" -classpath " + cp) + " " + className ;
- System.out.println("Command is "+command);
+ if (Ajc.verbose) {
+ System.out.println("\nCommand is "+command);
+ }
// Command is executed using ProcessBuilder to allow setting CWD for ajc sandbox compliance
ProcessBuilder pb = new ProcessBuilder(tokenizeCommand(command));
pb.directory( new File(ajc.getSandboxDirectory().getAbsolutePath()));
Class<?> toRun = sandboxLoader.loadClass(className);
Method mainMethod = toRun.getMethod("main", new Class[] { String[].class });
+
mainMethod.invoke(null, new Object[] { args });
} catch (ClassNotFoundException cnf) {
fail("Can't find class: " + className);
PrintWriter stdOutWriter = new PrintWriter(baosOut);
PrintWriter stdErrWriter = new PrintWriter(baosErr);
+ if (Ajc.verbose) {
+ System.out.println();
+ }
while ((line = stdInput.readLine()) != null) {
stdOutWriter.println(line);
- System.out.println(line);
+ if (Ajc.verbose) {
+ System.out.println(line);
+ }
}
stdOutWriter.flush();
while ((line = stdError.readLine()) != null) {
stdErrWriter.println(line);
- System.err.println(line);
-
+ if (Ajc.verbose) {
+ System.err.println(line);
+ }
}
stdErrWriter.flush();
/* *******************************************************************
* Copyright (c) 2004 IBM Corporation
- * All rights reserved.
- * This program and the accompanying materials are made available
- * under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Adrian Colyer,
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Adrian Colyer,
* ******************************************************************/
package org.aspectj.tools.ajc;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
import org.aspectj.bridge.IMessage;
/**
* Utility class that makes the results of a compiler run available.
* <p>
- * Instances of this class are returned by the Ajc.compile() and
+ * Instances of this class are returned by the Ajc.compile() and
* doIncrementalCompile() methods (and the AjcTestCase.ajc() wrapper).
* </p>
* <p>
* </p>
*/
public class CompilationResult {
-
+
private String[] args;
private String stdOut;
private String stdErr;
/**
* Build a compilation result - called by the Ajc.compile and
* Ajc.doIncrementalCompile methods. Should be no need for you
- * to construct an instance yourself.
+ * to construct an instance yourself.
*/
protected CompilationResult(
String[] args,
this.stdErr = stdErr;
this.infoMessages = (infoMessages == null) ? Collections.<IMessage>emptyList() : infoMessages;
this.errorMessages = (errorMessages == null) ? Collections.<IMessage>emptyList() : errorMessages;
- this.warningMessages = (warningMessages == null) ? Collections.<IMessage>emptyList() : warningMessages;
- this.failMessages = (failMessages == null) ? Collections.<IMessage>emptyList() : failMessages;
- this.weaveMessages = (weaveMessages == null) ? Collections.<IMessage>emptyList() : weaveMessages;
+ this.warningMessages = (warningMessages == null) ? Collections.<IMessage>emptyList() : warningMessages;
+ this.failMessages = (failMessages == null) ? Collections.<IMessage>emptyList() : failMessages;
+ this.weaveMessages = (weaveMessages == null) ? Collections.<IMessage>emptyList() : weaveMessages;
}
-
+
/**
* The arguments that were passed to the compiler.
*/
public String[] getArgs() { return args; }
/**
- * The standard output written by the compiler, excluding any messages.
+ * The standard output written by the compiler, excluding any messages.
*/
public String getStandardOutput() { return stdOut; }
/**
- * The standard error written by the compiler, excluding any messages.
+ * The standard error written by the compiler, excluding any messages.
*/
public String getStandardError() { return stdErr; }
-
+
/**
* True if the compiler issued any messages of any kind.
*/
* True if the compiler issued one or more weave info messages.
*/
public boolean hasWeaveMessages() { return !weaveMessages.isEmpty(); }
-
+
/**
* The informational messages produced by the compiler. The list
* entries are the <code>IMessage</code> objects created during the
* @see org.aspectj.tools.ajc.AjcTestCase
*/
public List<IMessage> getFailMessages() { return failMessages; }
-
+
public List<IMessage> getWeaveMessages() { return weaveMessages; }
-
+
/**
* Returns string containing message count summary, list of messages
* by type, and the actual ajc compilation command that was issued.
buff.append(" fail, )");
buff.append(weaveMessages.size());
buff.append(" weaveInfo");
- }
+ }
buff.append("\n");
int msgNo = 1;
for (IMessage failMessage : failMessages) {