diff --git a/ide/projectui/src/org/netbeans/modules/project/ui/ProjectsRootNode.java b/ide/projectui/src/org/netbeans/modules/project/ui/ProjectsRootNode.java index aed649f33aca..1843189d4855 100644 --- a/ide/projectui/src/org/netbeans/modules/project/ui/ProjectsRootNode.java +++ b/ide/projectui/src/org/netbeans/modules/project/ui/ProjectsRootNode.java @@ -276,16 +276,12 @@ public ProjectChildren( int type ) { @Override public void addNotify() { OpenProjectList.getDefault().addPropertyChangeListener(this); - if (Boolean.getBoolean("test.projectnode.sync")) { - setKeys( getKeys()); - } else { - RP.post(new Runnable() { - @Override - public void run() { - setKeys( getKeys() ); - } - }); - } + RP.post(new Runnable() { + @Override + public void run() { + setKeys( getKeys() ); + } + }); } @Override @@ -307,7 +303,13 @@ public int getNodesCount(boolean optimalResult) { return super.getNodesCount(optimalResult); } - + @Override + public Node[] getNodes(boolean optimalResult) { + if (optimalResult) { + setKeys(getKeys()); + } + return super.getNodes(optimalResult); + } @Override protected Node[] createNodes(Pair p) { diff --git a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/CloseProjectsTest.java b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/CloseProjectsTest.java index 4c439e23a989..784d2cd2d2a7 100644 --- a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/CloseProjectsTest.java +++ b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/CloseProjectsTest.java @@ -104,8 +104,6 @@ protected void setUp() throws Exception { OpenProjectListSettings.getInstance().setOpenProjectsURLs(list); OpenProjectListSettings.getInstance().setOpenProjectsDisplayNames(names); OpenProjectListSettings.getInstance().setOpenProjectsIcons(icons); - //compute project root node children in sync mode - System.setProperty("test.projectnode.sync", "true"); } public void testClose() throws Exception { @@ -113,11 +111,11 @@ public void testClose() throws Exception { L listener = new L(); logicalView.addNodeListener(listener); - assertEquals("30 children", 30, logicalView.getChildren().getNodesCount()); + assertEquals("30 children", 30, logicalView.getChildren().getNodesCount(true)); listener.assertEvents("None", 0); assertEquals("No project opened yet", 0, TestProjectOpenedHookImpl.opened); - Node[] nodeArray = logicalView.getChildren().getNodes(); + Node[] nodeArray = logicalView.getChildren().getNodes(true); Project[] arr = new Project[nodeArray.length]; int i = 0; for (Node n : nodeArray) { @@ -133,7 +131,7 @@ public void testClose() throws Exception { i++; } ProjectsRootNode.ProjectChildren.RP.post(new Runnable() {public @Override void run() {}}).waitFinished(); - assertEquals("Just fifteen left nodes", 15, logicalView.getChildren().getNodesCount()); + assertEquals("Just fifteen left nodes", 15, logicalView.getChildren().getNodesCount(true)); // let the project open hook run down.countDown(); @@ -141,7 +139,7 @@ public void testClose() throws Exception { OpenProjects.getDefault().close(arr); ProjectsRootNode.ProjectChildren.RP.post(new Runnable() {public @Override void run() {}}).waitFinished(); - assertEquals("View is empty", 0, logicalView.getChildren().getNodesCount()); + assertEquals("View is empty", 0, logicalView.getChildren().getNodesCount(true)); } private static class L implements NodeListener { diff --git a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/OpenProjectHookThrowsExceptionTest.java b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/OpenProjectHookThrowsExceptionTest.java index eb578e2471da..465406a25d8f 100644 --- a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/OpenProjectHookThrowsExceptionTest.java +++ b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/OpenProjectHookThrowsExceptionTest.java @@ -86,9 +86,6 @@ protected void setUp() throws Exception { OpenProjectListSettings.getInstance().setOpenProjectsURLs(list); OpenProjectListSettings.getInstance().setOpenProjectsDisplayNames(names); OpenProjectListSettings.getInstance().setOpenProjectsIcons(icons); - - //compute project root node children in sync mode - System.setProperty("test.projectnode.sync", "true"); } public void testBehaviourOfProjectsLogicNode() throws Exception { @@ -97,11 +94,11 @@ public void testBehaviourOfProjectsLogicNode() throws Exception { L listener = new L(); logicalView.addNodeListener(listener); - assertEquals("2 children", 2, logicalView.getChildren().getNodesCount()); + assertEquals("2 children", 2, logicalView.getChildren().getNodesCount(true)); listener.assertEvents("None", 0); assertEquals("No project opened yet", 0, TestProjectOpenedHookImpl.opened); - for (Node n : logicalView.getChildren().getNodes()) { + for (Node n : logicalView.getChildren().getNodes(true)) { TestSupport.TestProject p = n.getLookup().lookup(TestSupport.TestProject.class); assertNull("No project of this type, yet", p); } @@ -114,7 +111,7 @@ public void testBehaviourOfProjectsLogicNode() throws Exception { OpenProjectList.waitProjectsFullyOpen(); - Node[] nodes = logicalView.getChildren().getNodes(); + Node[] nodes = logicalView.getChildren().getNodes(true); assertEquals("No projects open", 0, nodes.length); listener.assertEvents("Goal is to receive no events at all", 1); diff --git a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/OpenProjectListNestedTest.java b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/OpenProjectListNestedTest.java new file mode 100644 index 000000000000..aba1b62dfc00 --- /dev/null +++ b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/OpenProjectListNestedTest.java @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.netbeans.modules.project.ui; + +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.concurrent.Callable; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.event.ChangeListener; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.api.project.ui.OpenProjects; +import org.netbeans.junit.NbTestCase; +import org.netbeans.modules.project.ui.actions.TestSupport; +import org.netbeans.spi.project.SubprojectProvider; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.lookup.Lookups; +import org.openide.util.test.MockLookup; + +public class OpenProjectListNestedTest extends NbTestCase { + static final Logger LOG = Logger.getLogger("test.OpenProjectListNestedTest"); + + public OpenProjectListNestedTest(String testName) { + super(testName); + } + + @Override + protected Level logLevel() { + return Level.FINER; + } + + @Override + protected void setUp() throws Exception { + OpenProjects.getDefault().close(OpenProjects.getDefault().openProjects().get()); + OpenProjectList.waitProjectsFullyOpen(); + } + + public void testOpenNestedProjects() throws Exception { + doOpenProjects(true, () -> { + var em = OpenProjects.getDefault().createLogicalView(); + var all = em.getRootContext().getChildren().getNodes(true); + assertEquals("Two projects are visible", 2, all.length); + return null; + }); + } + + public void testOpenNonNestedProjects() throws Exception { + doOpenProjects(false, () -> { + var em = OpenProjects.getDefault().createLogicalView(); + var all = em.getRootContext().getChildren().getNodes(true); + assertEquals("One project is visible", 1, all.length); + return null; + }); + } + + private void doOpenProjects(boolean withSubprojects, Callable inner) throws Exception { + MockLookup.setInstances(new TestSupport.TestProjectFactory()); + clearWorkDir(); + FileObject workDir = FileUtil.toFileObject(getWorkDir()); + assertNotNull(workDir); + FileObject prjFo = TestSupport.createTestProject(workDir, "prj1"); + FileObject nestedFo = TestSupport.createTestProject(prjFo, "nested1"); + final TestSupport.TestProject mainPrj = (TestSupport.TestProject) ProjectManager.getDefault().findProject(prjFo); + final TestSupport.TestProject nestedPrj = (TestSupport.TestProject) ProjectManager.getDefault().findProject(nestedFo); + assertNotNull("Project found", mainPrj); + var subProvider = new SubprojectProvider() { + @Override + public Set getSubprojects() { + return Set.of(nestedPrj); + } + + @Override + public void addChangeListener(ChangeListener listener) { + } + + @Override + public void removeChangeListener(ChangeListener listener) { + } + }; + if (withSubprojects) { + mainPrj.setLookup(Lookups.singleton(subProvider)); + } + + OpenProjectList.waitProjectsFullyOpen(); + assertEquals("Initially empty", 0, OpenProjects.getDefault().openProjects().get().length); + + OpenProjects.getDefault().open(new Project[] { mainPrj }, true); + + List arr = Arrays.asList(OpenProjects.getDefault().openProjects().get()); + if (withSubprojects) { + assertEquals("Both projects open", 2, arr.size()); + assertTrue("Prj1 is there", arr.contains(mainPrj)); + assertTrue("Nested1 is there", arr.contains(nestedPrj)); + inner.call(); + OpenProjects.getDefault().close (new Project[] { nestedPrj, mainPrj }); + } else { + assertEquals("However one project instance is there", 1, arr.size()); + assertEquals("arr[0] is equal to p", arr.get(0), mainPrj); + inner.call(); + OpenProjects.getDefault().close (new Project[] { mainPrj }); + } + + if (OpenProjects.getDefault().getOpenProjects().length != 0) { + fail("All projects shall be closed: " + Arrays.asList(OpenProjects.getDefault().getOpenProjects())); + } + assertFalse("No project is opened", OpenProjects.getDefault().isProjectOpen(mainPrj)); + assertFalse("No project is opened", OpenProjects.getDefault().isProjectOpen(nestedPrj)); + + OpenProjectList.OPENING_RP.post(new Runnable() {public void run() {}}).waitFinished(); // flush running tasks + } +} diff --git a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/OpenProjectListSetMain2Test.java b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/OpenProjectListSetMain2Test.java index afab716d614f..768dbfc4a465 100644 --- a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/OpenProjectListSetMain2Test.java +++ b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/OpenProjectListSetMain2Test.java @@ -88,9 +88,6 @@ protected void setUp() throws Exception { OpenProjectListSettings.getInstance().setOpenProjectsURLs(list); OpenProjectListSettings.getInstance().setOpenProjectsDisplayNames(names); OpenProjectListSettings.getInstance().setOpenProjectsIcons(icons); - - //compute project root node children in sync mode - System.setProperty("test.projectnode.sync", "true"); } @RandomlyFails // NB-Core-Build #1058 @@ -99,11 +96,11 @@ public void testBehaviourOfProjectsLogicNode() throws Throwable { L listener = new L(); logicalView.addNodeListener(listener); - assertEquals("30 children", 30, logicalView.getChildren().getNodesCount()); + assertEquals("30 children", 30, logicalView.getChildren().getNodesCount(true)); listener.assertEvents("None", 0); assertEquals("No project opened yet", 0, opened); - for (Node n : logicalView.getChildren().getNodes()) { + for (Node n : logicalView.getChildren().getNodes(true)) { TestSupport.TestProject p = n.getLookup().lookup(TestSupport.TestProject.class); assertNull("No project of this type, yet", p); @@ -127,7 +124,7 @@ public void testBehaviourOfProjectsLogicNode() throws Throwable { OpenProjectList.waitProjectsFullyOpen(); - for (Node n : logicalView.getChildren().getNodes()) { + for (Node n : logicalView.getChildren().getNodes(true)) { TestSupport.TestProject p = n.getLookup().lookup(TestSupport.TestProject.class); assertNotNull("Nodes have correct project of this type", p); } @@ -214,7 +211,7 @@ protected void projectOpened() { } int o = 0; - for (Node n : logicalView.getChildren().getNodes()) { + for (Node n : logicalView.getChildren().getNodes(true)) { TestSupport.TestProject p = n.getLookup().lookup(TestSupport.TestProject.class); if (p != null) { o++; diff --git a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/OpenProjectListSetMainTest.java b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/OpenProjectListSetMainTest.java index 2c7e1f5e2f45..a6d94c57d80a 100644 --- a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/OpenProjectListSetMainTest.java +++ b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/OpenProjectListSetMainTest.java @@ -87,9 +87,6 @@ protected void setUp() throws Exception { OpenProjectListSettings.getInstance().setOpenProjectsURLs(list); OpenProjectListSettings.getInstance().setOpenProjectsDisplayNames(names); OpenProjectListSettings.getInstance().setOpenProjectsIcons(icons); - - //compute project root node children in sync mode - System.setProperty("test.projectnode.sync", "true"); } @RandomlyFails // NB-Core-Build #1058 @@ -98,12 +95,12 @@ public void testBehaviourOfProjectsLogicNode() throws Exception { L listener = new L(); logicalView.addNodeListener(listener); - assertEquals("30 children", 30, logicalView.getChildren().getNodesCount()); + assertEquals("30 children", 30, logicalView.getChildren().getNodesCount(true)); listener.assertEvents("None", 0); assertEquals("No project opened yet", 0, TestProjectOpenedHookImpl.opened); Node main = null; - for (Node n : logicalView.getChildren().getNodes()) { + for (Node n : logicalView.getChildren().getNodes(true)) { TestSupport.TestProject p = n.getLookup().lookup(TestSupport.TestProject.class); assertNull("No project of this type, yet", p); @@ -127,7 +124,7 @@ public void testBehaviourOfProjectsLogicNode() throws Exception { OpenProjectList.waitProjectsFullyOpen(); - for (Node n : logicalView.getChildren().getNodes()) { + for (Node n : logicalView.getChildren().getNodes(true)) { TestSupport.TestProject p = n.getLookup().lookup(TestSupport.TestProject.class); assertNotNull("Nodes have correct project of this type", p); } diff --git a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodeFindTest.java b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodeFindTest.java index d66b9e4919e7..31ff0d99f120 100644 --- a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodeFindTest.java +++ b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodeFindTest.java @@ -47,10 +47,6 @@ public ProjectsRootNodeFindTest(String testName) { } public void testFindNode() throws Exception{ - - //compute project root node children in sync mode - System.setProperty("test.projectnode.sync", "true"); - //prepearing project MockLookup.setInstances(new TestSupport.TestProjectFactory()); CountDownLatch down = new CountDownLatch(1); @@ -79,7 +75,7 @@ public void testFindNode() throws Exception{ OpenProjectListSettings.getInstance().setOpenProjectsIcons(icons); Node logicalView = new ProjectsRootNode(ProjectsRootNode.LOGICAL_VIEW); - assertEquals("2 children", 2, logicalView.getChildren().getNodesCount()); + assertEquals("2 children", 2, logicalView.getChildren().getNodesCount(true)); // let project open code run down.countDown(); diff --git a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodeInitializedSoonerTest.java b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodeInitializedSoonerTest.java index fa6ec62ab428..d406d088edbc 100644 --- a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodeInitializedSoonerTest.java +++ b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodeInitializedSoonerTest.java @@ -60,10 +60,6 @@ protected Level logLevel() { } public void testWrongOrderOfInitialization() throws Exception { - - //compute project root node children in sync mode - System.setProperty("test.projectnode.sync", "true"); - MockLookup.setInstances(new TestSupport.TestProjectFactory()); List list = new ArrayList(); List icons = new ArrayList(); @@ -130,14 +126,14 @@ public void close() throws SecurityException { OpenProjectList.LOGGER.setUseParentHandlers(false); OpenProjectList.LOGGER.setLevel(Level.ALL); - assertEquals("30 children", 30, logicalView.getChildren().getNodesCount()); + assertEquals("30 children", 30, logicalView.getChildren().getNodesCount(true)); OpenProjectList.waitProjectsFullyOpen(); assertTrue("Handler was called", h.ok); assertEquals("All projects opened", 30, TestProjectOpenedHookImpl.opened); int i = 0; - for (Node n : logicalView.getChildren().getNodes()) { + for (Node n : logicalView.getChildren().getNodes(true)) { i++; TestSupport.TestProject p = n.getLookup().lookup(TestSupport.TestProject.class); assertNotNull("Project type is correct " + i, p); diff --git a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodeNotRecognizedTest.java b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodeNotRecognizedTest.java index ce60fd5a5f77..37dad94d4731 100644 --- a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodeNotRecognizedTest.java +++ b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodeNotRecognizedTest.java @@ -53,9 +53,6 @@ public ProjectsRootNodeNotRecognizedTest(String testName) { @RandomlyFails // NB-Core-Build #4346: child at 0 public void testBadgingNodeIsOKIfProjectIsNoLongerRecognized() throws Exception{ - - //compute project root node children in sync mode - System.setProperty("test.projectnode.sync", "true"); //prepearing project MockLookup.setInstances(new TestFactory()); down = new CountDownLatch(1); @@ -80,7 +77,7 @@ public void testBadgingNodeIsOKIfProjectIsNoLongerRecognized() throws Exception{ OpenProjectListSettings.getInstance().setOpenProjectsIcons(icons); Node logicalView = new ProjectsRootNode(ProjectsRootNode.PHYSICAL_VIEW); - assertEquals("2 children", 2, logicalView.getChildren().getNodesCount()); + assertEquals("2 children", 2, logicalView.getChildren().getNodesCount(true)); assertNotNull("Still lazy project", logicalView.getChildren().getNodeAt(0).getLookup().lookup(LazyProject.class)); // let project open code run diff --git a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePhysicalViewModeSourcesTest.java b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePhysicalViewModeSourcesTest.java index ee4de5c9d8d8..14ad0a5f6eb5 100644 --- a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePhysicalViewModeSourcesTest.java +++ b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePhysicalViewModeSourcesTest.java @@ -90,9 +90,6 @@ protected void setUp() throws Exception { OpenProjectListSettings.getInstance().setOpenProjectsURLs(list); OpenProjectListSettings.getInstance().setOpenProjectsDisplayNames(names); OpenProjectListSettings.getInstance().setOpenProjectsIcons(icons); - - //compute project root node children in sync mode - System.setProperty("test.projectnode.sync", "true"); } public void testBehaviourOfProjectsLogicNode() throws InterruptedException { @@ -100,11 +97,11 @@ public void testBehaviourOfProjectsLogicNode() throws InterruptedException { L listener = new L(); view.addNodeListener(listener); - assertEquals("30 children", 30, view.getChildren().getNodesCount()); + assertEquals("30 children", 30, view.getChildren().getNodesCount(true)); listener.assertEvents("None", 0); assertEquals("No project opened yet", 0, TestProjectOpenedHookImpl.opened); - for (Node n : view.getChildren().getNodes()) { + for (Node n : view.getChildren().getNodes(true)) { TestSupport.TestProject p = n.getLookup().lookup(TestSupport.TestProject.class); assertNull("No project of this type, yet", p); } @@ -117,7 +114,7 @@ public void testBehaviourOfProjectsLogicNode() throws InterruptedException { OpenProjectList.waitProjectsFullyOpen(); - Node[] all = view.getChildren().getNodes(); + Node[] all = view.getChildren().getNodes(true); assertEquals("3x30", 90, all.length); for (Node n : all) { LogicalView v = n.getLookup().lookup(LogicalView.class); diff --git a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePhysicalViewTest.java b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePhysicalViewTest.java index 0957551eb56f..271d0abab266 100644 --- a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePhysicalViewTest.java +++ b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePhysicalViewTest.java @@ -92,9 +92,6 @@ protected void setUp() throws Exception { OpenProjectListSettings.getInstance().setOpenProjectsURLs(list); OpenProjectListSettings.getInstance().setOpenProjectsDisplayNames(names); OpenProjectListSettings.getInstance().setOpenProjectsIcons(icons); - - //compute project root node children in sync mode - System.setProperty("test.projectnode.sync", "true"); } @RandomlyFails // NB-Core-Build #3939: "Can be garbage collected when closed" involving TimedWeakReference @@ -127,11 +124,11 @@ private Node doBehaviourOfProjectsNode() throws InterruptedException { L listener = new L(); view.addNodeListener(listener); - assertEquals("30 children", 30, view.getChildren().getNodesCount()); + assertEquals("30 children", 30, view.getChildren().getNodesCount(true)); listener.assertEvents("None", 0); assertEquals("No project opened yet", 0, TestProjectOpenedHookImpl.opened); - for (Node n : view.getChildren().getNodes()) { + for (Node n : view.getChildren().getNodes(true)) { TestSupport.TestProject p = n.getLookup().lookup(TestSupport.TestProject.class); assertNull("No project of this type, yet", p); } @@ -144,7 +141,7 @@ private Node doBehaviourOfProjectsNode() throws InterruptedException { OpenProjectList.waitProjectsFullyOpen(); - for (Node n : view.getChildren().getNodes()) { + for (Node n : view.getChildren().getNodes(true)) { LogicalView v = n.getLookup().lookup(LogicalView.class); assertEquals("View is not present in physical view", null, v); } @@ -152,7 +149,7 @@ private Node doBehaviourOfProjectsNode() throws InterruptedException { listener.assertEvents("Goal is to receive no events at all", 0); - return view.getChildren().getNodes()[0]; + return view.getChildren().getNodes(true)[0]; } private static class L implements NodeListener { diff --git a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePreferredFromContextOpenTest.java b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePreferredFromContextOpenTest.java index 152f685c2d33..c00ef0f416fe 100644 --- a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePreferredFromContextOpenTest.java +++ b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePreferredFromContextOpenTest.java @@ -91,9 +91,6 @@ protected void setUp() throws Exception { OpenProjectListSettings.getInstance().setOpenProjectsURLs(list); OpenProjectListSettings.getInstance().setOpenProjectsDisplayNames(names); OpenProjectListSettings.getInstance().setOpenProjectsIcons(icons); - - //compute project root node children in sync mode - System.setProperty("test.projectnode.sync", "true"); } public void testPreferencesInOpenCanBeChanged() throws InterruptedException, IOException { @@ -101,16 +98,16 @@ public void testPreferencesInOpenCanBeChanged() throws InterruptedException, IOE L listener = new L(); logicalView.addNodeListener(listener); - assertEquals("10 children", 10, logicalView.getChildren().getNodesCount()); + assertEquals("10 children", 10, logicalView.getChildren().getNodesCount(true)); listener.assertEvents("None", 0); assertEquals("No project opened yet", 0, TestProjectOpenedHookImpl.opened); - for (Node n : logicalView.getChildren().getNodes()) { + for (Node n : logicalView.getChildren().getNodes(true)) { TestSupport.TestProject p = n.getLookup().lookup(TestSupport.TestProject.class); assertNull("No project of this type, yet", p); } - Node midNode = logicalView.getChildren().getNodes()[5]; + Node midNode = logicalView.getChildren().getNodes(true)[5]; { TestSupport.TestProject p = midNode.getLookup().lookup(TestSupport.TestProject.class); assertNull("No project of this type, yet", p); @@ -135,7 +132,7 @@ public void testPreferencesInOpenCanBeChanged() throws InterruptedException, IOE { TestSupport.TestProject p = null; for (int i = 0; i < 10; i++) { - Node midNode2 = logicalView.getChildren().getNodes()[5]; + Node midNode2 = logicalView.getChildren().getNodes(true)[5]; p = midNode.getLookup().lookup(TestSupport.TestProject.class); if (p != null) { break; @@ -152,7 +149,7 @@ public void testPreferencesInOpenCanBeChanged() throws InterruptedException, IOE assertEquals("All projects opened", 10, TestProjectOpenedHookImpl.opened); - for (Node n : logicalView.getChildren().getNodes()) { + for (Node n : logicalView.getChildren().getNodes(true)) { TestSupport.TestProject p = n.getLookup().lookup(TestSupport.TestProject.class); assertNotNull("Nodes have correct project of this type", p); } diff --git a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePreferredFromPopupTest.java b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePreferredFromPopupTest.java index 31fd8c4d9698..2c0f0c86b1dc 100644 --- a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePreferredFromPopupTest.java +++ b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePreferredFromPopupTest.java @@ -93,9 +93,6 @@ protected void setUp() throws Exception { OpenProjectListSettings.getInstance().setOpenProjectsURLs(list); OpenProjectListSettings.getInstance().setOpenProjectsDisplayNames(names); OpenProjectListSettings.getInstance().setOpenProjectsIcons(icons); - - //compute project root node children in sync mode - System.setProperty("test.projectnode.sync", "true"); } public void testPreferencesInOpenCanBeChanged() throws InterruptedException, IOException, Exception { @@ -103,16 +100,16 @@ public void testPreferencesInOpenCanBeChanged() throws InterruptedException, IOE L listener = new L(); logicalView.addNodeListener(listener); - assertEquals("10 children", 10, logicalView.getChildren().getNodesCount()); + assertEquals("10 children", 10, logicalView.getChildren().getNodesCount(true)); listener.assertEvents("None", 0); assertEquals("No project opened yet", 0, TestProjectOpenedHookImpl.opened); - for (Node n : logicalView.getChildren().getNodes()) { + for (Node n : logicalView.getChildren().getNodes(true)) { TestSupport.TestProject p = n.getLookup().lookup(TestSupport.TestProject.class); assertNull("No project of this type, yet", p); } - Node midNode = logicalView.getChildren().getNodes()[5]; + Node midNode = logicalView.getChildren().getNodes(true)[5]; { TestSupport.TestProject p = midNode.getLookup().lookup(TestSupport.TestProject.class); assertNull("No project of this type, yet", p); @@ -141,7 +138,7 @@ public void testPreferencesInOpenCanBeChanged() throws InterruptedException, IOE { TestSupport.TestProject p = null; for (int i = 0; i < 10; i++) { - Node midNode2 = logicalView.getChildren().getNodes()[5]; + Node midNode2 = logicalView.getChildren().getNodes(true)[5]; p = midNode.getLookup().lookup(TestSupport.TestProject.class); if (p != null) { break; @@ -158,7 +155,7 @@ public void testPreferencesInOpenCanBeChanged() throws InterruptedException, IOE assertEquals("All projects opened", 10, TestProjectOpenedHookImpl.opened); - for (Node n : logicalView.getChildren().getNodes()) { + for (Node n : logicalView.getChildren().getNodes(true)) { TestSupport.TestProject p = n.getLookup().lookup(TestSupport.TestProject.class); assertNotNull("Nodes have correct project of this type", p); } diff --git a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePreferredOpen2Test.java b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePreferredOpen2Test.java index 33fe501c51d7..6558672f3bee 100644 --- a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePreferredOpen2Test.java +++ b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePreferredOpen2Test.java @@ -19,14 +19,11 @@ package org.netbeans.modules.project.ui; -import java.util.Collections; -import java.util.Iterator; import java.util.logging.Level; import java.util.logging.Logger; import org.netbeans.junit.Log; import org.netbeans.modules.project.ui.actions.TestSupport.TestProject; import org.netbeans.spi.project.ui.LogicalViewProvider; -import org.openide.loaders.DataObject; import org.openide.nodes.AbstractNode; import org.openide.nodes.Children; import org.openide.nodes.Node; @@ -55,8 +52,6 @@ protected void setUp() throws Exception { log = Log.enable("", Level.WARNING); Logger.getLogger("org.netbeans.ui").setLevel(Level.OFF); Logger.getLogger("org.openide.util").setLevel(Level.OFF); - //compute project root node children in sync mode - System.setProperty("test.projectnode.sync", "true"); } @Override diff --git a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePreferredOpenTest.java b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePreferredOpenTest.java index a4af1653e8bf..80e7ce8e6b50 100644 --- a/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePreferredOpenTest.java +++ b/ide/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectsRootNodePreferredOpenTest.java @@ -98,12 +98,8 @@ protected void setUp() throws Exception { OpenProjectListSettings.getInstance().setOpenProjectsIcons(icons); OpenProjects.getDefault().addPropertyChangeListener(this); - - //compute project root node children in sync mode - System.setProperty("test.projectnode.sync", "true"); } - @RandomlyFails // NB-Core-Build #1001 public void testPreferencesInOpenCanBeChanged() throws InterruptedException { assertEquals("No events in API", 0, events); @@ -112,18 +108,18 @@ public void testPreferencesInOpenCanBeChanged() throws InterruptedException { logicalView.addNodeListener(listener); assertEquals("No events in API", 0, events); - assertEquals("10 children", 10, logicalView.getChildren().getNodesCount()); + assertEquals("10 children", 10, logicalView.getChildren().getNodesCount(true)); listener.assertEvents("None", 0); assertEquals("No project opened yet", 0, TestProjectOpenedHookImpl.opened); assertEquals("No events in API", 0, events); - for (Node n : logicalView.getChildren().getNodes()) { + for (Node n : logicalView.getChildren().getNodes(true)) { TestSupport.TestProject p = n.getLookup().lookup(TestSupport.TestProject.class); assertNull("No project of this type, yet", p); } assertEquals("No events in API", 0, events); - Node midNode = logicalView.getChildren().getNodes()[5]; + Node midNode = logicalView.getChildren().getNodes(true)[5]; { TestSupport.TestProject p = midNode.getLookup().lookup(TestSupport.TestProject.class); assertNull("No project of this type, yet", p); @@ -138,7 +134,7 @@ public void testPreferencesInOpenCanBeChanged() throws InterruptedException { Thread.sleep(300); assertEquals("Still no processing", 0, TestProjectOpenedHookImpl.opened); // trigger initialization of the node, shall trigger OpenProjectList.preferredProject(lazyP); - midNode.getChildren().getNodes(); + midNode.getChildren().getNodes(true); first.countDown(); TestProjectOpenedHookImpl.toOpen.await(); @@ -146,7 +142,7 @@ public void testPreferencesInOpenCanBeChanged() throws InterruptedException { { TestSupport.TestProject p = null; for (int i = 0; i < 10; i++) { - Node midNode2 = logicalView.getChildren().getNodes()[5]; + Node midNode2 = logicalView.getChildren().getNodes(true)[5]; p = midNode.getLookup().lookup(TestSupport.TestProject.class); if (p != null) { break; @@ -160,7 +156,7 @@ public void testPreferencesInOpenCanBeChanged() throws InterruptedException { { int cnt = 0; for (int i = 0; i < 10; i++) { - Node n = logicalView.getChildren().getNodes()[i]; + Node n = logicalView.getChildren().getNodes(true)[i]; TestSupport.TestProject p = null; p = n.getLookup().lookup(TestSupport.TestProject.class); if (p != null) { @@ -180,7 +176,7 @@ public void testPreferencesInOpenCanBeChanged() throws InterruptedException { assertEquals("All projects opened", 10, TestProjectOpenedHookImpl.opened); - for (Node n : logicalView.getChildren().getNodes()) { + for (Node n : logicalView.getChildren().getNodes(true)) { TestSupport.TestProject p = n.getLookup().lookup(TestSupport.TestProject.class); assertNotNull("Nodes have correct project of this type", p); } diff --git a/java/java.lsp.server/arch.xml b/java/java.lsp.server/arch.xml index 2f36d684a6f8..a4d20ecf1140 100644 --- a/java/java.lsp.server/arch.xml +++ b/java/java.lsp.server/arch.xml @@ -513,6 +513,13 @@
  • com.dukescript.presenters.browserDebug
  • +
  • + + Should Children.getNodes(optimalResult) be called + with true? Then set the treeViewProvider.sync + property to "true". Useful while testing. + +
  • diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/explorer/TreeViewProvider.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/explorer/TreeViewProvider.java index 69039f028767..7fc9ac8ac083 100644 --- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/explorer/TreeViewProvider.java +++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/explorer/TreeViewProvider.java @@ -470,8 +470,9 @@ public final CompletionStage getChildren(int id) { } public final CompletionStage getChildren(Node nodeOrNull) { - Node node = getNodeOrRoot(nodeOrNull); - return CompletableFuture.completedFuture(node.getChildren().getNodes()); + var node = getNodeOrRoot(nodeOrNull); + var optimalResult = Boolean.getBoolean("treeViewProvider.sync"); + return CompletableFuture.completedFuture(node.getChildren().getNodes(optimalResult)); } public final CompletionStage getParent(Node node) { diff --git a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/explorer/ProjectViewTest.java b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/explorer/ProjectViewTest.java index 225169dccfe0..aedfb8064d92 100644 --- a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/explorer/ProjectViewTest.java +++ b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/explorer/ProjectViewTest.java @@ -417,7 +417,7 @@ private TreeItem findFirstProjectNode() throws Exception { InitializeResult result = server.initialize(new InitializeParams()).get(); // by default the ProjectsRootNode initializes its contents asynchronously; a proper reaction to that will be tested in another testcase. Save the complexity here. - System.setProperty("test.projectnode.sync", "true"); + System.setProperty("treeViewProvider.sync", "true"); CompletableFuture explorer = server.getTreeViewService().explorerManager(new CreateExplorerParams("foundProjects")); TreeItem root = explorer.get(); diff --git a/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/usages/ScanInProgressTest.java b/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/usages/ScanInProgressTest.java index 5ae434cf8b53..430f2cbb375e 100644 --- a/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/usages/ScanInProgressTest.java +++ b/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/usages/ScanInProgressTest.java @@ -75,9 +75,6 @@ Lookup createLookup(TestSupport.TestProject project, Object instance) { @Override protected void setUp() throws Exception { - //ensure ProjectsRootNode children are processed synchronously: - System.setProperty("test.projectnode.sync", "true"); - clearWorkDir(); MockServices.setServices(TestSupport.TestProjectFactory.class); @@ -119,18 +116,18 @@ public void testScanInProgressWhenOpeningProject() throws InterruptedException { logicalView.addNodeListener(listener); assertEquals("No events in API", 0, events); - assertEquals("10 children", 10, logicalView.getChildren().getNodesCount()); + assertEquals("10 children", 10, logicalView.getChildren().getNodesCount(true)); listener.assertEvents("None", 0); assertEquals("No project opened yet", 0, TestProjectOpenedHookImpl.opened); assertEquals("No events in API", 0, events); - for (Node n : logicalView.getChildren().getNodes()) { + for (Node n : logicalView.getChildren().getNodes(true)) { TestSupport.TestProject p = n.getLookup().lookup(TestSupport.TestProject.class); assertNull("No project of this type, yet", p); } assertEquals("No events in API", 0, events); - Node midNode = logicalView.getChildren().getNodes()[5]; + Node midNode = logicalView.getChildren().getNodes(true)[5]; { TestSupport.TestProject p = midNode.getLookup().lookup(TestSupport.TestProject.class); assertNull("No project of this type, yet", p); @@ -145,7 +142,7 @@ public void testScanInProgressWhenOpeningProject() throws InterruptedException { Thread.sleep(300); assertEquals("Still no processing", 0, TestProjectOpenedHookImpl.opened); // trigger initialization of the node, shall trigger OpenProjectList.preferredProject(lazyP); - midNode.getChildren().getNodes(); + midNode.getChildren().getNodes(true); first.countDown(); TestProjectOpenedHookImpl.toOpen.await(); @@ -153,7 +150,7 @@ public void testScanInProgressWhenOpeningProject() throws InterruptedException { { TestSupport.TestProject p = null; for (int i = 0; i < 10; i++) { - Node midNode2 = logicalView.getChildren().getNodes()[5]; + Node midNode2 = logicalView.getChildren().getNodes(true)[5]; p = midNode.getLookup().lookup(TestSupport.TestProject.class); if (p != null) { break; @@ -167,7 +164,7 @@ public void testScanInProgressWhenOpeningProject() throws InterruptedException { { int cnt = 0; for (int i = 0; i < 10; i++) { - Node n = logicalView.getChildren().getNodes()[i]; + Node n = logicalView.getChildren().getNodes(true)[i]; TestSupport.TestProject p = null; p = n.getLookup().lookup(TestSupport.TestProject.class); if (p != null) { @@ -187,7 +184,7 @@ public void testScanInProgressWhenOpeningProject() throws InterruptedException { assertEquals("All projects opened", 10, TestProjectOpenedHookImpl.opened); - for (Node n : logicalView.getChildren().getNodes()) { + for (Node n : logicalView.getChildren().getNodes(true)) { TestSupport.TestProject p = n.getLookup().lookup(TestSupport.TestProject.class); assertNotNull("Nodes have correct project of this type", p); }