Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.netbeans.modules.project.ui.groups;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -157,4 +156,8 @@ protected String toString(boolean scrubPersonalInfo) {
return super.toString(scrubPersonalInfo) + (isAutoSynch() ? "" : "[!autoSynch]");
}

@Override
boolean isSubprojects() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -35,6 +36,7 @@
import org.netbeans.spi.project.ui.support.ProjectConvertors;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.URLMapper;
import org.openide.util.Enumerations;
import org.openide.util.Exceptions;

/**
Expand Down Expand Up @@ -112,34 +114,44 @@ public GroupEditPanel createPropertiesPanel() {
}

private void processFolderChildren(FileObject fo, Set<Project> projects, ProgressHandle h, Counter counter, boolean checkShare) throws IllegalArgumentException {
Enumeration<? extends FileObject> e = fo.getFolders(false);
while (e.hasMoreElements()) {
try {
FileObject em = e.nextElement();
SharabilityQuery.Sharability share = SharabilityQuery.Sharability.UNKNOWN;
if (checkShare) {
share = SharabilityQuery.getSharability(fo);
Enumeration<? extends Project> rootProjects = Enumerations.queue(Enumerations.array(fo.getChildren()), (dir, toAdd) -> {
if (!dir.isFolder()) {
return null;
}
if (checkShare) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findProject is now inside the if (checkShare) block, so with checkShare == false no project would ever be found. The only caller passes true, so it works today, but it looks unintended. Also, the old code skipped further sharability queries below a folder that was SHARABLE; that optimization is gone. On the plus side, the new code queries dir, while the old one queried the parent fo by mistake.

try {
SharabilityQuery.Sharability share = SharabilityQuery.getSharability(dir);
if (share == SharabilityQuery.Sharability.NOT_SHARABLE) {
continue;
return null;
}
}
Project p = ProjectManager.getDefault().findProject(em);
if (p != null && !ProjectConvertors.isConvertorProject(p)) {
projects.add(p);
if (h != null) {
h.progress(progressMessage(p), Math.min(++counter.start, counter.end));
Project p = ProjectManager.getDefault().findProject(dir);
if (p != null && !ProjectConvertors.isConvertorProject(p)) {
return p;
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
return null;
}
}
toAdd.addAll(List.of(dir.getChildren()));
return null;
});
while (rootProjects.hasMoreElements()) {
Project p = rootProjects.nextElement();
if (p != null) {
projects.add(p);
if (h != null) {
h.progress(progressMessage(p), Math.min(++counter.start, counter.end));
}
checkShare = share != SharabilityQuery.Sharability.SHARABLE;
// don't need to check the sharability if the current folder is marked as recursively sharable

processFolderChildren(em, projects, h, counter, checkShare);

@jtulach jtulach Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • this PR changes the behavior when a valid "root" Project is found
    • previously the scan continued inside of project structure
    • now it stops and relies on open subprojects behavior of OpenProjects.open
  • such a behavior is way faster
    • scanning NetBeans repository now takes just 4s
    • while previously it took 16s
  • the new behavior is more predictable
  • some Git repositories (like NetBeans or Maven) contain a lot of "testing projects" hidden in test data
    • the previous behavior found those projects ...
    • ... which was greatly unexpected ...
    • ... and also dangerous as those projects are often (intentionally) corrupted, misconfigured or otherwise broken
  • in case of NetBeans there was more than three hundred of such modules
  • lowering the number might even improve the Matthias warning a bit
    • although tons of time is then going to be spend while parsing the projects anyway ...
    • ... to be addressed in some future PR
  • the speed gain and the matched expectations are the major UX improvements of this PR

} catch (IOException x) {
Exceptions.printStackTrace(x);
}
}
}

@Override
boolean isSubprojects() {
return true;
}

private static class Counter {
int start;
int end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,10 @@ static void open(final Group g, String oldGroupName, boolean isNewGroup, Prefere
oldOpen.add(real != null ? real : open);
}

long then = System.currentTimeMillis();
Set<Project> newOpen = g != null ? g.getProjects(h, 10, 100) : Collections.emptySet();
long now = System.currentTimeMillis();
LOG.log(Level.FINE, "Found {0} projects of group {1} in {2} ms", new Object[] { newOpen.size(), g, now - then });

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I am using netbeans -J-Dorg.netbeans.modules.project.ui.groups.Group.level=FINE to enabled this log message
  • and then grep Group nbbuild/testuserdir/var/log/messages.log for it
  • previously it would print Found 1 206 projects of group DirectoryGroup[id=netbeans,|projects|=1203] in 16 779 ms
  • now it prints Found 857 projects of group DirectoryGroup[id=netbeans,|projects|=857] in 3 665 ms

final Set<Project> toClose = new HashSet<Project>(oldOpen);
toClose.removeAll(newOpen);
final Set<Project> toOpen = new HashSet<Project>(newOpen);
Expand All @@ -591,12 +594,14 @@ static void open(final Group g, String oldGroupName, boolean isNewGroup, Prefere
IndexingBridge.Lock lock = IndexingBridge.getDefault().protectedMode();
try {
h.progress(Group_progress_closing(toClose.size()), 110);
Project[] arrClose = toClose.toArray(new Project[0]);
//close and remember the last opened files in the old group
opl.close(toClose.toArray(new Project[0]), false, oldGroupName);
opl.close(arrClose, false, oldGroupName);
h.switchToIndeterminate();
h.progress(Group_progress_opening(toOpen.size()));
//open the projects with current group
opl.open(toOpen.toArray(new Project[0]), false, false, h, null);
Project[] arrOpen = toOpen.toArray(new Project[0]);
opl.open(arrOpen, false, g != null && g.isSubprojects(), h, null);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since newOpen now contains only the root projects, subprojects can get closed without being reopened. Example: group A is a SubprojectsGroup of X, so X and its subprojects are open. Switching to group B, a DirectoryGroup that also contains X, gives toClose = oldOpen - newOpen = the subprojects of X. X itself stays open, so it is not in toOpen, and openSubprojects never runs for it, so the subprojects stay closed. For the same reason the subprojects drop out of stayOpened, so their open documents are no longer persisted or restored per group.


if(!isNewGroup) {
//for old and new group project intersection, save the old files list,
Expand Down Expand Up @@ -753,4 +758,6 @@ private void notifyListeners(Object object, String property, String oldValue, St
listener.propertyChange(new PropertyChangeEvent(object, property, oldValue, newValue));
}
}

abstract boolean isSubprojects();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
import org.netbeans.api.progress.ProgressHandle;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectUtils;
import org.netbeans.spi.project.ProjectContainerProvider;
import org.netbeans.spi.project.SubprojectProvider;
import org.netbeans.spi.project.ui.support.ProjectConvertors;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.URLMapper;

Expand Down Expand Up @@ -80,33 +77,7 @@ protected String getNameOrNull() {
protected void findProjects(Set<Project> projects, ProgressHandle h, int start, int end) {
assert !SwingUtilities.isEventDispatchThread();
Project p = projectForPath(prefs().get(KEY_PATH, null));
if (p != null) {
visitSubprojects(p, projects, true, h, new int[] {start, end});
}
}

private static void visitSubprojects(Project p, Set<Project> projects, boolean main, ProgressHandle h, int[] startEnd) {
if ((main || !ProjectConvertors.isConvertorProject(p)) && projects.add(p)) {
if (h != null) {
h.progress(progressMessage(p), Math.min(++startEnd[0], startEnd[1]));
}
ProjectContainerProvider pcp = p.getLookup().lookup(ProjectContainerProvider.class);
if (pcp != null) {
ProjectContainerProvider.Result res = pcp.getContainedProjects();
projects.addAll(res.getProjects());
if (!res.isRecursive()) {
visitSubprojects(p, projects, false, h, startEnd);
}
} else {
//fallback to semi-deprecated subprojectprovider
SubprojectProvider spp = p.getLookup().lookup(SubprojectProvider.class);
if (spp != null) {
for (Project p2 : spp.getSubprojects()) {
visitSubprojects(p2, projects, false, h, startEnd);
}
}
}
}
projects.add(p);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code had if (p != null) here. projectForPath returns null when the master project folder was deleted or moved, so null now ends up in the set. With assertions enabled that trips assert !projects.contains(null) in Group.getProjects; without them, the null is passed on to opl.open.

}

public FileObject getMasterProjectDirectory() {
Expand All @@ -126,4 +97,8 @@ public GroupEditPanel createPropertiesPanel() {
return new SubprojectsGroupEditPanel(this);
}

@Override
boolean isSubprojects() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.netbeans.modules.project.ui.groups;

import java.util.HashSet;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectManager;
import org.netbeans.api.project.ui.OpenProjects;
Expand Down Expand Up @@ -70,4 +71,24 @@ public void testSwitchingBackToNoGroupClearsOpenedProjects() throws Exception {
assertEquals("Fresh empty group is opened", 0, backToNoGroup.length);
}

public void testDirectoryGroupFindsJustRootProjects() throws Exception {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var root = FileUtil.toFileObject(getWorkDir());
var fo1 = TestSupport.createTestProject(root, "prj1");
var prj1 = ProjectManager.getDefault().findProject(fo1);
var fo2 = TestSupport.createTestProject(root, "prj2");
var prj2 = ProjectManager.getDefault().findProject(fo2);
var foNested = TestSupport.createTestProject(prj1.getProjectDirectory(), "nested1");
var prjNested = ProjectManager.getDefault().findProject(foNested);

var g = DirectoryGroup.create("Find just two", root);

var result = new HashSet<Project>();
g.findProjects(result, null, 0, 0);


assertTrue("There is prj1 in " + result, result.contains(prj1));
assertTrue("There is prj2 in " + result, result.contains(prj2));
assertFalse("There is no nested1 in " + result, result.contains(prjNested));
assertEquals("Exactly two projects found", 2, result.size());
}
}
Loading