public class ProjectHelper extends Object
This class also provide static wrappers for common introspection.
Modifier and Type | Class and Description |
---|---|
static class |
ProjectHelper.OnMissingExtensionPoint
Possible value for target's onMissingExtensionPoint attribute.
|
Modifier and Type | Field and Description |
---|---|
static String |
ANT_ATTRIBUTE_URI
The URI for ant specific attributes
|
static String |
ANT_CORE_URI
The URI for ant name space
|
static String |
ANT_CURRENT_URI
The URI for antlib current definitions
|
static String |
ANT_TYPE
Polymorphic attribute
|
static String |
ANTLIB_URI
The URI for defined types/tasks - the format is antlib:<package>
|
static String |
HELPER_PROPERTY
Name of JVM system property which provides the name of the
ProjectHelper class to use.
|
static String |
PROJECTHELPER_REFERENCE
name of project helper reference that we add to a project
|
static String |
SERVICE_ID
The service identifier in jars which provide Project Helper
implementations.
|
static String |
USE_PROJECT_NAME_AS_TARGET_PREFIX
constant to denote use project name as target prefix
|
Constructor and Description |
---|
ProjectHelper()
Default constructor
|
Modifier and Type | Method and Description |
---|---|
static BuildException |
addLocationToBuildException(BuildException ex,
Location newLocation)
Add location to build exception.
|
static void |
addText(Project project,
Object target,
char[] buf,
int start,
int count)
Adds the content of #PCDATA sections to an element.
|
static void |
addText(Project project,
Object target,
String text)
Adds the content of #PCDATA sections to an element.
|
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.
|
boolean |
canParseBuildFile(Resource buildFile)
Check if the helper supports the kind of file.
|
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 name
|
static String |
extractUriFromComponentName(String componentName)
extract a uri from a component name
|
static String |
genComponentName(String uri,
String name)
Map a namespaced {uri,name} to an internal string format.
|
static String |
getCurrentPrefixSeparator()
The separator between the prefix and the target name.
|
static String |
getCurrentTargetPrefix()
The prefix to prepend to imported target names.
|
String |
getDefaultBuildFile()
The file name of the build script to be parsed if none specified on the command line
|
List<String[]> |
getExtensionStack()
Extension stack.
|
Vector<Object> |
getImportStack()
Import stack.
|
static ProjectHelper |
getProjectHelper()
Get the first project helper found in the classpath
|
static boolean |
isInIncludeMode()
Whether the current file should be read in include as opposed
to import mode.
|
static String |
nsToComponentName(String ns)
Convert an attribute namespace to a "component name".
|
void |
parse(Project project,
Object source)
Parses the project file, configuring the project as it goes.
|
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.
|
void |
resolveExtensionOfAttributes(Project project)
Check extensionStack and inject all targets having extensionOf attributes
into extensionPoint.
|
static void |
setCurrentPrefixSeparator(String sep)
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.
|
public static final String ANT_ATTRIBUTE_URI
public static final String ANT_CORE_URI
public static final String ANT_CURRENT_URI
public static final String ANT_TYPE
public static final String ANTLIB_URI
public static final String HELPER_PROPERTY
public static final String PROJECTHELPER_REFERENCE
public static final String SERVICE_ID
public static final String USE_PROJECT_NAME_AS_TARGET_PREFIX
public static BuildException addLocationToBuildException(BuildException ex, Location newLocation)
ex
- the build exception, if the build exception
does not includenewLocation
- the location of the calling task (may be null)public static void addText(Project project, Object target, char[] buf, int start, int count) throws BuildException
project
- The project containing the target.
Must not be null
.target
- The target object to be configured.
Must not be null
.buf
- A character array of the text within the element.
Will not be null
.start
- The start element in the array.count
- The number of characters to read from the array.BuildException
- if the target object doesn't accept textpublic static void addText(Project project, Object target, String text) throws BuildException
project
- The project containing the target.
Must not be null
.target
- The target object to be configured.
Must not be null
.text
- Text to add to the target.
May be null
, in which case this
method call is a no-op.BuildException
- if the target object doesn't accept textpublic boolean canParseAntlibDescriptor(Resource r)
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.
public boolean canParseBuildFile(Resource buildFile)
buildFile
- the file expected to be parsed (never null
)public static void configureProject(Project project, File buildFile) throws BuildException
project
- The project to configure. Must not be null
.buildFile
- A build file giving the project's configuration.
Must not be null
.BuildException
- if the configuration is invalid or cannot be readpublic static String extractNameFromComponentName(String componentName)
componentName
- The stringified form for {uri, name}public static String extractUriFromComponentName(String componentName)
componentName
- The stringified form for {uri, name}public static String genComponentName(String uri, String name)
uri
- The namespace URIname
- The localnamepublic static String getCurrentPrefixSeparator()
May be set by <import>'s prefixSeparator attribute.
public static String getCurrentTargetPrefix()
May be set by <import>'s as attribute.
public String getDefaultBuildFile()
null
)public List<String[]> getExtensionStack()
ProjectHelper.OnMissingExtensionPoint
.public Vector<Object> getImportStack()
public static ProjectHelper getProjectHelper()
null
ProjectHelperRepository.getHelpers()
public static boolean isInIncludeMode()
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.
public static String nsToComponentName(String ns)
ns
- the xml namespace uri.public void parse(Project project, Object source) throws BuildException
project
- The project for the resulting ProjectHelper to configure.
Must not be null
.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.BuildException
- if the configuration is invalid or cannot
be readpublic UnknownElement parseAntlibDescriptor(Project containingProject, Resource source)
public void resolveExtensionOfAttributes(Project project) throws BuildException
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.
project
- The project containing the target. Must not be
null
.BuildException
- if OnMissingExtensionPoint.FAIL and
extensionPoint does not existProjectHelper.OnMissingExtensionPoint
public static void setCurrentPrefixSeparator(String sep)
public static void setCurrentTargetPrefix(String prefix)
public static void setInIncludeMode(boolean includeMode)
public static void storeChild(Project project, Object parent, Object child, String tag)
project
- Project containing the objects.
May be null
.parent
- Parent object to add child to.
Must not be null
.child
- Child object to store in parent.
Should not be null
.tag
- Name of element which generated the child.
May be null
, in which case
the child is not stored.