Class ProjectHelper
- Direct Known Subclasses:
ProjectHelper2
,ProjectHelperImpl
This class also provide static wrappers for common introspection.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Possible value for target's onMissingExtensionPoint attribute. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The URI for ant specific attributesstatic final String
The URI for ant name spacestatic final String
The URI for antlib current definitionsstatic final String
Polymorphic attributestatic final String
Deprecated.use MagicNames.ANTLIB_PREFIXstatic final String
Deprecated.use MagicNames.PROJECT_HELPER_CLASSstatic final String
Deprecated.use MagicNames.REFID_PROJECT_HELPERstatic final String
Deprecated.use MagicNames.PROJECT_HELPER_SERVICEstatic final String
constant to denote use project name as target prefix -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic BuildException
addLocationToBuildException
(BuildException ex, Location newLocation) Add location to build exception.static void
Adds the content of #PCDATA sections to an element.static void
Adds the content of #PCDATA sections to an element.boolean
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.boolean
canParseBuildFile
(Resource buildFile) Check if the helper supports the kind of file.static void
configure
(Object target, AttributeList attrs, Project project) Deprecated.since 1.6.x.static void
configureProject
(Project project, File buildFile) Configures the project with the contents of the specified build file.static String
extractNameFromComponentName
(String componentName) extract the element name from a component namestatic String
extractUriFromComponentName
(String componentName) extract a uri from a component namestatic String
genComponentName
(String uri, String name) Map a namespaced {uri,name} to an internal string format.static ClassLoader
Deprecated.since 1.6.x.static String
The separator between the prefix and the target name.static String
The prefix to prepend to imported target names.The file name of the build script to be parsed if none specified on the command lineExtension stack.Import stack.static ProjectHelper
Get the first project helper found in the classpathstatic boolean
Whether the current file should be read in include as opposed to import mode.static String
Convert an attribute namespace to a "component name".void
Parses the project file, configuring the project as it goes.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.static void
Deprecated.since 1.6.x.static String
replaceProperties
(Project project, String value) Deprecated.since 1.6.x.static String
Deprecated.since 1.6.x.void
resolveExtensionOfAttributes
(Project project) Check extensionStack and inject all targets having extensionOf attributes into extensionPoint.static void
Sets the separator between the prefix and the target name.static void
setCurrentTargetPrefix
(String prefix) Sets the prefix to prepend to imported target names.static void
setInIncludeMode
(boolean includeMode) Sets whether the current file should be read in include as opposed to import mode.static void
storeChild
(Project project, Object parent, Object child, String tag) Stores a configured child element within its parent object.
-
Field Details
-
ANT_CORE_URI
-
ANT_CURRENT_URI
-
ANT_ATTRIBUTE_URI
The URI for ant specific attributes- Since:
- Ant 1.9.1
- See Also:
-
ANTLIB_URI
Deprecated.use MagicNames.ANTLIB_PREFIXThe URI for defined types/tasks - the format is antlib:<package>- See Also:
-
ANT_TYPE
-
HELPER_PROPERTY
Deprecated.use MagicNames.PROJECT_HELPER_CLASSName of JVM system property which provides the name of the ProjectHelper class to use.- See Also:
-
SERVICE_ID
Deprecated.use MagicNames.PROJECT_HELPER_SERVICEThe service identifier in jars which provide Project Helper implementations.- See Also:
-
PROJECTHELPER_REFERENCE
Deprecated.use MagicNames.REFID_PROJECT_HELPERname of project helper reference that we add to a project- See Also:
-
USE_PROJECT_NAME_AS_TARGET_PREFIX
constant to denote use project name as target prefix- Since:
- Ant 1.9.1
- See Also:
-
-
Constructor Details
-
ProjectHelper
public ProjectHelper()
-
-
Method Details
-
configureProject
Configures the project with the contents of the specified build file.- Parameters:
project
- The project to configure. Must not benull
.buildFile
- A build file giving the project's configuration. Must not benull
.- Throws:
BuildException
- if the configuration is invalid or cannot be read
-
getImportStack
-
getExtensionStack
Extension stack. Used to keep track of targets that extend extension points.- 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
ProjectHelper.OnMissingExtensionPoint
.
-
getCurrentTargetPrefix
The prefix to prepend to imported target names.May be set by <import>'s as attribute.
- Returns:
- the configured prefix or null
- Since:
- Ant 1.8.0
-
setCurrentTargetPrefix
Sets the prefix to prepend to imported target names.- Parameters:
prefix
- String- Since:
- Ant 1.8.0
-
getCurrentPrefixSeparator
The separator between the prefix and the target name.May be set by <import>'s prefixSeparator attribute.
- Returns:
- String
- Since:
- Ant 1.8.0
-
setCurrentPrefixSeparator
Sets the separator between the prefix and the target name.- Parameters:
sep
- String- Since:
- Ant 1.8.0
-
isInIncludeMode
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
- Since:
- Ant 1.8.0
-
setInIncludeMode
public static void setInIncludeMode(boolean includeMode) Sets whether the current file should be read in include as opposed to import mode.- Parameters:
includeMode
- boolean- Since:
- Ant 1.8.0
-
parse
Parses the project file, configuring the project as it goes.- Parameters:
project
- The project for the resulting ProjectHelper to configure. Must not benull
.source
- The source for XML configuration. A helper must support at least File, for backward compatibility. Helpers may support URL, InputStream, etc or specialized types.- Throws:
BuildException
- if the configuration is invalid or cannot be read- Since:
- Ant1.5
-
getProjectHelper
Get the first project helper found in the classpath- Returns:
- an project helper, never
null
- See Also:
-
getContextClassLoader
Deprecated.since 1.6.x. Use LoaderUtils.getContextClassLoader()JDK1.1 compatible access to the context class loader. Cut & paste from JAXP.- Returns:
- the current context class loader, or
null
if the context class loader is unavailable.
-
configure
@Deprecated 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
- The target object to be configured. Must not benull
.attrs
- A list of attributes to configure within the target. Must not benull
.project
- The project containing the target. Must not benull
.- Throws:
BuildException
- if any of the attributes can't be handled by the target
-
addText
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
- The project containing the target. Must not benull
.target
- The target object to be configured. Must not benull
.buf
- A character array of the text within the element. Will not benull
.start
- The start element in the array.count
- The number of characters to read from the array.- Throws:
BuildException
- if the target object doesn't accept text
-
addText
Adds the content of #PCDATA sections to an element.- Parameters:
project
- The project containing the target. Must not benull
.target
- The target object to be configured. Must not benull
.text
- Text to add to the target. May benull
, in which case this method call is a no-op.- Throws:
BuildException
- if the target object doesn't accept text
-
storeChild
Stores a configured child element within its parent object.- Parameters:
project
- Project containing the objects. May benull
.parent
- Parent object to add child to. Must not benull
.child
- Child object to store in parent. Should not benull
.tag
- Name of element which generated the child. May benull
, in which case the child is not stored.
-
replaceProperties
@Deprecated 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
- The project containing the properties to replace. Must not benull
.value
- The string to be scanned for property references. May benull
.- Returns:
- the original string with the properties replaced, or
null
if the original string isnull
. - Throws:
BuildException
- if the string contains an opening${
without a closing}
- Since:
- 1.5
-
replaceProperties
@Deprecated public static String replaceProperties(Project project, String value, Hashtable<String, Object> keys) throws BuildExceptionDeprecated.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
- The container project. This is used solely for logging purposes. Must not benull
.value
- The string to be scanned for property references. May benull
, in which case this method returns immediately with no effect.keys
- Mapping (String to Object) of property names to their values. Must not benull
.- Returns:
- the original string with the properties replaced, or
null
if the original string isnull
. - Throws:
BuildException
- if the string contains an opening${
without a closing}
-
parsePropertyString
@Deprecated 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
- Text to parse. Must not benull
.fragments
- List to add text fragments to. Must not benull
.propertyRefs
- List to add property names to. Must not benull
.- Throws:
BuildException
- if the string contains an opening${
without a closing}
-
genComponentName
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
- The namespace URIname
- The localname- Returns:
- The stringified form of the ns name
-
extractUriFromComponentName
-
extractNameFromComponentName
-
nsToComponentName
-
addLocationToBuildException
Add location to build exception.- Parameters:
ex
- the build exception, if the build exception does not includenewLocation
- the location of the calling task (may be null)- 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
-
canParseAntlibDescriptor
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- Returns:
- boolean
- Since:
- Ant 1.8.0
-
parseAntlibDescriptor
Parse the given URL as an antlib descriptor and return the content as something that can be turned into an Antlib task.- Parameters:
containingProject
- Projectsource
- Resource- Returns:
- UnknownElement
- Since:
- ant 1.8.0
-
canParseBuildFile
Check if the helper supports the kind of file. Some basic check on the extension's file should be done here.- Parameters:
buildFile
- the file expected to be parsed (nevernull
)- Returns:
- true if the helper supports it
- Since:
- Ant 1.8.0
-
getDefaultBuildFile
The file name of the build script to be parsed if none specified on the command line- Returns:
- the name of the default file (never
null
) - Since:
- Ant 1.8.0
-
resolveExtensionOfAttributes
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
- The project containing the target. Must not benull
.- Throws:
BuildException
- if OnMissingExtensionPoint.FAIL and extensionPoint does not exist- Since:
- 1.9
- See Also:
-