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
  • Field Details

  • Constructor Details

    • AjcTask

      public AjcTask()
  • Method Details

    • setupAjc

      public String 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.

      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

      public static 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(String ignored)
    • validCommaList

      protected String validCommaList(String list, List valid, String label)
    • validCommaList

      protected String validCommaList(String list, List valid, String label, int max)
    • setProc

      public void setProc(String proc)
      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

      public void setProcessor(String processors)
      -processor class1[,class2,class3...] Names of the annotation processors to run. This bypasses the default discovery process.
    • setProcessorpath

      public 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.
    • setS

      public void setS(String s)
      -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

      public void setXJoinpoints(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(String warnings)
    • setDebug

      public void setDebug(boolean debug)
    • setDebugLevel

      public void setDebugLevel(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(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(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(String encoding)
    • setLog

      public void setLog(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(String maxMem)
    • createJvmarg

      public org.apache.tools.ant.types.Commandline.Argument createJvmarg()
      support for nested <jvmarg> elements
    • createCompilerarg

      public AjcTask.CompilerArg createCompilerarg()
    • setTagFile

      public void setTagFile(File file)
    • setOutjar

      public void setOutjar(File file)
    • setOutxml

      public void setOutxml(boolean outxml)
    • setOutxmlfile

      public void setOutxmlfile(String name)
    • setDestdir

      public void setDestdir(File dir)
    • setTarget

      public void setTarget(String input)
      Parameters:
      input - a String in TARGET_INPUTS
    • setCompliance

      public void setCompliance(String input)
      Language compliance level. If not set explicitly, eclipse default holds.
      Parameters:
      input - a String in COMPLIANCE_INPUTS
    • setSource

      public void setSource(String input)
      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

      public void setSourceRootCopyFilter(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(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(String input)
    • setXDoneSignal

      public void setXDoneSignal(String doneSignal)
    • setMessageHolder

      public void setMessageHolder(IMessageHolder holder)
      direct API for testing
    • setMessageHolderClass

      public void setMessageHolderClass(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:
      org.apache.tools.ant.BuildException - if unable to create instance of className
    • setCommandEditor

      public void setCommandEditor(ICommandEditor editor)
      direct API for testing
    • setCommandEditorClass

      public void setCommandEditorClass(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:
      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 null
      toAdd - 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

      public void setXWeaveDir(File file)
    • 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.BuildException
      Compile using ajc per settings.
      Overrides:
      execute in class org.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

      protected File zipDirectory(File dir)
    • verifyOptions

      protected void verifyOptions()
      Throws:
      org.apache.tools.ant.BuildException - if options conflict
    • executeInSameVM

      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.
      Throws:
      org.apache.tools.ant.BuildException - if abort or failure messages or if errors and failonerror.
    • executeInOtherVM

      protected void executeInOtherVM(String[] args)
      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

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

      protected static void addFlaggedPath(String flag, org.apache.tools.ant.types.Path path, List<String> list)
    • addListArgs

      protected void addListArgs(List<String> list) throws org.apache.tools.ant.BuildException
      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 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:
      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

      public void readArguments(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(String text)