public class Project extends Object implements ResourceFactory
This class also encapsulates methods which allow files to be referred to using abstract path names which are translated to native system file paths at runtime.
Modifier and Type | Field and Description |
---|---|
static int |
MSG_DEBUG
Message priority of "debug".
|
static int |
MSG_ERR
Message priority of "error".
|
static int |
MSG_INFO
Message priority of "information".
|
static int |
MSG_VERBOSE
Message priority of "verbose".
|
static int |
MSG_WARN
Message priority of "warning".
|
static String |
TOKEN_END
Default filter end token.
|
static String |
TOKEN_START
Default filter start token.
|
Constructor and Description |
---|
Project()
Create a new Ant project.
|
Modifier and Type | Method and Description |
---|---|
void |
addBuildListener(BuildListener listener)
Add a build listener to the list.
|
void |
addDataTypeDefinition(String typeName,
Class<?> typeClass)
Add a new datatype definition.
|
void |
addIdReference(String id,
Object value)
Add an id reference.
|
void |
addOrReplaceTarget(String targetName,
Target target)
Add a target to the project, or replaces one with the same
name.
|
void |
addOrReplaceTarget(Target target)
Add a target to the project, or replaces one with the same
name.
|
void |
addReference(String referenceName,
Object value)
Add a reference to the project.
|
void |
addTarget(String targetName,
Target target)
Add a new target to the project.
|
void |
addTarget(Target target)
Add a new target to the project.
|
void |
addTaskDefinition(String taskName,
Class<?> taskClass)
Add a new task definition to the project.
|
void |
checkTaskClass(Class<?> taskClass)
Check whether or not a class is suitable for serving as Ant task.
|
void |
copyInheritedProperties(Project other)
Copy all user properties that have not been set on the
command line or a GUI tool from this instance to the Project
instance given as the argument.
|
void |
copyUserProperties(Project other)
Copy all user properties that have been set on the command
line or a GUI tool from this instance to the Project instance
given as the argument.
|
AntClassLoader |
createClassLoader(java.lang.ClassLoader parent,
Path path)
Factory method to create a class loader for loading classes from
a given path.
|
AntClassLoader |
createClassLoader(Path path)
Factory method to create a class loader for loading classes from
a given path.
|
Object |
createDataType(String typeName)
Create a new instance of a data type.
|
Project |
createSubProject()
Create and initialize a subproject.
|
Task |
createTask(String taskType)
Create a new instance of a task, adding it to a list of
created tasks for later invalidation.
|
int |
defaultInput(byte[] buffer,
int offset,
int length)
Read data from the default input stream.
|
void |
demuxFlush(String output,
boolean isError)
Demultiplex flush operations so that each task receives the appropriate
messages.
|
int |
demuxInput(byte[] buffer,
int offset,
int length)
Demux an input request to the correct task.
|
void |
demuxOutput(String output,
boolean isWarning)
Demultiplex output so that each task receives the appropriate
messages.
|
void |
executeSortedTargets(Vector<Target> sortedTargets)
Execute a
Vector of sorted targets. |
void |
executeTarget(String targetName)
Execute the specified target and any targets it depends on.
|
void |
executeTargets(Vector<String> names)
Execute the specified sequence of targets, and the targets
they depend on.
|
void |
fireBuildFinished(Throwable exception)
Send a "build finished" event to the build listeners
for this project.
|
void |
fireBuildStarted()
Send a "build started" event
to the build listeners for this project.
|
protected void |
fireMessageLogged(Project project,
String message,
int priority)
Send a "message logged" project level event
to the build listeners for this project.
|
protected void |
fireMessageLogged(Project project,
String message,
Throwable throwable,
int priority)
Send a "message logged" project level event
to the build listeners for this project.
|
protected void |
fireMessageLogged(Target target,
String message,
int priority)
Send a "message logged" target level event
to the build listeners for this project.
|
protected void |
fireMessageLogged(Target target,
String message,
Throwable throwable,
int priority)
Send a "message logged" target level event
to the build listeners for this project.
|
protected void |
fireMessageLogged(Task task,
String message,
int priority)
Send a "message logged" task level event
to the build listeners for this project.
|
protected void |
fireMessageLogged(Task task,
String message,
Throwable throwable,
int priority)
Send a "message logged" task level event
to the build listeners for this project.
|
void |
fireSubBuildFinished(Throwable exception)
Send a "subbuild finished" event to the build listeners for
this project.
|
void |
fireSubBuildStarted()
Send a "subbuild started" event to the build listeners for
this project.
|
protected void |
fireTargetFinished(Target target,
Throwable exception)
Send a "target finished" event to the build listeners
for this project.
|
protected void |
fireTargetStarted(Target target)
Send a "target started" event to the build listeners
for this project.
|
protected void |
fireTaskFinished(Task task,
Throwable exception)
Send a "task finished" event to the build listeners for this
project.
|
protected void |
fireTaskStarted(Task task)
Send a "task started" event to the build listeners
for this project.
|
File |
getBaseDir()
Return the base directory of the project as a file object.
|
Vector<BuildListener> |
getBuildListeners()
Return a copy of the list of build listeners for the project.
|
Map<String,Class<?>> |
getCopyOfDataTypeDefinitions()
Return the current datatype definition map.
|
Map<String,Object> |
getCopyOfReferences()
Return a map of the references in the project (String to
Object).
|
Map<String,Target> |
getCopyOfTargets()
Return the map of targets.
|
Map<String,Class<?>> |
getCopyOfTaskDefinitions()
Return the current task definition map.
|
java.lang.ClassLoader |
getCoreLoader()
Return the core classloader to use for this project.
|
Hashtable<String,Class<?>> |
getDataTypeDefinitions()
Return the current datatype definition hashtable.
|
InputStream |
getDefaultInputStream()
Get this project's input stream.
|
String |
getDefaultTarget()
Return the name of the default target of the project.
|
String |
getDescription()
Return the project description, if one has been set.
|
String |
getElementName(Object element)
Return a description of the type of the given element, with
special handling for instances of tasks and data types.
|
Executor |
getExecutor()
Get this Project's Executor (setting it if necessary).
|
FilterSet |
getGlobalFilterSet()
Return the set of global filters.
|
Hashtable<String,Object> |
getInheritedProperties()
Return a copy of the inherited property hashtable.
|
InputHandler |
getInputHandler()
Retrieve the current input handler.
|
String |
getName()
Return the project name, if one has been set.
|
static Project |
getProject(Object o)
Get the Project instance associated with the specified object.
|
Hashtable<String,Object> |
getProperties()
Return a copy of the properties table.
|
String |
getProperty(String propertyName)
Return the value of a property, if it is set.
|
<T> T |
getReference(String key)
Look up a reference by its key (ID).
|
Hashtable<String,Object> |
getReferences()
Return a map of the references in the project (String to Object).
|
Resource |
getResource(String name)
Resolve the file relative to the project's basedir and return it as a
FileResource.
|
Hashtable<String,Target> |
getTargets()
Return the hashtable of targets.
|
Hashtable<String,Class<?>> |
getTaskDefinitions()
Return the current task definition hashtable.
|
Task |
getThreadTask(Thread thread)
Get the current task associated with a thread, if any.
|
Hashtable<String,Object> |
getUserProperties()
Return a copy of the user property hashtable.
|
String |
getUserProperty(String propertyName)
Return the value of a user property, if it is set.
|
boolean |
hasReference(String key)
Does the project know this reference?
|
void |
inheritIDReferences(Project parent)
Inherit the id references.
|
void |
init()
Initialise the project.
|
void |
initProperties()
Initializes the properties.
|
void |
initSubProject(Project subProject)
Initialize a subproject.
|
boolean |
isKeepGoingMode()
Return the keep-going mode.
|
void |
log(String message)
Write a message to the log with the default log level
of MSG_INFO .
|
void |
log(String message,
int msgLevel)
Write a project level message to the log with the given log level.
|
void |
log(String message,
Throwable throwable,
int msgLevel)
Write a project level message to the log with the given log level.
|
void |
log(Target target,
String message,
int msgLevel)
Write a target level message to the log with the given log level.
|
void |
log(Target target,
String message,
Throwable throwable,
int msgLevel)
Write a target level message to the log with the given log level.
|
void |
log(Task task,
String message,
int msgLevel)
Write a task level message to the log with the given log level.
|
void |
log(Task task,
String message,
Throwable throwable,
int msgLevel)
Write a task level message to the log with the given log level.
|
void |
registerThreadTask(Thread thread,
Task task)
Register a task as the current task for a thread.
|
void |
removeBuildListener(BuildListener listener)
Remove a build listener from the list.
|
String |
replaceProperties(String value)
Replace ${} style constructions in the given value with the
string value of the corresponding data types.
|
File |
resolveFile(String fileName)
Return the canonical form of a filename.
|
void |
setBaseDir(File baseDir)
Set the base directory for the project, checking that
the given file exists and is a directory.
|
void |
setBasedir(String baseD)
Set the base directory for the project, checking that
the given filename exists and is a directory.
|
void |
setCoreLoader(java.lang.ClassLoader coreLoader)
Set the core classloader for the project.
|
void |
setDefault(String defaultTarget)
Set the default target of the project.
|
void |
setDefaultInputStream(InputStream defaultInputStream)
Set the default System input stream.
|
void |
setDescription(String description)
Set the project description.
|
void |
setExecutor(Executor e)
Set the Executor instance for this Project.
|
void |
setInheritedProperty(String name,
String value)
Set a user property, which cannot be overwritten by set/unset
property calls.
|
void |
setInputHandler(InputHandler handler)
Set the input handler.
|
void |
setJavaVersionProperty()
Set the
ant.java.version property and tests for
unsupported JVM versions. |
void |
setKeepGoingMode(boolean keepGoingMode)
Set "keep-going" mode.
|
void |
setName(String name)
Set the name of the project, also setting the user
property
ant.project.name . |
void |
setNewProperty(String name,
String value)
Set a property if no value currently exists.
|
void |
setProjectReference(Object obj)
Set a reference to this Project on the parameterized object.
|
void |
setProperty(String name,
String value)
Set a property.
|
void |
setSystemProperties()
Add all system properties which aren't already defined as
user properties to the project properties.
|
void |
setUserProperty(String name,
String value)
Set a user property, which cannot be overwritten by
set/unset property calls.
|
static boolean |
toBoolean(String s)
Return the boolean equivalent of a string, which is considered
true if either "on" , "true" ,
or "yes" is found, ignoring case. |
Vector<Target> |
topoSort(String[] root,
Hashtable<String,Target> targetTable,
boolean returnAll)
Topologically sort a set of targets.
|
Vector<Target> |
topoSort(String root,
Hashtable<String,Target> targetTable)
Topologically sort a set of targets.
|
Vector<Target> |
topoSort(String root,
Hashtable<String,Target> targetTable,
boolean returnAll)
Topologically sort a set of targets.
|
public static final int MSG_DEBUG
public static final int MSG_ERR
public static final int MSG_INFO
public static final int MSG_VERBOSE
public static final int MSG_WARN
public static final String TOKEN_END
public static final String TOKEN_START
public void addBuildListener(BuildListener listener)
listener
- The listener to add to the list.
Must not be null
.public void addDataTypeDefinition(String typeName, Class<?> typeClass)
typeName
- The name of the datatype.
Must not be null
.typeClass
- The full name of the class implementing the datatype.
Must not be null
.public void addIdReference(String id, Object value)
id
- the id to set.value
- the value to set it to (Unknown element in this case.public void addOrReplaceTarget(String targetName, Target target)
targetName
- The name to use for the target.
Must not be null
.target
- The target to be added or replaced in the project.
Must not be null
.public void addOrReplaceTarget(Target target)
target
- The target to be added or replaced in the project.
Must not be null
.public void addReference(String referenceName, Object value)
referenceName
- The name of the reference. Must not be null
.value
- The value of the reference.public void addTarget(String targetName, Target target) throws BuildException
targetName
- The name to use for the target.
Must not be null
.target
- The target to be added to the project.
Must not be null
.BuildException
- if the target already exists in the project.addOrReplaceTarget(String, Target)
public void addTarget(Target target) throws BuildException
target
- The target to be added to the project.
Must not be null
.BuildException
- if the target already exists in the projectaddOrReplaceTarget(Target)
public void addTaskDefinition(String taskName, Class<?> taskClass) throws BuildException
taskName
- The name of the task to add.
Must not be null
.taskClass
- The full name of the class implementing the task.
Must not be null
.BuildException
- if the class is unsuitable for being an Ant
task. An error level message is logged before
this exception is thrown.checkTaskClass(Class)
public void checkTaskClass(Class<?> taskClass) throws BuildException
taskClass
- The class to be checked.
Must not be null
.BuildException
- if the class is unsuitable for being an Ant
task. An error level message is logged before
this exception is thrown.public void copyInheritedProperties(Project other)
To copy all "user" properties, you will also have to call
copyUserProperties
.
other
- the project to copy the properties to. Must not be null.public void copyUserProperties(Project other)
To copy all "user" properties, you will also have to call
copyInheritedProperties
.
other
- the project to copy the properties to. Must not be null.public AntClassLoader createClassLoader(java.lang.ClassLoader parent, Path path)
parent
- the parent classloader for the new loader.path
- the path from which classes are to be loaded.public AntClassLoader createClassLoader(Path path)
path
- the path from which classes are to be loaded.public Object createDataType(String typeName) throws BuildException
typeName
- The name of the data type to create an instance of.
Must not be null
.null
if
the data type name is not recognised.BuildException
- if the data type name is recognised but
instance creation fails.public Project createSubProject()
Project
class will be used.public Task createTask(String taskType) throws BuildException
taskType
- The name of the task to create an instance of.
Must not be null
.null
if
the task name is not recognised.BuildException
- if the task name is recognised but task
creation fails.public int defaultInput(byte[] buffer, int offset, int length) throws IOException
buffer
- the buffer into which data is to be read.offset
- the offset into the buffer at which data is stored.length
- the amount of data to read.IOException
- if the data cannot be read.public void demuxFlush(String output, boolean isError)
output
- Message to handle. Should not be null
.isError
- Whether the text represents an error (true
)
or information (false
).public int demuxInput(byte[] buffer, int offset, int length) throws IOException
buffer
- the buffer into which data is to be read.offset
- the offset into the buffer at which data is stored.length
- the amount of data to read.IOException
- if the data cannot be read.public void demuxOutput(String output, boolean isWarning)
output
- Message to handle. Should not be null
.isWarning
- Whether the text represents an warning (true
)
or information (false
).public void executeSortedTargets(Vector<Target> sortedTargets) throws BuildException
Vector
of sorted targets.sortedTargets
- the aforementioned Vector
.BuildException
- on error.public void executeTarget(String targetName) throws BuildException
targetName
- The name of the target to execute.
Must not be null
.BuildException
- if the build failed.public void executeTargets(Vector<String> names) throws BuildException
names
- A vector of target name strings to execute.
Must not be null
.BuildException
- if the build failed.public void fireBuildFinished(Throwable exception)
exception
- an exception indicating a reason for a build
failure. May be null
, indicating
a successful build.public void fireBuildStarted()
protected void fireMessageLogged(Project project, String message, int priority)
project
- The project generating the event.
Should not be null
.message
- The message to send. Should not be null
.priority
- The priority of the message.protected void fireMessageLogged(Project project, String message, Throwable throwable, int priority)
project
- The project generating the event.
Should not be null
.message
- The message to send. Should not be null
.throwable
- The exception that caused this message. May be null
.priority
- The priority of the message.protected void fireMessageLogged(Target target, String message, int priority)
target
- The target generating the event.
Must not be null
.message
- The message to send. Should not be null
.priority
- The priority of the message.protected void fireMessageLogged(Target target, String message, Throwable throwable, int priority)
target
- The target generating the event.
Must not be null
.message
- The message to send. Should not be null
.throwable
- The exception that caused this message. May be null
.priority
- The priority of the message.protected void fireMessageLogged(Task task, String message, int priority)
task
- The task generating the event.
Must not be null
.message
- The message to send. Should not be null
.priority
- The priority of the message.protected void fireMessageLogged(Task task, String message, Throwable throwable, int priority)
task
- The task generating the event.
Must not be null
.message
- The message to send. Should not be null
.throwable
- The exception that caused this message. May be null
.priority
- The priority of the message.public void fireSubBuildFinished(Throwable exception)
exception
- an exception indicating a reason for a build
failure. May be null
, indicating
a successful build.public void fireSubBuildStarted()
protected void fireTargetFinished(Target target, Throwable exception)
target
- The target which has finished building.
Must not be null
.exception
- an exception indicating a reason for a build
failure. May be null
, indicating
a successful build.protected void fireTargetStarted(Target target)
target
- The target which is starting to build.
Must not be null
.protected void fireTaskFinished(Task task, Throwable exception)
task
- The task which has finished executing.
Must not be null
.exception
- an exception indicating a reason for a build
failure. May be null
, indicating
a successful build.protected void fireTaskStarted(Task task)
task
- The target which is starting to execute.
Must not be null
.public File getBaseDir()
null
if the
base directory has not been successfully set to a valid value.public Vector<BuildListener> getBuildListeners()
public Map<String,Class<?>> getCopyOfDataTypeDefinitions()
public Map<String,Object> getCopyOfReferences()
public Map<String,Target> getCopyOfTargets()
public Map<String,Class<?>> getCopyOfTaskDefinitions()
public java.lang.ClassLoader getCoreLoader()
null
, indicating that
the parent classloader should be used.public Hashtable<String,Class<?>> getDataTypeDefinitions()
public InputStream getDefaultInputStream()
public String getDefaultTarget()
null
if no default has been set.public String getDescription()
null
if it hasn't
been set.public String getElementName(Object element)
This is useful for logging purposes.
element
- The element to describe.
Must not be null
.public Executor getExecutor()
public FilterSet getGlobalFilterSet()
public Hashtable<String,Object> getInheritedProperties()
public InputHandler getInputHandler()
public String getName()
null
if it hasn't been set.public static Project getProject(Object o)
o
- the object to query.public Hashtable<String,Object> getProperties()
public String getProperty(String propertyName)
propertyName
- The name of the property.
May be null
, in which case
the return value is also null
.null
for no match
or if a null
name is provided.public <T> T getReference(String key)
key
- The key for the desired reference.
Must not be null
.null
if
there is no such reference in the project, with type inference.public Hashtable<String,Object> getReferences()
public Resource getResource(String name)
getResource
in interface ResourceFactory
name
- the name of the file to resolve.public Hashtable<String,Target> getTargets()
public Hashtable<String,Class<?>> getTaskDefinitions()
public Task getThreadTask(Thread thread)
thread
- the thread for which the task is required.public Hashtable<String,Object> getUserProperties()
public String getUserProperty(String propertyName)
propertyName
- The name of the property.
May be null
, in which case
the return value is also null
.null
for no match
or if a null
name is provided.public boolean hasReference(String key)
public void inheritIDReferences(Project parent)
parent
- the parent project of this project.public void init() throws BuildException
BuildException
- if the default task list cannot be loaded.public void initProperties() throws BuildException
BuildException
- if an vital property could not be set.public void initSubProject(Project subProject)
subProject
- the subproject to initialize.public boolean isKeepGoingMode()
ant.executor.class
property, they will have no effect.public void log(String message)
message
- The text to log. Should not be null
.public void log(String message, int msgLevel)
message
- The text to log. Should not be null
.msgLevel
- The log priority level to use.public void log(String message, Throwable throwable, int msgLevel)
message
- The text to log. Should not be null
.throwable
- The exception causing this log, may be null
.msgLevel
- The log priority level to use.public void log(Target target, String message, int msgLevel)
target
- The target to use in the log.
Must not be null
.message
- The text to log. Should not be null
.msgLevel
- The log priority level to use.public void log(Target target, String message, Throwable throwable, int msgLevel)
target
- The target to use in the log.
Must not be null
.message
- The text to log. Should not be null
.throwable
- The exception causing this log, may be null
.msgLevel
- The log priority level to use.public void log(Task task, String message, int msgLevel)
task
- The task to use in the log. Must not be null
.message
- The text to log. Should not be null
.msgLevel
- The log priority level to use.public void log(Task task, String message, Throwable throwable, int msgLevel)
task
- The task to use in the log. Must not be null
.message
- The text to log. Should not be null
.throwable
- The exception causing this log, may be null
.msgLevel
- The log priority level to use.public void registerThreadTask(Thread thread, Task task)
thread
- the thread on which the task is registered.task
- the task to be registered.public void removeBuildListener(BuildListener listener)
listener
- The listener to remove from the list.
Should not be null
.public String replaceProperties(String value) throws BuildException
value
- The string to be scanned for property references.
May be null
.null
if the given string is
null
.BuildException
- if the given value has an unclosed
property name, e.g. ${xxx
.public File resolveFile(String fileName)
If the specified file name is relative it is resolved with respect to the project's base directory.
fileName
- The name of the file to resolve.
Must not be null
.public void setBaseDir(File baseDir) throws BuildException
baseDir
- The project base directory.
Must not be null
.BuildException
- if the specified file doesn't exist or
isn't a directory.public void setBasedir(String baseD) throws BuildException
baseD
- The project base directory.
Must not be null
.BuildException
- if the directory if invalid.public void setCoreLoader(java.lang.ClassLoader coreLoader)
null
classloader is specified, the parent classloader should be used.coreLoader
- The classloader to use for the project.
May be null
.public void setDefault(String defaultTarget)
defaultTarget
- The name of the default target for this project.
May be null
, indicating that there is
no default target.public void setDefaultInputStream(InputStream defaultInputStream)
defaultInputStream
- the default input stream to use when input
is requested.public void setDescription(String description)
description
- The description of the project.
May be null
.public void setExecutor(Executor e)
e
- the Executor to use.public void setInheritedProperty(String name, String value)
name
- The name of property to set.
Must not be null
.value
- The new value of the property.
Must not be null
.setProperty(String,String)
public void setInputHandler(InputHandler handler)
handler
- the InputHandler instance to use for gathering input.public void setJavaVersionProperty() throws BuildException
ant.java.version
property and tests for
unsupported JVM versions. If the version is supported,
verbose log messages are generated to record the Java version
and operating system name.BuildException
- if this Java version is not supported.JavaEnvUtils.getJavaVersion()
public void setKeepGoingMode(boolean keepGoingMode)
ant.executor.class
property, they will have no effect.keepGoingMode
- "keep-going" modepublic void setName(String name)
ant.project.name
.name
- The name of the project.
Must not be null
.public void setNewProperty(String name, String value)
name
- The name of property to set.
Must not be null
.value
- The new value of the property.
Must not be null
.public final void setProjectReference(Object obj)
obj
- the object to invoke setProject(this) on.public void setProperty(String name, String value)
name
- The name of property to set.
Must not be null
.value
- The new value of the property.
Must not be null
.public void setSystemProperties()
public void setUserProperty(String name, String value)
name
- The name of property to set.
Must not be null
.value
- The new value of the property.
Must not be null
.setProperty(String,String)
public static boolean toBoolean(String s)
true
if either "on"
, "true"
,
or "yes"
is found, ignoring case.s
- The string to convert to a boolean value.true
if the given string is "on"
,
"true"
or "yes"
, or
false
otherwise.public final Vector<Target> topoSort(String[] root, Hashtable<String,Target> targetTable, boolean returnAll) throws BuildException
root
- String[]
containing the names of the root targets.
The sort is created in such a way that the ordered sequence of
Targets is the minimum possible such sequence to the specified
root targets.
Must not be null
.targetTable
- A map of names to targets (String to Target).
Must not be null
.returnAll
- boolean
indicating whether to return all
targets, or the execution sequence only.BuildException
- if there is a cyclic dependency among the
targets, or if a named target does not exist.public final Vector<Target> topoSort(String root, Hashtable<String,Target> targetTable) throws BuildException
topoSort(new String[] {root}, targets, true)
.root
- The name of the root target. The sort is created in such
a way that the sequence of Targets up to the root
target is the minimum possible such sequence.
Must not be null
.targetTable
- A Hashtable mapping names to Targets.
Must not be null
.BuildException
- if there is a cyclic dependency among the
targets, or if a named target does not exist.public final Vector<Target> topoSort(String root, Hashtable<String,Target> targetTable, boolean returnAll) throws BuildException
topoSort(new String[] {root}, targets, returnAll)
.root
- The name of the root target. The sort is created in such
a way that the sequence of Targets up to the root
target is the minimum possible such sequence.
Must not be null
.targetTable
- A Hashtable mapping names to Targets.
Must not be null
.returnAll
- boolean
indicating whether to return all
targets, or the execution sequence only.BuildException
- if there is a cyclic dependency among the
targets, or if a named target does not exist.