public final class AntProjectHelper extends Object
As of 1.24, project.xml
or private.xml
reads or writes
are first validated against any registered XML schemas.
You must register a schema using the target namespace http://www.netbeans.org/ns/foo/1
as ProjectXMLCatalog/foo/1.xsd
in your layer for it to be found.
Modifier and Type | Field and Description |
---|---|
static String |
PRIVATE_PROPERTIES_PATH
Relative path from project directory to the customary private properties file.
|
static String |
PRIVATE_XML_PATH
Relative path from project directory to the required private project metadata file.
|
static String |
PROJECT_PROPERTIES_PATH
Relative path from project directory to the customary shared properties file.
|
static String |
PROJECT_XML_PATH
Relative path from project directory to the required shared project metadata file.
|
Modifier and Type | Method and Description |
---|---|
void |
addAntProjectListener(AntProjectListener listener)
Add a listener to changes in the project configuration.
|
AuxiliaryConfiguration |
createAuxiliaryConfiguration()
Create an object permitting this project to store auxiliary configuration.
|
AuxiliaryProperties |
createAuxiliaryProperties()
Create an object permitting this project to expose
AuxiliaryProperties . |
CacheDirectoryProvider |
createCacheDirectoryProvider()
Create an object permitting this project to expose a cache directory.
|
FileBuiltQueryImplementation |
createGlobFileBuiltQuery(PropertyEvaluator eval,
String[] from,
String[] to)
Create an implementation of
FileBuiltQuery that works with files
within the project based on simple glob pattern mappings. |
SharabilityQueryImplementation |
createSharabilityQuery(PropertyEvaluator eval,
String[] sourceRoots,
String[] buildDirectories)
Deprecated.
|
SharabilityQueryImplementation2 |
createSharabilityQuery2(PropertyEvaluator eval,
String[] sourceRoots,
String[] buildDirectories)
Create an implementation of the file sharability query.
|
AntArtifact |
createSimpleAntArtifact(String type,
String locationProperty,
PropertyEvaluator eval,
String targetName,
String cleanTargetName)
Create a basic implementation of
AntArtifact which assumes everything of interest
is in a fixed location under a standard Ant-based project. |
AntArtifact |
createSimpleAntArtifact(String type,
String locationProperty,
PropertyEvaluator eval,
String targetName,
String cleanTargetName,
String buildScriptProperty)
Create a basic implementation of
AntArtifact which assumes everything of interest
is in a fixed location under a standard Ant-based project. |
String |
getLibrariesLocation()
Returns location of shared libraries associated with this project or null.
|
Element |
getPrimaryConfigurationData(boolean shared)
Get the primary configuration data for this project.
|
FileObject |
getProjectDirectory()
Get the top-level project directory.
|
PropertyProvider |
getProjectLibrariesPropertyProvider()
Creates a property provider which can load definitions of project libraries.
|
EditableProperties |
getProperties(String path)
Load a property file from some location in the project.
|
PropertyProvider |
getPropertyProvider(String path)
Get a property provider that works with loadable project properties.
|
PropertyEvaluator |
getStandardPropertyEvaluator()
Get a property evaluator that can evaluate properties according to the default
file layout for Ant-based projects.
|
PropertyProvider |
getStockPropertyPreprovider()
Get a property provider which defines
basedir according to
the project directory and also copies all system properties in the current VM. |
boolean |
isSharableProject()
Is this project shared with other or not, that is is it using shrared
libraries or not.
|
void |
notifyDeleted()
Notification that this project has been deleted.
|
void |
putPrimaryConfigurationData(Element data,
boolean shared)
Store the primary configuration data for this project.
|
void |
putProperties(String path,
EditableProperties props)
Store a property file to some location in the project.
|
void |
removeAntProjectListener(AntProjectListener listener)
Remove a listener to changes in the project configuration.
|
File |
resolveFile(String filename)
Find an absolute file path from a possibly project-relative path.
|
FileObject |
resolveFileObject(String filename)
Same as
AntProjectHelper.resolveFile(java.lang.String) , but produce a FileObject if possible. |
String |
resolvePath(String path)
Take an Ant-style path specification and convert it to a platform-specific absolute path.
|
void |
setLibrariesLocation(String location)
Change project's associated shared libraries location.
|
String |
toString() |
public static final String PROJECT_PROPERTIES_PATH
public static final String PRIVATE_PROPERTIES_PATH
public static final String PROJECT_XML_PATH
public static final String PRIVATE_XML_PATH
public void addAntProjectListener(AntProjectListener listener)
Thread-safe.
listener
- a listener to addpublic void removeAntProjectListener(AntProjectListener listener)
Thread-safe.
listener
- a listener to removepublic FileObject getProjectDirectory()
public void notifyDeleted()
ProjectState.notifyDeleted()
public EditableProperties getProperties(@NonNull String path)
AntProjectHelper.putProperties(java.lang.String, org.netbeans.spi.project.support.ant.EditableProperties)
to save any changes you make.
If the file does not (yet) exist or could not be loaded for whatever reason,
an empty properties list is returned instead.path
- a relative URI in the project directory, e.g.
AntProjectHelper.PROJECT_PROPERTIES_PATH
or AntProjectHelper.PRIVATE_PROPERTIES_PATH
public void putProperties(@NonNull String path, EditableProperties props)
Acquires write access from ProjectManager.mutex()
. However, you are well
advised to explicitly enclose a complete operation within write access,
starting with AntProjectHelper.getProperties(java.lang.String)
, to prevent race conditions.
path
- a relative URI in the project directory, e.g.
AntProjectHelper.PROJECT_PROPERTIES_PATH
or AntProjectHelper.PRIVATE_PROPERTIES_PATH
props
- a set of properties to store, or null to delete any existing properties file therepublic PropertyProvider getPropertyProvider(String path)
AntProjectHelper.getProperties(java.lang.String)
, and calls to
AntProjectHelper.putProperties(java.lang.String, org.netbeans.spi.project.support.ant.EditableProperties)
should cause it to fire changes.path
- a relative URI in the project directory, e.g.
AntProjectHelper.PROJECT_PROPERTIES_PATH
or AntProjectHelper.PRIVATE_PROPERTIES_PATH
public Element getPrimaryConfigurationData(boolean shared)
AntBasedProjectType.getPrimaryConfigurationDataElementName(boolean)
and
AntBasedProjectType.getPrimaryConfigurationDataElementNamespace(boolean)
.
The project may read this document fragment to get custom information
from nbproject/project.xml
and nbproject/private/private.xml
.
The fragment will have no parent node and while it may be modified, you must
use AntProjectHelper.putPrimaryConfigurationData(org.w3c.dom.Element, boolean)
to store any changes.shared
- if true, refers to project.xml
, else refers to
private.xml
public void putPrimaryConfigurationData(Element data, boolean shared) throws IllegalArgumentException
AntBasedProjectType.getPrimaryConfigurationDataElementName(boolean)
and
AntBasedProjectType.getPrimaryConfigurationDataElementNamespace(boolean)
.
The project may save this document fragment to set custom information
in nbproject/project.xml
and nbproject/private/private.xml
.
The fragment will be cloned and so further modifications will have no effect.
Acquires write access from ProjectManager.mutex()
. However, you are well
advised to explicitly enclose a complete operation within write access,
starting with AntProjectHelper.getPrimaryConfigurationData(boolean)
, to prevent race conditions.
data
- the desired new configuration datashared
- if true, refers to project.xml
, else refers to
private.xml
IllegalArgumentException
- if the element is not correctly namedpublic AuxiliaryConfiguration createAuxiliaryConfiguration()
public CacheDirectoryProvider createCacheDirectoryProvider()
public AuxiliaryProperties createAuxiliaryProperties()
AuxiliaryProperties
.
Would be placed into the project's lookup.
This implementation places the properties into AntProjectHelper.PROJECT_PROPERTIES_PATH
or AntProjectHelper.PRIVATE_PROPERTIES_PATH
(depending on shared value). The properties are
prefixed with "auxiliary.
".AuxiliaryProperties
suitable for the project lookuppublic FileBuiltQueryImplementation createGlobFileBuiltQuery(PropertyEvaluator eval, String[] from, String[] to) throws IllegalArgumentException
FileBuiltQuery
that works with files
within the project based on simple glob pattern mappings.
It is intended to be
placed in Project.getLookup()
.
It will return status objects for any files in the project matching a source
glob pattern - this must include exactly one asterisk (*
)
representing a variable portion of a source file path (always slash-separated
and relative to the project directory) and may include some Ant property
references which will be resolved as per the property evaluator.
A file is considered out of date if there is no file represented by the
matching target pattern (which has the same format), or the target file is older
than the source file, or the source file is modified as per
DataObject#isModified().
An attempt is made to fire changes from the status object whenever the result
should change from one call to the next.
The (evaluated) source and target patterns may be relative, resolved against the project directory (perhaps going outside it), or absolute.
A typical set of source and target patterns would be:
eval
- a property evaluator to interpret the patterns withfrom
- a list of glob patterns for source filesto
- a matching list of glob patterns for built filesIllegalArgumentException
- if either from or to patterns
have zero or multiple asterisks,
or the arrays are not of equal lengthspublic AntArtifact createSimpleAntArtifact(String type, String locationProperty, PropertyEvaluator eval, String targetName, String cleanTargetName)
AntArtifact
which assumes everything of interest
is in a fixed location under a standard Ant-based project.type
- the type of artifact, e.g. JavaProjectConstants.ARTIFACT_TYPE_JAR
locationProperty
- an Ant property name giving the project-relative
location of the artifact, e.g. dist.jareval
- a way to evaluate the location property (e.g. AntProjectHelper.getStandardPropertyEvaluator()
)targetName
- the name of an Ant target which will build the artifact,
e.g. jarcleanTargetName
- the name of an Ant target which will delete the artifact
(and maybe other build products), e.g. cleanpublic AntArtifact createSimpleAntArtifact(String type, String locationProperty, PropertyEvaluator eval, String targetName, String cleanTargetName, String buildScriptProperty)
AntArtifact
which assumes everything of interest
is in a fixed location under a standard Ant-based project.type
- the type of artifact, e.g. JavaProjectConstants.ARTIFACT_TYPE_JAR
locationProperty
- an Ant property name giving the project-relative
location of the artifact, e.g. dist.jareval
- a way to evaluate the location property (e.g. AntProjectHelper.getStandardPropertyEvaluator()
)targetName
- the name of an Ant target which will build the artifact,
e.g. jarcleanTargetName
- the name of an Ant target which will delete the artifact
(and maybe other build products), e.g. cleanbuildScriptProperty
- an Ant property name giving the project-relative
location and name of the build.xml or null if default one (build.xml)
should be used; default value is also used if property is given but its value is nullpublic SharabilityQueryImplementation2 createSharabilityQuery2(PropertyEvaluator eval, String[] sourceRoots, String[] buildDirectories)
The project directory itself is automatically included in the list of sharable directories
so you need not explicitly specify it.
Similarly, the nbproject/private
subdirectory is automatically excluded
from VCS, so you do not need to explicitly specify it.
Any file (or directory) mentioned (explicitly or implicity) in the source
directory list but not in any of the build directory lists, and not containing
any build directories inside it, will be given as sharable. If a directory itself
is sharable but some directory inside it is not, it will be given as mixed.
A file or directory inside some build directory will be listed as not sharable.
A file or directory matching neither the source list nor the build directory list
will be treated as of unknown status, but in practice such a file should never
have been passed to this implementation anyway - SharabilityQuery
will
normally only call an implementation in project lookup if the file is owned by
that project.
Each entry in either list should be a string evaluated first for Ant property escapes (if any), then treated as a file path relative to the project directory (or it may be absolute).
It is permitted, and harmless, to include items that overlap others. For example, you can have both a directory and one of its children in the include list.
Whether or not you use this method, all files named *-private.properties
outside the project are marked unsharable, as are such files inside the project if currently referenced
as project libraries. (See AntProjectHelper.getProjectLibrariesPropertyProvider()
.)
Typical usage would be:
helper.createSharabilityQuery2(helper.getStandardPropertyEvaluator(), new String[] {"${src.dir}", "${test.src.dir}"}, new String[] {"${build.dir}", "${dist.dir}"})
A quick rule of thumb is that the include list should contain any source directories which might reside outside the project directory; and the exclude list should contain any directories which you would want to add to a .cvsignore file if using CVS (for example).
Note that in this case ${src.dir} and ${test.src.dir}
may be relative paths inside the project directory; relative paths pointing
outside of the project directory; or absolute paths (generally outside of the
project directory). If they refer to locations inside the project directory,
including them does nothing but is harmless - since the project directory itself
is always treated as sharable. If they refer to external locations, you will
need to also make sure that FileOwnerQuery
actually maps files in those
directories to this project, or else SharabilityQuery
will never find
this implementation in your project lookup and may return UNKNOWN
.
eval
- a property evaluator to interpret paths withsourceRoots
- a list of additional paths to treat as sharablebuildDirectories
- a list of paths to treat as not sharableProject.getLookup()
@Deprecated public SharabilityQueryImplementation createSharabilityQuery(PropertyEvaluator eval, String[] sourceRoots, String[] buildDirectories)
AntProjectHelper.createSharabilityQuery2(org.netbeans.spi.project.support.ant.PropertyEvaluator, java.lang.String[], java.lang.String[])
insteadpublic PropertyProvider getStockPropertyPreprovider()
basedir
according to
the project directory and also copies all system properties in the current VM.
It may also define ant.home
and ant.core.lib
if it is able.PropertyUtils.sequentialPropertyEvaluator(org.netbeans.spi.project.support.ant.PropertyProvider, org.netbeans.spi.project.support.ant.PropertyProvider...)
public PropertyProvider getProjectLibrariesPropertyProvider()
${base}
replaced by the appropriate value.public boolean isSharableProject()
true
for shared projectpublic String getLibrariesLocation()
public void setLibrariesLocation(String location)
null
then project will not have shared libraries and will
be considered as not being shared.location
- project relative or absolute OS path or nullpublic PropertyEvaluator getStandardPropertyEvaluator()
stock properties
are predefined.
Then AntProjectHelper.PRIVATE_PROPERTIES_PATH
is loaded via AntProjectHelper.getPropertyProvider(java.lang.String)
,
then AntProjectHelper.getProjectLibrariesPropertyProvider()
,
then global definitions from PropertyUtils.globalPropertyProvider()
(though these may be overridden using the property user.properties.file
in private.properties
), then AntProjectHelper.PROJECT_PROPERTIES_PATH
.@NonNull public File resolveFile(@NonNull String filename)
filename
- a pathname which may be project-relative or absolute and may
use / or \ as the path separator@CheckForNull public FileObject resolveFileObject(@NonNull String filename)
AntProjectHelper.resolveFile(java.lang.String)
, but produce a FileObject
if possible.filename
- a pathname according to Ant conventions@NonNull public String resolvePath(@NonNull String path)
AntProjectHelper.resolveFile(java.lang.String)
.path
- an Ant-style abstract path