org.netbeans.modules.java.project/1 1.38.1

org.netbeans.spi.java.project.classpath
Class ProjectClassPathModifierImplementation

java.lang.Object
  extended by org.netbeans.spi.java.project.classpath.ProjectClassPathModifierImplementation

public abstract class ProjectClassPathModifierImplementation
extends Object

An SPI for project's classpaths modification. A project can provide subclass of this class in its lookup to allow clients to add or remove new classpath elements (JAR, folder, dependent project, or library) to its classpaths.

Since:
org.netbeans.modules.java.project/1 1.10

Constructor Summary
protected ProjectClassPathModifierImplementation()
           
 
Method Summary
protected abstract  boolean addAntArtifacts(AntArtifact[] artifacts, URI[] artifactElements, SourceGroup sourceGroup, String type)
          Adds artifacts (e.g.
protected abstract  boolean addLibraries(Library[] libraries, SourceGroup sourceGroup, String type)
          Adds libraries into the project's classpath if the libraries are not already included.
protected  boolean addProjects(Project[] projects, SourceGroup sg, String classPathType)
          Adds projects as dependencies into project's classpath if the artifacts are not already on it.
protected  boolean addRoots(URI[] classPathRoots, SourceGroup sourceGroup, String type)
          Adds archive files or folders into the project's classpath if the entries are not already there.
protected abstract  boolean addRoots(URL[] classPathRoots, SourceGroup sourceGroup, String type)
          Adds archive files or folders into the project's classpath if the entries are not already there.
protected static URI[] convertURLsToURIs(URL[] entry)
          Converts array of URLs to array of URIs.
protected abstract  String[] getExtensibleClassPathTypes(SourceGroup sourceGroup)
          Returns the types of classpaths for given SourceGroup which may be modified.
protected abstract  SourceGroup[] getExtensibleSourceGroups()
          Returns the SourceGroups providing classpath(s) which may be modified.
protected  String performSharabilityHeuristics(URI classpathRoot, AntProjectHelper helper)
          Takes a classpath root and tries to figure the best way to reference that file for that particular project.
protected abstract  boolean removeAntArtifacts(AntArtifact[] artifacts, URI[] artifactElements, SourceGroup sourceGroup, String type)
          Removes artifacts (e.g.
protected abstract  boolean removeLibraries(Library[] libraries, SourceGroup sourceGroup, String type)
          Removes libraries from the project's classpath if the libraries are included on it.
protected  boolean removeRoots(URI[] classPathRoots, SourceGroup sourceGroup, String type)
          Removes archive files or folders from the project's classpath if the entries are included on it.
protected abstract  boolean removeRoots(URL[] classPathRoots, SourceGroup sourceGroup, String type)
          Removes archive files or folders from the project's classpath if the entries are included on it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProjectClassPathModifierImplementation

protected ProjectClassPathModifierImplementation()
Method Detail

getExtensibleSourceGroups

protected abstract SourceGroup[] getExtensibleSourceGroups()
Returns the SourceGroups providing classpath(s) which may be modified.

Returns:
(possibly empty) array of SourceGroup, never returns null

getExtensibleClassPathTypes

protected abstract String[] getExtensibleClassPathTypes(SourceGroup sourceGroup)
Returns the types of classpaths for given SourceGroup which may be modified.

Parameters:
sourceGroup - for which the classpath types should be returned
Returns:
(possibly empty) array of classpath types, never returns null

addLibraries

protected abstract boolean addLibraries(Library[] libraries,
                                        SourceGroup sourceGroup,
                                        String type)
                                 throws IOException,
                                        UnsupportedOperationException
Adds libraries into the project's classpath if the libraries are not already included.

Parameters:
libraries - to be added
sourceGroup - of type JavaProjectConstants.SOURCES_TYPE_JAVA identifying the compilation unit to change
type - the type of the classpath the library should be added to, eg ClassPath.COMPILE
Returns:
true in case the classpath was changed (at least one library was added to the classpath), the value false is returned when all the libraries are already included on the classpath.
Throws:
IOException - in case the project metadata cannot be changed
UnsupportedOperationException - is thrown when the project does not support adding of a library to the classpath of the given type.

removeLibraries

protected abstract boolean removeLibraries(Library[] libraries,
                                           SourceGroup sourceGroup,
                                           String type)
                                    throws IOException,
                                           UnsupportedOperationException
Removes libraries from the project's classpath if the libraries are included on it.

Parameters:
libraries - to be removed
sourceGroup - of type JavaProjectConstants.SOURCES_TYPE_JAVA identifying the compilation unit to change
type - the type of the classpath the library should be removed from, eg ClassPath.COMPILE
Returns:
true in case the classpath was changed, (at least one library was removed from the classpath), the value false is returned when none of the libraries was included on the classpath.
Throws:
IOException - in case the project metadata cannot be changed
UnsupportedOperationException - is thrown when the project does not support removing of a library from the classpath of the given type.

addRoots

protected abstract boolean addRoots(URL[] classPathRoots,
                                    SourceGroup sourceGroup,
                                    String type)
                             throws IOException,
                                    UnsupportedOperationException
Adds archive files or folders into the project's classpath if the entries are not already there.

Parameters:
classPathRoots - roots to be added, each root has to be either a root of an archive or a folder
sourceGroup - of type JavaProjectConstants.SOURCES_TYPE_JAVA identifying the compilation unit to change
type - the type of the classpath the root should be added to, eg ClassPath.COMPILE
Returns:
true in case the classpath was changed, (at least one classpath root was added to the classpath), the value false is returned when all the classpath roots are already included on the classpath.
Throws:
IOException - in case the project metadata cannot be changed
UnsupportedOperationException - is thrown when the project does not support adding of a root to the classpath of the given type.

addRoots

protected boolean addRoots(URI[] classPathRoots,
                           SourceGroup sourceGroup,
                           String type)
                    throws IOException,
                           UnsupportedOperationException
Adds archive files or folders into the project's classpath if the entries are not already there.

This method is not abstract only for backward compatibility and therefore should be always overrriden. Default implementation converts given URIs to URLs and calls addRoots(URL[], SourceGroup, String). It throws UnsupportedOperationException if URIs are not absolute.

Parameters:
classPathRoots - roots to be added, each root has to be either a root of an archive or a folder; URI can be relative
sourceGroup - of type JavaProjectConstants.SOURCES_TYPE_JAVA identifying the compilation unit to change
type - the type of the classpath the root should be added to, eg ClassPath.COMPILE
Returns:
true in case the classpath was changed, (at least one classpath root was added to the classpath), the value false is returned when all the classpath roots are already included on the classpath.
Throws:
IOException - in case the project metadata cannot be changed
UnsupportedOperationException - is thrown when the project does not support adding of a root to the classpath of the given type.
Since:
org.netbeans.modules.java.project/1 1.16

convertURLsToURIs

protected static URI[] convertURLsToURIs(URL[] entry)
Converts array of URLs to array of URIs.

Parameters:
entry - list of URLs to convert
Returns:
URIs
Since:
org.netbeans.modules.java.project/1 1.16

removeRoots

protected abstract boolean removeRoots(URL[] classPathRoots,
                                       SourceGroup sourceGroup,
                                       String type)
                                throws IOException,
                                       UnsupportedOperationException
Removes archive files or folders from the project's classpath if the entries are included on it.

Parameters:
classPathRoots - roots to be removed, each root has to be either a root of an archive or a folder
sourceGroup - of type JavaProjectConstants.SOURCES_TYPE_JAVA identifying the compilation unit to change
type - the type of the classpath the root should be removed from, eg ClassPath.COMPILE
Returns:
true in case the classpath was changed, (at least one classpath root was removed from the classpath), the value false is returned when none of the classpath roots was included on the classpath.
Throws:
IOException - in case the project metadata cannot be changed
UnsupportedOperationException - is thrown when the project does not support removing of a root from the classpath of the given type.

removeRoots

protected boolean removeRoots(URI[] classPathRoots,
                              SourceGroup sourceGroup,
                              String type)
                       throws IOException,
                              UnsupportedOperationException
Removes archive files or folders from the project's classpath if the entries are included on it.

This method is not abstract only for backward compatibility and therefore should be always overrriden. Default implementation converts given URIs to URLs and calls removeRoots(URL[], SourceGroup, String). It throws UnsupportedOperationException if URIs are not absolute.

Parameters:
classPathRoots - roots to be removed, each root has to be either a root of an archive or a folder; URI can be relative
sourceGroup - of type JavaProjectConstants.SOURCES_TYPE_JAVA identifying the compilation unit to change
type - the type of the classpath the root should be removed from, eg ClassPath.COMPILE
Returns:
true in case the classpath was changed, (at least one classpath root was removed from the classpath), the value false is returned when none of the classpath roots was included on the classpath.
Throws:
IOException - in case the project metadata cannot be changed
UnsupportedOperationException - is thrown when the project does not support removing of a root from the classpath of the given type.

addAntArtifacts

protected abstract boolean addAntArtifacts(AntArtifact[] artifacts,
                                           URI[] artifactElements,
                                           SourceGroup sourceGroup,
                                           String type)
                                    throws IOException,
                                           UnsupportedOperationException
Adds artifacts (e.g. subprojects) into project's classpath if the artifacts are not already on it.

Parameters:
artifacts - to be added
artifactElements - the URIs of the build output, the artifactElements has to have the same length as artifacts. (must be owned by the artifact and be relative to it)
sourceGroup - of type JavaProjectConstants.SOURCES_TYPE_JAVA identifying the compilation unit to change
type - the type of the classpath the artifact should be added to, eg ClassPath.COMPILE
Returns:
true in case the classpath was changed, (at least one artifact was added to the classpath), the value false is returned when all the artifacts are already included on the classpath.
Throws:
IOException - in case the project metadata cannot be changed
UnsupportedOperationException - is thrown when the project does not support adding of an artifact to the classpath of the given type.

removeAntArtifacts

protected abstract boolean removeAntArtifacts(AntArtifact[] artifacts,
                                              URI[] artifactElements,
                                              SourceGroup sourceGroup,
                                              String type)
                                       throws IOException,
                                              UnsupportedOperationException
Removes artifacts (e.g. subprojects) from project's classpath if the artifacts are included on it.

Parameters:
artifacts - to be added
artifactElements - the URIs of the build output, the artifactElements has to have the same length as artifacts. (must be owned by the artifact and be relative to it)
sourceGroup - of type JavaProjectConstants.SOURCES_TYPE_JAVA identifying the compilation unit to change
type - the type of the classpath the artifact should be removed from, eg ClassPath.COMPILE
Returns:
true in case the classpath was changed, (at least one artifact was removed from the classpath), the value false is returned when none of the artifacts was included on the classpath.
Throws:
IOException - in case the project metadata cannot be changed
UnsupportedOperationException - is thrown when the project does not support removing of an artifact from the classpath of the given type.

addProjects

protected boolean addProjects(Project[] projects,
                              SourceGroup sg,
                              String classPathType)
                       throws IOException,
                              UnsupportedOperationException
Adds projects as dependencies into project's classpath if the artifacts are not already on it. The default behaviour will behave as addAntArtifacts(org.netbeans.api.project.ant.AntArtifact[], java.net.URI[], org.netbeans.api.project.SourceGroup, java.lang.String) Other project types can override the behaviour.

Parameters:
projects - to be added (must be owned by the artifact and be relative to it)
sourceGroup - of type JavaProjectConstants.SOURCES_TYPE_JAVA identifying the compilation unit to change
type - the type of the classpath the artifact should be added to, eg ClassPath.COMPILE
Returns:
true in case the classpath was changed, (at least one artifact was added to the classpath), the value false is returned when all the artifacts are already included on the classpath.
Throws:
IOException - in case the project metadata cannot be changed
UnsupportedOperationException - is thrown when the project does not support adding of an artifact to the classpath of the given type.
Since:
org.netbeans.modules.java.project/1 1.24

performSharabilityHeuristics

protected final String performSharabilityHeuristics(URI classpathRoot,
                                                    AntProjectHelper helper)
                                             throws URISyntaxException,
                                                    IOException
Takes a classpath root and tries to figure the best way to reference that file for that particular project. The possible actions include relativization of path, copying to sharable libraries folder etc.

Parameters:
classpathRoot - passed in through the addRoots() and removeRoots() methods
helper -
Returns:
a relative or absolute path to the original jar/folder or to a copy of it.
Throws:
URISyntaxException
IOException
Since:
org.netbeans.modules.java.project/1 1.15

org.netbeans.modules.java.project/1 1.38.1

Built on December 5 2011.  |  Portions Copyright 1997-2011 Sun Microsystems, Inc. All rights reserved.