+ Added SourcesHelper.registerExternalRoots
with additional parameter
+ minimalSubfolders
controlling how the roots having an explicit include
+ list are registered. When true
only those subfolders which are included
+ (or folders directly containing included files) will be registered, otherwise the
+ whole source root is registered.
+
SourcesHelper
object
*/
public void registerExternalRoots(int algorithm) throws IllegalArgumentException, IllegalStateException {
+ registerExternalRoots(algorithm, true);
+ }
+
+ /**
+ * Register all external source or non-source roots using {@link FileOwnerQuery#markExternalOwner}.
+ * + * Only roots added by {@link #addPrincipalSourceRoot} and {@link #addNonSourceRoot} + * are considered. They are registered if (and only if) they in fact fall + * outside of the project directory, and of course only if the folders really + * exist on disk. Currently it is not defined when this file existence check + * is done (e.g. when this method is first called, or periodically) or whether + * folders which are created subsequently will be registered, so project type + * providers are encouraged to create all desired external roots before calling + * this method. + *
+ *+ * If the actual value of the location changes (due to changes being + * fired from the property evaluator), roots which were previously internal + * and are now external will be registered, and roots which were previously + * external and are now internal will be unregistered. The (un-)registration + * will be done using the same algorithm as was used initially. + *
+ *+ * If a minimalSubfolders is true and an explicit include list is configured + * for a principal source root, only those subfolders which are included + * (or folders directly containing included files) + * will be registered, otherwise the whole source root is registered. + * Note that the source root, or an included subfolder, will + * be registered even if it contains excluded files or folders beneath it. + *
+ *+ * Calling this method causes the helper object to hold strong references to the + * current external roots, which helps a project satisfy the requirements of + * {@link FileOwnerQuery#EXTERNAL_ALGORITHM_TRANSIENT}. + *
+ *+ * You may not call this method inside the project's constructor, as + * it requires the actual project to exist and be registered in {@link ProjectManager}. + * Typically you would use {@link org.openide.util.Mutex#postWriteRequest} to run it + * later, if you were creating the helper in your constructor, since the project construction + * normally occurs in read access. + *
+ * @param algorithm an external root registration algorithm as per + * {@link FileOwnerQuery#markExternalOwner} + * @param minimalSubfolders controls how the roots having an explicit include list + * are registered. When true only those subfolders which are included + * (or folders directly containing included files) will be registered, + * otherwise the whole source root is registered. + * @throws IllegalArgumentException if the algorithm is unrecognized + * @throws IllegalStateException if this method is called more than once on a + * givenSourcesHelper
object
+ * @since 1.26
+ */
+ public void registerExternalRoots (int algorithm, boolean minimalSubfolders) throws IllegalArgumentException, IllegalStateException {
if (lastRegisteredRoots != null) {
throw new IllegalStateException("registerExternalRoots was already called before"); // NOI18N
}
registeredRootAlgorithm = algorithm;
+ this.minimalSubfolders = minimalSubfolders;
remarkExternalRoots();
}
@@ -539,7 +598,7 @@
// that was last computed, and just check if that has changed... otherwise we wind
// up calling APH.resolveFileObject repeatedly (for each property change)
for (Root r : allRoots) {
- for (FileObject loc : r.getIncludeRoots()) {
+ for (FileObject loc : r.getIncludeRoots(minimalSubfolders)) {
if (FileUtil.getRelativePath(pdir, loc) != null) {
// Inside projdir already. Skip it.
continue;
--- a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/SourcesHelperTest.java
+++ a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/SourcesHelperTest.java
@@ -562,6 +562,59 @@
assertExcluded("but that does not apply to other children", gg1, "javax/lang/Foo.java");
//
}
+
+ public void testMinimalSubfolders () throws Exception {
+ scratch = TestUtil.makeScratchDir(this); // have our own setup
+ maindir = scratch.createFolder("dir");
+ projdir = maindir.createFolder("proj-dir");
+ src1dir = maindir.createFolder("src1");
+
+ //