|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.netbeans.spi.project.support.ant.ReferenceHelper
Helps manage inter-project references.
Normally you would create an instance of this object and keep it in your
project object in order to support SubprojectProvider
and various
operations that change settings which might refer to build artifacts from
other projects: e.g. when changing the classpath for a Java-based project
you would want to use this helper to scan potential classpath entries for
JARs coming from other projects that you would like to be able to build
as dependencies before your project is built.
You probably only need the higher-level methods such as addReference(org.netbeans.api.project.ant.AntArtifact)
and removeReference(String,String)
; the lower-level methods such as addRawReference(org.netbeans.spi.project.support.ant.ReferenceHelper.RawReference)
are provided for completeness, but typical client code should not need them.
Only deals with references needed to support build artifacts coming from
foreign projects. If for some reason you wish to store other kinds of
references to foreign projects, you do not need this class; just store
them however you wish, and be sure to create an appropriate SubprojectProvider
.
Modification methods (add, remove) mark the project as modified but do not save it.
Nested Class Summary | |
static class |
ReferenceHelper.RawReference
A raw reference descriptor representing a link to a foreign project and some build artifact used from it. |
Constructor Summary | |
ReferenceHelper(AntProjectHelper helper,
AuxiliaryConfiguration aux,
PropertyEvaluator eval)
Create a new reference helper. |
Method Summary | |
void |
addExtraBaseDirectory(String propertyName)
Add extra folder which can be used as base directory (in addition to project base folder) for creating references. |
boolean |
addRawReference(ReferenceHelper.RawReference ref)
Add a raw reference to a foreign project artifact. |
boolean |
addReference(AntArtifact artifact)
Deprecated. to add reference use addReference(AntArtifact, URI) ;
to check whether reference exist or not use isReferenced(AntArtifact, URI) .
This method creates reference for the first artifact location only. |
String |
addReference(AntArtifact artifact,
URI location)
Add a reference to an artifact's location coming from a foreign project. |
String |
createForeignFileReference(AntArtifact artifact)
Deprecated. use addReference(AntArtifact, URI) instead |
String |
createForeignFileReference(File file,
String expectedArtifactType)
Create an Ant-interpretable string referring to a file on disk. |
SubprojectProvider |
createSubprojectProvider()
Create an object permitting this project to represent subprojects. |
void |
destroyForeignFileReference(String reference)
Deprecated. use destroyReference(java.lang.String) instead which does exactly
the same but has more appropriate name |
boolean |
destroyReference(String reference)
Remove a reference to a foreign file from the project. |
Object[] |
findArtifactAndLocation(String reference)
Try to find an AntArtifact object and location corresponding
to a given reference. |
AntArtifact |
getForeignFileReferenceAsArtifact(String reference)
Deprecated. use findArtifactAndLocation(java.lang.String) instead |
ReferenceHelper.RawReference |
getRawReference(String foreignProjectName,
String id)
Get a particular raw reference from this project to another. |
ReferenceHelper.RawReference[] |
getRawReferences()
Get a list of raw references from this project to others. |
boolean |
isReferenced(AntArtifact artifact,
URI location)
Tests whether reference for artifact's location was already created by addReference(AntArtifact, URI) for this project or not. |
void |
removeExtraBaseDirectory(String propertyName)
Remove extra base directory. |
boolean |
removeRawReference(String foreignProjectName,
String id)
Remove a raw reference to an artifact coming from a foreign project. |
boolean |
removeReference(String fileReference)
Deprecated. use destroyReference(java.lang.String) instead; was unused anyway |
boolean |
removeReference(String foreignProjectName,
String id)
Deprecated. use destroyReference(java.lang.String) instead; was unused anyway |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ReferenceHelper(AntProjectHelper helper, AuxiliaryConfiguration aux, PropertyEvaluator eval)
AntProjectHelper
object in order to update references
in project.xml
,
as well as set project or private properties referring to the locations
of foreign projects on disk.
The property evaluator may be used in getForeignFileReferenceAsArtifact(java.lang.String)
,
ReferenceHelper.RawReference.toAntArtifact(org.netbeans.spi.project.support.ant.ReferenceHelper)
, or
createSubprojectProvider()
. Typically this would
be AntProjectHelper.getStandardPropertyEvaluator()
. You can substitute
a custom evaluator but be warned that this helper class assumes that
AntProjectHelper.PROJECT_PROPERTIES_PATH
and AntProjectHelper.PRIVATE_PROPERTIES_PATH
have their customary meanings; specifically that they are both used when evaluating
properties (such as the location of a foreign project) and that private properties
can override public properties.
helper
- an Ant project helper object representing this project's configurationaux
- an auxiliary configuration provider needed to store referenceseval
- a property evaluatorMethod Detail |
public boolean addReference(AntArtifact artifact) throws IllegalArgumentException
addReference(AntArtifact, URI)
;
to check whether reference exist or not use isReferenced(AntArtifact, URI)
.
This method creates reference for the first artifact location only.
For more info see addReference(AntArtifact, URI)
.
artifact
- the artifact to add
IllegalArgumentException
- if the artifact is not associated with a projectpublic String addReference(AntArtifact artifact, URI location) throws IllegalArgumentException
Records the name of the foreign project. Normally the foreign project name is that project's code name, but it may be uniquified if that name is already taken to refer to a different project with the same code name.
Adds a project property if necessary to refer to its location of the foreign
project - a shared property if the foreign project
is collocated
with this one, else a private property.
This property is named project.foreignProjectName.
Example: project.mylib=../mylib
Adds a project property to refer to the artifact's location. This property is named reference.foreignProjectName.targetName and will use ${project.foreignProjectName} and be a shared property - unless the artifact location is an absolute URI, in which case the property will also be private. Example: reference.mylib.jar=${project.mylib}/dist/mylib.jar
Also records the artifact type, (relative) script path, and build and clean target names.
If the reference already exists (keyed by foreign project object and target name), nothing is done, unless some other field (script location, clean target name, or artifact type) needed to be updated, in which case the new information replaces the old. Similarly, the artifact location property is updated if necessary.
Acquires write access.
artifact
- the artifact to addlocation
- the artifact's location to create reference to
IllegalArgumentException
- if the artifact is not associated with a project
or if the location is not artifact's locationpublic boolean isReferenced(AntArtifact artifact, URI location) throws IllegalArgumentException
addReference(AntArtifact, URI)
for this project or not. This
method returns false also in case when reference exist but needs to be
updated.
Acquires read access.
artifact
- the artifact to addlocation
- the artifact's location to create reference to
IllegalArgumentException
- if the artifact is not associated with a project
or if the location is not artifact's locationpublic boolean addRawReference(ReferenceHelper.RawReference ref)
If the reference already exists (keyed by foreign project name and target name), nothing is done, unless some other field (script location, clean target name, or artifact type) needed to be updated, in which case the new information replaces the old.
Note that since ReferenceHelper.RawReference
is just a descriptor, it is not guaranteed
that after adding one getRawReferences()
or getRawReference(java.lang.String, java.lang.String)
would return the identical object.
Acquires write access.
ref
- a raw reference descriptor
public boolean removeReference(String foreignProjectName, String id)
destroyReference(java.lang.String)
instead; was unused anyway
The property giving the location of the artifact is removed if it existed.
If this was the last reference to the foreign project, its location property is removed as well.
If the reference does not exist, nothing is done.
Acquires write access.
foreignProjectName
- the local name of the foreign project
(usually its code name)id
- the ID of the build artifact (usually build target name)
public boolean removeReference(String fileReference)
destroyReference(java.lang.String)
instead; was unused anyway
If the reference does not exist, nothing is done.
Acquires write access.
fileReference
- file reference as created by
createForeignFileReference(File, String)
public boolean removeRawReference(String foreignProjectName, String id)
If the reference does not exist, nothing is done.
Acquires write access.
foreignProjectName
- the local name of the foreign project
(usually its code name)id
- the ID of the build artifact (usually build target name)
public ReferenceHelper.RawReference[] getRawReferences()
ReferenceHelper.RawReference.toAntArtifact(org.netbeans.spi.project.support.ant.ReferenceHelper)
to get
live information from each reference, such as its associated project.
Acquires read access.
public ReferenceHelper.RawReference getRawReference(String foreignProjectName, String id)
ReferenceHelper.RawReference.toAntArtifact(org.netbeans.spi.project.support.ant.ReferenceHelper)
to get
live information from each reference, such as its associated project.
Acquires read access.
foreignProjectName
- the local name of the foreign project
(usually its code name)id
- the ID of the build artifact (usually the build target name)
public String createForeignFileReference(File file, String expectedArtifactType)
AntArtifactQuery.findArtifactFromFile(java.io.File)
, of the expected type
and associated with a particular project,
the behavior is identical to createForeignFileReference(AntArtifact)
.
Otherwise, a reference for the file is created. The file path will
be relative in case CollocationQuery.areCollocated(java.io.File, java.io.File)
says that
the file is collocated with this project's main directory, else it
will be an absolute path.
Acquires write access.
file
- a file to refer to (need not currently exist)expectedArtifactType
- the required AntArtifact.getType()
public void addExtraBaseDirectory(String propertyName)
Acquires write access.
propertyName
- property name which value is path to folder which
can be used as alternative project's base directory; cannot be null;
property must exist
IllegalArgumentException
- if propertyName is null or such a
property does not existpublic void removeExtraBaseDirectory(String propertyName)
addExtraBaseDirectory(java.lang.String)
method call. At the time when this
method is called the property must still exist and must be valid. This
method will replace all references of the extra base directory property
with its current value and if needed it may move such a property from
shared project properties into the private properties.
Acquires write access.
propertyName
- property name which was added by
addExtraBaseDirectory(java.lang.String)
method.
IllegalArgumentException
- if given property is not extra base
directorypublic String createForeignFileReference(AntArtifact artifact) throws IllegalArgumentException
addReference(AntArtifact, URI)
instead
addReference(org.netbeans.api.project.ant.AntArtifact)
and returns an Ant string which will
refer to that artifact correctly.
Acquires write access.
artifact
- a known build artifact to refer to
IllegalArgumentException
- if the artifact is not associated with a projectpublic AntArtifact getForeignFileReferenceAsArtifact(String reference)
findArtifactAndLocation(java.lang.String)
instead
AntArtifact
object corresponding to a given
foreign file reference.
If the supplied string is not a recognized reference to a build
artifact, returns null.
Acquires read access.
reference
- a reference string as present in an Ant property
public Object[] findArtifactAndLocation(String reference)
AntArtifact
object and location corresponding
to a given reference. If the supplied string is not a recognized
reference to a build artifact, returns null.
Acquires read access.
reference
- a reference string as present in an Ant property and as
created by addReference(AntArtifact, URI)
public void destroyForeignFileReference(String reference)
destroyReference(java.lang.String)
instead which does exactly
the same but has more appropriate name
destroyReference(java.lang.String)
for more information.
reference
- an Ant-interpretable foreign file reference as created e.g.
by createForeignFileReference(File,String)
or
by createForeignFileReference(AntArtifact)
public boolean destroyReference(String reference)
addReference(AntArtifact, URI)
or file reference created by
createForeignFileReference(File, String)
, that reference is removed.
Since this would break any other identical foreign
file references present in the project, you should first confirm that this
reference was the last one of its kind (by string match).
If the passed string is anything else (i.e. a plain file path, relative or absolute), nothing is done.
Acquires write access.
reference
- an Ant-interpretable foreign file reference as created e.g.
by createForeignFileReference(File,String)
or
by createForeignFileReference(AntArtifact)
public SubprojectProvider createSubprojectProvider()
Project.getLookup()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |