Top Description Inners Fields Constructors Methods
org.apache.tools.ant

public Class ProjectHelper

extends Object
Class Inheritance
Known Direct Subclasses
org.apache.tools.ant.helper.ProjectHelper2, org.apache.tools.ant.helper.ProjectHelperImpl
Imports
java.io.File, java.util.Hashtable, .LinkedList, .List, .Locale, .Vector, org.apache.tools.ant.types.Resource, org.apache.tools.ant.types.resources.FileResource, org.apache.tools.ant.util.LoaderUtils, org.xml.sax.AttributeList

Configures a Project (complete with Targets and Tasks) based on a build file. It'll rely on a plugin to do the actual processing of the file.

This class also provide static wrappers for common introspection.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ProjectHelper.OnMissingExtensionPoint

Possible value for target's onMissingExtensionPoint attribute.

Field Summary

Modifier and TypeField and Description
public static final String
ANT_ATTRIBUTE_URI

The URI for ant specific attributes

public static final String
ANT_CORE_URI

The URI for ant name space

public static final String
ANT_CURRENT_URI

The URI for antlib current definitions

public static final String
ANT_TYPE

Polymorphic attribute

public static final String
ANTLIB_URI

The URI for defined types/tasks - the format is antlib:<package>

private List<String[]>
public static final String
HELPER_PROPERTY

Name of JVM system property which provides the name of the ProjectHelper class to use.

private Vector<Object>
private static final ThreadLocal<Boolean>
private static final ThreadLocal<String>
public static final String
PROJECTHELPER_REFERENCE

name of project helper reference that we add to a project

public static final String
SERVICE_ID

The service identifier in jars which provide Project Helper implementations.

private static final ThreadLocal<String>
public static final String
USE_PROJECT_NAME_AS_TARGET_PREFIX

constant to denote use project name as target prefix

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static BuildException

Returns:

a new build exception based in the build exception with location set to newLocation. If the original exception did not have a location, just return the build exception
addLocationToBuildException
(BuildException
the build exception, if the build exception does not include
ex
,
Location
the location of the calling task (may be null)
newLocation
)

Add location to build exception.

public static void
addText(Project
The project containing the target. Must not be null.
project
,
Object
The target object to be configured. Must not be null.
target
,
char[]
A character array of the text within the element. Will not be null.
buf
,
int
The start element in the array.
start
,
int
The number of characters to read from the array.
count
)

Adds the content of #PCDATA sections to an element.

public static void
addText(Project
The project containing the target. Must not be null.
project
,
Object
The target object to be configured. Must not be null.
target
,
String
Text to add to the target. May be null, in which case this method call is a no-op.
text
)

Adds the content of #PCDATA sections to an element.

public boolean

Returns:

boolean
canParseAntlibDescriptor
(Resource
Resource
r
)

Whether this instance of ProjectHelper can parse an Antlib descriptor given by the URL and return its content as an UnknownElement ready to be turned into an Antlib task.

public boolean

Returns:

true if the helper supports it
canParseBuildFile
(Resource
the file expected to be parsed (never null)
buildFile
)

Check if the helper supports the kind of file.

public static void
configure(Object
The target object to be configured. Must not be null.
target
,
AttributeList
A list of attributes to configure within the target. Must not be null.
attrs
,
Project
The project containing the target. Must not be null.
project
)

Deprecated since 1.6.x. Use IntrospectionHelper for each property.
Configures an object using an introspection handler.
public static void
configureProject(Project
The project to configure. Must not be null.
project
,
File
A build file giving the project's configuration. Must not be null.
buildFile
)

Configures the project with the contents of the specified build file.

public static String

Returns:

The element name of the component
extractNameFromComponentName
(String
The stringified form for {uri, name}
componentName
)

extract the element name from a component name

public static String

Returns:

The uri or "" if not present
extractUriFromComponentName
(String
The stringified form for {uri, name}
componentName
)

extract a uri from a component name

public static String

Returns:

The stringified form of the ns name
genComponentName
(String
The namespace URI
uri
,
String
The localname
name
)

Map a namespaced {uri,name} to an internal string format.

public static ClassLoader

Returns:

the current context class loader, or null if the context class loader is unavailable.
getContextClassLoader
()

Deprecated since 1.6.x. Use LoaderUtils.getContextClassLoader()
JDK1.1 compatible access to the context class loader.
public static String

Returns:

String
getCurrentPrefixSeparator
()

The separator between the prefix and the target name.

public static String

Returns:

the configured prefix or null
getCurrentTargetPrefix
()

The prefix to prepend to imported target names.

public String

Returns:

the name of the default file (never null)
getDefaultBuildFile
()

The file name of the build script to be parsed if none specified on the command line

public List<String[]>

Returns:

a list of three element string arrays where the first element is the name of the extensionpoint, the second the name of the target and the third the name of the enum like class OnMissingExtensionPoint.
getExtensionStack
()

Extension stack.

public Vector<Object>

Returns:

the stack of import source objects.
getImportStack
()

Import stack.

public static ProjectHelper

Returns:

an project helper, never null
getProjectHelper
()

Get the first project helper found in the classpath

public static boolean

Returns:

boolean
isInIncludeMode
()

Whether the current file should be read in include as opposed to import mode.

public static String

Returns:

the converted value.
nsToComponentName
(String
the xml namespace uri.
ns
)

Convert an attribute namespace to a "component name".

public void
parse(Project
The project for the resulting ProjectHelper to configure. Must not be null.
project
,
Object
The source for XML configuration. A helper must support at least File, for backward compatibility. Helpers may support URL, InputStream, etc or specialized types.
source
)

Parses the project file, configuring the project as it goes.

public UnknownElement

Returns:

UnknownElement
parseAntlibDescriptor
(Project
Project
containingProject
,
Resource
Resource
source
)

Parse the given URL as an antlib descriptor and return the content as something that can be turned into an Antlib task.

public static void
parsePropertyString(String
Text to parse. Must not be null.
value
,
Vector<String>
List to add text fragments to. Must not be null.
fragments
,
Vector<String>
List to add property names to. Must not be null.
propertyRefs
)

Deprecated since 1.6.x. Use PropertyHelper.
Parses a string containing ${xxx} style property references into two lists.
public static String

Returns:

the original string with the properties replaced, or null if the original string is null.
replaceProperties
(Project
The project containing the properties to replace. Must not be null.
project
,
String
The string to be scanned for property references. May be null.
value
)

Deprecated since 1.6.x. Use project.replaceProperties().
Replaces ${xxx} style constructions in the given value with the string value of the corresponding properties.
public static String

Returns:

the original string with the properties replaced, or null if the original string is null.
replaceProperties
(Project
The container project. This is used solely for logging purposes. Must not be null.
project
,
String
The string to be scanned for property references. May be null, in which case this method returns immediately with no effect.
value
,
Hashtable<String, Object>
Mapping (String to Object) of property names to their values. Must not be null.
keys
)

Deprecated since 1.6.x. Use PropertyHelper.
Replaces ${xxx} style constructions in the given value with the string value of the corresponding data types.
public void
resolveExtensionOfAttributes(Project
The project containing the target. Must not be null.
project
)

Check extensionStack and inject all targets having extensionOf attributes into extensionPoint.

public static void
setCurrentPrefixSeparator(String
String
sep
)

Sets the separator between the prefix and the target name.

public static void
setCurrentTargetPrefix(String
String
prefix
)

Sets the prefix to prepend to imported target names.

public static void
setInIncludeMode(boolean
boolean
includeMode
)

Sets whether the current file should be read in include as opposed to import mode.

public static void
storeChild(Project
Project containing the objects. May be null.
project
,
Object
Parent object to add child to. Must not be null.
parent
,
Object
Child object to store in parent. Should not be null.
child
,
String
Name of element which generated the child. May be null, in which case the child is not stored.
tag
)

Stores a configured child element within its parent object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ANT_ATTRIBUTE_URIback to summary
public static final String ANT_ATTRIBUTE_URI

The URI for ant specific attributes

Since
Ant 1.9.1
ANT_CORE_URIback to summary
public static final String ANT_CORE_URI

The URI for ant name space

ANT_CURRENT_URIback to summary
public static final String ANT_CURRENT_URI

The URI for antlib current definitions

ANT_TYPEback to summary
public static final String ANT_TYPE

Polymorphic attribute

ANTLIB_URIback to summary
public static final String ANTLIB_URI

Deprecated

use MagicNames.ANTLIB_PREFIX

The URI for defined types/tasks - the format is antlib:<package>

Annotations
@Deprecated
extensionStackback to summary
private List<String[]> extensionStack
HELPER_PROPERTYback to summary
public static final String HELPER_PROPERTY

Deprecated

use MagicNames.PROJECT_HELPER_CLASS

Name of JVM system property which provides the name of the ProjectHelper class to use.

Annotations
@Deprecated
importStackback to summary
private Vector<Object> importStack
inIncludeModeback to summary
private static final ThreadLocal<Boolean> inIncludeMode
prefixSeparatorback to summary
private static final ThreadLocal<String> prefixSeparator
PROJECTHELPER_REFERENCEback to summary
public static final String PROJECTHELPER_REFERENCE

Deprecated

use MagicNames.REFID_PROJECT_HELPER

name of project helper reference that we add to a project

Annotations
@Deprecated
SERVICE_IDback to summary
public static final String SERVICE_ID

Deprecated

use MagicNames.PROJECT_HELPER_SERVICE

The service identifier in jars which provide Project Helper implementations.

Annotations
@Deprecated
targetPrefixback to summary
private static final ThreadLocal<String> targetPrefix
USE_PROJECT_NAME_AS_TARGET_PREFIXback to summary
public static final String USE_PROJECT_NAME_AS_TARGET_PREFIX

constant to denote use project name as target prefix

Since
Ant 1.9.1

Constructor Detail

ProjectHelperback to summary
public ProjectHelper()

Method Detail

addLocationToBuildExceptionback to summary
public static BuildException addLocationToBuildException(BuildException ex, Location newLocation)

Add location to build exception.

Parameters
ex:BuildException

the build exception, if the build exception does not include

newLocation:Location

the location of the calling task (may be null)

Returns:BuildException

a new build exception based in the build exception with location set to newLocation. If the original exception did not have a location, just return the build exception

addTextback to summary
public static void addText(Project project, Object target, char[] buf, int start, int count) throws BuildException

Adds the content of #PCDATA sections to an element.

Parameters
project:Project

The project containing the target. Must not be null.

target:Object

The target object to be configured. Must not be null.

buf:char[]

A character array of the text within the element. Will not be null.

start:int

The start element in the array.

count:int

The number of characters to read from the array.

Exceptions
BuildException:
if the target object doesn't accept text
addTextback to summary
public static void addText(Project project, Object target, String text) throws BuildException

Adds the content of #PCDATA sections to an element.

Parameters
project:Project

The project containing the target. Must not be null.

target:Object

The target object to be configured. Must not be null.

text:String

Text to add to the target. May be null, in which case this method call is a no-op.

Exceptions
BuildException:
if the target object doesn't accept text
canParseAntlibDescriptorback to summary
public boolean canParseAntlibDescriptor(Resource r)

Whether this instance of ProjectHelper can parse an Antlib descriptor given by the URL and return its content as an UnknownElement ready to be turned into an Antlib task.

This method should not try to parse the content of the descriptor, the URL is only given as an argument to allow subclasses to decide whether they can support a given URL scheme or not.

Subclasses that return true in this method must also override parseAntlibDescriptor.

This implementation returns false.

Parameters
r:Resource

Resource

Returns:boolean

boolean

Since
Ant 1.8.0
canParseBuildFileback to summary
public boolean canParseBuildFile(Resource buildFile)

Check if the helper supports the kind of file. Some basic check on the extension's file should be done here.

Parameters
buildFile:Resource

the file expected to be parsed (never null)

Returns:boolean

true if the helper supports it

Since
Ant 1.8.0
configureback to summary
public static void configure(Object target, AttributeList attrs, Project project) throws BuildException

Deprecated

since 1.6.x. Use IntrospectionHelper for each property.

Configures an object using an introspection handler.

Parameters
target:Object

The target object to be configured. Must not be null.

attrs:AttributeList

A list of attributes to configure within the target. Must not be null.

project:Project

The project containing the target. Must not be null.

Annotations
@Deprecated
Exceptions
BuildException:
if any of the attributes can't be handled by the target
configureProjectback to summary
public static void configureProject(Project project, File buildFile) throws BuildException

Configures the project with the contents of the specified build file.

Parameters
project:Project

The project to configure. Must not be null.

buildFile:File

A build file giving the project's configuration. Must not be null.

Exceptions
BuildException:
if the configuration is invalid or cannot be read
extractNameFromComponentNameback to summary
public static String extractNameFromComponentName(String componentName)

extract the element name from a component name

Parameters
componentName:String

The stringified form for {uri, name}

Returns:String

The element name of the component

extractUriFromComponentNameback to summary
public static String extractUriFromComponentName(String componentName)

extract a uri from a component name

Parameters
componentName:String

The stringified form for {uri, name}

Returns:String

The uri or "" if not present

genComponentNameback to summary
public static String genComponentName(String uri, String name)

Map a namespaced {uri,name} to an internal string format. For BC purposes the names from the ant core uri will be mapped to "name", other names will be mapped to uri + ":" + name.

Parameters
uri:String

The namespace URI

name:String

The localname

Returns:String

The stringified form of the ns name

getContextClassLoaderback to summary
public static ClassLoader getContextClassLoader()

Deprecated

since 1.6.x. Use LoaderUtils.getContextClassLoader()

JDK1.1 compatible access to the context class loader. Cut & paste from JAXP.

Returns:ClassLoader

the current context class loader, or null if the context class loader is unavailable.

Annotations
@Deprecated
getCurrentPrefixSeparatorback to summary
public static String getCurrentPrefixSeparator()

The separator between the prefix and the target name.

May be set by <import>'s prefixSeparator attribute.

Returns:String

String

Since
Ant 1.8.0
getCurrentTargetPrefixback to summary
public static String getCurrentTargetPrefix()

The prefix to prepend to imported target names.

May be set by <import>'s as attribute.

Returns:String

the configured prefix or null

Since
Ant 1.8.0
getDefaultBuildFileback to summary
public String getDefaultBuildFile()

The file name of the build script to be parsed if none specified on the command line

Returns:String

the name of the default file (never null)

Since
Ant 1.8.0
getExtensionStackback to summary
public List<String[]> getExtensionStack()

Extension stack. Used to keep track of targets that extend extension points.

Returns:List<String[]>

a list of three element string arrays where the first element is the name of the extensionpoint, the second the name of the target and the third the name of the enum like class OnMissingExtensionPoint.

getImportStackback to summary
public Vector<Object> getImportStack()

Import stack. Used to keep track of imported files. Error reporting should display the import path.

Returns:Vector<Object>

the stack of import source objects.

getProjectHelperback to summary
public static ProjectHelper getProjectHelper()

Get the first project helper found in the classpath

Returns:ProjectHelper

an project helper, never null

See Also
org.apache.tools.ant.ProjectHelperRepository#getHelpers()
isInIncludeModeback to summary
public static boolean isInIncludeMode()

Whether the current file should be read in include as opposed to import mode.

In include mode included targets are only known by their prefixed names and their depends lists get rewritten so that all dependencies get the prefix as well.

In import mode imported targets are known by an adorned as well as a prefixed name and the unadorned target may be overwritten in the importing build file. The depends list of the imported targets is not modified at all.

Returns:boolean

boolean

Since
Ant 1.8.0
nsToComponentNameback to summary
public static String nsToComponentName(String ns)

Convert an attribute namespace to a "component name".

Parameters
ns:String

the xml namespace uri.

Returns:String

the converted value.

Since
Ant 1.9.1
parseback to summary
public void parse(Project project, Object source) throws BuildException

Parses the project file, configuring the project as it goes.

Parameters
project:Project

The project for the resulting ProjectHelper to configure. Must not be null.

source:Object

The source for XML configuration. A helper must support at least File, for backward compatibility. Helpers may support URL, InputStream, etc or specialized types.

Exceptions
BuildException:
if the configuration is invalid or cannot be read
Since
Ant1.5
parseAntlibDescriptorback to summary
public UnknownElement parseAntlibDescriptor(Project containingProject, Resource source)

Parse the given URL as an antlib descriptor and return the content as something that can be turned into an Antlib task.

Parameters
containingProject:Project

Project

source:Resource

Resource

Returns:UnknownElement

UnknownElement

Since
ant 1.8.0
parsePropertyStringback to summary
public static void parsePropertyString(String value, Vector<String> fragments, Vector<String> propertyRefs) throws BuildException

Deprecated

since 1.6.x. Use PropertyHelper.

Parses a string containing ${xxx} style property references into two lists. The first list is a collection of text fragments, while the other is a set of string property names. null entries in the first list indicate a property reference from the second list.

As of Ant 1.8.0 this method is never invoked by any code inside of Ant itself.

Parameters
value:String

Text to parse. Must not be null.

fragments:Vector<String>

List to add text fragments to. Must not be null.

propertyRefs:Vector<String>

List to add property names to. Must not be null.

Annotations
@Deprecated
Exceptions
BuildException:
if the string contains an opening ${ without a closing }
replacePropertiesback to summary
public static String replaceProperties(Project project, String value) throws BuildException

Deprecated

since 1.6.x. Use project.replaceProperties().

Replaces ${xxx} style constructions in the given value with the string value of the corresponding properties.

Parameters
project:Project

The project containing the properties to replace. Must not be null.

value:String

The string to be scanned for property references. May be null.

Returns:String

the original string with the properties replaced, or null if the original string is null.

Annotations
@Deprecated
Exceptions
BuildException:
if the string contains an opening ${ without a closing }
Since
1.5
replacePropertiesback to summary
public static String replaceProperties(Project project, String value, Hashtable<String, Object> keys) throws BuildException

Deprecated

since 1.6.x. Use PropertyHelper.

Replaces ${xxx} style constructions in the given value with the string value of the corresponding data types.

Parameters
project:Project

The container project. This is used solely for logging purposes. Must not be null.

value:String

The string to be scanned for property references. May be null, in which case this method returns immediately with no effect.

keys:Hashtable<String, Object>

Mapping (String to Object) of property names to their values. Must not be null.

Returns:String

the original string with the properties replaced, or null if the original string is null.

Annotations
@Deprecated
Exceptions
BuildException:
if the string contains an opening ${ without a closing }
resolveExtensionOfAttributesback to summary
public void resolveExtensionOfAttributes(Project project) throws BuildException

Check extensionStack and inject all targets having extensionOf attributes into extensionPoint.

This method allow you to defer injection and have a powerful control of extensionPoint wiring.

This should be invoked by each concrete implementation of ProjectHelper when the root "buildfile" and all imported/included buildfile are loaded.

Parameters
project:Project

The project containing the target. Must not be null.

Exceptions
BuildException:
if OnMissingExtensionPoint.FAIL and extensionPoint does not exist
Since
1.9
See Also
OnMissingExtensionPoint
setCurrentPrefixSeparatorback to summary
public static void setCurrentPrefixSeparator(String sep)

Sets the separator between the prefix and the target name.

Parameters
sep:String

String

Since
Ant 1.8.0
setCurrentTargetPrefixback to summary
public static void setCurrentTargetPrefix(String prefix)

Sets the prefix to prepend to imported target names.

Parameters
prefix:String

String

Since
Ant 1.8.0
setInIncludeModeback to summary
public static void setInIncludeMode(boolean includeMode)

Sets whether the current file should be read in include as opposed to import mode.

Parameters
includeMode:boolean

boolean

Since
Ant 1.8.0
storeChildback to summary
public static void storeChild(Project project, Object parent, Object child, String tag)

Stores a configured child element within its parent object.

Parameters
project:Project

Project containing the objects. May be null.

parent:Object

Parent object to add child to. Must not be null.

child:Object

Child object to store in parent. Should not be null.

tag:String

Name of element which generated the child. May be null, in which case the child is not stored.

org.apache.tools.ant back to summary

public final Class ProjectHelper.OnMissingExtensionPoint

extends Object
Class Inheritance

Possible value for target's onMissingExtensionPoint attribute. It determines how to deal with targets that want to extend missing extension-points.

This class behaves like a Java 1.5 Enum class.

Since
1.8.2

Field Summary

Modifier and TypeField and Description
public static final ProjectHelper.OnMissingExtensionPoint
FAIL

fail if the extension-point is not defined

public static final ProjectHelper.OnMissingExtensionPoint
IGNORE

ignore the extensionOf attribute if the extension-point is not defined

private final String
private static final ProjectHelper.OnMissingExtensionPoint[]
public static final ProjectHelper.OnMissingExtensionPoint
WARN

warn if the extension-point is not defined

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public String
name()

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public static ProjectHelper.OnMissingExtensionPoint
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

FAILback to summary
public static final ProjectHelper.OnMissingExtensionPoint FAIL

fail if the extension-point is not defined

IGNOREback to summary
public static final ProjectHelper.OnMissingExtensionPoint IGNORE

ignore the extensionOf attribute if the extension-point is not defined

nameback to summary
private final String name
valuesback to summary
private static final ProjectHelper.OnMissingExtensionPoint[] values
WARNback to summary
public static final ProjectHelper.OnMissingExtensionPoint WARN

warn if the extension-point is not defined

Constructor Detail

OnMissingExtensionPointback to summary
private OnMissingExtensionPoint(String name)

Method Detail

nameback to summary
public String name()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

valueOfback to summary
public static ProjectHelper.OnMissingExtensionPoint valueOf(String name)