Repository navigation
Unify and speed opening of DirectoryGroup up
#9821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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; | ||
|
|
||
| /** | ||
|
|
@@ -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) { | ||
| 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); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } catch (IOException x) { | ||
| Exceptions.printStackTrace(x); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| boolean isSubprojects() { | ||
| return true; | ||
| } | ||
|
|
||
| private static class Counter { | ||
| int start; | ||
| int end; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 }); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| final Set<Project> toClose = new HashSet<Project>(oldOpen); | ||
| toClose.removeAll(newOpen); | ||
| final Set<Project> toOpen = new HashSet<Project>(newOpen); | ||
|
|
@@ -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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||
|
|
||
| if(!isNewGroup) { | ||
| //for old and new group project intersection, save the old files list, | ||
|
|
@@ -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 |
|---|---|---|
|
|
@@ -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; | ||
|
|
||
|
|
@@ -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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The old code had |
||
| } | ||
|
|
||
| public FileObject getMasterProjectDirectory() { | ||
|
|
@@ -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 |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -70,4 +71,24 @@ public void testSwitchingBackToNoGroupClearsOpenedProjects() throws Exception { | |
| assertEquals("Fresh empty group is opened", 0, backToNoGroup.length); | ||
| } | ||
|
|
||
| public void testDirectoryGroupFindsJustRootProjects() throws Exception { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
findProjectis now inside theif (checkShare)block, so withcheckShare == falseno project would ever be found. The only caller passestrue, 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 queriesdir, while the old one queried the parentfoby mistake.