aboutsummaryrefslogtreecommitdiffstats
path: root/taskdefs
diff options
context:
space:
mode:
authorAndy Clement <aclement@pivotal.io>2018-02-14 14:05:31 -0800
committerAndy Clement <aclement@pivotal.io>2018-02-14 14:05:31 -0800
commit9e4928968907207a1a0557b1db8475690d921f39 (patch)
treed9407df7a8f606443c81fc8145ff2f3e8c3a7357 /taskdefs
parent323a9c2b24df0aa92dc40137de98e106f9dc18ea (diff)
downloadaspectj-9e4928968907207a1a0557b1db8475690d921f39.tar.gz
aspectj-9e4928968907207a1a0557b1db8475690d921f39.zip
Fix Bug 531179 - Add compiler arg support to iajc task
Diffstat (limited to 'taskdefs')
-rw-r--r--taskdefs/src/org/aspectj/tools/ant/taskdefs/Ajc10.java25
-rw-r--r--taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java49
-rw-r--r--taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java63
3 files changed, 111 insertions, 26 deletions
diff --git a/taskdefs/src/org/aspectj/tools/ant/taskdefs/Ajc10.java b/taskdefs/src/org/aspectj/tools/ant/taskdefs/Ajc10.java
index 686b3b75a..065f44e71 100644
--- a/taskdefs/src/org/aspectj/tools/ant/taskdefs/Ajc10.java
+++ b/taskdefs/src/org/aspectj/tools/ant/taskdefs/Ajc10.java
@@ -12,6 +12,16 @@
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;
@@ -28,23 +38,13 @@ import org.aspectj.tools.ajc.Main;
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",
@@ -398,7 +398,8 @@ public class Ajc10 extends MatchingTask {
// ------------------------- 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);
diff --git a/taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java b/taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java
index e5e726add..1bbab168a 100644
--- a/taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java
+++ b/taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java
@@ -227,6 +227,7 @@ public class AjcTask extends MatchingTask {
private static final int MAX_COMMANDLINE = 4096;
private static final File DEFAULT_DESTDIR = new File(".") {
+ @Override
public String toString() {
return "(no destination dir specified)";
}
@@ -326,6 +327,8 @@ public class AjcTask extends MatchingTask {
private File xweaveDir;
private String xdoneSignal;
+ private List<CompilerArg> compilerArgs;
+
// ----- added by adapter - integrate better?
private List /* File */adapterFiles;
private String[] adapterArguments;
@@ -390,6 +393,7 @@ public class AjcTask extends MatchingTask {
// need declare for "all fields initialized in ..."
adapterArguments = null;
adapterFiles = new ArrayList();
+ compilerArgs = null;
argfiles = null;
inxmlfiles = null;
executing = false;
@@ -481,7 +485,7 @@ public class AjcTask extends MatchingTask {
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.
@@ -694,6 +698,33 @@ public class AjcTask extends MatchingTask {
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) {
@@ -1076,6 +1107,7 @@ public class AjcTask extends MatchingTask {
*
* @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) {
@@ -1273,6 +1305,7 @@ public class AjcTask extends MatchingTask {
Main newmain = new Main();
newmain.setHolder(holder);
newmain.setCompletionRunner(new Runnable() {
+ @Override
public void run() {
doCompletionTasks();
}
@@ -1480,7 +1513,7 @@ public class AjcTask extends MatchingTask {
// ------------------------------ 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());
@@ -1490,7 +1523,7 @@ public class AjcTask extends MatchingTask {
/**
* 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);
@@ -1498,6 +1531,12 @@ public class AjcTask extends MatchingTask {
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();
@@ -2070,6 +2109,7 @@ public class AjcTask extends MatchingTask {
*
* @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();
@@ -2104,6 +2144,7 @@ public class AjcTask extends MatchingTask {
*
* @see org.aspectj.bridge.IMessageHandler#isIgnoring(org.aspectj.bridge.IMessage.Kind)
*/
+ @Override
public boolean isIgnoring(Kind kind) {
return false;
}
@@ -2113,6 +2154,7 @@ public class AjcTask extends MatchingTask {
*
* @see org.aspectj.bridge.IMessageHandler#dontIgnore(org.aspectj.bridge.IMessage.Kind)
*/
+ @Override
public void dontIgnore(Kind kind) {
}
@@ -2121,6 +2163,7 @@ public class AjcTask extends MatchingTask {
*
* @see org.aspectj.bridge.IMessageHandler#ignore(org.aspectj.bridge.IMessage.Kind)
*/
+ @Override
public void ignore(Kind kind) {
}
diff --git a/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java b/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java
index 6d88baf44..f7f3908c3 100644
--- a/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java
+++ b/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java
@@ -27,8 +27,6 @@ import java.util.Arrays;
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;
@@ -40,9 +38,12 @@ import org.aspectj.bridge.IMessage;
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.
@@ -85,6 +86,7 @@ public class AjcTaskTest extends TestCase {
testdataDir = null;
}
PICK_CLASS_FILES = new FileFilter() {
+ @Override
public boolean accept(File file) {
return (
(null != file)
@@ -160,6 +162,7 @@ public class AjcTaskTest extends TestCase {
super(name);
}
+ @Override
public void tearDown() {
deleteTempDir();
MESSAGES.setLength(0);
@@ -240,7 +243,8 @@ public class AjcTaskTest extends TestCase {
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());
}
@@ -252,7 +256,8 @@ public class AjcTaskTest extends TestCase {
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();
@@ -692,6 +697,32 @@ public class AjcTaskTest extends TestCase {
"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
@@ -1007,17 +1038,24 @@ public class AjcTaskTest extends TestCase {
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]);
}
@@ -1026,6 +1064,7 @@ public class AjcTaskTest extends TestCase {
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;
@@ -1036,6 +1075,7 @@ class SnoopingCommandEditor implements ICommandEditor {
}
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])) {
@@ -1065,6 +1105,7 @@ class AppendingCommandEditor implements ICommandEditor {
this.suffix = suffix;
}
+ @Override
public String[] editCommand(String[] command) {
int len = command.length + prefix.length + suffix.length;
String[] result = new String[len];