terp - the ANT Tasks
v1.3.337

com.codemesh.terp.ant.compiler.cpp
Class DynamicSourcesOption

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.Task
          extended by org.apache.tools.ant.taskdefs.Sequential
              extended by com.codemesh.terp.ant.TerpSequential
                  extended by com.codemesh.terp.ant.compiler.cpp.DynamicSourcesOption
All Implemented Interfaces:
CompilerOption<CppCompiler>, CppFileCreating, FileCreating<CppCompiler>, TerpAware, TerpContextHolder, java.lang.Cloneable, org.apache.tools.ant.TaskContainer

public class DynamicSourcesOption
extends TerpSequential
implements CppFileCreating

An option that acts as a task container for echo commands that dynamically create source files.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.codemesh.terp.ant.TerpAware
TerpAware.Delegate
 
Field Summary
 
Fields inherited from class org.apache.tools.ant.Task
target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project
 
Constructor Summary
DynamicSourcesOption()
           
 
Method Summary
 void addCommands(java.util.List<java.lang.String> commandList, CppCompiler compiler, CompilerPhase phase)
          Adds the compiler switches repreesnted by this option to the list of switches.
 boolean appliesTo(CppCompiler compiler, CompilerPhase phase)
          Returns true if this compiler option applies to the given compiler and compiler phase.
 TerpEcho createCreate()
          Adds a TerpEcho task to this task.
 java.util.List<java.lang.String> creates(CppCompiler compiler, CompilerPhase phase)
          Returns a list of filenames representing the files that are created due to the presence of this compiler option.
 void execute()
          Generates the files represented by the nested <create> elements, if and only if all task conditions are met.
 java.util.List<TerpEcho> getCreates()
          Returns all nested TerpEcho tasks.
 java.lang.String getIf()
          Returns the condition that must be satidifed to execute the implementing task.
 java.lang.String getOptions()
          Returns an optional identifier of an external compiler options instance.
 java.lang.String getUnless()
          Returns the condition that must not be satidifed to execute the implementing task.
protected  java.io.File safeGetFile(CppCompiler compiler, TerpEcho echo)
           
 boolean satisfies(TerpContext ctx)
          Returns true if both conditions are met within the given terp context.
 void setIf(java.lang.String condition)
          Sets a condition that must be satisfied to execute the implementing task.
 void setOptions(java.lang.String options)
          Sets the optional identifier of an external compiler options instance to be applied to the sources represented by this element.
 void setPhase(java.lang.String phase)
          Sets the compilation phase in which the sources are dynamically generated.
 void setProject(org.apache.tools.ant.Project p)
           
 void setUnless(java.lang.String condition)
          Sets a condition that must not be satisfied to execute the implementing task.
 
Methods inherited from class com.codemesh.terp.ant.TerpSequential
getContext, satisfiesConditions, setContext
 
Methods inherited from class org.apache.tools.ant.taskdefs.Sequential
addTask
 
Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DynamicSourcesOption

public DynamicSourcesOption()
Method Detail

setProject

public void setProject(org.apache.tools.ant.Project p)
Overrides:
setProject in class TerpSequential

setPhase

public void setPhase(java.lang.String phase)
Sets the compilation phase in which the sources are dynamically generated.

Parameters:
phase - the compilation phase, one of "precomp", "comp", "link", or "postlink".

getOptions

public java.lang.String getOptions()
Returns an optional identifier of an external compiler options instance. This option allows the addition of compilation options to a subset of source files.

Returns:
an external options set identifier or null if none is configured.

setOptions

public void setOptions(java.lang.String options)
Sets the optional identifier of an external compiler options instance to be applied to the sources represented by this element.

Parameters:
options - an identifier of a compiler options set.

addCommands

public void addCommands(java.util.List<java.lang.String> commandList,
                        CppCompiler compiler,
                        CompilerPhase phase)
Adds the compiler switches repreesnted by this option to the list of switches. Some compiler options may result in more than one switch being added to a compiler invocation. Other compiler options may result in different options being added in different phases (compilation vs. linking) of the build.

This method is called by the compiler repeatedly with different values for the compiler phase to account for these possibilities. Does not perform any action unless an external options identifier is set and it is the compilation phase.

Specified by:
addCommands in interface CompilerOption<CppCompiler>
Parameters:
commandList - the list to which the compiler switches represented by this option (if any) are added.
compiler - the compiler for which we're doing this.
phase - the compiler phase in wihch we're doing this.

appliesTo

public boolean appliesTo(CppCompiler compiler,
                         CompilerPhase phase)
Returns true if this compiler option applies to the given compiler and compiler phase. Not every option has switches to contribute for every compiler and every compilation phase. This method allows a quick, inexpensive check to filter out potentially more expensive calls later on. This function returns true if the given phase is equal to the phase to which this task applies.

Specified by:
appliesTo in interface CompilerOption<CppCompiler>
Parameters:
compiler - the compiler for which we're asking.
phase - the compiler phase we're executing.
Returns:

createCreate

public TerpEcho createCreate()
Adds a TerpEcho task to this task. The nested tasks will be executed sequentially if all conditions for task execution are met.

Returns:
a newly created, nested TerpEcho task.

getCreates

public java.util.List<TerpEcho> getCreates()
Returns all nested TerpEcho tasks.

Returns:
a list of nested tasks.

getIf

public java.lang.String getIf()
Returns the condition that must be satidifed to execute the implementing task.

Specified by:
getIf in interface CompilerOption<CppCompiler>
Specified by:
getIf in interface TerpAware
Overrides:
getIf in class TerpSequential
Returns:
the boolean expression.

setIf

public void setIf(java.lang.String condition)
Sets a condition that must be satisfied to execute the implementing task.

Specified by:
setIf in interface CompilerOption<CppCompiler>
Specified by:
setIf in interface TerpAware
Overrides:
setIf in class TerpSequential
Parameters:
condition - a terp expression that must evaluate to a boolean value.

getUnless

public java.lang.String getUnless()
Returns the condition that must not be satidifed to execute the implementing task.

Specified by:
getUnless in interface CompilerOption<CppCompiler>
Specified by:
getUnless in interface TerpAware
Overrides:
getUnless in class TerpSequential
Returns:
the boolean expression.

setUnless

public void setUnless(java.lang.String condition)
Sets a condition that must not be satisfied to execute the implementing task.

Specified by:
setUnless in interface CompilerOption<CppCompiler>
Specified by:
setUnless in interface TerpAware
Overrides:
setUnless in class TerpSequential
Parameters:
condition - a terp expression that must evaluate to a boolean value.

satisfies

public boolean satisfies(TerpContext ctx)
Returns true if both conditions are met within the given terp context.

Specified by:
satisfies in interface CompilerOption<CppCompiler>
Parameters:
ctx - the terp context in which the logical expressions are evaluated.
Returns:
true or false.

creates

public java.util.List<java.lang.String> creates(CppCompiler compiler,
                                                CompilerPhase phase)
Returns a list of filenames representing the files that are created due to the presence of this compiler option. The list of files is predictable and repeatable if the nested TerpEcho tasks specify target filenames, which they are not strictly required to do. If a nested <create> element does not specify a target filename, a random filename is generated. This filename will be different every time this method is invoked.

Specified by:
creates in interface FileCreating<CppCompiler>
Parameters:
compiler - the compiler.
phase - the compilation phase.
Returns:
a list of files, possibly empty.

safeGetFile

protected java.io.File safeGetFile(CppCompiler compiler,
                                   TerpEcho echo)

execute

public void execute()
             throws org.apache.tools.ant.BuildException
Generates the files represented by the nested <create> elements, if and only if all task conditions are met.

Overrides:
execute in class TerpSequential
Throws:
org.apache.tools.ant.BuildException

terp - the ANT Tasks
v1.3.337

Copyright © 2008-2016 by Codemesh, Inc. All Rights Reserved.