Package org.aspectj.tools.ant.taskdefs
Class AjcTask
java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.tools.ant.taskdefs.MatchingTask
org.aspectj.tools.ant.taskdefs.AjcTask
- All Implemented Interfaces:
org.apache.tools.ant.types.selectors.SelectorContainer
public class AjcTask
extends org.apache.tools.ant.taskdefs.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
Modifier and TypeClassDescriptionstatic class
static class
Commandline wrapper that only permits addition of non-empty values and converts to argfile form if necessary. -
Field Summary
Fields inherited from class org.apache.tools.ant.taskdefs.MatchingTask
fileset
Fields inherited from class org.apache.tools.ant.Task
description, location, target, taskName, taskType, wrapper
Fields inherited from class org.apache.tools.ant.ProjectComponent
project
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected static void
addFlaggedPath(String flag, org.apache.tools.ant.types.Path path, List<String> list)
protected void
addListArgs(List<String> list)
Add to list any path or plural arguments.protected boolean
Throw BuildException unless file is valid.org.apache.tools.ant.types.Path
org.apache.tools.ant.types.Path
org.apache.tools.ant.types.Path
org.apache.tools.ant.types.Path
org.apache.tools.ant.types.Path
org.apache.tools.ant.types.Path
org.apache.tools.ant.types.Path
org.apache.tools.ant.types.Path
org.apache.tools.ant.types.Path
org.apache.tools.ant.types.Commandline.Argument
support for nested <jvmarg> elementsorg.apache.tools.ant.types.Path
org.apache.tools.ant.types.Path
org.apache.tools.ant.types.Path
protected void
Called when compile or incremental compile is completing, this completes the output jar or directory by copying resources if requested.protected int
execInOtherVM(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(String[] args)
Execute in a separate VM.protected void
executeInSameVM(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 File
Find aspectjtools.jar on the task or system classpath.protected void
protected org.apache.tools.ant.types.Path
incPath(org.apache.tools.ant.types.Path source, org.apache.tools.ant.types.Path toAdd)
Add path elements to source path and return result.boolean
isForked()
boolean
boolean
protected void
logVerbose(String text)
boolean
quit()
Halt processing.void
readArguments(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(org.apache.tools.ant.types.Path path)
void
setArgfilesref(org.apache.tools.ant.types.Reference ref)
void
setAspectpath(org.apache.tools.ant.types.Path path)
void
setAspectpathref(org.apache.tools.ant.types.Reference ref)
void
setBootclasspath(org.apache.tools.ant.types.Path path)
void
setBootclasspathref(org.apache.tools.ant.types.Reference bootclasspathref)
void
setCheckRuntimeVersion(boolean b)
void
setClasspath(org.apache.tools.ant.types.Path path)
void
setClasspathref(org.apache.tools.ant.types.Reference classpathref)
void
setCommandEditor(ICommandEditor editor)
direct API for testingvoid
setCommandEditorClass(String className)
Setup command-line filter.void
setCompliance(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(String level)
void
setDeprecation(boolean deprecation)
void
setDestdir(File dir)
void
setEmacssym(boolean emacssym)
void
setEncoding(String encoding)
void
setExtdirs(org.apache.tools.ant.types.Path path)
void
setExtdirsref(org.apache.tools.ant.types.Reference ref)
void
setFailonerror(boolean failonerror)
void
setFork(boolean fork)
void
setForkclasspath(org.apache.tools.ant.types.Path path)
void
setForkclasspathref(org.apache.tools.ant.types.Reference forkclasspathref)
void
setHelp(boolean help)
void
setIncremental(boolean incremental)
void
setInjars(org.apache.tools.ant.types.Path path)
void
setInjarsref(org.apache.tools.ant.types.Reference ref)
void
setInpath(org.apache.tools.ant.types.Path path)
void
setInpathDirCopyFilter(String filter)
Option to copy all files from all inpath directories except the files specified here.void
setInpathref(org.apache.tools.ant.types.Reference ref)
void
setInxml(org.apache.tools.ant.types.Path path)
void
setInxmlref(org.apache.tools.ant.types.Reference ref)
void
setListFileArgs(boolean listFileArgs)
void
void
setLogCommand(boolean logCommand)
void
void
setMessageHolder(IMessageHolder holder)
direct API for testingvoid
setMessageHolderClass(String className)
Setup custom message handling.void
setNoExit(boolean noExit)
void
setNoImportError(boolean noImportError)
void
setNowarn(boolean nowarn)
void
setNoWeave(boolean b)
void
void
setOutxml(boolean outxml)
void
setOutxmlfile(String name)
void
setParameters(boolean b)
void
setPreserveAllLocals(boolean preserveAllLocals)
void
Controls whether annotation processing and/or compilation is done.void
setProceedOnError(boolean proceedOnError)
void
setProcessor(String processors)
-processor class1[,class2,class3...]void
setProcessorpath(String processorpath)
-processorpath path Specify where to find annotation processors; if this option is not used, the class path will be searched for processors.void
setReferenceInfo(boolean referenceInfo)
void
-s dir Specify the directory where to place generated source files.void
setShowWeaveInfo(boolean showweaveinfo)
void
Source compliance level.void
setSourceRootCopyFilter(String filter)
Option to copy all files from all source root directories except those specified here.void
setSourceRoots(org.apache.tools.ant.types.Path roots)
void
setSourcerootsref(org.apache.tools.ant.types.Reference ref)
void
setSrcDir(org.apache.tools.ant.types.Path path)
void
setTagFile(File file)
void
void
setTime(boolean time)
void
setTimers(boolean timers)
setupAjc(org.apache.tools.ant.taskdefs.Javac javac)
This method extracts javac arguments to ajc, and add arguments to make ajc behave more like javac in copying resources.protected void
Create any pseudo-options required to implement some of the macro optionsvoid
setVerbose(boolean verbose)
void
setVersion(boolean version)
void
void
void
setXaddSerialVersionUID(boolean addUID)
void
setXDoneSignal(String doneSignal)
void
setXJoinpoints(String optionalJoinpoints)
void
-Xlint:{error|warning|info} - set default level for -Xlint messagesvoid
setXlintfile(File xlintFile)
-Xlintfile {lint.properties} - enable or disable specific forms of -Xlint messages based on a lint properties file (default isorg/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(File file)
protected String
validCommaList(String list, List valid, String label)
protected String
validCommaList(String list, List valid, String label, int max)
protected void
protected File
zipDirectory(File dir)
Methods inherited from class org.apache.tools.ant.taskdefs.MatchingTask
add, addAnd, addContains, addContainsRegexp, addCustom, addDate, addDepend, addDepth, addDifferent, addFilename, addMajority, addModified, addNone, addNot, addOr, addPresent, addSelector, addSize, addType, appendSelector, createExclude, createExcludesFile, createInclude, createIncludesFile, createPatternSet, getDirectoryScanner, getImplicitFileSet, getSelectors, hasSelectors, selectorCount, selectorElements, setCaseSensitive, setDefaultexcludes, setExcludes, setExcludesfile, setFollowSymlinks, setIncludes, setIncludesfile, setProject, XsetIgnore, XsetItems
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, reconfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
Methods inherited from class org.apache.tools.ant.ProjectComponent
getProject
-
Field Details
-
COMMAND_EDITOR_NAME
-
cmd
-
-
Constructor Details
-
AjcTask
public AjcTask()
-
-
Method Details
-
setupAjc
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)- Returns:
- null if no error, or String error otherwise
-
findAspectjtoolsJar
Find aspectjtools.jar on the task or system classpath. Acceptaspectj{-}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
-
validCommaList
-
validCommaList
-
setProc
Controls whether annotation processing and/or compilation is done. -proc:none means that compilation takes place without annotation processing. -proc:only means that only annotation processing is done, without any subsequent compilation. -
setProcessor
-processor class1[,class2,class3...] Names of the annotation processors to run. This bypasses the default discovery process. -
setProcessorpath
-processorpath path Specify where to find annotation processors; if this option is not used, the class path will be searched for processors. -
setS
-s dir Specify the directory where to place generated source files. The directory must already exist; javac will not create it. If a class is part of a package, the compiler puts the source file in a subdirectory reflecting the package name, creating directories as needed. For example, if you specify -s C:\mysrc and the class is called com.mypackage.MyClass, then the source file will be placed in C:\mysrc\com\mypackage\MyClass.java. -
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
-
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
-
setDebug
public void setDebug(boolean debug) -
setDebugLevel
-
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
-Xlint:{error|warning|info} - set default level for -Xlint messages- Parameters:
xlint
- the String with one of error, warning, ignored
-
setXlintfile
-Xlintfile {lint.properties} - enable or disable specific forms of -Xlint messages based on a lint properties file (default isorg/aspectj/weaver/XLintDefault.properties
)- Parameters:
xlintFile
- the File with lint properties
-
setPreserveAllLocals
public void setPreserveAllLocals(boolean preserveAllLocals) -
setNoImportError
public void setNoImportError(boolean noImportError) -
setEncoding
-
setLog
-
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
-
createJvmarg
public org.apache.tools.ant.types.Commandline.Argument createJvmarg()support for nested <jvmarg> elements -
createCompilerarg
-
setTagFile
-
setOutjar
-
setOutxml
public void setOutxml(boolean outxml) -
setOutxmlfile
-
setDestdir
-
setTarget
- Parameters:
input
- a String in TARGET_INPUTS
-
setCompliance
Language compliance level. If not set explicitly, eclipse default holds.- Parameters:
input
- a String in COMPLIANCE_INPUTS
-
setSource
Source compliance level. If not set explicitly, eclipse default holds.- Parameters:
input
- a String in SOURCE_INPUTS
-
setParameters
public void setParameters(boolean b) -
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
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
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
-
setXDoneSignal
-
setMessageHolder
direct API for testing -
setMessageHolderClass
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:
org.apache.tools.ant.BuildException
- if unable to create instance of className
-
setCommandEditor
direct API for testing -
setCommandEditorClass
Setup command-line filter. To do this staticly, define the environment variableorg.aspectj.tools.ant.taskdefs.AjcTask.COMMAND_EDITOR
with theclassName
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:
org.apache.tools.ant.BuildException
- if unable to create instance of className
-
incPath
protected org.apache.tools.ant.types.Path incPath(org.apache.tools.ant.types.Path source, org.apache.tools.ant.types.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 nulltoAdd
- the Path to add - may be null- Returns:
- the (never-null) Path that results
-
setSourcerootsref
public void setSourcerootsref(org.apache.tools.ant.types.Reference ref) -
setSourceRoots
public void setSourceRoots(org.apache.tools.ant.types.Path roots) -
createSourceRoots
public org.apache.tools.ant.types.Path createSourceRoots() -
setXWeaveDir
-
setInjarsref
public void setInjarsref(org.apache.tools.ant.types.Reference ref) -
setInpathref
public void setInpathref(org.apache.tools.ant.types.Reference ref) -
setInjars
public void setInjars(org.apache.tools.ant.types.Path path) -
setInpath
public void setInpath(org.apache.tools.ant.types.Path path) -
createInjars
public org.apache.tools.ant.types.Path createInjars() -
createInpath
public org.apache.tools.ant.types.Path createInpath() -
setClasspath
public void setClasspath(org.apache.tools.ant.types.Path path) -
setClasspathref
public void setClasspathref(org.apache.tools.ant.types.Reference classpathref) -
createClasspath
public org.apache.tools.ant.types.Path createClasspath() -
setBootclasspath
public void setBootclasspath(org.apache.tools.ant.types.Path path) -
setBootclasspathref
public void setBootclasspathref(org.apache.tools.ant.types.Reference bootclasspathref) -
createBootclasspath
public org.apache.tools.ant.types.Path createBootclasspath() -
setForkclasspath
public void setForkclasspath(org.apache.tools.ant.types.Path path) -
setForkclasspathref
public void setForkclasspathref(org.apache.tools.ant.types.Reference forkclasspathref) -
createForkclasspath
public org.apache.tools.ant.types.Path createForkclasspath() -
setExtdirs
public void setExtdirs(org.apache.tools.ant.types.Path path) -
setExtdirsref
public void setExtdirsref(org.apache.tools.ant.types.Reference ref) -
createExtdirs
public org.apache.tools.ant.types.Path createExtdirs() -
setAspectpathref
public void setAspectpathref(org.apache.tools.ant.types.Reference ref) -
setAspectpath
public void setAspectpath(org.apache.tools.ant.types.Path path) -
createAspectpath
public org.apache.tools.ant.types.Path createAspectpath() -
setSrcDir
public void setSrcDir(org.apache.tools.ant.types.Path path) -
createSrc
public org.apache.tools.ant.types.Path createSrc() -
createSrcdir
public org.apache.tools.ant.types.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(org.apache.tools.ant.types.Reference ref) -
setArgfiles
public void setArgfiles(org.apache.tools.ant.types.Path path) -
createArgfiles
public org.apache.tools.ant.types.Path createArgfiles() -
setInxmlref
public void setInxmlref(org.apache.tools.ant.types.Reference ref) -
setInxml
public void setInxml(org.apache.tools.ant.types.Path path) -
createInxml
public org.apache.tools.ant.types.Path createInxml() -
execute
public void execute() throws org.apache.tools.ant.BuildExceptionCompile using ajc per settings.- Overrides:
execute
in classorg.apache.tools.ant.Task
- Throws:
org.apache.tools.ant.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:
org.apache.tools.ant.BuildException
- if options conflict
-
zipDirectory
-
verifyOptions
protected void verifyOptions()- Throws:
org.apache.tools.ant.BuildException
- if options conflict
-
executeInSameVM
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:
org.apache.tools.ant.BuildException
- if abort or failure messages or if errors and failonerror.
-
executeInOtherVM
Execute in a separate VM. Differences from normal same-VM execution:- ignores any message holder {class} set
- No resource-copying between interative runs
- failonerror fails when process interface fails to return negative values
- Parameters:
args
- String[] of the complete compiler command to execute- Throws:
org.apache.tools.ant.BuildException
- if ajc aborts (negative value) or if failonerror and there were compile errors.
-
execInOtherVM
Execute in another process using the same JDK and the base directory of the project. XXX correct? -
addFlaggedPath
-
addListArgs
Add to list any path or plural arguments.- Throws:
org.apache.tools.ant.BuildException
-
check
protected final boolean check(File file, String name, boolean isDir, org.apache.tools.ant.Location loc)Throw BuildException unless file is valid.- Parameters:
file
- the File to checkname
- the symbolic name to print on errorisDir
- if true, verify file is a directoryloc
- the Location used to create sensible BuildException- Returns:
- Throws:
org.apache.tools.ant.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
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
-