From: Andy Clement Date: Wed, 14 Feb 2018 22:05:31 +0000 (-0800) Subject: Fix Bug 531179 - Add compiler arg support to iajc task X-Git-Tag: V1_9_0_RC4~5 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9e4928968907207a1a0557b1db8475690d921f39;p=aspectj.git Fix Bug 531179 - Add compiler arg support to iajc task --- 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, ajc. * 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 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 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(); + } + 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 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 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