org.aspectj.tools.ant.taskdefs
Class AjcTask

java.lang.Object
  extended by MatchingTask
      extended by org.aspectj.tools.ant.taskdefs.AjcTask

public class AjcTask
extends MatchingTask

This runs the AspectJ 1.1 compiler, supporting all the command-line options. In 1.1.1, ajc copies resources from input jars, but you can copy resources from the source directories using sourceRootCopyFilter. When not forking, things will be copied as needed for each iterative compile, but when forking things are only copied at the completion of a successful compile.

See the development environment guide for usage documentation.

Since:
AspectJ 1.1, Ant 1.5

Nested Class Summary
static class AjcTask.GuardedCommand
          Commandline wrapper that only permits addition of non-empty values and converts to argfile form if necessary.
 
Field Summary
protected  AjcTask.GuardedCommand cmd
           
static java.lang.String COMMAND_EDITOR_NAME
           
 
Constructor Summary
AjcTask()
           
 
Method Summary
protected static void addFlaggedPath(java.lang.String flag, Path path, java.util.List list)
           
protected  void addListArgs(java.util.List list)
          Add to list any path or plural arguments.
protected  boolean check(java.io.File file, java.lang.String name, boolean isDir, Location loc)
          Throw BuildException unless file is valid.
 Path createArgfiles()
           
 Path createAspectpath()
           
 Path createBootclasspath()
           
 Path createClasspath()
           
 Path createExtdirs()
           
 Path createForkclasspath()
           
 Path createInjars()
           
 Path createInpath()
           
 Path createInxml()
           
 Commandline.Argument createJvmarg()
          support for nested <jvmarg> elements
 Path createSourceRoots()
           
 Path createSrc()
           
 Path createSrcdir()
           
protected  void doCompletionTasks()
          Called when compile or incremental compile is completing, this completes the output jar or directory by copying resources if requested.
protected  int execInOtherVM(java.lang.String[] args)
          Execute in another process using the same JDK and the base directory of the project.
 void execute()
          Compile using ajc per settings.
protected  void executeInOtherVM(java.lang.String[] args)
          Execute in a separate VM.
protected  void executeInSameVM(java.lang.String[] args)
          Run the compile in the same VM by loading the compiler (Main), setting up any message holders, doing the compile, and converting abort/failure and error messages to BuildException, as appropriate.
static java.io.File findAspectjtoolsJar()
          Find aspectjtools.jar on the task or system classpath.
protected  void ignore(java.lang.String ignored)
           
protected  Path incPath(Path source, Path toAdd)
          Add path elements to source path and return result.
 boolean isForked()
           
 boolean isInIncrementalFileMode()
           
 boolean isInIncrementalMode()
           
protected  void logVerbose(java.lang.String text)
           
 boolean quit()
          Halt processing.
 void readArguments(java.lang.String[] args)
          Read arguments in as if from a command line, mainly to support compiler adapter compilerarg subelement.
 void reset()
          to use this same Task more than once (testing)
 void setArgfiles(Path path)
           
 void setArgfilesref(Reference ref)
           
 void setAspectpath(Path path)
           
 void setAspectpathref(Reference ref)
           
 void setBootclasspath(Path path)
           
 void setBootclasspathref(Reference bootclasspathref)
           
 void setCheckRuntimeVersion(boolean b)
           
 void setClasspath(Path path)
           
 void setClasspathref(Reference classpathref)
           
 void setCommandEditor(ICommandEditor editor)
          direct API for testing
 void setCommandEditorClass(java.lang.String className)
          Setup command-line filter.
 void setCompliance(java.lang.String input)
          Language compliance level.
 void setCopyInjars(boolean doCopy)
          Flag to copy all non-.class contents of injars to outjar after compile completes.
 void setCrossrefs(boolean on)
           
 void setDebug(boolean debug)
           
 void setDebugLevel(java.lang.String level)
           
 void setDeprecation(boolean deprecation)
           
 void setDestdir(java.io.File dir)
           
 void setEmacssym(boolean emacssym)
           
 void setEncoding(java.lang.String encoding)
           
 void setExtdirs(Path path)
           
 void setExtdirsref(Reference ref)
           
 void setFailonerror(boolean failonerror)
           
 void setFork(boolean fork)
           
 void setForkclasspath(Path path)
           
 void setForkclasspathref(Reference forkclasspathref)
           
 void setHelp(boolean help)
           
 void setIncremental(boolean incremental)
           
 void setInjars(Path path)
           
 void setInjarsref(Reference ref)
           
 void setInpath(Path path)
           
 void setInpathDirCopyFilter(java.lang.String filter)
          Option to copy all files from all inpath directories except the files specified here.
 void setInpathref(Reference ref)
           
 void setInxml(Path path)
           
 void setInxmlref(Reference ref)
           
 void setListFileArgs(boolean listFileArgs)
           
 void setLog(java.io.File file)
           
 void setLogCommand(boolean logCommand)
           
 void setMaxmem(java.lang.String maxMem)
           
 void setMessageHolder(IMessageHolder holder)
          direct API for testing
 void setMessageHolderClass(java.lang.String className)
          Setup custom message handling.
 void setNoExit(boolean noExit)
           
 void setNoImportError(boolean noImportError)
           
 void setNowarn(boolean nowarn)
           
 void setNoWeave(boolean b)
           
 void setOutjar(java.io.File file)
           
 void setOutxml(boolean outxml)
           
 void setOutxmlfile(java.lang.String name)
           
 void setPreserveAllLocals(boolean preserveAllLocals)
           
 void setProceedOnError(boolean proceedOnError)
           
 void setReferenceInfo(boolean referenceInfo)
           
 void setShowWeaveInfo(boolean showweaveinfo)
           
 void setSource(java.lang.String input)
          Source compliance level.
 void setSourceRootCopyFilter(java.lang.String filter)
          Option to copy all files from all source root directories except those specified here.
 void setSourceRoots(Path roots)
           
 void setSourcerootsref(Reference ref)
           
 void setSrcDir(Path path)
           
 void setTagFile(java.io.File file)
           
 void setTarget(java.lang.String input)
           
 void setTime(boolean time)
           
 void setTimers(boolean timers)
           
 java.lang.String setupAjc(Javac javac)
          This method extracts javac arguments to ajc, and add arguments to make ajc behave more like javac in copying resources.
protected  void setupOptions()
          Create any pseudo-options required to implement some of the macro options
 void setVerbose(boolean verbose)
           
 void setVersion(boolean version)
           
 void setWarn(java.lang.String warnings)
           
 void setX(java.lang.String input)
           
 void setXaddSerialVersionUID(boolean addUID)
           
 void setXDoneSignal(java.lang.String doneSignal)
           
 void setXJoinpoints(java.lang.String optionalJoinpoints)
           
 void setXlint(java.lang.String xlint)
          -Xlint:{error|warning|info} - set default level for -Xlint messages
 void setXlintfile(java.io.File xlintFile)
          -Xlintfile {lint.properties} - enable or disable specific forms of -Xlint messages based on a lint properties file (default is org/aspectj/weaver/XLintDefault.properties)
 void setXlintwarnings(boolean xlintwarnings)
          -Xlint - set default level of -Xlint messages to warning (same as -Xlint:warning)
 void setXmlConfigured(boolean xmlConfigured)
           
 void setXNoInline(boolean noInline)
           
 void setXNotReweavable(boolean notReweavable)
           
 void setXNoWeave(boolean b)
           
 void setXReweavable(boolean reweavable)
           
 void setXTerminateAfterCompilation(boolean b)
           
 void setXWeaveDir(java.io.File file)
           
protected  java.lang.String validCommaList(java.lang.String list, java.util.List valid, java.lang.String label)
           
protected  java.lang.String validCommaList(java.lang.String list, java.util.List valid, java.lang.String label, int max)
           
protected  void verifyOptions()
           
protected  java.io.File zipDirectory(java.io.File dir)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMMAND_EDITOR_NAME

public static final java.lang.String COMMAND_EDITOR_NAME

cmd

protected AjcTask.GuardedCommand cmd
Constructor Detail

AjcTask

public AjcTask()
Method Detail

setupAjc

public java.lang.String setupAjc(Javac javac)
This method extracts javac arguments to ajc, and add arguments to make ajc behave more like javac in copying resources.

Pass ajc-specific options using compilerarg sub-element:

 <javac srcdir="src">
     <compilerarg compiler="..." line="-argfile src/args.lst"/>
 <javac>
 
Some javac arguments are not supported in this component (yet):
 String memoryInitialSize;
 boolean includeAntRuntime = true;
 boolean includeJavaRuntime = false;
 
Other javac arguments are not supported in ajc 1.1:
 boolean optimize;
 String forkedExecutable;
 FacadeTaskHelper facade;
 boolean depend;
 String debugLevel;
 Path compileSourcepath;
 

Parameters:
javac - the Javac command to implement (not null)
ajc - the AjcTask to adapt (not null)
destDir - the File class destination directory (may be null)
Returns:
null if no error, or String error otherwise

findAspectjtoolsJar

public static java.io.File findAspectjtoolsJar()
Find aspectjtools.jar on the task or system classpath. Accept aspectj{-}tools{...}.jar mainly to support build systems using maven-style re-naming (e.g., aspectj-tools-1.1.0.jar. Note that we search the task classpath first, though an entry on the system classpath would be loaded first, because it seems more correct as the more specific one.

Returns:
readable File for aspectjtools.jar, or null if not found.

reset

public void reset()
to use this same Task more than once (testing)


ignore

protected void ignore(java.lang.String ignored)

validCommaList

protected java.lang.String validCommaList(java.lang.String list,
                                          java.util.List valid,
                                          java.lang.String label)

validCommaList

protected java.lang.String validCommaList(java.lang.String list,
                                          java.util.List valid,
                                          java.lang.String label,
                                          int max)

setIncremental

public void setIncremental(boolean incremental)

setLogCommand

public void setLogCommand(boolean logCommand)

setHelp

public void setHelp(boolean help)

setVersion

public void setVersion(boolean version)

setXTerminateAfterCompilation

public void setXTerminateAfterCompilation(boolean b)

setXReweavable

public void setXReweavable(boolean reweavable)

setXmlConfigured

public void setXmlConfigured(boolean xmlConfigured)

setXJoinpoints

public void setXJoinpoints(java.lang.String optionalJoinpoints)

setCheckRuntimeVersion

public void setCheckRuntimeVersion(boolean b)

setXNoWeave

public void setXNoWeave(boolean b)

setNoWeave

public void setNoWeave(boolean b)

setXNotReweavable

public void setXNotReweavable(boolean notReweavable)

setXaddSerialVersionUID

public void setXaddSerialVersionUID(boolean addUID)

setXNoInline

public void setXNoInline(boolean noInline)

setShowWeaveInfo

public void setShowWeaveInfo(boolean showweaveinfo)

setNowarn

public void setNowarn(boolean nowarn)

setDeprecation

public void setDeprecation(boolean deprecation)

setWarn

public void setWarn(java.lang.String warnings)

setDebug

public void setDebug(boolean debug)

setDebugLevel

public void setDebugLevel(java.lang.String level)

setEmacssym

public void setEmacssym(boolean emacssym)

setCrossrefs

public void setCrossrefs(boolean on)

setXlintwarnings

public void setXlintwarnings(boolean xlintwarnings)
-Xlint - set default level of -Xlint messages to warning (same as -Xlint:warning)


setXlint

public void setXlint(java.lang.String xlint)
-Xlint:{error|warning|info} - set default level for -Xlint messages

Parameters:
xlint - the String with one of error, warning, ignored

setXlintfile

public void setXlintfile(java.io.File xlintFile)
-Xlintfile {lint.properties} - enable or disable specific forms of -Xlint messages based on a lint properties file (default is org/aspectj/weaver/XLintDefault.properties)

Parameters:
xlintFile - the File with lint properties

setPreserveAllLocals

public void setPreserveAllLocals(boolean preserveAllLocals)

setNoImportError

public void setNoImportError(boolean noImportError)

setEncoding

public void setEncoding(java.lang.String encoding)

setLog

public void setLog(java.io.File file)

setProceedOnError

public void setProceedOnError(boolean proceedOnError)

setVerbose

public void setVerbose(boolean verbose)

setTimers

public void setTimers(boolean timers)

setListFileArgs

public void setListFileArgs(boolean listFileArgs)

setReferenceInfo

public void setReferenceInfo(boolean referenceInfo)

setTime

public void setTime(boolean time)

setNoExit

public void setNoExit(boolean noExit)

setFailonerror

public void setFailonerror(boolean failonerror)

isForked

public boolean isForked()
Returns:
true if fork was set

setFork

public void setFork(boolean fork)

setMaxmem

public void setMaxmem(java.lang.String maxMem)

createJvmarg

public Commandline.Argument createJvmarg()
support for nested <jvmarg> elements


setTagFile

public void setTagFile(java.io.File file)

setOutjar

public void setOutjar(java.io.File file)

setOutxml

public void setOutxml(boolean outxml)

setOutxmlfile

public void setOutxmlfile(java.lang.String name)

setDestdir

public void setDestdir(java.io.File dir)

setTarget

public void setTarget(java.lang.String input)
Parameters:
input - a String in TARGET_INPUTS

setCompliance

public void setCompliance(java.lang.String input)
Language compliance level. If not set explicitly, eclipse default holds.

Parameters:
input - a String in COMPLIANCE_INPUTS

setSource

public void setSource(java.lang.String input)
Source compliance level. If not set explicitly, eclipse default holds.

Parameters:
input - a String in SOURCE_INPUTS

setCopyInjars

public void setCopyInjars(boolean doCopy)
Flag to copy all non-.class contents of injars to outjar after compile completes. Requires both injars and outjar.

Parameters:
doCopy -

setSourceRootCopyFilter

public void setSourceRootCopyFilter(java.lang.String filter)
Option to copy all files from all source root directories except those specified here. If this is specified and sourceroots are specified, then this will copy all files except those specified in the filter pattern. Requires sourceroots.

Parameters:
filter - a String acceptable as an excludes filter for an Ant Zip fileset.

setInpathDirCopyFilter

public void setInpathDirCopyFilter(java.lang.String filter)
Option to copy all files from all inpath directories except the files specified here. If this is specified and inpath directories are specified, then this will copy all files except those specified in the filter pattern. Requires inpath. If the input does not contain "**\/*.class", then this prepends it, to avoid overwriting woven classes with unwoven input.

Parameters:
filter - a String acceptable as an excludes filter for an Ant Zip fileset.

setX

public void setX(java.lang.String input)

setXDoneSignal

public void setXDoneSignal(java.lang.String doneSignal)

setMessageHolder

public void setMessageHolder(IMessageHolder holder)
direct API for testing


setMessageHolderClass

public void setMessageHolderClass(java.lang.String className)
Setup custom message handling.

Parameters:
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.
Throws:
BuildException - if unable to create instance of className

setCommandEditor

public void setCommandEditor(ICommandEditor editor)
direct API for testing


setCommandEditorClass

public void setCommandEditorClass(java.lang.String className)
Setup command-line filter. To do this staticly, define the environment variable org.aspectj.tools.ant.taskdefs.AjcTask.COMMAND_EDITOR with the className parameter.

Parameters:
className - the String fully-qualified-name of a class reachable from this object's class loader, implementing ICommandEditor, and having a public no-argument constructor.
Throws:
BuildException - if unable to create instance of className

incPath

protected Path incPath(Path source,
                       Path toAdd)
Add path elements to source path and return result. Elements are added even if they do not exist.

Parameters:
source - the Path to add to - may be null
toAdd - the Path to add - may be null
Returns:
the (never-null) Path that results

setSourcerootsref

public void setSourcerootsref(Reference ref)

setSourceRoots

public void setSourceRoots(Path roots)

createSourceRoots

public Path createSourceRoots()

setXWeaveDir

public void setXWeaveDir(java.io.File file)

setInjarsref

public void setInjarsref(Reference ref)

setInpathref

public void setInpathref(Reference ref)

setInjars

public void setInjars(Path path)

setInpath

public void setInpath(Path path)

createInjars

public Path createInjars()

createInpath

public Path createInpath()

setClasspath

public void setClasspath(Path path)

setClasspathref

public void setClasspathref(Reference classpathref)

createClasspath

public Path createClasspath()

setBootclasspath

public void setBootclasspath(Path path)

setBootclasspathref

public void setBootclasspathref(Reference bootclasspathref)

createBootclasspath

public Path createBootclasspath()

setForkclasspath

public void setForkclasspath(Path path)

setForkclasspathref

public void setForkclasspathref(Reference forkclasspathref)

createForkclasspath

public Path createForkclasspath()

setExtdirs

public void setExtdirs(Path path)

setExtdirsref

public void setExtdirsref(Reference ref)

createExtdirs

public Path createExtdirs()

setAspectpathref

public void setAspectpathref(Reference ref)

setAspectpath

public void setAspectpath(Path path)

createAspectpath

public Path createAspectpath()

setSrcDir

public void setSrcDir(Path path)

createSrc

public Path createSrc()

createSrcdir

public Path createSrcdir()

isInIncrementalMode

public boolean isInIncrementalMode()
Returns:
true if in incremental mode (command-line or file)

isInIncrementalFileMode

public boolean isInIncrementalFileMode()
Returns:
true if in incremental file mode

setArgfilesref

public void setArgfilesref(Reference ref)

setArgfiles

public void setArgfiles(Path path)

createArgfiles

public Path createArgfiles()

setInxmlref

public void setInxmlref(Reference ref)

setInxml

public void setInxml(Path path)

createInxml

public Path createInxml()

execute

public void execute()
             throws BuildException
Compile using ajc per settings.

Throws:
BuildException - if the compilation has problems or if there were compiler errors and failonerror is true.

quit

public boolean quit()
Halt processing. This tells main in the same vm to quit. It fails when running in forked mode.

Returns:
true if not in forked mode and main has quit or been told to quit

setupOptions

protected void setupOptions()
Create any pseudo-options required to implement some of the macro options

Throws:
BuildException - if options conflict

zipDirectory

protected java.io.File zipDirectory(java.io.File dir)

verifyOptions

protected void verifyOptions()

executeInSameVM

protected void executeInSameVM(java.lang.String[] args)
Run the compile in the same VM by loading the compiler (Main), setting up any message holders, doing the compile, and converting abort/failure and error messages to BuildException, as appropriate.

Throws:
BuildException - if abort or failure messages or if errors and failonerror.

executeInOtherVM

protected void executeInOtherVM(java.lang.String[] args)
Execute in a separate VM. Differences from normal same-VM execution:

Parameters:
args - String[] of the complete compiler command to execute
Throws:
BuildException - if ajc aborts (negative value) or if failonerror and there were compile errors.
See Also:
DefaultCompilerAdapter#executeExternalCompile(String[], int)

execInOtherVM

protected int execInOtherVM(java.lang.String[] args)
Execute in another process using the same JDK and the base directory of the project. XXX correct?

Parameters:
args -
Returns:

addFlaggedPath

protected static void addFlaggedPath(java.lang.String flag,
                                     Path path,
                                     java.util.List list)

addListArgs

protected void addListArgs(java.util.List list)
                    throws BuildException
Add to list any path or plural arguments.

Throws:
BuildException

check

protected final boolean check(java.io.File file,
                              java.lang.String name,
                              boolean isDir,
                              Location loc)
Throw BuildException unless file is valid.

Parameters:
file - the File to check
name - the symbolic name to print on error
isDir - if true, verify file is a directory
loc - the Location used to create sensible BuildException
Returns:
Throws:
BuildException - unless file valid

doCompletionTasks

protected void doCompletionTasks()
Called when compile or incremental compile is completing, this completes the output jar or directory by copying resources if requested. Note: this is a callback run synchronously by the compiler. That means exceptions thrown here are caught by Main.run(..) and passed to the message handler.


readArguments

public void readArguments(java.lang.String[] args)
Read arguments in as if from a command line, mainly to support compiler adapter compilerarg subelement.

Parameters:
args - the String[] of arguments to read

logVerbose

protected void logVerbose(java.lang.String text)