package org.aspectj.tools.ant.taskdefs;
+import java.io.File;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Location;
import org.apache.tools.ant.Project;
import org.aspectj.tools.ajc.Main.MessagePrinter;
import org.aspectj.util.FileUtil;
-import java.io.File;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.StringTokenizer;
-import java.util.Vector;
-
/**
* Main taskdef class for the AspectJ 1.0 compiler, <code>ajc</code>.
* See the README and examples/build.xml for more information.
*/
public class Ajc10 extends MatchingTask {
- private static final List VALID_XOPTIONS;
+ private static final List<String> VALID_XOPTIONS;
static {
String[] xs = new String[]
{ "lint", "serializableAspects", "targetNearSource", "OcodeSize",
// ------------------------- operational methods
- public void execute() throws BuildException {
+ @Override
+ public void execute() throws BuildException {
if (srcdir == null && argfiles == null) {
throw new BuildException("one of srcdir or argfiles must be set!",
location);
private static final int MAX_COMMANDLINE = 4096;
private static final File DEFAULT_DESTDIR = new File(".") {
+ @Override
public String toString() {
return "(no destination dir specified)";
}
private File xweaveDir;
private String xdoneSignal;
+ private List<CompilerArg> compilerArgs;
+
// ----- added by adapter - integrate better?
private List /* File */adapterFiles;
private String[] adapterArguments;
// need declare for "all fields initialized in ..."
adapterArguments = null;
adapterFiles = new ArrayList();
+ compilerArgs = null;
argfiles = null;
inxmlfiles = null;
executing = false;
public void setProcessor(String processors) {
cmd.addFlagged("-processor", processors);
}
-
+
/**
* -processorpath path
* Specify where to find annotation processors; if this option is not used, the class path will be searched for processors.
public Commandline.Argument createJvmarg() {
return this.javaCmd.createVmArgument();
}
+
+ public static class CompilerArg {
+
+ private String value;
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return value;
+ }
+ }
+
+ public CompilerArg createCompilerarg() {
+ CompilerArg compilerArg = new CompilerArg();
+ if (compilerArgs == null) {
+ compilerArgs = new ArrayList<CompilerArg>();
+ }
+ compilerArgs.add(compilerArg);
+ return compilerArg;
+ }
// ----------------
public void setTagFile(File file) {
*
* @exception BuildException if the compilation has problems or if there were compiler errors and failonerror is true.
*/
+ @Override
public void execute() throws BuildException {
this.logger = new TaskLogger(this);
if (executing) {
Main newmain = new Main();
newmain.setHolder(holder);
newmain.setCompletionRunner(new Runnable() {
+ @Override
public void run() {
doCompletionTasks();
}
// ------------------------------ setup and reporting
/** @return null if path null or empty, String rendition otherwise */
- protected static void addFlaggedPath(String flag, Path path, List list) {
+ protected static void addFlaggedPath(String flag, Path path, List<String> list) {
if (!LangUtil.isEmpty(flag) && ((null != path) && (0 < path.size()))) {
list.add(flag);
list.add(path.toString());
/**
* Add to list any path or plural arguments.
*/
- protected void addListArgs(List list) throws BuildException {
+ protected void addListArgs(List<String> list) throws BuildException {
addFlaggedPath("-classpath", classpath, list);
addFlaggedPath("-bootclasspath", bootclasspath, list);
addFlaggedPath("-extdirs", extdirs, list);
addFlaggedPath("-injars", injars, list);
addFlaggedPath("-inpath", inpath, list);
addFlaggedPath("-sourceroots", sourceRoots, list);
+
+ if (this.compilerArgs != null) {
+ for (CompilerArg compilerArg:compilerArgs) {
+ list.add(compilerArg.toString());
+ }
+ }
if (argfiles != null) {
String[] files = argfiles.list();
*
* @see org.aspectj.bridge.IMessageHandler#handleMessage(org.aspectj.bridge.IMessage)
*/
+ @Override
public boolean handleMessage(IMessage message) throws AbortException {
Kind messageKind = message.getKind();
String messageText = message.toString();
*
* @see org.aspectj.bridge.IMessageHandler#isIgnoring(org.aspectj.bridge.IMessage.Kind)
*/
+ @Override
public boolean isIgnoring(Kind kind) {
return false;
}
*
* @see org.aspectj.bridge.IMessageHandler#dontIgnore(org.aspectj.bridge.IMessage.Kind)
*/
+ @Override
public void dontIgnore(Kind kind) {
}
*
* @see org.aspectj.bridge.IMessageHandler#ignore(org.aspectj.bridge.IMessage.Kind)
*/
+ @Override
public void ignore(Kind kind) {
}
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
-import junit.framework.TestCase;
-
import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildListener;
import org.aspectj.bridge.IMessageHolder;
import org.aspectj.bridge.MessageHandler;
import org.aspectj.bridge.MessageUtil;
+import org.aspectj.tools.ant.taskdefs.AjcTask.CompilerArg;
import org.aspectj.util.FileUtil;
import org.aspectj.util.LangUtil;
+import junit.framework.TestCase;
+
/**
* AjcTask test cases.
* Please put new ones with others between ------- comments.
testdataDir = null;
}
PICK_CLASS_FILES = new FileFilter() {
+ @Override
public boolean accept(File file) {
return (
(null != file)
super(name);
}
+ @Override
public void tearDown() {
deleteTempDir();
MESSAGES.setLength(0);
public static class InfoHolder extends MessageHandler {
public InfoHolder() {
}
- public boolean handleMessage(IMessage message) {
+ @Override
+ public boolean handleMessage(IMessage message) {
if (0 == IMessage.INFO.compareTo(message.getKind())) {
AjcTaskTest.collectMessage(message.getMessage());
}
public static class Holder extends MessageHandler {
public Holder() {
}
- public boolean handleMessage(IMessage message) {
+ @Override
+ public boolean handleMessage(IMessage message) {
IMessage.Kind kind = message.getKind();
if (IMessage.ERROR.isSameOrLessThan(kind)) {
String m = kind.toString();
"expecting aspectj in classpath",
(-1 != classpath.indexOf("aspectjrt.jar")));
}
+
+ CompilerArg createCompilerArg(String value) {
+ CompilerArg c = new CompilerArg();
+ c.setValue(value);
+ return c;
+ }
+
+ public void testAddModulesJ9() {
+ AjcTask task = getTask(NOFILE);
+ task.createCompilerarg().setValue("--add-modules");
+ task.createCompilerarg().setValue("java.xml.bind,java.io");
+ String[] cmd = task.makeCommand();
+ System.out.println(Arrays.toString(cmd));
+ int addModulesPos = findOptionPosition(cmd,"--add-modules");
+ assertNotSame(-1, addModulesPos);
+ assertEquals("java.xml.bind,java.io",cmd[addModulesPos+1]);
+ }
+
+ private int findOptionPosition(String[] cmd, String optionString) {
+ for (int i=0;i<cmd.length;i++) {
+ if (cmd[i].equals(optionString)) {
+ return i;
+ }
+ }
+ return -1;
+ }
// ---------------------------------------- sourcefile
// XXX need to figure out how to specify files directly programmatically
private LogListener(int priority) {
this.priority = priority;
}
- public void buildFinished(BuildEvent event) {}
- public void buildStarted(BuildEvent event) {}
- public void messageLogged(BuildEvent event) {
+ @Override
+ public void buildFinished(BuildEvent event) {}
+ @Override
+ public void buildStarted(BuildEvent event) {}
+ @Override
+ public void messageLogged(BuildEvent event) {
if (priority == event.getPriority()) {
results.add(event.getMessage());
}
}
- public void targetFinished(BuildEvent event) {}
- public void targetStarted(BuildEvent event) {}
- public void taskFinished(BuildEvent event) {}
- public void taskStarted(BuildEvent event) {}
+ @Override
+ public void targetFinished(BuildEvent event) {}
+ @Override
+ public void targetStarted(BuildEvent event) {}
+ @Override
+ public void taskFinished(BuildEvent event) {}
+ @Override
+ public void taskStarted(BuildEvent event) {}
String[] getResults() {
return (String[]) results.toArray(new String[0]);
}
class SnoopingCommandEditor implements ICommandEditor {
private static final String[] NONE = new String[0];
String[] lastCommand;
+ @Override
public String[] editCommand(String[] command) {
lastCommand = (String[]) LangUtil.safeCopy(command, NONE);
return command;
}
class VerboseCommandEditor implements ICommandEditor {
public static final String VERBOSE = "-verbose";
+ @Override
public String[] editCommand(String[] command) {
for (int i = 0; i < command.length; i++) {
if (VERBOSE.equals(command[i])) {
this.suffix = suffix;
}
+ @Override
public String[] editCommand(String[] command) {
int len = command.length + prefix.length + suffix.length;
String[] result = new String[len];