diff -r ffef4cca2ff4 project.ant/apichanges.xml
--- a/project.ant/apichanges.xml Tue Jan 22 05:32:07 2008 +0000
+++ b/project.ant/apichanges.xml Thu Feb 21 14:37:31 2008 +0100
@@ -40,8 +40,8 @@
Version 2 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
-->
-
-
+
+
+ A new XML schema
+ (http://www.netbeans.org/ns/ant-project-libraries/1
),
+ several new API methods
+ (AntProjectHelper.getProjectLibrariesPropertyProvider
,
+ AntProjectHelper.isSharableProject
,
+ AntProjectHelper.getLibrariesLocation
,
+ AntProjectHelper.setLibrariesLocation
,
+ ProjectGenerator.createProject(FileObject, String, String)
,
+ ReferenceHelper.createForeignFileReferenceAsIs
,
+ ReferenceHelper.createExtraForeignFileReferenceAsIs
,
+ ReferenceHelper.copyLibrary
,
+ ReferenceHelper.getLibraryChooserImportHandler
,
+ ReferenceHelper.createLibraryReference
,
+ ReferenceHelper.getProjectLibraryManager
,
+ ReferenceHelper.findLibrary
) and
+ custom file chooser (FileChooser
)
+ provide support for collocated library definitions
+ referred to from Ant-based projects.
+
+ * 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 {@link #getProjectLibrariesPropertyProvider}.)
+ *
* Typical usage would be:
@@ -1072,12 +1082,59 @@
public PropertyProvider getStockPropertyPreprovider() {
return properties.getStockPropertyPreprovider();
}
+
+ /**
+ * Creates a property provider which can load definitions of project libraries.
+ * If this project refers to any project library definition files, they will
+ * be included, with
+ * Acquires write access.
+ * @param path a file path to refer to (need not currently exist)
+ * @param property name of the property
+ * @return a string which can refer to that file somehow
+ *
+ * @since org.netbeans.modules.project.ant/1 1.19
+ */
+ public String createExtraForeignFileReferenceAsIs(final String path, final String property) {
+ return ProjectManager.mutex().writeAccess(new Mutex.Action Library creation is done under write access of ProjectManager.mutex().
+ *
+ * @param lib global library; cannot be null
+ * @return newly created sharable version of library in case of sharable
+ * project or given global library in case of non-sharable project
+ * @throws java.io.IOException if there was problem copying files
+ * @since org.netbeans.modules.project.ant/1 1.19
+ */
+ public Library copyLibrary(Library lib) throws IOException {
+ Parameters.notNull("lib", lib);
+ if (lib.getManager() != LibraryManager.getDefault()) {
+ throw new IllegalArgumentException("cannot copy non-global library "+lib.getManager().getLocation()); // NOI18N
+ }
+ if (!h.isSharableProject()) {
+ return lib;
+ }
+ File mainPropertiesFile = h.resolveFile(h.getLibrariesLocation());
+ return ProjectLibraryProvider.copyLibrary(lib, mainPropertiesFile.toURI().toURL(), true);
+ }
+ /**
+ * Returns library import handler which imports global library to sharable
+ * one. See {@link LibraryChooser#showDialog} for usage of this handler.
+ * @return copy handler
+ * @since org.netbeans.modules.project.ant/1 1.19
+ */
+ public LibraryChooser.LibraryImportHandler getLibraryChooserImportHandler() {
+ return new LibraryChooser.LibraryImportHandler() {
+ public Library importLibrary(Library library) throws IOException {
+ return copyLibrary(library);
+ }
+ };
+ }
+ /**
+ * Tries to find a library by name in library manager associated with the project.
+ * It is not guaranteed that any returned library is an identical object to one which passed in to {@link #createLibraryReference}.
+ * @param name either a bare {@link Library#getName}, or a reference as created by {@link #createLibraryReference}
+ * @return the first library to be found matching that name, or null if not found
+ * @since org.netbeans.modules.project.ant/1 1.19
+ */
+ public Library findLibrary(String name) {
+ Matcher m = LIBRARY_REFERENCE.matcher(name);
+ if (m.matches()) {
+ name = m.group(1);
+ }
+ LibraryManager mgr = getProjectLibraryManager();
+ if (mgr == null) {
+ return LibraryManager.getDefault().getLibrary(name);
+ } else {
+ return mgr.getLibrary(name);
+ }
+ }
+
/**
* A raw reference descriptor representing a link to a foreign project
* and some build artifact used from it.
@@ -1638,7 +1862,11 @@
public String getID() {
return artifactID;
}
-
+
+ /**
+ * Get an extra properties used for target execution.
+ * @return a set of properties (may be empty but not null)
+ */
public Properties getProperties() {
return props;
}
diff -r ffef4cca2ff4 project.ant/src/org/netbeans/spi/project/support/ant/SharabilityQueryImpl.java
--- a/project.ant/src/org/netbeans/spi/project/support/ant/SharabilityQueryImpl.java Tue Jan 22 05:32:07 2008 +0000
+++ b/project.ant/src/org/netbeans/spi/project/support/ant/SharabilityQueryImpl.java Thu Feb 21 14:37:31 2008 +0100
@@ -47,6 +47,7 @@
import java.util.ArrayList;
import java.util.List;
import org.netbeans.api.queries.SharabilityQuery;
+import org.netbeans.modules.project.ant.ProjectLibraryProvider;
import org.netbeans.spi.queries.SharabilityQueryImplementation;
import org.openide.util.WeakListeners;
@@ -54,7 +55,7 @@
* Standard impl of {@link SharabilityQueryImplementation}.
* @author Jesse Glick
*/
-final class SharabilityQueryImpl implements SharabilityQueryImplementation, PropertyChangeListener {
+final class SharabilityQueryImpl implements SharabilityQueryImplementation, PropertyChangeListener, AntProjectListener {
private final AntProjectHelper h;
private final PropertyEvaluator eval;
@@ -72,12 +73,13 @@
this.excludes = excludes;
computeFiles();
eval.addPropertyChangeListener(WeakListeners.propertyChange(this, eval));
+ h.addAntProjectListener(this);
}
/** Compute the absolute paths which are and are not sharable. */
private void computeFiles() {
- String[] _includePaths = computeFrom(includes);
- String[] _excludePaths = computeFrom(excludes);
+ String[] _includePaths = computeFrom(includes, false);
+ String[] _excludePaths = computeFrom(excludes, true);
synchronized (this) {
includePaths = _includePaths;
excludePaths = _excludePaths;
@@ -85,7 +87,7 @@
}
/** Compute a list of absolute paths based on some abstract names. */
- private String[] computeFrom(String[] list) {
+ private String[] computeFrom(String[] list, boolean excludeProjectLibraryPrivate) {
List${base}
replaced by the appropriate value.
+ * @return a property provider
+ * @since org.netbeans.modules.project.ant/1 1.19
+ * @see Schema for project library references
+ */
+ public PropertyProvider getProjectLibrariesPropertyProvider() {
+ return ProjectLibraryProvider.createPropertyProvider(this);
+ }
+
+ /**
+ * Is this project shared with other or not, that is is it using shrared
+ * libraries or not.
+ * @return true
for shared project
+ * @since org.netbeans.modules.project.ant/1 1.19
+ */
+ public boolean isSharableProject()
+ {
+ return getLibrariesLocation() != null;
+ }
+
+ /**
+ * Returns location of shared libraries associated with this project or null.
+ * @return relative or absolute OS path or null
+ * @since org.netbeans.modules.project.ant/1 1.19
+ */
+ public String getLibrariesLocation()
+ {
+ return ProjectLibraryProvider.getLibrariesLocationText(this.createAuxiliaryConfiguration());
+ }
+
+ /**
+ * Change project's associated shared libraries location. If location is
+ * null
then project will not have shared libraries and will
+ * be considered as not being shared.
+ *
+ * @param location project relative or absolute OS path or null
+ * @since org.netbeans.modules.project.ant/1 1.18
+ */
+ public void setLibrariesLocation(String location)
+ {
+ ProjectLibraryProvider.setLibrariesLocation(this, location);
+ }
/**
* Get a property evaluator that can evaluate properties according to the default
* file layout for Ant-based projects.
* First, {@link #getStockPropertyPreprovider stock properties} are predefined.
* Then {@link #PRIVATE_PROPERTIES_PATH} is loaded via {@link #getPropertyProvider},
+ * then {@link #getProjectLibrariesPropertyProvider},
* then global definitions from {@link PropertyUtils#globalPropertyProvider}
* (though these may be overridden using the property user.properties.file
* in private.properties
), then {@link #PROJECT_PROPERTIES_PATH}.
@@ -1127,6 +1184,7 @@
return PropertyUtils.resolvePath(FileUtil.toFile(dir), path);
}
+ @Override
public String toString() {
return "AntProjectHelper[" + getProjectDirectory() + "]"; // NOI18N
}
diff -r ffef4cca2ff4 project.ant/src/org/netbeans/spi/project/support/ant/ProjectGenerator.java
--- a/project.ant/src/org/netbeans/spi/project/support/ant/ProjectGenerator.java Tue Jan 22 05:32:07 2008 +0000
+++ b/project.ant/src/org/netbeans/spi/project/support/ant/ProjectGenerator.java Thu Feb 21 14:37:31 2008 +0100
@@ -41,12 +41,14 @@
package org.netbeans.spi.project.support.ant;
+import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectManager;
import org.netbeans.modules.project.ant.AntBasedProjectFactorySingleton;
+import org.netbeans.modules.project.ant.ProjectLibraryProvider;
import org.openide.filesystems.FileLock;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
@@ -90,10 +92,24 @@
* new project on disk is recognized by some other factory
*/
public static AntProjectHelper createProject(final FileObject directory, final String type) throws IOException, IllegalArgumentException {
- return createProject0(directory, type, null);
+ return createProject0(directory, type, null, null);
}
- private static AntProjectHelper createProject0(final FileObject directory, final String type, final String name) throws IOException, IllegalArgumentException {
+ /**
+ * See {@link #createProject(FileObject, String)} for more datails. This
+ * method in addition allows to setup shared libraries location
+ * @param directory the main project directory to create it in
+ * (see {@link AntProjectHelper#getProjectDirectory})
+ * @param type a unique project type identifier (see {@link AntBasedProjectType#getType})
+ * @param librariesDefinition relative or absolute OS path; can be null
+ */
+ public static AntProjectHelper createProject(final FileObject directory, final String type,
+ final String librariesDefinition) throws IOException, IllegalArgumentException {
+ return createProject0(directory, type, null, librariesDefinition);
+ }
+
+ private static AntProjectHelper createProject0(final FileObject directory, final String type,
+ final String name, final String librariesDefinition) throws IOException, IllegalArgumentException {
try {
return ProjectManager.mutex().writeAccess(new Mutex.ExceptionActionAntArtifact
object corresponding to a given
@@ -1304,7 +1389,12 @@
File absolutePath = FileUtil.normalizeFile(PropertyUtils.resolveFile(originalPath, value));
//TODO: extra base dir relativization:
- if (!CollocationQuery.areCollocated(absolutePath, projectDir)) {
+
+ //mkleint: removed CollocationQuery.areCollocated() reference
+ // when AlwaysRelativeCQI gets removed the condition resolves to false more frequently.
+ // that might not be desirable.
+ String rel = PropertyUtils.relativizeFile(projectDir, absolutePath);
+ if (rel == null) {
pubRemove.add(key);
privAdd.put(key, absolutePath.getAbsolutePath());
}
@@ -1338,8 +1428,13 @@
}
//TODO: extra base dir relativization:
- if (CollocationQuery.areCollocated(absolutePath, projectDir)) {
- pubAdd.put(key, PropertyUtils.relativizeFile(projectDir, absolutePath));
+
+ //mkleint: removed CollocationQuery.areCollocated() reference
+ // when AlwaysRelativeCQI gets removed the condition resolves to false more frequently.
+ // that might not be desirable.
+ String rel = PropertyUtils.relativizeFile(projectDir, absolutePath);
+ if (rel != null) {
+ pubAdd.put(key, rel);
}
}
@@ -1357,7 +1452,136 @@
h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, pub);
h.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, priv);
}
+
+ /**
+ * Create a reference to one volume of a library.
+ * @param library a library
+ * @param volumeType a legal volume type for that library
+ * @return substitutable Ant text suitable for inclusion in a properties file when also loading {@link AntProjectHelper#getProjectLibrariesPropertyProvider}
+ * @see #findLibrary
+ * @since org.netbeans.modules.project.ant/1 1.19
+ */
+ public String createLibraryReference(Library library, String volumeType) {
+ if (library.getManager() == LibraryManager.getDefault()) {
+ if (h.isSharableProject()) {
+ throw new IllegalArgumentException("Project ["+ // NOI18N
+ h.getProjectDirectory()+
+ "] is sharable and cannot reference global library "+library.getName()); // NOI18N
+ }
+ } else {
+ if (!ProjectLibraryProvider.isReachableLibrary(library, h)) {
+ throw new IllegalArgumentException("Project ["+ // NOI18N
+ h.getProjectDirectory()+
+ "] cannot reference a library from "+library.getManager().getLocation()); // NOI18N
+ }
+ }
+ return "${libs." + library.getName() + "." + volumeType + "}"; // NOI18N
+ }
+
+ /**
+ * Gets a library manager corresponding to library definition file referred to from this project.
+ * There is no guarantee that the manager is the same object from call to call
+ * even if the location remain the same; in particular, it is not guaranteed that
+ * the manager match that returned from {@link Library#getManager} for libraries added
+ * from {@link #createLibraryReference}.
+ * @return a library manager associated with project's libraries or null if project is
+ * not shared (will not include {@link LibraryManager#getDefault})
+ * @see #createLibraryReference
+ * @see #findLibrary
+ * @since org.netbeans.modules.project.ant/1 1.19
+ */
+ public LibraryManager getProjectLibraryManager() {
+ return ProjectLibraryProvider.getProjectLibraryManager(h);
+ }
+
+ /**
+ * Gets a library manager of the given project.
+ * There is no guarantee that the manager is the same object from call to call
+ * even if the project is the same; in particular, it is not guaranteed that
+ * the manager match that returned from {@link Library#getManager} for libraries added
+ * from {@link #createLibraryReference}.
+ * @return a library manager associated with project's libraries or null if project is
+ * not shared (will not include {@link LibraryManager#getDefault})
+ * {@link LibraryManager#getDefault})
+ * @since org.netbeans.modules.project.ant/1 1.19
+ */
+ public static LibraryManager getProjectLibraryManager(Project p) {
+ AuxiliaryConfiguration aux = p.getLookup().lookup(AuxiliaryConfiguration.class);
+ if (aux != null) {
+ File libFile = ProjectLibraryProvider.getLibrariesLocation(aux,
+ FileUtil.toFile(p.getProjectDirectory()));
+ if (libFile != null) {
+ try {
+ return LibraryManager.forLocation(libFile.toURI().toURL());
+ } catch (MalformedURLException e) {
+ // ok, no project manager
+ Logger.getLogger(ReferenceHelper.class.getName()).info(
+ "library manager cannot be found for "+libFile+". "+e.toString()); //NOI18N
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Copy global IDE library to sharable libraries definition associated with
+ * this project. Does nothing if project is not sharable.
+ * When a library with same name already exists in sharable location, the new one
+ * is copied with generated unique name.
+ *
+ *