diff options
author | wisberg <wisberg> | 2002-12-16 17:58:19 +0000 |
---|---|---|
committer | wisberg <wisberg> | 2002-12-16 17:58:19 +0000 |
commit | d842c4f1139629c1f062b74ba818d233b2c31043 (patch) | |
tree | 842d3871620bc0eb60edcd95e55804d67e0f61fa /taskdefs | |
parent | 3ce247199704eae6b2c92c6e38c69584e3250c52 (diff) | |
download | aspectj-d842c4f1139629c1f062b74ba818d233b2c31043.tar.gz aspectj-d842c4f1139629c1f062b74ba818d233b2c31043.zip |
initial version
Diffstat (limited to 'taskdefs')
17 files changed, 3432 insertions, 0 deletions
diff --git a/taskdefs/src/org/aspectj/tools/ant/taskdefs/Ajc10.java b/taskdefs/src/org/aspectj/tools/ant/taskdefs/Ajc10.java new file mode 100644 index 000000000..7c79d0284 --- /dev/null +++ b/taskdefs/src/org/aspectj/tools/ant/taskdefs/Ajc10.java @@ -0,0 +1,641 @@ +/* ******************************************************************* + * Copyright (c) 2000-2001 Xerox Corporation. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + +package org.aspectj.tools.ant.taskdefs; + +import org.apache.tools.ant.*; +import org.apache.tools.ant.types.*; +import org.apache.tools.ant.types.Path; +import org.aspectj.bridge.AbortException; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.IMessageHolder; +import org.aspectj.bridge.MessageHandler; +import org.aspectj.bridge.MessageUtil; +import org.aspectj.tools.ajc.Main; +import org.apache.tools.ant.taskdefs.*; +import org.apache.tools.ant.taskdefs.compilers.*; +import java.io.*; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.Vector; +import java.util.Iterator; +import java.util.ArrayList; +import java.util.StringTokenizer; +import java.lang.reflect.*; +import java.net.*; + +/** + * 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; + static { + String[] xs = new String[] + { "lint", "serializableAspects", "targetNearSource", "OcodeSize", + "incrementalFile" }; + VALID_XOPTIONS = Collections.unmodifiableList(Arrays.asList(xs)); + } + //protected boolean version; + protected boolean source14; + protected Set ignoredOptions; + protected Commandline cmd; + protected Commandline vmcmd; + private int threads = -1; + private File destdir; + private File workingdir; + private Path internalclasspath; + private Path classpath; + private Path bootclasspath; + private Path extdirs; + private Path srcdir; + private List argfiles; + private boolean fork; + private boolean failonerror; + private String encoding; + private String source; + + public Ajc10() { + reset(); + } + + // ------------------------- options + // find option types and whether ignored: + // sed -n '/void set/p' Ajc.java | sed 's/.*\/\/ //' | sort -u + // sed -n '/ignoredOptions/d;/ignored/p' Ajc.java + // each option may be "ignored" and is one+ of: + // ajc-old used to be an ajc option + // ajc-only only an option for ajc, not javac + // ajc-taskdef only only an option for ajc taskdef, not ajc + // javac-also also an option in javac + // eajc-also + + // ------------------------- options in order per ajc output + + public void setVerbose(boolean verbose) { // javac-also eajc-also docDone + setif(verbose, "-verbose"); + } + + public void setVersion(boolean version) { // javac-also eajc-also docDone + // let the compiler handle it + if (version) { + setif(true, "-version"); + } + //this.version = version; + } + + public void setNocomments(boolean nocomments) { // ajc-only not-eajc docDone + if (nocomments) { + ignore("-nocomments"); + } + //setif(nocomments, "-nocomments"); + } + + public void setEmacssym(boolean input) { // ajc-only eajc-also docDone + setif(input, "-emacssym"); + } + + public void setUsejavac(boolean input) { // ajc-only not-eajc docDone + if (input) { + ignore("-usejavac"); + } + //setif(input, "-usejavac"); + } + + public void setPreprocess(boolean preprocess) { // ajc-only not-eajc docDone + if (preprocess) { + ignore("-preprocess"); + //setif(preprocess, "-preprocess"); + } + } + + public void setWorkingdir(String workingdir) { // ajc-only not-eajc ocDone + ignore("-workingdir"); + //this.workingdir = project.resolveFile(workingdir); + } + + public void setDestdir(String destdir) { // javac-also eajc-also docDone + this.destdir = project.resolveFile(destdir); + } + + public void setOptimize(boolean optimize) { // javac-also ignored docDone + setif(optimize, "-O"); + } + + + public void setClasspath(Path classpath) { // javac-also eajc-also docDone + if (this.classpath == null) { + this.classpath = classpath; + } else { + this.classpath.append(classpath); + } + } + public Path createClasspath() { // javac-also docDone + if (classpath == null) { + classpath = new Path(project); + } + return classpath.createPath(); + } + + public void setClasspathref(Reference classpathref) { // javac-also docDone + createClasspath().setRefid(classpathref); + } + + public void setBootclasspath(Path bootclasspath) { // javac-also not-eajc docDone + ignore("bootclasspath"); // XXX may jury-rig +// if (this.bootclasspath == null) { +// this.bootclasspath = bootclasspath; +// } else { +// this.bootclasspath.append(bootclasspath); +// } + } + public Path createBootclasspath() { // javac-also not-eajc docDone + ignore("bootclasspath"); // XXX may jury-rig + if (bootclasspath == null) { + bootclasspath = new Path(project); + } + return bootclasspath.createPath(); + } + + public void setBootclasspathref(Reference bootclasspathref) { // javac-also not-eajc docDone + ignore("bootclasspath"); // XXX may jury-rig +// createBootclasspath().setRefid(bootclasspathref); + } + + public void setExtdirs(Path extdirs) { // javac-also not-eajc docDone + ignore("-extdirs"); +// if (this.extdirs == null) { +// this.extdirs = extdirs; +// } else { +// this.extdirs.append(extdirs); +// } + } + + public Path createExtdirs() { // javac-also not-eajc docDone + ignore("-extdirs"); + if (extdirs == null) { + extdirs = new Path(project); + } + return extdirs.createPath(); + } + + public void setArgfile(File argfile) { // ajc-only eajc-also docDone + if (argfiles == null) { + argfiles = new Vector(); + } + argfiles.add(argfile); + } + + public void setArgfiles(String argfiles) { // ajc-only eajc-also docDone + StringTokenizer tok = new StringTokenizer(argfiles, ", ", false); + if (tok.hasMoreTokens() && this.argfiles == null) { + this.argfiles = new Vector(); + } + while (tok.hasMoreTokens()) { + this.argfiles.add(project.resolveFile(tok.nextToken().trim())); + } + } + + public void setEncoding(String encoding) { // ignored eajc-also docDone + // XXX add support + //ignore("encoding"); + this.encoding = encoding; + } + + public void setSource(String input) { // javac-also (Ant 1.4) eajc-also docDone + source = input; + //source14 = "1.4".equals(input); // XXX todo + } + + public void setLenient(boolean input) { // ajc-only not-eajc docDone + ignore("-lenient"); + //setif(input, "-lenient"); + } + + public void setStrict(boolean input) { // ajc-only not-eajc docDone + ignore("-strict"); + //setif(input, "-strict"); + } + + public void setPorting(boolean input) { // ajc-only not-eajc docDone + ignore("-porting"); + //setif(input, "-porting"); + } + + public void setX(String input) { // ajc-only eajc-also docDone + StringTokenizer tokens = new StringTokenizer(input, ",", false); + while (tokens.hasMoreTokens()) { + String token = tokens.nextToken().trim(); + if (1 < token.length()) { + if (VALID_XOPTIONS.contains(token)) { + setif(true, "-X" + token); + } else { + ignore("-X" + token); + } + } + } + } + + // ------------------------- vestigial + public void setThreads(int threads) { // ajc-old docDone ignored + ignore("-threads"); + //this.threads = threads; + } + + public void setDumpstack(boolean dumpstack) { // ajc-old + ignore("-dumpstack"); + //setif(dumpstack, "-dumpstack"); + } + + // ------------------------- specific to taskdef + + public void setInternalclasspath(Path internalclasspath) { // ajc-taskdef only + if (this.internalclasspath == null) { + this.internalclasspath = internalclasspath; + } else { + this.internalclasspath.append(internalclasspath); + } + } + public Path createInternalclasspath() { // ajc-taskdef only + if (internalclasspath == null) { + internalclasspath = new Path(project); + } + return internalclasspath.createPath(); + } + + public void setInternalclasspathref(Reference internalclasspathref) { // ajc-taskdef only + createInternalclasspath().setRefid(internalclasspathref); + } + + public void setSrcdir(Path srcdir) { // javac-also eajc-also docDone + if (this.srcdir == null) { + this.srcdir = srcdir; + } else { + this.srcdir.append(srcdir); + } + } + + public Path createSrc() { // javac-also eajc-also docDone + return createSrcdir(); + } + + public Path createSrcdir() { // javac-also eajc-also docDone + if (srcdir == null) { + srcdir = new Path(project); + } + return srcdir.createPath(); + } + + public void setFork(boolean fork) { // ajc-only not-eajc docDone + ignore("fork"); + //this.fork = fork; + } + + public void setFailonerror(boolean failonerror) { // javac-also docDone + this.failonerror = failonerror; + } + + public void setMaxmemory(String max) { // ajc-taskdef only docDone + ignore("-maxmemory"); + // we do not run under 1.1 anyway... +// createJvmarg().setValue((Project.getJavaVersion(). +// startsWith("1.1") ? +// "-mx" : "-Xmx") +max); + } + + public void setJvmarg(String input) { // ajc-taskdef only docDone + ignore("jvmarg"); // XXX fork + //vmcmd.createArgument().setValue(input); + } + + public Commandline.Argument createJvmarg() { // ajc-taskdef only docDone + ignore("jvmarg"); // XXX fork + return vmcmd.createArgument(); + } + + // ------------------------- javac task compatibility + public void setNosymbols(boolean nosymbols) { // todo remove? + ignore("-nosymbols"); + //setif(nosymbols, "-nosymbols"); + } + + public void setDebug(boolean debug) { // javac-also eajc-also docDone + setif(debug, "-g"); // todo: changed from -debug + } + + public void setDeprecation(boolean deprecation) { // javac-also eajc-also docDone + setif(deprecation, "-deprecation"); // XXX eajc: also "warn:deprecation" + } + + // ------------------------- javac task compatibility - ignored + public void setTarget(String target) { // javac-also ignored docDone + ignore("target"); // todo: ajc accepts but doesn't use - pass in? + } + public void setDepend(String depend) { // javac-also ignored docDone + ignore("depend"); + } + public void setIncludeantruntime(boolean includeAntruntime) { // javac-also ignored docDone + ignore("includeantruntime"); + } + public void setIncludejavaruntime(boolean includeJavaruntime ) { // javac-also ignored docDone + ignore("includeJavaruntime"); + } + + // ------------------------- other state methods + + protected final void ignore(String attribute) { + ignoredOptions.add(attribute); + } + + public void backdoorSetFile(File file) { + if (null != file) { + cmd.createArgument().setFile(file); + } + } + + /** reset variables to permit gc */ + public void reset() { + //version = false; + source14 = false; + ignoredOptions = new HashSet(); + cmd = new Commandline(); + vmcmd = new Commandline(); + threads = -1; + destdir = null; + workingdir = null; + internalclasspath = null; + classpath = null; + bootclasspath = null; + extdirs = null; + srcdir = null; + argfiles = null; + fork = false; + failonerror = true; + encoding = null; + source = null; + } + + protected final void setif(boolean b, String flag) { + if (b) cmd.createArgument().setValue(flag); + } + + // ------------------------- operational methods + + public void execute() throws BuildException { + if (srcdir == null && argfiles == null) { + throw new BuildException("one of srcdir or argfiles must be set!", + location); + } +// if (threads != -1) { +// cmd.createArgument().setValue("-threads"); +// cmd.createArgument().setValue(threads+""); +// } +// if (workingdir != null) { +// cmd.createArgument().setValue("-workingdir"); +// cmd.createArgument().setFile(workingdir); +// } + if (destdir != null) { + cmd.createArgument().setValue("-d"); + cmd.createArgument().setFile(destdir); + } + if (classpath != null) { + cmd.createArgument().setValue("-classpath"); + cmd.createArgument().setPath(classpath); + } + if (bootclasspath != null) { + cmd.createArgument().setValue("-bootclasspath"); + cmd.createArgument().setPath(bootclasspath); + } + if (extdirs != null) { + cmd.createArgument().setValue("-extdirs"); + cmd.createArgument().setPath(extdirs); + } + if (null != encoding) { + cmd.createArgument().setValue("-encoding"); + cmd.createArgument().setValue(encoding); + } + if (null != source) { + cmd.createArgument().setValue("-source"); + cmd.createArgument().setValue(source); + } + + int numargfiles = 0; + if (argfiles != null) { + for (Iterator i = argfiles.iterator(); i.hasNext();) { + String name = i.next()+""; + File argfile = project.resolveFile(name); + if (check(argfile, name, false, location)) { + cmd.createArgument().setValue("-argfile"); + cmd.createArgument().setFile(argfile); + numargfiles++; + } + } + } + int numfiles = 0; + if (srcdir != null) { + // todo: ignore any srcdir if any argfiles and no explicit includes + String[] dirs = srcdir.list(); + for (int i = 0; i < dirs.length; i++) { + File dir = project.resolveFile(dirs[i]); + check(dir, dirs[i], true, location); + String[] files = getDirectoryScanner(dir).getIncludedFiles(); + for (int j = 0; j < files.length; j++) { + File file = new File(dir, files[j]); + if (file.getName().endsWith(".java") + || file.getName().endsWith(".aj")) { + cmd.createArgument().setFile(file); + numfiles++; + } + } + } + } + if ((null != ignoredOptions) && (ignoredOptions.size() > 0)) { + log("The following attributes were ignored " + ignoredOptions, + Project.MSG_WARN); + if (ignoredOptions.contains("-preprocess")) { + throw new BuildException("preprocess no longer supported"); + } + } + log("Compiling " + numfiles + " source and " + + + numargfiles + " arg files" + + (null == destdir ? "" : " to " + destdir.getPath()), Project.MSG_INFO); + + // here is the actual invocation + //int result = (fork || (internalclasspath != null)) ? fork() : spoon(); + if (fork || (internalclasspath != null)) { + log("WARNING: fork not supported", Project.MSG_WARN); + } + int result = spoon(); + if (result != 0) { + String msg = "Compilation error: " + result; + if (failonerror) { + reset(); + throw new BuildException(msg); + } else { + log(msg, Project.MSG_WARN); + } + } + reset(); // see throw above + } + +// now leaving version to compiler - remove +// protected void version(Path classpath) { +// try { +// Class main = findClass("org.aspectj.tools.ajc.Main", +// classpath); +// Method printVersion = main.getDeclaredMethod("printVersion", +// new Class[]{}); +// printVersion.setAccessible(true); +// printVersion.invoke(main.newInstance(), new Object[]{}); +// } catch (Exception e) {} +// } +// +// protected Class findClass(String classname, Path classpathPath) { +// String classpath = (classpathPath != null ? +// classpathPath+"" : "").trim(); +// if (classpath.length() == 0) { +// try { +// return Class.forName(classname); +// } catch (ClassNotFoundException e){} +// } +// List urls = new ArrayList(); +// for (StringTokenizer t = new StringTokenizer(classpath, +// File.pathSeparator); +// t.hasMoreTokens();) { +// File f = new File(t.nextToken().trim()); +// try { +// if (f.exists()) { +// URL url = f.toURL(); +// if (url != null) urls.add(url); +// } +// } catch (MalformedURLException e) {} +// } +// if (urls.size() == 0) return null; +// try { +// return new URLClassLoader((URL[])urls.toArray +// (new URL[urls.size()]), +// null).loadClass(classname); +// } catch (ClassNotFoundException e) {} +// return null; +// } + +// unused now, but leave in +// protected int fork() throws BuildException { +// Java java = (Java)project.createTask("java"); +// java.setTaskName(getTaskName()); +// Path compileClasspath; +// if (internalclasspath != null) { +// compileClasspath = internalclasspath; +// compileClasspath.append(Path.systemClasspath); +// } else { +// compileClasspath = Path.systemClasspath; +// } +// //if (version) version(compileClasspath); +// java.setClasspath(compileClasspath); +// java.setClassname(FALSE_MAIN); +// String[] args; +// args = cmd.getArguments(); +// for (int i = 0; i < args.length; i++) { +// java.createArg().setValue(args[i]); +// } +// args = vmcmd.getArguments(); +// for (int i = 0; i < args.length; i++) { +// java.createJvmarg().setValue(args[i]); +// } +// java.setFork(fork); +// // java handles its own verbose logging when forking +// return java.executeJava(); +// } + + /** utility to render String[] for logging */ + public static String render(String[] args) { + if (null == args) return ""; + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < args.length; i++) { + sb.append(args[i]); + sb.append(" "); + } + return sb.toString(); + } + + protected int spoon() throws BuildException { + //if (version) version(null); + int result = -1; + IMessageHolder holder = new MessageHandler(); + try { + String[] args = cmd.getCommandline(); + // XXX avoid rendering if not verbosely logging? + log("Running in-process using " + + Ajc10.render(cmd.getCommandline()), Project.MSG_VERBOSE); + + Main main = new Main(); + main.run(args, holder); + int errs = holder.numMessages(IMessage.ERROR, true); + if (0 < errs) { + result = 1; + } else { + result = 0; + } + } catch (Throwable t) { + while (t instanceof AbortException) { + // check for "just quit -- message printed already" + if (AbortException.ABORT.equals(t)) { + t = null; + break; + } + IMessage m = ((AbortException) t).getIMessage(); + if (null == m) { + break; + } else { + Throwable tt = m.getThrown(); + if (null != tt) { + t = tt; + } else { + break; + } + } + } + if (null != t) { + t.printStackTrace(); + throw new BuildException("Couldn't create compiler!", + t, location); + } + } finally { + if (0 < holder.numMessages(null, true)) { + MessageUtil.print(System.err, holder, ""); + } + // XXX handle ABORT messages by throwing? + } + return result; + } + + protected final boolean check(File file, String name, + boolean isDir, Location loc) { + loc = loc != null ? loc : location; + if (file == null) { + throw new BuildException(name + " is null!", loc); + } + if (!file.exists()) { + throw new BuildException(file + "doesn't exist!", loc); + } + if (isDir ^ file.isDirectory()) { + String e = file + " should" + (isDir ? "" : "n't") + + " be a directory!"; + throw new BuildException(e, loc); + } + return true; + } +} diff --git a/taskdefs/src/org/aspectj/tools/ant/taskdefs/Ajc11CompilerAdapter.java b/taskdefs/src/org/aspectj/tools/ant/taskdefs/Ajc11CompilerAdapter.java new file mode 100644 index 000000000..c4e87f3de --- /dev/null +++ b/taskdefs/src/org/aspectj/tools/ant/taskdefs/Ajc11CompilerAdapter.java @@ -0,0 +1,192 @@ +/* ******************************************************************* + * Copyright (c) 2001-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.tools.ant.taskdefs; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.types.Commandline; +import org.apache.tools.ant.taskdefs.compilers.DefaultCompilerAdapter; + +import java.io.File; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.ListIterator; + +import org.aspectj.bridge.*; +import org.aspectj.util.LangUtil; + + +/** + * EXPERIMENTAL - This adapts the AspectJ compiler as if it were Javac. + * It just passes the arguments through to the compiler. + * Limitations: + * <ol> + * <li>Users still must specify all source files to compile.</li> + * <li>No support for non-Javac options</li> + * <li>Javac srcdir are treated as sourceroots unless -DajcAdapterSkipRoots=...</li> + * </ol> + * + * @author Wes Isberg <a href="mailto:isberg@aspectj.org">isberg@aspectj.org</a> + * @since AspectJ 1.1, Ant 1.3 + */ +public class Ajc11CompilerAdapter extends DefaultCompilerAdapter { + /* + * Not sure how best to implement our functionality -- not documented. + * Desired functionality: + * - ability to run in-line or forked + * - switch based only on fork="[true|false]" + * (so classpath required to fork must be calculated) + * - able to set memory available when forking + * - handles .lst files on command-line by prefixing with @ + * - and/or handles compiler option -XargPrefix=... + * - this means all AspectJ-specific options (injars/outjars...) + * are in the .lst file? + * + * Implementation options: + * - straight CompilerAdapter + * - override DefaultCompilerAdapter methods for template processes + * - create a new FacadeTaskHelper, supply to DefaultCompilerAdaper + */ + public static final String SKIP_ROOTS_NAME = "ajcAdapterSkipRoots"; + + // ------------------------------ setup + /** + * Adds the command line arguments specifc to the current implementation. + */ + protected void addCurrentCompilerArgs(Commandline cmd) { + cmd.addArguments(getJavac().getCurrentCompilerArgs()); + } + + // ------------------------------ run + /** + * Run the compilation. + * + * @exception BuildException if the compilation has problems. + */ + public boolean execute() throws BuildException { + Commandline cmd = setupModernJavacCommand(); + + try { + String[] args = cmd.getArguments(); + int result = runCompiler(args); + return (0 == result); + } catch (BuildException e) { + throw e; + } catch (AbortException x) { + if (AbortException.ABORT.equals(x)) { // no message, just return + return false; + } else { + Throwable t = x.getThrown(); + if (null == t) { + t = x; + } + throw new BuildException("Thrown: ", t, location); + } + } catch (Throwable x) { + throw new BuildException("Thrown: ", x, location); + } + } + + // run? handle forking? + private int runCompiler(String[] args) { + int result = -1; + IMessageHolder sink = new MessageHandler(); + ICommand compiler = ReflectionFactory.makeCommand(ReflectionFactory.ECLIPSE, sink); + if ((null == compiler) || sink.hasAnyMessage(IMessage.FAIL, true)) { + throwBuildException("loading compiler", sink); + } else { + args = filterArgs(args); + if (!compiler.runCommand(args, sink)) { + System.err.println("runCompiler args: " + Arrays.asList(args)); + throwBuildException("running compiler", sink); + } else { + result = 0; + } + } + return result; + } + + /** + * Method throwBuildException. + * @param string + * @param sink + */ + private void throwBuildException(String string, IMessageHolder sink) { // XXX nicer + if ((null != sink) && (0 < sink.numMessages(null, true))) { + MessageUtil.print(System.err, sink, null); + } + throw new BuildException(string + ": " + sink, location); + } + + /** Convert javac argument list to a form acceptable by ajc */ + protected String[] filterArgs(String[] args) { + LinkedList argList = new LinkedList(); + argList.addAll(LangUtil.arrayAsList(args)); + ArrayList roots = new ArrayList(); + for (ListIterator iter = argList.listIterator(); iter.hasNext();) { + String arg = (String) iter.next(); + if ("-sourcepath".equals(arg)) { // similar to -sourceroots? + iter.remove(); + roots.add(iter.next()); // need next after remove? + iter.remove(); + } else if ("-0".equals(arg)) { // unsupported + System.err.println("warning: ignoring -0 argument"); + iter.remove(); + } else if ("-bootclasspath".equals(arg)) { // ajc fakes + } else if ("-extdirs".equals(arg)) { // ajc fakes + } else if ("-target".equals(arg)) { // -1.4 or -1.3 + iter.remove(); + String vers = (String) iter.next(); + if ("1.3".equals(vers)) { + iter.set("-1.3"); + } else if ("1.4".equals(vers)) { + iter.set("-1.4"); + } else { // huh? + String s = "expecting 1.3 or 1.4 at " + vers + " in " + argList; + throwBuildException(s, null); + } + } + } + + if (0 < roots.size()) { + String skipRoots = null; + try { + skipRoots = System.getProperty(SKIP_ROOTS_NAME); + } catch (Throwable t) { + // ignore SecurityException, etc. + } + + if (null == skipRoots) { + StringBuffer sb = new StringBuffer(); + boolean first = true; + for (Iterator iter = roots.iterator(); iter.hasNext();) { + if (!first) { + sb.append(File.pathSeparator); + } else { + first = false; + } + sb.append((String) iter.next()); + } + argList.add(0, "-sourceroots"); + argList.add(1, sb.toString()); + } + } + + return (String[]) argList.toArray(new String[0]); + } +} diff --git a/taskdefs/src/org/aspectj/tools/ant/taskdefs/Ajc2.java b/taskdefs/src/org/aspectj/tools/ant/taskdefs/Ajc2.java new file mode 100644 index 000000000..e4d6f145b --- /dev/null +++ b/taskdefs/src/org/aspectj/tools/ant/taskdefs/Ajc2.java @@ -0,0 +1,540 @@ +/* ******************************************************************* + * Copyright (c) 2000-2001 Xerox Corporation. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + +package org.aspectj.tools.ant.taskdefs; + +import org.apache.tools.ant.*; +import org.apache.tools.ant.types.*; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.taskdefs.*; +import org.apache.tools.ant.taskdefs.compilers.*; +import java.io.*; +import java.util.List; +import java.util.Iterator; +import java.util.ArrayList; +import java.util.StringTokenizer; +import java.lang.reflect.*; + +/** + * Ant task for the AspectJ compiler -- AJC. + * List (.lst) files are passed in as includes. + * + * This task was developed by the <a href="http://aspectj.org">AspectJ Project</a> + * + * @author <a href="mailto:palm@parc.xerox.com">Jeffrey Palm</a> + * @see org.aspectj.tools.ant.taskdefs.compilers.AjcCompiler + */ +public class Ajc2 extends Javac { + + /** + * The name of the adapter we use. + */ + public final static String ADAPTER_CLASS = + "org.aspectj.tools.ant.taskdefs.compilers.Ajc"; + + /* ---------------------------------------------------------------------- + * Attribute members + * ---------------------------------------------------------------------- + */ + + /** + * How many concurrent threads to use for compilation, + * defaults to 0 -- multi-threading disabled. + */ + private Integer threads; + + /** + * Don't generate any comments into the woven code. + */ + private boolean nocomments; + + /** + * Don't generate .ajsym or .ajsline files. + */ + private boolean nosymbols; + + /** + * Generate regular Java code into <workingdir>. + */ + private boolean preprocess; + + /** + * Specify where to place intermediate .java files <dir> + * defaults to ./ajworkingdir. + */ + private File workingdir; + + /** + * The file is a line-delimited list of arguments + * these arguments are inserted into the argument list + */ + private List argfiles; + + + /* ---------------------------------------------------------------------- + * Misc. members + * ---------------------------------------------------------------------- + */ + + /** + * Whether we have used the <code>excludes</code> attribute. + */ + private boolean haveExcludes = false; + + /** + * Whether we have used the <code>includes</code> attribute. + */ + private boolean haveIncludes = false; + + /** + * Whether we have used the <code>excludes</code> attribute. + * @return Whether we have used the <code>excludes</code> attribute. + */ + protected boolean hasExcludes() { + return haveExcludes; + } + + /** + * Whether we have used the <code>includes</code> attribute. + * @return Whether we have used the <code>includes</code> attribute. + */ + protected boolean hasIncludes() { + return haveIncludes; + } + + /* ---------------------------------------------------------------------- + * Attribute access methods + * ---------------------------------------------------------------------- + */ + + /** + * Sets the number of threads. + * + * @param threads the number of threads. + * @see Ajc2#threads + */ + public void setThreads(Integer threads) { + this.threads = threads; + } + + /** + * Returns the number of threads. + * + * @return the number of threads. + * @see Ajc2#threads + */ + public Integer getThreads() { + return threads; + } + + /** + * Set the <code>-nocomments</code> flag. + * + * @param nocomments true turns on the flag. + * @see Ajc2#nocomments + */ + public void setNocomments(boolean nocomments) { + this.nocomments = nocomments; + } + + /** + * Returns if the <code>-nocomments</code> flag is turned on. + * + * @return <code>true</code> if the <code>-nocomments</code> flag is on. + * @see Ajc2#nocomments + */ + public boolean getNocomments() { + return nocomments; + } + + /** + * Set the <code>-nosymbols</code> flag. + * + * @param nosymbols true turns on the flag. + * @see Ajc2#nosymbols + */ + public void setNosymbols(boolean nosymbols) { + this.nosymbols = nosymbols; + } + + /** + * Returns if the <code>-nosymbols</code> flag is turned on. + * + * @return <code>true</code> if the <code>-nosymbols</code> flag is on. + * @see Ajc2#nosymbols + */ + public boolean getNosymbols() { + return nosymbols; + } + + /** + * Returns if the <code>-preprocess</code> flag is turned on. + * + * @return <code>true</code> if the <code>-preprocess</code> flag is on. + * @see Ajc2#preprocess + */ + public void setPreprocess(boolean preprocess) { + this.preprocess = preprocess; + } + + /** + * Returns if the <code>-preprocess</code> flag is turned on. + * + * @return <code>true</code> if the <code>-preprocess</code> flag is on. + * @see Ajc2#preprocess + */ + public boolean getPreprocess() { + return preprocess; + } + + /** + * Sets the workingdir. + * + * @param workingdir the new workingdir. + * @see Ajc2#workingdir + */ + public void setWorkingdir(File workingdir) { + this.workingdir = workingdir; + } + + /** + * Returns the current workingdir. + * + * @return the current workingdir. + * @see Ajc2#workingdir + */ + public File getWorkingdir() { + return workingdir; + } + + /** + * Sets the the argument files by the comma-delimited String passed in. + * + * @param argfiles comma-delimited String contained argument files. + */ + public void setArgfiles(String argfiles) { + StringTokenizer tok = new StringTokenizer(argfiles, ","); + while (tok.hasMoreTokens()) { + File argfile = project.resolveFile(tok.nextToken()); + if (argfile != null && argfile.exists() && !argfile.isDirectory()) { + createArgfile().setFile(argfile); + } + } + } + + /** + * Creates a nested <code>Argfile</code>, add it to the list + * <code>argfiles</code>, and returns the new <code>Argfile</code> + * instance. + * + * @return a new <code>Argfile</code> instance. + */ + public Argfile createArgfile() { + Argfile argfile = new Argfile(); + if (argfiles == null) { + argfiles = new ArrayList(); + } + argfiles.add(argfile); + return argfile; + } + + /** + * Returns the java.util.List of argfiles. + * This could be <code>null</code>. + * + * @return the list of argfiles. + */ + public List getArgfiles() { + return argfiles; + } + + /** + * A simple class with one member -- <code>file</code> -- that + * represents an argument file. + */ + public static class Argfile { + private File file; + public void setFile(File file) { this.file = file; } + public File getFile() { return file; } + public String toString() { return file.getAbsolutePath(); } + } + + /* ---------------------------------------------------------------------- + * Misc. methods + * ---------------------------------------------------------------------- + */ + + /* Leaving the includes blank in the Javac task defaults to including all. + * In Ajc, if the user specifies an argfile, but leaves the includes and + * excludes blank that person probably meant to just includes to argfile. + * So, we keep track of whether includes and/or excludes have been explicitly + * used with the have{In,Ex}cludes members, and setting these flags + * in the create... and set... methods. + * + * When constructing the compileList, if both haveIncludes and haveExcludes + * are false, but the user has specified an argfile, then we set includes + * to '!**' before adding the contents of the argfile. + */ + + /** + * Override Javac.createInclude() to set <code>haveIncludes</code> + * to <code>true</code>. + * + * @return new PatternSet.NameEntry to be added to the include list. + * @see org.apache.tools.taskdefs.Javac#createInclude() + */ + public PatternSet.NameEntry createInclude() { + haveIncludes = true; + return super.createInclude(); + } + + /** + * Override Javac.createExclude() to set <code>haveExcludes</code> + * to <code>true</code>. + * + * @return new PatternSet.NameEntry to be added to the exclude list. + * @see org.apache.tools.taskdefs.Javac#createExclude() + */ + public PatternSet.NameEntry createExclude() { + haveExcludes = true; + return super.createExclude(); + } + + /** + * Override Javac.setIncludes(String) to set <code>haveIncludes</code> + * to <code>true</code>. + * + * @param includes Comma-separated list of includes. + * @see org.apache.tools.taskdefs.Javac#setIncludes(java.lang.String) + */ + public void setIncludes(String includes) { + haveIncludes = true; + super.setIncludes(includes); + } + + /** + * Override Javac.setExcludes(String) to set <code>haveExcludes</code> + * to <code>true</code>. + * + * @param excludes Comma-separated list of excludes. + * @see org.apache.tools.taskdefs.Javac#setExcludes(java.lang.String) + */ + public void setExcludes(String excludes) { + haveExcludes = true; + super.setExcludes(excludes); + } + + public String getAdapterClass() { + return ADAPTER_CLASS; + } + + + public final void execute() throws BuildException { + prepare(); + executeAfterPrepare(); + } + + /** + * Executes by first setting the <code>build.compiler</code> property + * to AjcCompiler, then invokes the super.execute() method. + * + * @throws org.apache.tools.ant.BuildException + * @see org.apache.tools.ant.taskdefs.Javac#execute() + */ + public void executeAfterPrepare() throws BuildException { + + // Save the old build.compiler property + String oldBuildCompiler = project.getProperty("build.compiler"); + + // If oldBuildCompiler is null try to resolve it + if (oldBuildCompiler == null) { + String javaVersion = Project.getJavaVersion(); + if (javaVersion.equals(Project.JAVA_1_0)) { + // Cannot happen + } else if (javaVersion.equals(Project.JAVA_1_1)) { + oldBuildCompiler = "classic"; + } else if (javaVersion.equals(Project.JAVA_1_2)) { + oldBuildCompiler = "classic"; + } else if (javaVersion.equals(Project.JAVA_1_3)) { + oldBuildCompiler = "modern"; + } + } + + // Set the new adapter + project.setProperty("build.compiler", getAdapterClass()); + BuildException caught = null; + try { + super.execute(); + } catch (BuildException be) { + caught = be; + } finally { + + // Reset to the old compiler + if (oldBuildCompiler != null) { + project.setProperty("build.compiler", oldBuildCompiler); + } + } + + // If we caught an exception executing throw it + if (caught != null) { + throw caught; + } + } + + /** + * Guaranteed to be called before doing real execute. + */ + public void prepare() { + if (argfiles != null && !haveIncludes && + !haveExcludes && getSrcdir() == null) { + useDefaultSrcdir(); + } + } + + protected final void useDefaultSrcdir() { + setSrcdir(new Path(project, ".")); + } + + /** + * Overrides Javac.scanDir(..) so that it doesn't check dependencies. + * + * @see org.apache.tools.ant.taskdefs.Javac#scanDir + */ + protected void scanDir(File srcDir, File destDir, String files[]) { + List newFiles = new ArrayList(); + + // Add the files listed in the argfiles to the includes + List newIncludes = new ArrayList(); + List newArguments = new ArrayList(); + if (argfiles != null) { + Iterator iter = argfiles.iterator(); + while (iter.hasNext()) { + File argfile = ((Argfile)iter.next()).getFile(); + expandArgfile(argfile, newIncludes, newArguments); + } + } + + // If there aren't any includes, but we've used an argfile then we should + // set the includes to be the one's found in newIncludes + // If we do this, we need to re-read files from the directory scanner + if (!haveIncludes && !haveExcludes && argfiles != null) { + log("Setting includes to '!**'", Project.MSG_VERBOSE); + setIncludes("!**"); + //files = getDirectoryScanner(srcDir).getIncludedFiles(); + } + + // Otherwise we want to add all .java files to the compileList + else { + for (int i = 0; i < files.length; i++) { + File newFile = new File(srcDir, files[i]); + if (newFile != null && + newFile.exists() && + newFile.getName().endsWith(".java")) { + newFiles.add(newFile); + } + } + } + + // Add the new included files + Iterator iter = newIncludes.iterator(); + while (iter.hasNext()) { + newFiles.add((File)iter.next()); + } + + // This is the same behavior found in Javac + int newFileSize = newFiles.size(); + if (newFileSize > 0) { + File[] newCompileList = new File[compileList.length + newFileSize]; + System.arraycopy(compileList, 0, newCompileList, 0, compileList.length); + System.arraycopy(newFiles.toArray(), 0, newCompileList, + compileList.length, newFileSize); + compileList = newCompileList; + } + } + + private void expandArgfile(File argfile, List includes, List arguments) { + + log("argfile:" + argfile, Project.MSG_VERBOSE); + + // All paths are relative to the parent + File parent = argfile.getParentFile(); + + // Sanity check + if (parent == null || !parent.exists() || !parent.isDirectory()) { + return; + } + + // Read the file + BufferedReader in = null; + try { + in = new BufferedReader(new FileReader(argfile)); + String line; + while ((line = in.readLine()) != null) { + line = line.trim(); + + // Skip blank lines + if ("".equals(line)) { + continue; + } + + // Allow '#' and '//' line comments + int isharp = line.indexOf("#"); + if (isharp != -1) { + line = line.substring(0, isharp); + } + + int istar = -1; + + // Argument + if (line.startsWith("-")) { + arguments.add(line); + } + + // If there are stars we'll try to resolve the file here + else if ((istar = line.indexOf("*")) != -1) { + log("The argfile line '" + line + "' is invalid", + Project.MSG_WARN); + } + + // Another argfile + else if (line.startsWith("@")) { + String newArgfileName = line.substring(1); + File newArgfile = new File(parent, newArgfileName); + expandArgfile(newArgfile, includes, arguments); + } + + // Source file + else { + File newfile = new File(line); + if (!newfile.isAbsolute()) { + newfile = new File(parent, line); + } + if (newfile != null && newfile.exists() && + !newfile.isDirectory() && + newfile.getName().endsWith(".java")) { + includes.add(newfile); + } + } + + } + } catch (IOException ioe) { + log("trouble with argfile: " + argfile + ":" + ioe, Project.MSG_ERR); + } finally { + try { + if (in != null) { + in.close(); + } + } catch (IOException ioe2) { + } + } + } +} diff --git a/taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcCompilerAdapter.java b/taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcCompilerAdapter.java new file mode 100644 index 000000000..c98d943a6 --- /dev/null +++ b/taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcCompilerAdapter.java @@ -0,0 +1,117 @@ +/* ******************************************************************* + * Copyright (c) 2000-2001 Xerox Corporation. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + +package org.aspectj.tools.ant.taskdefs; + +import org.apache.tools.ant.taskdefs.Javac; +import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.types.Path; + + +import java.io.File; + +/** + * Partial implementation of CompilerAdapter for ajc task. + * The Javac interface does not support argfiles which are + * typically necessary to compile under ajc, so this + * implementation is not documented, recommended, or supported. + * See Apache request for enhancement + * <a href="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7542"> + * 7542</a>. + * @see CompilerAdapter + */ +public class AjcCompilerAdapter implements CompilerAdapter { + // Cannot extend Ajc because CompilerAdapter.execute() returns boolean. + + Ajc10 ajc = null; + + /** @see CompilerAdapter */ + public void setJavac(Javac javac) { + if (null == javac) { + throw new IllegalArgumentException("null javac"); + } + Object task = javac.getProject().createTask("ajc"); + String err = null; + if (null == task) { + err = "ajc not defined - put ajc taskdef library on classpath"; + } else if (!(task instanceof Ajc10)) { + String name = task.getClass().getName(); + err = "Wrong class for Ajc task - "; + if (name.equals(Ajc10.class.getName())) { + err = err + "second class loader - put ajc taskdef library " + + "only on system classpath via ant/lib"; + } else { + err = err + name; + } + } + if (null != err) { + throw new Error(err); + } + + Ajc10 tempAjc = (Ajc10) task; + Path srcDir = javac.getSrcdir(); + if (null != srcDir) { + tempAjc.setSrcdir(srcDir); + } + File destDir = javac.getDestdir(); + if (null != destDir) { + tempAjc.setDestdir(destDir.getPath()); + } + Path classpath = javac.getClasspath(); + if (null != classpath) { + tempAjc.setClasspath(classpath); + } + Path bootclasspath = javac.getBootclasspath(); + if (null != bootclasspath) { + tempAjc.setBootclasspath(bootclasspath); + } + Path extDirs = javac.getExtdirs(); + if (null != extDirs) { + tempAjc.setExtdirs(extDirs); + } + + tempAjc.setFailonerror(javac.getFailonerror()); + tempAjc.setDeprecation(javac.getDeprecation()); // XXX unsupported + tempAjc.setEncoding(javac.getEncoding()); + tempAjc.setDebug(javac.getDebug()); // XXX unsupported + tempAjc.setOptimize(javac.getOptimize()); // XXX unsupported + tempAjc.setDepend(javac.getDepend()?"on":"off"); // XXX unsupported + tempAjc.setVerbose(javac.getVerbose()); + String target = javac.getTarget(); + if (null != target) { + tempAjc.setTarget(target); + } + tempAjc.setIncludeantruntime(javac.getIncludeantruntime()); // XXX unsupported + File[] files = javac.getFileList(); + if (null != files) { + for (int i = 0; i < files.length; i++) { + tempAjc.backdoorSetFile(files[i]); + } + } + ajc = tempAjc; + } + + /** + * Run the compiler. + * @see CompilerAdapter#execute() + * @throws BuildException if setJavac(Javac) was not called before each call of this + */ + public boolean execute() throws BuildException { + if (null == ajc) { + throw new BuildException("setJavac(Javac) not completed"); + } + ajc.execute(); + ajc = null; // enforce one-shot + return true; + } +} diff --git a/taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java b/taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java new file mode 100644 index 000000000..5041b2855 --- /dev/null +++ b/taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java @@ -0,0 +1,591 @@ +/* ******************************************************************* + * Copyright (c) 2001-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.tools.ant.taskdefs; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +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.taskdefs.MatchingTask; +import org.apache.tools.ant.types.Commandline; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.Reference; +import org.aspectj.bridge.CountingMessageHandler; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.IMessageHandler; +import org.aspectj.bridge.IMessageHolder; +import org.aspectj.bridge.MessageHandler; +import org.aspectj.tools.ajc.Main; +import org.aspectj.tools.ajc.Main.MessagePrinter; + + +/** + * This runs the AspectJ 1.1 compiler. + * @since AspectJ 1.1, Ant 1.5 + */ +public class AjcTask extends MatchingTask { + + + /** @return true if readable and ends with [.java|.aj] */ + protected static boolean isSrcFile(File file) { + return ((null != file) && file.canRead() + && (file.getName().endsWith(".java") + || file.getName().endsWith(".aj"))); + } + + /** valid -X[...] options other than -Xlint variants */ + private static final List VALID_XOPTIONS; + + /** valid warning (-warn:[...]) variants */ + private static final List VALID_WARNINGS; + + /** valid debugging (-g:[...]) variants */ + private static final List VALID_DEBUG; + + /** -Xlint variants + * @see org.aspectj.weaver.Lint + */ + private static final List VALID_XLINT; + + static { + String[] xs = new String[] + { "serializableAspects", "incrementalFile" + //, "targetNearSource", "OcodeSize", + }; + VALID_XOPTIONS = Collections.unmodifiableList(Arrays.asList(xs)); + + xs = new String[] + {"constructorName", "packageDefaultMethod", "deprecation", + "maskedCatchBlocks", "unusedLocals", "unusedArguments", + "unusedImports", "syntheticAccess", "assertIdentifier" }; + VALID_WARNINGS = Collections.unmodifiableList(Arrays.asList(xs)); + + xs = new String[] {"none", "lines", "vars", "source" }; + VALID_DEBUG = Collections.unmodifiableList(Arrays.asList(xs)); + + + xs = new String[] + { "invalidAbsoluteTypeName", "invalidWildcardTypeName", + "unresolvableMember" }; + VALID_XLINT = Collections.unmodifiableList(Arrays.asList(xs)); + } + // ---------------------------- state and Ant interface thereto + + // ------- single entries dumped into cmd + protected Commandline cmd; + + // ------- lists resolved in addListArgs() at execute() time + private Path srcdir; + private Path injars; + private Path classpath; + private Path aspectpath; + private Path bootclasspath; // XXX supported? + private List argfiles; + private List ignored; + private Path sourceRoots; + + // also note MatchingTask grabs source files... + + // ------- interpreted here + private boolean verbose; + private boolean failonerror; + + AjcTask() { + reset(); + } + + /** to use this same Task more than once */ + public void reset() { + cmd = new Commandline(); + srcdir = null; + injars = null; + classpath = null; + aspectpath = null; + bootclasspath = null; + argfiles = null; + ignored = new ArrayList(); + sourceRoots = null; + } + + // ---- private, but delegates of all public setters + protected void addFlag(String flag, boolean doAdd) { + if (doAdd) { + cmd.addArguments(new String[] {flag}); + } + } + + protected void ignore(String ignored) { + this.ignored.add(ignored); + } + protected void addFlagged(String flag, String argument) { + cmd.addArguments(new String[] {flag, argument}); + } + + protected String validCommaList(String list, List valid) { + StringBuffer result = new StringBuffer(); + StringTokenizer st = new StringTokenizer(list, ","); + while (st.hasMoreTokens()) { + String token = st.nextToken().trim(); + if (!valid.contains(token)) { + ignore("commaList entry: " + token); // XXX weak message + } else { + if (0 < result.length()) { + result.append(","); + } + result.append(token); + } + } + return (0 == result.length() ? null : result.toString()); + } + + // -------------- Ant interface + public void setIncremental(boolean incremental) { + addFlag("-incremental", incremental); + } + + public void setHelp(boolean help) { + addFlag("-help", help); + } + + public void setVersion(boolean version) { + addFlag("-version", version); + } + + public void setNoweave(boolean noweave) { + addFlag("-noweave", noweave); + } + + public void setNowarn(boolean nowarn) { + addFlag("-nowarn", nowarn); + } + + public void setDeprecation(boolean deprecation) { + addFlag("-deprecation", deprecation); + } + + public void setWarn(String warnings) { + warnings = validCommaList(warnings, VALID_WARNINGS); + addFlag("-g:" + warnings, (null != warnings)); + } + + public void setDebug(boolean debug) { + addFlag("-g", debug); + } + + public void setDebugLevel(String level) { + level = validCommaList(level, VALID_DEBUG); + addFlag("-g:" + level, (null != level)); + } + + /** -Xlint - enable or disable all forms of -Xlint messages */ + public void setXlintenabled(boolean xlintenabled) { + addFlag("-Xlint", xlintenabled); + } + + /** -Xlint:{xlint} - enable or disable specific forms of -Xlint messages + * @param xlint the String with comma-delimited lint + */ + public void setXlint(String xlint) { // XXX confirm form supported + xlint = validCommaList(xlint, VALID_XLINT); + addFlag("-Xlint:" + xlint, (null != xlint)); + } + + /** + * -Xlint:file={xlintFile} - enable or disable specific forms + * of -Xlint messages based on a lint properties file + * @param xlintFile the File with lint properties + */ + public void setXlintFile(File xlintFile) { + String flag = "-Xlint:file=" + xlintFile.getAbsolutePath(); + //addFlag(flag); + ignore(flag + "[XXX unimplemented in compiler]"); + } + + public void setPreserveAllLocals(boolean preserveAllLocals) { + addFlag("-preserveAllLocals", preserveAllLocals); + } + + public void setNoImportError(boolean noImportError) { + addFlag("-noImportError", noImportError); + } + + public void setEncoding(String encoding) { // XXX encoding unvalidated + addFlagged("-encoding", encoding); + } + + public void setLog(File file) { + addFlagged("-log", file.getAbsolutePath()); + } + + public void setProceedOnError(boolean proceedOnError) { + addFlag("-proceedOnError", proceedOnError); + } + + public void setVerbose(boolean verbose) { + addFlag("-verbose", verbose); + this.verbose = verbose; + } + + public void setReferenceInfo(boolean referenceInfo) { + addFlag("-referenceInfo", referenceInfo); + } + + public void setProgress(boolean progress) { + addFlag("-progress", progress); + } + + public void setTime(boolean time) { + addFlag("-time", time); + } + + public void setNoExit(boolean noExit) { + addFlag("-noExit", noExit); + } + + public void setFailonerror(boolean failonerror) { + this.failonerror = failonerror; + } + + // ---------------- + public void setTagFile(File file) { + addFlagged(Main.CommandController.TAG_FILE_OPTION, + file.getAbsolutePath()); + } + + public void setOutjar(File file) { + addFlagged("-outjar", file.getAbsolutePath()); + } + + public void setDestdir(File dir) { + addFlagged("-d", dir.getAbsolutePath()); + } + + public void setTarget(String either11or12) { + if ("1.1".equals(either11or12)) { + addFlagged("-target", "1.1"); + } else if ("1.2".equals(either11or12)) { + addFlagged("-target", "1.2"); + } else { + ignore("-target " + either11or12); + } + } + + /** + * Language compliance level. + * If not set explicitly, eclipse default holds. + * @param either13or14 either "1.3" or "1.4" + */ + public void setCompliance(String either13or14) { + if ("1.3".equals(either13or14)) { + addFlag("-1.3", true); + } else if ("1.4".equals(either13or14)) { + addFlag("-1.4", true); + } else { + ignore(either13or14 + "[compliance]"); + } + } + + /** + * Source compliance level. + * If not set explicitly, eclipse default holds. + * @param either13or14 either "1.3" or "1.4" + */ + public void setSource(String either13or14) { + if ("1.3".equals(either13or14)) { + addFlagged("-source", "1.3"); + } else if ("1.4".equals(either13or14)) { + addFlagged("-source", "1.4"); + } else { + ignore("-source " + either13or14); + } + } + //---------------------- accumulate these lists + public void setSourceRoots(Path roots) { + if (this.sourceRoots == null) { + this.sourceRoots = roots; + } else { + this.sourceRoots.append(roots); + } + } + + public Path createSourceRoots() { + if (sourceRoots == null) { + sourceRoots = new Path(project); + } + return sourceRoots.createPath(); + } + + public void setClasspath(Path classpath) { + if (this.classpath == null) { + this.classpath = classpath; + } else { + this.classpath.append(classpath); + } + } + + public Path createClasspath() { + if (classpath == null) { + classpath = new Path(project); + } + return classpath.createPath(); + } + + public void setInjars(Path injars) { + if (this.injars == null) { + this.injars = injars; + } else { + this.injars.append(injars); + } + } + + public Path createInjars() { + if (injars == null) { + injars = new Path(project); + } + return injars.createPath(); + } + + public void setAspectpath(Path aspectpath) { + if (this.aspectpath == null) { + this.aspectpath = aspectpath; + } else { + this.aspectpath.append(aspectpath); + } + } + + public Path createSrc() { + return createSrcdir(); + } + + public Path createSrcdir() { + if (srcdir == null) { + srcdir = new Path(project); + } + return srcdir.createPath(); + } + + public Path createAspectpath() { + if (aspectpath == null) { + aspectpath = new Path(project); + } + return aspectpath.createPath(); + } + + public void setClasspathref(Reference classpathref) { + createClasspath().setRefid(classpathref); + } + + public void setBootclasspath(Path bootclasspath) { + if (this.bootclasspath == null) { + this.bootclasspath = bootclasspath; + } else { + this.bootclasspath.append(bootclasspath); + } + } + public Path createBootclasspath() { + if (bootclasspath == null) { + bootclasspath = new Path(project); + } + return bootclasspath.createPath(); + } + + public void setBootclasspathref(Reference bootclasspathref) { + createBootclasspath().setRefid(bootclasspathref); + } + + public void setArgfile(File argfile) { // ajc-only eajc-also docDone + if (argfiles == null) { + argfiles = new Vector(); + } + argfiles.add(argfile); + } + + public void setArgfiles(String argfiles) { // ajc-only eajc-also docDone + StringTokenizer tok = new StringTokenizer(argfiles, ", ", false); + if (tok.hasMoreTokens() && this.argfiles == null) { + this.argfiles = new Vector(); + } + while (tok.hasMoreTokens()) { + this.argfiles.add(project.resolveFile(tok.nextToken().trim())); + } + } + + public void setX(String input) { // ajc-only eajc-also docDone + StringTokenizer tokens = new StringTokenizer(input, ",", false); + while (tokens.hasMoreTokens()) { + String token = tokens.nextToken().trim(); + if (1 < token.length()) { + if (VALID_XOPTIONS.contains(token)) { + addFlag("-X" + token, true); + } else { + ignore("-X" + token); + } + } + } + } + // ---------------------------- test state and interface thereto + + private IMessageHolder messageHolder; + + void setMessageHolder(IMessageHolder holder) { + this.messageHolder = holder; + } + + /** + * Setup custom message handling. + * @param className the String fully-qualified-name of a class + * reachable from this object's class loader, + * implementing IMessageHolder, and + * having a public no-argument constructor. + */ + public void setMessageHolderClass(String className) { + try { + Class mclass = Class.forName(className); + IMessageHolder holder = (IMessageHolder) mclass.newInstance(); + setMessageHolder(holder); + } catch (Throwable t) { // XXX better message + ignore("unable to load message holder class " + className + + t.getClass().getName() + ": " + t.getMessage()); + } + } + + // ------------------------------ run + /** + * Compile using ajc per settings. + * This prints the messages in verbose or terse form + * unless an IMessageHolder was set using setMessageHolder. + * @exception BuildException if the compilation has problems + * or if there were compiler errors and failonerror is true. + */ + public void execute() throws BuildException { + IMessageHolder holder = messageHolder; + int numPreviousErrors; + if (null == holder) { + MessageHandler mhandler = new MessageHandler(true); + final IMessageHandler delegate + = verbose ? MessagePrinter.VERBOSE: MessagePrinter.TERSE; + mhandler.setInterceptor(delegate); + holder = mhandler; + numPreviousErrors = 0; + } else { + numPreviousErrors = holder.numMessages(IMessage.ERROR, true); + } + + try { + if (0 < ignored.size()) { + for (Iterator iter = ignored.iterator(); iter.hasNext();) { + log("ignored: " + iter.next(), project.MSG_INFO); + } + } + Main main = new Main(); + main.setHolder(holder); + addListArgs(); + String[] args = cmd.getArguments(); + if (verbose) { + log("ajc " + Arrays.asList(args), project.MSG_VERBOSE); + } + main.runMain(args, false); + + if (failonerror) { + int errs = holder.numMessages(IMessage.ERROR, true); + errs -= numPreviousErrors; + if (0 < errs) { + // errors should already be printed by interceptor + throw new BuildException(errs + " errors"); + } + } + } catch (BuildException e) { + throw e; + } catch (Throwable x) { + throw new BuildException("Thrown: ", x); + } + } + + // ------------------------------ setup and reporting + /** + * @return String[] of command-line arguments + * @throws BuildException if tagFile or sourceRoots invalid + */ + protected void addListArgs() throws BuildException { + + if (classpath != null) { + addFlagged("-classpath", classpath.toString()); + } + if (aspectpath != null) { + addFlagged("-aspectpath", aspectpath.toString()); + } + if (bootclasspath != null) { + addFlagged("-bootclasspath", bootclasspath.toString()); + } + if (injars != null) { + addFlagged("-injars", injars.toString()); + } + if (sourceRoots != null) { + addFlagged("-sourceroots", sourceRoots.toString()); + } + int numargfiles = 0; + if (argfiles != null) { + for (Iterator i = argfiles.iterator(); i.hasNext();) { + String name = i.next()+""; + File argfile = project.resolveFile(name); + if (check(argfile, name, false, location)) { + addFlagged("-argfile", argfile.getAbsolutePath()); + numargfiles++; + } + } + } + int numSources = 0; + if (srcdir != null) { + // todo: ignore any srcdir if any argfiles and no explicit includes + String[] dirs = srcdir.list(); + for (int i = 0; i < dirs.length; i++) { + File dir = project.resolveFile(dirs[i]); + check(dir, dirs[i], true, location); + String[] files = getDirectoryScanner(dir).getIncludedFiles(); + for (int j = 0; j < files.length; j++) { + File file = new File(dir, files[j]); + if (isSrcFile(file)) { + cmd.createArgument().setFile(file); + numSources++; + } + } + } + } + } + + protected final boolean check(File file, String name, + boolean isDir, Location loc) { + loc = loc != null ? loc : location; + if (file == null) { + throw new BuildException(name + " is null!", loc); + } + if (!file.exists()) { + throw new BuildException(file + " doesn't exist!", loc); + } + if (isDir ^ file.isDirectory()) { + String e = file + " should" + (isDir ? "" : "n't") + + " be a directory!"; + throw new BuildException(e, loc); + } + return true; + } +} diff --git a/taskdefs/src/org/aspectj/tools/ant/taskdefs/Ajdoc.java b/taskdefs/src/org/aspectj/tools/ant/taskdefs/Ajdoc.java new file mode 100644 index 000000000..e14ca2467 --- /dev/null +++ b/taskdefs/src/org/aspectj/tools/ant/taskdefs/Ajdoc.java @@ -0,0 +1,722 @@ +/* ******************************************************************* + * Copyright (c) 2000-2001 Xerox Corporation. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.tools.ant.taskdefs; + +import org.apache.tools.ant.*; + + +public class Ajdoc extends Task { // XXX disabled pending ajdoc implementation + +} + + +// +//import org.aspectj.tools.ajdoc.Main; +//import org.apache.tools.ant.*; +//import org.apache.tools.ant.types.*; +//import org.apache.tools.ant.taskdefs.*; +//import java.io.*; +//import java.util.*; +// +///** +// * A task to run the ajdoc tool. +// * +// * @author Jeff Palm +// */ +//public class Ajdoc extends MatchingTask { +// /** The name of ajdoc class we're using. */ +// public final static String AJDOC_CLASSNAME = "org.aspectj.tools.ajdoc.Main"; +// +// /** If true, ignore fork param and use FORCE_FORK_VALUE */ +// public final static boolean FORCE_FORK = false; +// +// /** value used as fork when FORCE_FORK is true */ +// public final static boolean FORCE_FORK_VALUE = true; +// +// protected Commandline cmd; +// protected Commandline vmcmd; +// private Path sourcepath; +// private File destdir; +// private Collection sourcefiles; +// private Collection packagenames; +// private File packageList; +// private Path bootclasspath; +// private Path extdirs; +// private Path classpath; +// private Path internalclasspath; +// private List argfiles; +// private Path docletpath; +// private Collection links; +// private Collection groups; +// private Doclet doclet; +// private boolean failonerror; +// private boolean fork; +// +// private boolean source14; +// +// /** reset all to initial values - permit gc if Ajdoc is held */ +// public Ajdoc() { +// reset(); +// } +// +// protected void reset() { +// cmd = new Commandline(); +// vmcmd = new Commandline(); +// sourcepath = null; +// destdir = null ; +// sourcefiles = null; +// packagenames = null; +// packageList = null; +// bootclasspath = null; +// extdirs = null; +// classpath = null; +// internalclasspath = null; +// argfiles = null; +// docletpath = null; +// links = new ArrayList(); +// groups = new ArrayList(); +// doclet = null; +// failonerror = false; +// fork = false; +// } +// +// protected final boolean setif(boolean b, String flag) { +// if (b) cmd.createArgument().setValue(flag); +// return b; +// } +// +// protected final void setfile(String flag, String file) { +// set(flag, project.resolveFile(file).getAbsolutePath()); +// } +// +// protected final void set(String flag, String val) { +// setif(true, flag, val); +// } +// +// protected final boolean setif(boolean b, String flag, String val) { +// if (setif(b, flag)) cmd.createArgument().setValue(val); +// return b; +// } +// +// public void setSource(String input) { +// source14 = "1.4".equals(input); +// } +// +// public void setSourcepath(Path path) { +// if (sourcepath == null) { +// sourcepath = path; +// } else { +// sourcepath.append(path); +// } +// } +// +// public Path createSourcepath() { +// return sourcepath == null ? +// (sourcepath = new Path(project)) : +// sourcepath.createPath(); +// } +// +// public void setSourcepathRef(Reference id) { +// createSourcepath().setRefid(id); +// } +// +// public void setSrcdir(Path path) { setSourcepath(path); } +// +// public Path createSrcdir() { return createSourcepath(); } +// +// public void setSrcdirRef(Reference id) { setSourcepathRef(id); } +// +// public void setDestdir(String destdir) { +// this.destdir = project.resolveFile(destdir); +// } +// +// public void setSourcefiles(String list) { +// (sourcefiles == null ? +// sourcefiles = new ArrayList() : +// sourcefiles).addAll(strings(list)); +// } +// +// public void setPackagenames(String list) { +// (packagenames == null ? +// packagenames = new ArrayList() : +// packagenames).addAll(strings(list, true)); +// } +// +// public void setPackageList(String packageList) { +// this.packageList = project.resolveFile(packageList); +// } +// +// public void setClasspath(Path path) { +// if (classpath == null) { +// classpath = path; +// } else { +// classpath.append(path); +// } +// } +// +// public Path createClasspath() { +// return (classpath == null ? +// classpath = new Path(project) : +// classpath).createPath(); +// } +// +// public void setClasspathref(Reference id) { +// createClasspath().setRefid(id); +// } +// +// public void setBootclasspath(Path path) { // todo: unsupported +// if (bootclasspath == null) { +// bootclasspath = path; +// } else { +// bootclasspath.append(path); +// } +// } +// +// public Path createBootclasspath() { // todo: unsupported +// return (bootclasspath == null ? +// bootclasspath = new Path(project) : +// bootclasspath).createPath(); +// } +// +// public void setBootclasspathref(Reference bootclasspathref) { // todo: unsupported +// createBootclasspath().setRefid(bootclasspathref); +// } +// +// public void setInternalclasspath(Path internalclasspath) { +// if (this.internalclasspath == null) { +// this.internalclasspath = internalclasspath; +// } else { +// this.internalclasspath.append(internalclasspath); +// } +// } +// +// public Path createInternalclasspath() { +// if (internalclasspath == null) { +// internalclasspath = new Path(project); +// } +// return internalclasspath.createPath(); +// } +// +// +// public void setInternalclasspathref(Reference internalclasspathref) { +// createInternalclasspath().setRefid(internalclasspathref); +// } +// +// public void setExtdirs(Path path) { +// if (extdirs == null) { +// extdirs = path; +// } else { +// extdirs.append(path); +// } +// } +// +// public List createArgfiles() { +// return (argfiles == null ? +// argfiles = new ArrayList() : +// argfiles); +// } +// +// public void setArgfile(String argfile) { +// createArgfiles().add(project.resolveFile(argfile)); +// } +// +// public void setArgfiles(String argfiles) { +// createArgfiles().addAll(files(argfiles)); +// } +// +// public void setOverview(String overview) { +// setfile("-overview", overview); +// } +// +// public void setPublic(boolean b) { +// setif(b, "-public"); +// } +// +// public void setPackage(boolean b) { +// setif(b, "-package"); +// } +// +// public void setProtected(boolean b) { +// setif(b, "-protected"); +// } +// +// public void setPrivate(boolean b) { +// setif(b, "-private"); +// } +// +// public void setOld(boolean old) { +// setif(old, "-old"); +// } +// +// public void setAuthor(boolean author) { +// setif(author, "-author"); +// } +// +// public void setSplitindex(boolean splitindex) { +// setif(splitindex, "-splitindex"); +// } +// +// public void setWindowtitle(String windowtitle) { +// set("-windowtitle", windowtitle); +// } +// +// public void setDoctitle(String doctitle) { +// set("-doctitle", doctitle); +// } +// +// public void setHeader(String header) { +// set("-header", header); +// } +// +// public void setFooter(String footer) { +// set("-footer", footer); +// } +// +// public void setBottom(String bottom) { +// set("-bottom", bottom); +// } +// +// public void setVerbose(boolean b) { +// setif(b, "-verbose"); +// } +// +// public void setVersion(boolean b) { +// setif(b, "-version"); +// } +// +// public void setUse(boolean b) { +// setif(b, "-use"); +// } +// +// public void setStandard(boolean b) { +// setif(b, "-standard"); +// } +// +// public class Link { +// protected String href; +// protected boolean offline; +// protected String packagelistLoc; +// public Link() {} +// public void setHref(String href) { +// this.href = href; +// } +// public void setOffline(boolean offline) { +// this.offline = offline; +// } +// public void setPackagelistLoc(String packagelistLoc) { +// this.packagelistLoc = packagelistLoc; +// } +// } +// +// public void setLink(String href) { +// createLink().setHref(href); +// } +// +// public Link createLink() { +// Link link = new Link(); +// links.add(link); +// return link; +// } +// +// public void setLinkoffline(String linkoffline) { +// Link link = createLink(); +// int ispace = linkoffline.indexOf(" "); +// if (ispace == -1) { +// throw new BuildException("linkoffline usage: <url> <url2>!", location); +// } +// link.setHref(linkoffline.substring(0, ispace).trim()); +// link.setPackagelistLoc(linkoffline.substring(ispace+1).trim()); +// } +// +// public class Group { +// private String title; +// private List packages; +// public Group() {} +// public void setTitle(String title) { +// this.title = title; +// } +// public final void setPackages(String packages) { +// setPackagenames(packages); +// } +// public void setPackagenames(String packages) { +// this.packages = strings(packages); +// } +// } +// +// public void setGroup(String str) { +// for (StringTokenizer t = new StringTokenizer(str, ",", false); +// t.hasMoreTokens();) { +// String s = t.nextToken().trim(); +// int ispace = s.indexOf(' '); +// if (ispace != -1) { +// Group group = createGroup(); +// group.setTitle(s.substring(0, ispace)); +// group.setPackagenames(s.substring(ispace+1)); +// } else { +// throw new BuildException +// ("group usage: group=[<title> <pkglist>]*", location); +// } +// } +// } +// +// public Group createGroup() { +// Group group = new Group(); +// groups.add(group); +// return group; +// } +// +// public void setNodeprecated(boolean nodeprecated) { +// setif(nodeprecated, "-nodeprecated"); +// } +// +// public void setNodeprecatedlist(boolean nodeprecatedlist) { +// setif(nodeprecatedlist, "-nodeprecatedlist"); +// } +// +// public void setNotree(boolean notree) { +// setif(notree, "-notree"); +// } +// +// public void setNoindex(boolean noindex) { +// setif(noindex, "-noindex"); +// } +// +// public void setNohelp(boolean nohelp) { +// setif(nohelp, "-nohelp"); +// } +// +// public void setNonavbar(boolean nonavbar) { +// setif(nonavbar, "-nonavbar"); +// } +// +// public void setSerialwarn(boolean serialwarn) { +// setif(serialwarn, "-serialwarn"); +// } +// +// public void setHelpfile(String helpfile) { +// setfile("-helpfile", helpfile); +// } +// +// public void setStylesheetfile(String stylesheetfile) { +// setfile("-stylesheetfile", stylesheetfile); +// } +// +// public void setCharset(String charset) { set("-charset", charset); } +// +// public void setDocencoding(String docencoding) { +// set("-docencoding", docencoding); +// } +// +// public void setDoclet(String doclet) { +// createDoclet().setName(doclet); +// } +// +// public static class Param { +// protected String name; +// protected String value; +// public Param() {} +// public void setName(String name) { this.name = name; } +// public void setValue(String value) { this.value = value; } +// } +// +// public class Doclet { +// protected String name; +// protected Path path; +// protected List params = new ArrayList(); +// public Doclet() {} +// public void setName(String name) { +// this.name = name; +// } +// public void setPath(Path path) { +// if (this.path == null) { +// this.path = path; +// } else { +// this.path.append(path); +// } +// } +// public Path createPath() { +// return (path == null ? +// path = new Path(project) : +// path).createPath(); +// } +// public Param createParam() { +// Param param = new Param(); +// params.add(param); +// return param; +// } +// } +// +// public Doclet createDoclet() { +// if (doclet != null) { +// throw new BuildException("Only one doclet is allowed!"); +// } +// return doclet = new Doclet(); +// } +// +// public void setDocletpath(Path path) { +// (docletpath == null ? +// docletpath = path : +// docletpath).append(path); +// } +// +// public Path createDocletpath() { +// return docletpath == null ? +// (docletpath = new Path(project)) : +// docletpath.createPath(); +// } +// +// public void setDocletpathRef(Reference id) { +// createDocletpath().setRefid(id); +// } +// +// public void setAdditionalparam(String additionalparam) { +// cmd.createArgument().setLine(additionalparam); +// } +// +// public void setFailonerror(boolean failonerror) { +// this.failonerror = failonerror; +// } +// +// public void setFork(boolean fork) { +// this.fork = fork; +// } +// +// public Commandline.Argument createJvmarg() { +// return vmcmd.createArgument(); +// } +// +// public void setMaxmemory(String max) { +// createJvmarg().setValue((Project.getJavaVersion(). +// startsWith("1.1") ? +// "-mx" : "-Xmx") +max); +// } +// +// public void execute() throws BuildException { +// if (sourcepath == null && argfiles == null) { +// throw new BuildException("one of sourcepath or argfiles must be set!", +// location); +// } +// if (sourcepath != null) { +// cmd.createArgument().setValue("-sourcepath"); +// cmd.createArgument().setPath(sourcepath); +// } +// if (destdir != null) { +// cmd.createArgument().setValue("-d"); +// cmd.createArgument().setFile(destdir); +// } +// if (classpath != null) { +// cmd.createArgument().setValue("-classpath"); +// cmd.createArgument().setPath(classpath); +// } +// if (bootclasspath != null) { +// cmd.createArgument().setValue("-bootclasspath"); +// cmd.createArgument().setPath(bootclasspath); +// } +// if (extdirs != null) { +// cmd.createArgument().setValue("-extdirs"); +// cmd.createArgument().setPath(extdirs); +// } +// +// if (source14) { +// cmd.createArgument().setValue("-source"); +// cmd.createArgument().setValue("1.4"); +// } +// +// for (Iterator i = links.iterator(); i.hasNext();) { +// Link link = (Link)i.next(); +// if (link.href == null) { +// throw new BuildException("Link href cannot be null!", location); +// } +// if (link.packagelistLoc != null) { +// cmd.createArgument().setValue("-linkoffline"); +// cmd.createArgument().setValue(link.href); +// cmd.createArgument().setValue(link.packagelistLoc); +// } else { +// cmd.createArgument().setValue("-link"); +// cmd.createArgument().setValue(link.href); +// } +// } +// if (doclet != null) { +// if (doclet.name == null) { +// throw new BuildException("Doclet name cannot be null!", location); +// } +// cmd.createArgument().setValue("-doclet"); +// cmd.createArgument().setValue(doclet.name); +// if (doclet.path != null) { +// cmd.createArgument().setValue("-docletpath"); +// cmd.createArgument().setPath(doclet.path); +// } +// for (Iterator i = doclet.params.iterator(); i.hasNext();) { +// Param param = (Param)i.next(); +// if (param.name == null) { +// throw new BuildException("Doclet params cannot be null!", +// location); +// } +// cmd.createArgument().setValue(param.name); +// if (param.value == null) { +// cmd.createArgument().setValue(param.value); +// } +// } +// } +// Map groupMap = new HashMap(); +// for (Iterator i = groups.iterator(); i.hasNext();) { +// Group group = (Group)i.next(); +// if (group.title == null) { +// throw new BuildException("Group names cannot be null!", +// location); +// } +// if (group.packages == null) { +// throw new BuildException("Group packages cannot be null!", +// location); +// } +// List packages = (List)groupMap.get(group.title); +// if (packages == null) { +// packages = new ArrayList(); +// } +// packages.addAll(group.packages); +// groupMap.put(group.title, packages); +// } +// for (Iterator i = groupMap.keySet().iterator(); i.hasNext();) { +// String title = (String)i.next(); +// List packages = (List)groupMap.get(title); +// String pkgstr = ""; +// for (Iterator j = packages.iterator(); j.hasNext();) { +// pkgstr += j.next(); +// if (j.hasNext()) pkgstr += ","; +// } +// cmd.createArgument().setValue("-group"); +// cmd.createArgument().setValue(title); +// cmd.createArgument().setValue(pkgstr); +// } +// if (argfiles != null) { +// for (Iterator i = argfiles.iterator(); i.hasNext();) { +// String name = i.next()+""; +// File argfile = project.resolveFile(name); +// if (check(argfile, name, false, location)) { +// cmd.createArgument().setValue("-argfile"); +// cmd.createArgument().setFile(argfile); +// } +// } +// } +// if (packageList != null) { +// cmd.createArgument().setValue("@" + packageList); +// } +// if (null != packagenames) { +// for (Iterator i = packagenames.iterator(); i.hasNext();) { +// cmd.createArgument().setValue((String)i.next()); +// } +// } +// // support for include parameter as a MatchingTask +// int numfiles = 0; +// if (sourcepath != null) { +// String[] dirs = sourcepath.list(); +// for (int i = 0; i < dirs.length; i++) { +// File dir = project.resolveFile(dirs[i]); +// check(dir, dirs[i], true, location); +// String[] files = getDirectoryScanner(dir).getIncludedFiles(); +// for (int j = 0; j < files.length; j++) { +// File file = new File(dir, files[j]); +// if (file.getName().endsWith(".java") +// || file.getName().endsWith(".aj")) { +// cmd.createArgument().setFile(file); +// numfiles++; +// } +// } +// } +// } +// if (sourcefiles != null) { +// for (Iterator i = sourcefiles.iterator(); i.hasNext();) { +// // let ajdoc resolve sourcefiles relative to sourcepath, +// cmd.createArgument().setValue((String)i.next()); +// } +// } +// // XXX PR682 weak way to report errors - need to refactor +// int result = compile(); +// if (failonerror && (0 != result)) { +// throw new BuildException("Ajdoc failed with code " + result); +// } +// reset(); +// } +// +// protected int compile() throws BuildException { // todo: doc that fork is ignored +// try { +// String[] args = cmd.getArguments(); +// if (fork) { +// log("Warning: fork is ignored ", Project.MSG_WARN); +// } +// return Main.execute(args); // todo: direct to new Ajdoc().execute(..)? +// } catch (Throwable t) { +// throw new BuildException(t); +// } +// } +// +// protected interface Mapper { +// public Object map(String str); +// } +// +// protected final List list(String str, Mapper mapper) { +// if (str == null) return Collections.EMPTY_LIST; +// List list = new ArrayList(); +// for (StringTokenizer t = new StringTokenizer(str, ",", false); +// t.hasMoreTokens();) { +// list.add(mapper.map(t.nextToken().trim())); +// } +// return list; +// } +// +// protected final List files(String str) { +// return list(str, new Mapper() { +// public Object map(String s) { +// return project.resolveFile(s); +// } +// }); +// } +// +// protected final List strings(String str) { +// return strings(str, false); +// } +// +// protected final List strings(String str, final boolean filterSlashes) { +// return list(str, new Mapper() { +// public Object map(String s) { +// return filterSlashes ? filterSlashes(s) : s; +// } +// }); +// } +// +// protected final String filterSlashes(String str) { +// if (str == null) return null; +// return str. +// replace('/', '.'). +// replace('\\', '.'). +// replace(File.separatorChar, '.'); +// } +// +// protected final boolean check(File file, String name, +// boolean isDir, Location loc) { +// loc = loc != null ? loc : location; +// if (file == null) { +// throw new BuildException(name + " is null!", loc); +// } +// if (!file.exists()) { +// throw new BuildException(file + "doesn't exist!", loc); +// } +// if (isDir ^ file.isDirectory()) { +// throw new BuildException(file + " should" + +// (!isDir ? "n't" : "") + +// " be a directory!", loc); +// } +// return true; +// } +//} diff --git a/taskdefs/src/org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties b/taskdefs/src/org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties new file mode 100644 index 000000000..5f2239518 --- /dev/null +++ b/taskdefs/src/org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties @@ -0,0 +1,2 @@ +ajc=org.aspectj.tools.ant.taskdefs.Ajc10 +iajc=org.aspectj.tools.ant.taskdefs.AjcTask diff --git a/taskdefs/src/org/aspectj/tools/ant/taskdefs/compilers/Ajc.java b/taskdefs/src/org/aspectj/tools/ant/taskdefs/compilers/Ajc.java new file mode 100644 index 000000000..1785b76a6 --- /dev/null +++ b/taskdefs/src/org/aspectj/tools/ant/taskdefs/compilers/Ajc.java @@ -0,0 +1,220 @@ +/* ******************************************************************* + * Copyright (c) 2000-2001 Xerox Corporation. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + +package org.aspectj.tools.ant.taskdefs.compilers; + +import org.apache.tools.ant.*; +import org.apache.tools.ant.types.*; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.taskdefs.*; +import org.apache.tools.ant.taskdefs.compilers.*; +import java.io.*; +import java.util.Iterator; +import java.util.List; +import java.util.ArrayList; +import java.lang.reflect.*; + +//XXX +import java.util.*; + +/** + * Ajc uses this as the CompilerAdapter. + * + * This task was developed by the <a href="http://aspectj.org">AspectJ Project</a> + * + * @author <a href="mailto:palm@parc.xerox.com">Jeffrey Palm</a> + * @see org.aspectj.tools.ant.taskdefs.Ajc + */ +public class Ajc extends DefaultCompilerAdapter { + + /** The value of a compiler success. */ + public final static int AJC_COMPILER_SUCCESS = 0; + + /** The name of the compiler's main class. */ + private final static String MAIN_CLASS_NAME = "org.aspectj.tools.ajc.Main"; + + /** + * List of arguments allowed only by javac and <b>not</b> ajc. + */ + final static List javacOnlyFlags + = finalList(new String[] { "-g:none", "-g:lines", + "-g:vars", "-g:source", "-nowarn"}); + final static List javacOnlyArgs + = finalList(new String[] { "-sourcepath", + "-encoding", "-target" }); + + private static List finalList(String[] args) { + List result = new ArrayList(); + result.addAll(Arrays.asList(args)); + return Collections.unmodifiableList(result); + } + + /** + * Checks the command line for arguments allowed only in AJC and + * disallowed by AJC and then calls the <code>compile()<code> method. + * + * @return true if a good compile, false otherwise. + * @throws org.apache.tools.ant.BuildException + */ + public boolean execute() throws BuildException { + attributes.log("Using AJC", Project.MSG_VERBOSE); + return compile(addAjcOptions(setupJavacCommand())); + } + + /** + * Invokes the AJC compiler using reflection. + * + * @param cline the command line to pass the compiler + * @return true for a good compile (0), false otherwise + * @throws org.apache.tools.ant.BuildException + */ + private boolean compile(Commandline cline) throws BuildException { + PrintStream err = System.err; + PrintStream out = System.out; + try { + Class main = Class.forName(MAIN_CLASS_NAME); + if (main == null) { + throw new ClassNotFoundException(MAIN_CLASS_NAME); + } + PrintStream logstr = + new PrintStream(new LogOutputStream(attributes, + Project.MSG_WARN)); + System.setOut(logstr); + System.setErr(logstr); + return ((Integer)main.getMethod + ("compile", new Class[]{String[].class}).invoke + (main.newInstance(), new Object[]{ + removeUnsupported(cline, logstr) + })).intValue() == AJC_COMPILER_SUCCESS; + } catch (Exception e) { + if (e instanceof BuildException) { + throw (BuildException)e; + } else { + throw new BuildException("Error starting AJC compiler", + e, location); + } + } finally { + System.setErr(err); + System.setOut(out); + } + } + + + /** + * Removes unsupported arguments from <code>cline</code> + * issuing warnings for each using <code>log</code>. + * + * @param cline the <code>org.apache.tools.ant.types.Commandline</code> from + * which the argument is removed. + * @return a new <code>java.lang.String</code> array containing all the + * supported arguments found in <code>cline</code>. + * @throws org.apache.tools.ant.BuildException + */ + private String[] removeUnsupported(Commandline cline, PrintStream log) { + if (null == log) log = System.err; + String[] args = cline.getCommandline(); + List argsList = new ArrayList(); + for (int i = 0; i < args.length; i++) { + String arg = args[i]; + if (javacOnlyFlags.contains(arg)) { + log.println("ignored by ajc " + arg); + } else if (javacOnlyArgs.contains(arg)) { + i++; + if (i < args.length) { + arg = arg + " " + args[i]; + } + log.println("ignored by ajc " + arg); + } else { + argsList.add(args[i]); + } + } + return (String[])argsList.toArray(new String[argsList.size()]); + } + + /** + * Adds arguments that setupJavacCommand() doesn't pick up. + * + * @param cline <code>org.apache.tools.ant.types.Commandline</code> to + * which arguments are added. + * @throws org.apache.tools.ant.BuildException + * @see AjcCompiler#ajcOnlyArgs + * @see org.apache.tools.ant.taskdefs.compilers#DefaultCompilerAdapter.setupJavacCommand() + */ + private Commandline addAjcOptions(Commandline cline) throws BuildException { + Javac javac = getJavac(); + + org.aspectj.tools.ant.taskdefs.Ajc2 ajc = null; + + try { + ajc = (org.aspectj.tools.ant.taskdefs.Ajc2)javac; + } catch (ClassCastException cce) { + throw new BuildException(cce+""); + } + + if (ajc.getThreads() != null) { + cline.createArgument().setValue("-threads"); + cline.createArgument().setValue(ajc.getThreads() + ""); + } + if (ajc.getNocomments()) { + cline.createArgument().setValue("-nocomments"); + } + if (ajc.getNosymbols()) { + cline.createArgument().setValue("-nosymbols"); + } + if (ajc.getPreprocess()) { + cline.createArgument().setValue("-preprocess"); + } + if (ajc.getWorkingdir() != null) { + cline.createArgument().setValue("-workingdir"); + cline.createArgument().setFile(ajc.getWorkingdir()); + } + + return cline; + } + + /** + * Logs the compilation parameters, adds the files to compile and logs the + * &qout;niceSourceList" + */ + protected void logAndAddFilesToCompile(Commandline cmd) { + + // Same behavior as DefaultCompilerAdapter.logAndAddFilesToCompile + attributes.log("Compilation args: " + cmd.toString(), Project.MSG_VERBOSE); + StringBuffer niceSourceList = new StringBuffer("File"); + if (compileList.length != 1) { + niceSourceList.append("s"); + } + niceSourceList.append(" to be compiled:"); + niceSourceList.append(lSep); + + for (int i=0; i < compileList.length; i++) { + + // DefaultCompilerAdapter only expects .java files but we must deal + // with .lst files also + File file = compileList[i]; + + if (file == null) continue; + + String arg = file.getAbsolutePath(); + String rest = ""; + String name = file.getName(); + + // For .java files take the default behavior and add that + // file to the command line + if (name.endsWith(".java")) { + cmd.createArgument().setValue(arg); + } + niceSourceList.append(" " + arg + rest + lSep); + } + attributes.log(niceSourceList.toString(), Project.MSG_VERBOSE); + } +} diff --git a/taskdefs/testdata/Ajdoc14Source.java b/taskdefs/testdata/Ajdoc14Source.java new file mode 100644 index 000000000..2e0f87f74 --- /dev/null +++ b/taskdefs/testdata/Ajdoc14Source.java @@ -0,0 +1,13 @@ + + +public class Ajdoc14Source { + { assert(false); } + + public Ajdoc14Source() { + assert(true); + } + + public void doAssert() { + assert(true); + } +}
\ No newline at end of file diff --git a/taskdefs/testdata/CompileError.java b/taskdefs/testdata/CompileError.java new file mode 100644 index 000000000..9a71c1dab --- /dev/null +++ b/taskdefs/testdata/CompileError.java @@ -0,0 +1,5 @@ + + +public class CompileError { + here // CE here +}
\ No newline at end of file diff --git a/taskdefs/testdata/CompileWarning.java b/taskdefs/testdata/CompileWarning.java new file mode 100644 index 000000000..9f68068af --- /dev/null +++ b/taskdefs/testdata/CompileWarning.java @@ -0,0 +1,10 @@ + + +public class CompileWarning { + void run() { + } + static aspect A { + declare warning : execution(void CompileWarning.run()) : + "expected warning"; + } +}
\ No newline at end of file diff --git a/taskdefs/testdata/Default.java b/taskdefs/testdata/Default.java new file mode 100644 index 000000000..7688bcb14 --- /dev/null +++ b/taskdefs/testdata/Default.java @@ -0,0 +1,4 @@ + + +public class Default { +}
\ No newline at end of file diff --git a/taskdefs/testdata/test-build.xml b/taskdefs/testdata/test-build.xml new file mode 100644 index 000000000..cb66c09b9 --- /dev/null +++ b/taskdefs/testdata/test-build.xml @@ -0,0 +1,9 @@ + +<project default="default"> + <target name="default"> + <taskdef properties="src/org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties"/> + <iajc> + <fileset dir="testdata" includes="Default.j*"/> + </iajc> + </target> +</project> diff --git a/taskdefs/testsrc/TaskdefsModuleTests.java b/taskdefs/testsrc/TaskdefsModuleTests.java new file mode 100644 index 000000000..df92e50cd --- /dev/null +++ b/taskdefs/testsrc/TaskdefsModuleTests.java @@ -0,0 +1,28 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +// default package + +import junit.framework.*; + +public class TaskdefsModuleTests extends TestCase { + + public static Test suite() { + TestSuite suite = new TestSuite(TaskdefsModuleTests.class.getName()); + suite.addTest(org.aspectj.tools.ant.taskdefs.TaskdefsTests.suite()); + return suite; + } + + public TaskdefsModuleTests(String name) { super(name); } +} diff --git a/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java b/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java new file mode 100644 index 000000000..035c0546a --- /dev/null +++ b/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java @@ -0,0 +1,251 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + +package org.aspectj.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.taskdefs.Ant; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.selectors.FilenameSelector; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.IMessageHandler; +import org.aspectj.bridge.IMessageHolder; +import org.aspectj.bridge.MessageHandler; +import org.aspectj.bridge.MessageUtil; +import org.aspectj.util.FileUtil; +import org.aspectj.util.LangUtil; + +import java.io.File; + +import junit.framework.TestCase; + +/** + * + */ +public class AjcTaskTest extends TestCase { + + private static final Class NO_EXCEPTION = null; + private static final String NOFILE = "NOFILE"; + + private static File tempDir; + + private static void deleteTempDir() { + if ((null != tempDir) && tempDir.exists()) { + FileUtil.deleteContents(tempDir); + tempDir.delete(); + } + } + private static final File getTempDir() { + if (null == tempDir) { + tempDir = new File("IncrementalAjcTaskTest-temp"); + } + return tempDir; + } + + public AjcTaskTest(String name) { + super(name); + } + + public void tearDown() { + deleteTempDir(); + } + + protected AjcTask getTask(String input) { + AjcTask task = new AjcTask(); + Project p = new Project(); + task.setProject(p); + task.setDestdir(getTempDir()); + if (NOFILE.equals(input)) { + // add nothing + } else if (input.endsWith(".lst")) { + if (-1 != input.indexOf(",")) { + task.setArgfiles(input); + } else { + task.setArgfile(new File(input)); + } + } else if ((input.endsWith(".java") || input.endsWith(".aj"))) { + // not working + FilenameSelector fns = new FilenameSelector(); + fns.setName(input); + task.addFilename(fns); + } else { + File dir = new File(input); + if (dir.canRead() && dir.isDirectory()) { + task.setSourceRoots(new Path(task.getProject(), input)); + } + } + task.setVerbose(true); // XXX + return task; + } + + // ---------------------------------------- argfile + public void testDefaultList() { + AjcTask task = getTask("testdata/default.lst"); + runTest(task, NO_EXCEPTION, IMessageHolderChecker.INFOS); + } + + public void testCompileErrorList() { + AjcTask task = getTask("testdata/compileError.lst"); + runTest(task, NO_EXCEPTION, IMessageHolderChecker.ONE_ERROR); + } + + public void testCompileWarningList() { + AjcTask task = getTask("testdata/compileWarning.lst"); + runTest(task, NO_EXCEPTION, IMessageHolderChecker.ONE_WARNING); + } + + public void testNoSuchFileList() { + AjcTask task = getTask("testdata/NoSuchFile.lst"); + runTest(task, NO_EXCEPTION, IMessageHolderChecker.ONE_ERROR); + } + + // ---------------------------------------- ant drivers? + // doesn't work.. +// public void testAntScript() { +// Ant ant = new Ant(); +// ant.setProject(new Project()); +// ant.setDir(new File(".")); +// ant.setAntfile("test-build.xml"); +// ant.execute(); +// } + // ---------------------------------------- sourcefile + public void testDefaultFile() { + AjcTask task = getTask("testdata/Default.java"); + runTest(task, NO_EXCEPTION, IMessageHolderChecker.INFOS); + } + + + public void testNoFile() { + AjcTask task = getTask(NOFILE); + runTest(task, NO_EXCEPTION, IMessageHolderChecker.ONE_ERROR); + } + + // XXX find out how to feed files into MatchingTask +// public void testCompileErrorFile() { +// AjcTask task = getTask("testdata/CompilerError.java"); +// runTest(task, NO_EXCEPTION, IMessageHolderChecker.ONE_ERROR); +// } +// +// public void testCompileWarningFile() { +// AjcTask task = getTask("testdata/CompilerWarning.lst"); +// runTest(task, NO_EXCEPTION, IMessageHolderChecker.ONE_WARNING); +// } +// +// public void testNoSuchFile() { +// AjcTask task = getTask("testdata/NoSuchFile.java"); +// runTest(task, NO_EXCEPTION, IMessageHolderChecker.ONE_ERROR); +// } +// +// public void testDefaultFileComplete() { +// AjcTask task = getTask("testdata/Default.java"); +// task.setDebugLevel("none"); +// task.setDeprecation(true); +// task.setFailonerror(false); +// task.setNoExit(true); // ok to override Ant? +// task.setNoImportError(true); +// task.setNowarn(true); +// task.setNoweave(true); +// task.setPreserveAllLocals(true); +// task.setProceedOnError(true); +// task.setReferenceInfo(true); +// task.setSource("1.3"); +// task.setTarget("1.1"); +// task.setTime(true); +// task.setVerbose(true); +// task.setXlintenabled(true); +// runTest(task, NO_EXCEPTION, IMessageHolderChecker.INFOS); +// } + + protected void runTest( + AjcTask task, + Class exceptionType, + IMessageHolderChecker checker) { + Throwable thrown = null; + MessageHandler holder = new MessageHandler(); + task.setMessageHolder(holder); + try { + task.execute(); + } catch (Throwable t) { + thrown = t; + } finally { + deleteTempDir(); + } + if (null == exceptionType) { + if (null != thrown) { + assertTrue("thrown: " + render(thrown), false); + } + } else if (null == thrown) { + assertTrue("expected " + exceptionType.getName(), false); + } else if (!(exceptionType.isAssignableFrom(thrown.getClass()))) { + assertTrue("expected " + exceptionType.getName() + + " got " + render(thrown), false); + } + if (null == checker) { + checker = IMessageHolderChecker.NONE; + } + checker.check(holder); + } + + protected String render(Throwable thrown) { + return LangUtil.renderException(thrown); + } + + static class IMessageHolderChecker { // XXX export to testing-utils + /** use as value to ignore results */ + static int IGNORE = Integer.MIN_VALUE; + + static IMessageHolderChecker NONE = + new IMessageHolderChecker(0,0,0,0,0); + /** any number (0+) of info messages */ + static IMessageHolderChecker INFOS = + new IMessageHolderChecker(0,0,0,0,IGNORE); + /** one error, any number of info messages */ + static IMessageHolderChecker ONE_ERROR= + new IMessageHolderChecker(0,0,1,0,IGNORE); + /** one warning, any number of info messages */ + static IMessageHolderChecker ONE_WARNING = + new IMessageHolderChecker(0,0,0,1,IGNORE); + + int aborts, fails, errors, warnings, infos; + public IMessageHolderChecker(int aborts, int fails, int errors, int warnings, int infos) { + this.aborts = aborts; + this.fails = fails; + this.errors = errors; + this.warnings = warnings; + this.infos = infos; + } + public void check(IMessageHolder holder) { + boolean failed = true; + try { + check(holder, aborts, IMessage.ABORT); + check(holder, fails, IMessage.FAIL); + check(holder, errors, IMessage.ERROR); + check(holder, warnings,IMessage.WARNING); + check(holder, infos, IMessage.INFO); + failed = false; + } finally { + if (failed) { + MessageUtil.print(System.err, holder, "failed?"); + } + } + } + + private void check(IMessageHolder holder, int num, IMessage.Kind kind) { + if (num != IGNORE) { + assertEquals(num, holder.numMessages(kind, false)); + } + } + } +} diff --git a/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjdocTest.java b/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjdocTest.java new file mode 100644 index 000000000..b58362e4c --- /dev/null +++ b/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjdocTest.java @@ -0,0 +1,55 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + +package org.aspectj.tools.ant.taskdefs; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.Path; + +import java.io.File; + +import junit.framework.TestCase; + +/** + * + */ +public class AjdocTest extends TestCase { + + public AjdocTest(String name) { + super(name); + } + + public void testSource14() { + new File("bin/AjdocTest").mkdirs(); + + Ajdoc task = new Ajdoc(); + Project p = new Project(); + task.setProject(p); + // XXX restore when ajdoc is restored +// task.setSource("1.4"); +// task.setSourcepath(new Path(p, "testdata")); +// task.setIncludes("Ajdoc14Source.java"); +// task.setDestdir("bin/AjdocTest"); +// task.setClasspath(new Path(p, "../lib/test/aspectjrt.jar")); + task.execute(); + } +// public void testHelp() { +// Ajdoc task = new Ajdoc(); +// Project p = new Project(); +// task.setProject(p); +// task.setSourcepath(new Path(p, "testdata")); +// task.setIncludes("none"); +// task.setDestdir("bin/AjdocTest"); +// task.execute(); +// } +} diff --git a/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/TaskdefsTests.java b/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/TaskdefsTests.java new file mode 100644 index 000000000..8971936c1 --- /dev/null +++ b/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/TaskdefsTests.java @@ -0,0 +1,32 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.tools.ant.taskdefs; + +import junit.framework.*; + +public class TaskdefsTests extends TestCase { + + public static Test suite() { + TestSuite suite = new TestSuite(TaskdefsTests.class.getName()); + //$JUnit-BEGIN$ + suite.addTestSuite(AjdocTest.class); + suite.addTestSuite(AjcTaskTest.class); + //$JUnit-END$ + return suite; + } + + public TaskdefsTests(String name) { super(name); } + +} |