return "null javac";
} else if (null == destDir) {
destDir = javac.getDestdir();
- if (null == destDir) {
- destDir = new File(".");
- }
}
// no null checks b/c AjcTask handles null input gracefully
ajc.setProject(javac.getProject());
ajc.setTarget(javac.getTarget());
ajc.setSource(javac.getSource());
ajc.setEncoding(javac.getEncoding());
- ajc.setDestdir(destDir);
+ if (DEFAULT_DESTDIR != destDir) {
+ ajc.setDestdir(destDir);
+ }
ajc.setBootclasspath(javac.getBootclasspath());
ajc.setExtdirs(javac.getExtdirs());
ajc.setClasspath(javac.getClasspath());
*/
private static final int MAX_COMMANDLINE = 4096;
- private static final File DEFAULT_DESTDIR = new File(".");
+ private static final File DEFAULT_DESTDIR = new File(".") {
+ public String toString() {
+ return "AjcTask.DEFAULT_DESTDIR";
+ }
+ };
/** do not throw BuildException on fail/abort message with usage */
private static final String USAGE_SUBSTRING = "AspectJ-specific options";
* @see org.aspectj.weaver.Lint
*/
private static final List VALID_XLINT;
-
+
+ public static final String COMMAND_EDITOR_NAME
+ = AjcTask.class.getName() + ".COMMAND_EDITOR";
+
+ private static final ICommandEditor COMMAND_EDITOR;
+
static {
String[] xs = new String[]
{ "serializableAspects", "incrementalFile"
xs = new String[] { "error", "warning", "ignore"};
VALID_XLINT = Collections.unmodifiableList(Arrays.asList(xs));
-
+
+ ICommandEditor editor = null;
+ try {
+ String editorClassName = System.getProperty(COMMAND_EDITOR_NAME);
+ if (null != editorClassName) {
+ ClassLoader cl = AjcTask.class.getClassLoader();
+ Class editorClass = cl.loadClass(editorClassName);
+ editor = (ICommandEditor) editorClass.newInstance();
+ }
+ } catch (Throwable t) {
+ System.err.println("Warning: unable to load command editor");
+ t.printStackTrace(System.err);
+ }
+ COMMAND_EDITOR = editor;
}
// ---------------------------- state and Ant interface thereto
private boolean verbose;
private String[] adapterArguments;
private IMessageHolder messageHolder;
+ private ICommandEditor commandEditor;
// -------- resource-copying
/** true if copying injar non-.class files to the output jar */
throw new BuildException(m, t);
}
}
-
+
+ /** direct API for testing */
+ public void setCommandEditor(ICommandEditor editor) {
+ this.commandEditor = editor;
+ }
+
+ /**
+ * Setup command-line filter.
+ * To do this staticly, define the environment variable
+ * <code>org.aspectj.tools.ant.taskdefs.AjcTask.COMMAND_EDITOR</code>
+ * with the <code>className</code> parameter.
+ * @param className the String fully-qualified-name of a class
+ * reachable from this object's class loader,
+ * implementing ICommandEditor, and
+ * having a public no-argument constructor.
+ * @throws BuildException if unable to create instance of className
+ */
+ public void setCommandEditorClass(String className) { // skip Ant interface?
+ try {
+ Class mclass = Class.forName(className);
+ setCommandEditor((ICommandEditor) mclass.newInstance());
+ } catch (Throwable t) {
+ String m = "unable to instantiate command editor: " + className;
+ throw new BuildException(m, t);
+ }
+ }
//---------------------- Path lists
/**
result.addAll(cmd.extractArguments());
addListArgs(result);
- return (String[]) result.toArray(new String[0]);
+
+ String[] command = (String[]) result.toArray(new String[0]);
+ if (null != commandEditor) {
+ command = commandEditor.editCommand(command);
+ } else if (null != COMMAND_EDITOR) {
+ command = COMMAND_EDITOR.editCommand(command);
+ }
+ return command;
}
/**
* @throw BuildException if options conflict
*/
protected void verifyOptions() {
+ StringBuffer sb = new StringBuffer();
if (fork && isInIncrementalMode() && !isInIncrementalFileMode()) {
- String m = "can fork incremental only using tag file";
- throw new BuildException(m);
+ sb.append("can fork incremental only using tag file.\n");
+ }
+
+ if ((null == outjar) && (DEFAULT_DESTDIR == destDir)) {
+ final String REQ = " requires dest dir or output jar.\n";\r if (copyInjars) {
+ sb.append("copyInjars");
+ sb.append(REQ);
+ }
+ if (null != sourceRootCopyFilter) {
+ sb.append("sourceRootCopyFilter");
+ sb.append(REQ);
+ }
+ }
+ if (0 < sb.length()) {
+ throw new BuildException(sb.toString());
}
-
}
/**
private void completeDestdir() {
if (!copyInjars && (null == sourceRootCopyFilter)) {
return;
- } else if (!destDir.canWrite()) {
+ } else if ((destDir == DEFAULT_DESTDIR)
+ || !destDir.canWrite()) {
String s = "unable to copy resources to destDir: " + destDir;
throw new BuildException(s);
}
MESSAGES.setLength(0);
}
+ public void testNullDestDir() {
+ AjcTask task = getTask(NOFILE, null);
+ String[] cmd = task.makeCommand();
+
+ for (int i = 0; i < cmd.length; i++) {
+ assertTrue(!"-d".equals(cmd[i]));
+ }
+ }
+
+ public void testOutputRequirement() {
+ AjcTask task = getTask("default.lst");
+ checkRun(task, null);
+
+ task = getTask("default.lst", null);
+ task.setCopyInjars(true);
+ checkRun(task, "copyInjars");
+
+ task = getTask("default.lst", null);
+ task.setSourceRootCopyFilter("*.java");
+ checkRun(task, "sourceRoot");
+ }
+
+ private void checkRun(AjcTask task, String exceptionString) {
+ try {
+ task.execute();
+ assertTrue(null == exceptionString);
+ } catch (BuildException e) {
+ if(-1 == e.getMessage().indexOf(exceptionString)) {
+ assertEquals(exceptionString, e.getMessage());
+ }
+ }
+
+ }
+
+ public void testCommandEditor() {
+ String className = VerboseCommandEditor.class.getName();
+ System.setProperty(AjcTask.COMMAND_EDITOR_NAME, className);
+ assertEquals(className,
+ System.getProperty(AjcTask.COMMAND_EDITOR_NAME));
+ AjcTask task = getTask(NOFILE);
+ task.setCommandEditor(new VerboseCommandEditor());
+ String[] cmd = task.makeCommand();
+ assertEquals(VerboseCommandEditor.VERBOSE, cmd[0]);
+
+ task = getTask(NOFILE);
+ task.setCommandEditorClass(VerboseCommandEditor.class.getName());
+ cmd = task.makeCommand();
+ assertEquals(VerboseCommandEditor.VERBOSE, cmd[0]);
+ }
+// public void testStaticCommandEditor() {
+// // XXX need to test COMMAND_EDITOR, but can't require property when run
+// }
+
public void testLimitTo() {
int numArgs = 100;
String arg = "123456789";
}
protected AjcTask getTask(String input) {
+ return getTask(input, getTempDir());
+ }
+
+ protected AjcTask getTask(String input, File destDir) {
AjcTask task = new AjcTask();
Project p = new Project();
task.setProject(p);
- task.setDestdir(getTempDir());
+ if (null != destDir) {
+ task.setDestdir(destDir);
+ }
if (NOFILE.equals(input)) {
// add nothing
} else if (input.endsWith(".lst")) {
}
}
task.setClasspath(new Path(p, "../lib/test/aspectjrt.jar"));
- task.setVerbose(true); // XXX
+ //task.setVerbose(true);
return task;
}
}
}
}
+
+class VerboseCommandEditor implements ICommandEditor {
+ public static final String VERBOSE = "-verbose";
+ public String[] editCommand(String[] command) {
+ for (int i = 0; i < command.length; i++) {
+ if (VERBOSE.equals(command[i])) {
+ return command;
+ }
+ }
+
+ String[] result = new String[1+command.length];
+ result[0] = VERBOSE;
+ System.arraycopy(result, 1, command, 0, command.length);
+ return result;
+ }
+}
+
+class AppendingCommandEditor implements ICommandEditor {
+ private static String[] NONE = new String[0];
+ public static ICommandEditor VERBOSE =
+ new AppendingCommandEditor(new String[] {"-verbose"}, NONE);
+ public static ICommandEditor INVALID =
+ new AppendingCommandEditor(NONE, new String[] {"-invalidOption"});
+
+ final String[] prefix;
+ final String[] suffix;
+
+ public AppendingCommandEditor(String[] prefix, String[] suffix) {
+ this.prefix = prefix;
+ this.suffix = suffix;
+ }
+
+ public String[] editCommand(String[] command) {
+ int len = command.length + prefix.length + suffix.length;
+ String[] result = new String[len];
+ System.arraycopy(result, 0, prefix, 0, prefix.length);
+ System.arraycopy(result, prefix.length, command, 0, command.length);
+ System.arraycopy(result, prefix.length + command.length, suffix, 0, suffix.length);
+ return result;
+ }
+}