From 64dca83ac40946d3d9a5940d48d09acacbbdcdc7 Mon Sep 17 00:00:00 2001 From: Roland Grunberg Date: Tue, 23 Apr 2024 14:43:42 -0400 Subject: [PATCH] Create the default project only when it is necessary. - Default project is configured with a (default) JRE, that will produce unwanted symbols when other projects don't use the default JRE - Place default project creation logic into the invisible project importer since that is the importer requiring it - Continue to support some special cases where default project should be created (eg. Maven/Gradle project & opening a standalone file) - Update testcases & add a testcase Signed-off-by: Roland Grunberg --- .../jdt/ls/core/internal/JDTUtils.java | 6 +++++ .../handlers/BuildWorkspaceHandler.java | 6 +++-- .../managers/InvisibleProjectImporter.java | 9 +++---- .../internal/managers/ProjectsManager.java | 10 ++++---- .../ls/core/internal/JVMConfiguratorTest.java | 16 +++++++++++++ .../internal/commands/ProjectCommandTest.java | 2 +- .../GradleProjectMetadataFileTest.java | 2 +- .../MavenProjectMetadataFileTest.java | 4 ++-- .../handlers/BuildWorkspaceHandlerTest.java | 4 ++-- .../handlers/ImportNewProjectsTest.java | 20 ++++++++-------- .../NavigateToDefinitionHandlerTest.java | 3 +-- .../handlers/WorkspaceSymbolHandlerTest.java | 2 +- .../AbstractProjectsManagerBasedTest.java | 7 ++++++ .../managers/EclipseProjectImporterTest.java | 4 ++-- .../managers/GradleProjectImporterTest.java | 24 +++++++++---------- .../managers/MavenBuildSupportTest.java | 4 ++-- .../managers/MavenProjectImporterTest.java | 6 ++--- .../core/internal/managers/MultiRootTest.java | 12 +++++----- .../managers/ProjectsManagerTest.java | 21 +++++++--------- 19 files changed, 95 insertions(+), 67 deletions(-) diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JDTUtils.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JDTUtils.java index 25003fc7e2..f415004ccb 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JDTUtils.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JDTUtils.java @@ -266,6 +266,12 @@ static ICompilationUnit getFakeCompilationUnit(URI uri, IProgressMonitor monitor return null; } + try { + ProjectsManager.createJavaProject(ProjectsManager.getDefaultProject(), new NullProgressMonitor()); + ProjectsManager.cleanupResources(ProjectsManager.getDefaultProject()); + } catch (Exception e) { + // continue + } IProject project = JavaLanguageServerPlugin.getProjectsManager().getDefaultProject(); if (project == null || !project.isAccessible()) { String fileName = path.getFileName().toString(); diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/BuildWorkspaceHandler.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/BuildWorkspaceHandler.java index 2331f38750..91b8354732 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/BuildWorkspaceHandler.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/BuildWorkspaceHandler.java @@ -56,7 +56,9 @@ public BuildWorkspaceStatus buildWorkspace(boolean forceReBuild, IProgressMonito if (monitor.isCanceled()) { return BuildWorkspaceStatus.CANCELLED; } - projectsManager.cleanupResources(projectsManager.getDefaultProject()); + if (ProjectUtils.getAllProjects(false).length == 0) { + ProjectsManager.cleanupResources(ProjectsManager.getDefaultProject()); + } if (forceReBuild) { SubMonitor subMonitor = SubMonitor.convert(monitor, 100); ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.CLEAN_BUILD, subMonitor.split(50)); @@ -67,7 +69,7 @@ public BuildWorkspaceStatus buildWorkspace(boolean forceReBuild, IProgressMonito List problemMarkers = new ArrayList<>(); IProject[] projects = ProjectUtils.getAllProjects(); for (IProject project : projects) { - if (!project.equals(projectsManager.getDefaultProject())) { + if (!project.equals(ProjectsManager.getDefaultProject())) { List markers = ResourceUtils.getErrorMarkers(project); if (markers != null) { problemMarkers.addAll(markers); diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/InvisibleProjectImporter.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/InvisibleProjectImporter.java index 3a3489ad3b..0fe42702a7 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/InvisibleProjectImporter.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/InvisibleProjectImporter.java @@ -26,7 +26,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Comparator; import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; @@ -51,15 +50,14 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.IJavaModelStatus; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.internal.core.ClasspathEntry; import org.eclipse.jdt.ls.core.internal.AbstractProjectImporter; import org.eclipse.jdt.ls.core.internal.IConstants; import org.eclipse.jdt.ls.core.internal.JDTUtils; @@ -102,6 +100,9 @@ public void importToWorkspace(IProgressMonitor monitor) throws OperationCanceled return; } + ProjectsManager.createJavaProject(ProjectsManager.getDefaultProject(), new NullProgressMonitor()); + ProjectsManager.cleanupResources(ProjectsManager.getDefaultProject()); + IPath rootPath = ResourceUtils.filePathFromURI(rootFolder.toPath().toUri().toString()); Optional triggerJavaFile = triggerFiles.stream().filter(triggerFile -> rootPath.isPrefixOf(triggerFile)).findFirst(); if (!triggerJavaFile.isPresent()) { @@ -201,7 +202,7 @@ private static Collection collectSourcePaths(IPath triggerFilePath, IFold return Collections.emptySet(); } Collection triggerFiles = collectTriggerFiles(currentProject, foldersToSearch); - + Set sourcePaths = new HashSet<>(); sourcePaths.add(triggerFolder.getFullPath()); diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/ProjectsManager.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/ProjectsManager.java index 94e6772ac3..c0549f05d3 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/ProjectsManager.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/ProjectsManager.java @@ -116,8 +116,10 @@ public void initializeProjects(final Collection rootPaths, IProgressMonit if (!preferenceManager.getClientPreferences().skipProjectConfiguration()) { SubMonitor subMonitor = SubMonitor.convert(monitor, 100); cleanInvalidProjects(rootPaths, subMonitor.split(20)); - createJavaProject(getDefaultProject(), subMonitor.split(10)); - cleanupResources(getDefaultProject()); + if (rootPaths.isEmpty() && !ProjectsManager.getDefaultProject().exists()) { + ProjectsManager.createJavaProject(ProjectsManager.getDefaultProject(), subMonitor.split(10)); + ProjectsManager.cleanupResources(ProjectsManager.getDefaultProject()); + } Collection projectConfigurations = preferenceManager.getPreferences().getProjectConfigurations(); if (projectConfigurations == null) { // old way to import project @@ -336,7 +338,7 @@ public IStatus runInWorkspace(IProgressMonitor monitor) { return job; } - public void cleanupResources(IProject project) throws CoreException { + public static void cleanupResources(IProject project) throws CoreException { IJavaProject javaProj = JavaCore.create(project); if (javaProj == null) { return; @@ -724,7 +726,7 @@ public IStatus runInWorkspace(IProgressMonitor monitor) { for (Entry> entry : groupByBuildSupport(projects).entrySet()) { IStatus onWillUpdateStatus = onWillConfigurationUpdate(entry.getKey(), entry.getValue(), monitor); - + // if onWillUpdate() failed, skip updating the projects. if (!onWillUpdateStatus.isOK()) { status.add(onWillUpdateStatus); diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/JVMConfiguratorTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/JVMConfiguratorTest.java index 7a55c1820c..839c897dc3 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/JVMConfiguratorTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/JVMConfiguratorTest.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.jdt.ls.core.internal; +import static org.eclipse.jdt.ls.core.internal.ProjectUtils.getJavaSourceLevel; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; @@ -30,6 +31,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.URIUtil; import org.eclipse.jdt.core.IJavaProject; @@ -42,11 +44,13 @@ import org.eclipse.jdt.launching.JavaRuntime; import org.eclipse.jdt.launching.LibraryLocation; import org.eclipse.jdt.launching.environments.IExecutionEnvironment; +import org.eclipse.jdt.ls.core.internal.handlers.WorkspaceSymbolHandler; import org.eclipse.jdt.ls.core.internal.managers.AbstractInvisibleProjectBasedTest; import org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences; import org.eclipse.jdt.ls.core.internal.preferences.Preferences; import org.eclipse.lsp4j.MessageParams; import org.eclipse.lsp4j.MessageType; +import org.eclipse.lsp4j.SymbolInformation; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -246,6 +250,18 @@ public void testInvalidRuntime() throws Exception { assertEquals("Invalid runtime for " + runtime.getName() + ": 'bin' should be removed from the path (" + runtime.getPath() + ").", notification.getMessage()); } + // https://github.com/redhat-developer/vscode-java/issues/3452 + @Test + public void testJavaRuntimesDoNotLeak() throws Exception { + importProjects("maven/salut-java11"); + IProject project = WorkspaceHelper.getProject("salut-java11"); + assertIsJavaProject(project); + assertEquals("11", getJavaSourceLevel(project)); + List results = WorkspaceSymbolHandler.search("java.lang.Object", new NullProgressMonitor()); + int numOfObjectSymbols = results.stream().filter(s -> "java.lang".equals(s.getContainerName()) && "Object".equals(s.getName())).toList().size(); + assertEquals(1, numOfObjectSymbols); + } + private void assertComplianceAndPreviewSupport(IJavaProject javaProject, String compliance, boolean previewEnabled) { assertEquals(previewEnabled ? JavaCore.ENABLED : JavaCore.DISABLED, javaProject.getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true)); assertEquals(compliance, javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true)); diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/commands/ProjectCommandTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/commands/ProjectCommandTest.java index 7df8e225de..081f4b941e 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/commands/ProjectCommandTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/commands/ProjectCommandTest.java @@ -391,7 +391,7 @@ public void testIsTestFileForGradle() throws Exception { public void getAllJavaProject() throws Exception { importProjects("maven/multimodule"); List projects = ProjectCommand.getAllJavaProjects(); - assertEquals(4, projects.size()); + assertEquals(3, projects.size()); } private static Range START_OF_DOCUMENT = new Range(new Position(0, 0), new Position(0, 0)); diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/filesystem/GradleProjectMetadataFileTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/filesystem/GradleProjectMetadataFileTest.java index 1fd2ab9cc8..5593c41866 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/filesystem/GradleProjectMetadataFileTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/filesystem/GradleProjectMetadataFileTest.java @@ -121,7 +121,7 @@ public void testMetadataFileLocation2() throws Exception { @Test public void testSettingsGradle() throws Exception { List projects = importProjects("gradle/sample"); - assertEquals(3, projects.size());//default, app, sample + assertEquals(2, projects.size()); // app, sample IProject root = WorkspaceHelper.getProject("sample"); assertIsGradleProject(root); IProject project = WorkspaceHelper.getProject("app"); diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/filesystem/MavenProjectMetadataFileTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/filesystem/MavenProjectMetadataFileTest.java index 1cda0e465d..1184957d1b 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/filesystem/MavenProjectMetadataFileTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/filesystem/MavenProjectMetadataFileTest.java @@ -111,7 +111,7 @@ public void testMetadataFileSync() throws Exception { @Test public void testInvalidProject() throws Exception { List projects = importProjects(MAVEN_INVALID); - assertEquals(2, projects.size()); + assertEquals(1, projects.size()); IProject invalid = WorkspaceHelper.getProject(INVALID); assertIsMavenProject(invalid); IFile projectFile = invalid.getFile(IProjectDescription.DESCRIPTION_FILE_NAME); @@ -123,7 +123,7 @@ public void testInvalidProject() throws Exception { file.delete(); assertFalse(file.exists()); projects = importProjects(MAVEN_INVALID); - assertEquals(2, projects.size()); + assertEquals(1, projects.size()); invalid = WorkspaceHelper.getProject(INVALID); assertIsMavenProject(invalid); } diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/BuildWorkspaceHandlerTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/BuildWorkspaceHandlerTest.java index 251f5ff68d..ef5d69c4ab 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/BuildWorkspaceHandlerTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/BuildWorkspaceHandlerTest.java @@ -87,7 +87,7 @@ public void testParallelBuildForEclipseProjects() throws Exception preferences.setMaxBuildCount(4); List projects = importProjects("eclipse/multi"); - assertEquals(3, projects.size()); + assertEquals(2, projects.size()); BuildWorkspaceStatus result = handler.buildWorkspace(false, monitor); assertEquals(String.format("BuildWorkspaceStatus is: %s.", result.toString()), result, BuildWorkspaceStatus.SUCCEED); @@ -98,7 +98,7 @@ public void testParallelBuildSupport() throws Exception { preferences.setMaxBuildCount(4); List projects = importProjects("maven/multimodule"); - assertEquals(6, projects.size()); + assertEquals(5, projects.size()); BuildWorkspaceStatus result = handler.buildWorkspace(false, monitor); assertEquals(String.format("BuildWorkspaceStatus is: %s.", result.toString()), result, BuildWorkspaceStatus.SUCCEED); diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/ImportNewProjectsTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/ImportNewProjectsTest.java index 59899425db..c5d489af97 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/ImportNewProjectsTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/ImportNewProjectsTest.java @@ -72,7 +72,7 @@ public void testImportNewMavenProjects() throws Exception { importProjects("maven/multimodule"); waitForJobs(); projects = workspace.getRoot().getProjects(); - assertEquals(6, projects.length); + assertEquals(5, projects.length); // Add new sub-module IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("multimodule"); @@ -103,7 +103,7 @@ public void testImportNewMavenProjects() throws Exception { // Verify no projects imported projects = workspace.getRoot().getProjects(); - assertEquals(6, projects.length); + assertEquals(5, projects.length); // Verify import projects projectsManager.setConnection(client); @@ -112,7 +112,7 @@ public void testImportNewMavenProjects() throws Exception { IProject newProject = workspace.getRoot().getProject("module4"); assertTrue(newProject.exists()); projects = workspace.getRoot().getProjects(); - assertEquals(7, projects.length); + assertEquals(6, projects.length); ArgumentCaptor argument = ArgumentCaptor.forClass(EventNotification.class); verify(client, times(1)).sendEventNotification(argument.capture()); @@ -130,7 +130,7 @@ public void testManualImportNewMavenProjects() throws Exception { importProjects("maven/multimodule"); waitForJobs(); projects = workspace.getRoot().getProjects(); - assertEquals(6, projects.length); + assertEquals(5, projects.length); // Add new sub-module IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("multimodule"); @@ -161,7 +161,7 @@ public void testManualImportNewMavenProjects() throws Exception { // Verify no projects imported projects = workspace.getRoot().getProjects(); - assertEquals(6, projects.length); + assertEquals(5, projects.length); // Verify import projects projectsManager.setConnection(client); @@ -173,7 +173,7 @@ public void testManualImportNewMavenProjects() throws Exception { IProject newProject = workspace.getRoot().getProject("module4"); assertTrue("New module is imported", newProject.exists()); projects = workspace.getRoot().getProjects(); - assertEquals(7, projects.length); + assertEquals(6, projects.length); ArgumentCaptor argument = ArgumentCaptor.forClass(EventNotification.class); verify(client, times(1)).sendEventNotification(argument.capture()); @@ -192,7 +192,7 @@ public void testImportNewGradleProjects() throws Exception { importProjects("gradle/multi-module"); waitForJobs(); projects = workspace.getRoot().getProjects(); - assertEquals(4, projects.length); + assertEquals(3, projects.length); // Add new sub-module IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("multi-module"); File projectBasePath = project.getLocation().toFile(); @@ -207,7 +207,7 @@ public void testImportNewGradleProjects() throws Exception { // Verify no projects imported projects = workspace.getRoot().getProjects(); - assertEquals(4, projects.length); + assertEquals(3, projects.length); // Verify import projects projectsManager.setConnection(client); @@ -216,7 +216,7 @@ public void testImportNewGradleProjects() throws Exception { IProject newProject = workspace.getRoot().getProject("test"); assertTrue(newProject.exists()); projects = workspace.getRoot().getProjects(); - assertEquals(5, projects.length); + assertEquals(4, projects.length); ArgumentCaptor argument = ArgumentCaptor.forClass(EventNotification.class); verify(client, times(1)).sendEventNotification(argument.capture()); @@ -231,7 +231,7 @@ public void testImportMixedProjects() throws Exception { IProject[] projects = workspace.getRoot().getProjects(); assertEquals(0, projects.length); importProjects("mixed"); - assertEquals(4, wsRoot.getProjects().length); + assertEquals(3, wsRoot.getProjects().length); IProject hello = wsRoot.getProject("hello"); assertNotNull(hello); assertIsJavaProject(hello); diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/NavigateToDefinitionHandlerTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/NavigateToDefinitionHandlerTest.java index 6c302cd2e4..d59d085946 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/NavigateToDefinitionHandlerTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/NavigateToDefinitionHandlerTest.java @@ -44,14 +44,12 @@ public class NavigateToDefinitionHandlerTest extends AbstractProjectsManagerBase private NavigateToDefinitionHandler handler; private IProject project; - private IProject defaultProject; @Before public void setUp() throws Exception { handler = new NavigateToDefinitionHandler(preferenceManager); importProjects("maven/salut"); project = WorkspaceHelper.getProject("salut"); - defaultProject = linkFilesToDefaultProject("singlefile/Single.java").getProject(); Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, monitor); Job.getJobManager().join(ResourcesPlugin.FAMILY_MANUAL_BUILD, monitor); Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_REFRESH, monitor); @@ -144,6 +142,7 @@ public void testMethodInAnonymousClass2() throws Exception { public void testJdkClasses() throws Exception { // because for test, we are using fake rt.jar(rtstubs.jar), the issue of issue https://bugs.eclipse.org/bugs/show_bug.cgi?id=541573 will // never occur in test cases + IProject defaultProject = linkFilesToDefaultProject("singlefile/Single.java").getProject(); String uri = ClassFileUtil.getURI(defaultProject, "Single"); TextDocumentIdentifier identifier = new TextDocumentIdentifier(uri); handler.definition(new TextDocumentPositionParams(identifier, new Position(1, 31)), monitor); diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/WorkspaceSymbolHandlerTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/WorkspaceSymbolHandlerTest.java index 4cf6636a37..0098f55c4f 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/WorkspaceSymbolHandlerTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/WorkspaceSymbolHandlerTest.java @@ -78,7 +78,7 @@ public void testWorkspaceSearch() { String query = "Array"; List results = WorkspaceSymbolHandler.search(query, monitor); assertNotNull(results); - assertEquals("Unexpected results", 22, results.size()); + assertEquals("Unexpected results", 11, results.size()); Range defaultRange = JDTUtils.newRange(); for (SymbolInformation symbol : results) { assertNotNull("Kind is missing", symbol.getKind()); diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/AbstractProjectsManagerBasedTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/AbstractProjectsManagerBasedTest.java index ebb8c15b65..3f025cab18 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/AbstractProjectsManagerBasedTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/AbstractProjectsManagerBasedTest.java @@ -56,6 +56,7 @@ import org.eclipse.core.runtime.IRegistryChangeEvent; import org.eclipse.core.runtime.IRegistryChangeListener; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.jobs.Job; @@ -211,6 +212,12 @@ protected IJavaProject newDefaultProject() throws Exception { } protected IFile linkFilesToDefaultProject(String path) throws Exception { + try { + ProjectsManager.createJavaProject(ProjectsManager.getDefaultProject(), new NullProgressMonitor()); + ProjectsManager.cleanupResources(ProjectsManager.getDefaultProject()); + } catch (OperationCanceledException e) { + } catch (CoreException e) { + } IProject testProject = ProjectsManager.getDefaultProject(); String fullpath = copyFiles(path, true).getAbsolutePath().replace('\\', '/'); String fileName = fullpath.substring(fullpath.lastIndexOf("/") + 1); diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/EclipseProjectImporterTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/EclipseProjectImporterTest.java index d801822f27..705073da5b 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/EclipseProjectImporterTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/EclipseProjectImporterTest.java @@ -94,7 +94,7 @@ public void ignoreMissingResourceFilters() throws Exception { @Test public void importMultipleJavaProject() throws Exception { List projects = importProjects("eclipse/multi"); - assertEquals(3, projects.size()); + assertEquals(2, projects.size()); IProject bar = getProject("bar"); assertIsJavaProject(bar); @@ -123,7 +123,7 @@ public void testJavaImportExclusions() throws Exception { try { javaImportExclusions.add(BAR_PATTERN); List projects = importProjects("eclipse/multi"); - assertEquals(2, projects.size()); + assertEquals(1, projects.size()); IProject bar = getProject("bar"); assertNull(bar); IProject foo = getProject("foo"); diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/GradleProjectImporterTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/GradleProjectImporterTest.java index bbd864e9fa..d96ced73ca 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/GradleProjectImporterTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/GradleProjectImporterTest.java @@ -107,7 +107,7 @@ public void cleanUp() throws Exception { @Test public void importNestedGradleProject() throws Exception { List projects = importProjects("gradle/nested"); - assertEquals(4, projects.size());//default + 3 gradle projects + assertEquals(3, projects.size()); // 3 gradle projects IProject gradle1 = WorkspaceHelper.getProject("gradle1"); assertIsGradleProject(gradle1); IProject gradle2 = WorkspaceHelper.getProject("gradle2"); @@ -120,14 +120,14 @@ public void importNestedGradleProject() throws Exception { @Test public void testDeleteInvalidProjects() throws Exception { List projects = importProjects(Arrays.asList("gradle/nested/gradle1", "gradle/nested/gradle2")); - assertEquals(3, projects.size());//default + 2 gradle projects + assertEquals(2, projects.size()); // 2 gradle projects IProject gradle1 = WorkspaceHelper.getProject("gradle1"); assertIsGradleProject(gradle1); IProject gradle2 = WorkspaceHelper.getProject("gradle2"); assertIsGradleProject(gradle2); projects = importProjects("gradle/nested/gradle1"); - assertEquals(2, projects.size()); + assertEquals(1, projects.size()); gradle1 = WorkspaceHelper.getProject("gradle1"); assertNotNull(gradle1); gradle2 = WorkspaceHelper.getProject("gradle2"); @@ -140,7 +140,7 @@ public void testJavaImportExclusions() throws Exception { try { javaImportExclusions.add(GRADLE1_PATTERN); List projects = importProjects("gradle/nested"); - assertEquals(3, projects.size());//default + 2 gradle projects + assertEquals(2, projects.size()); // 2 gradle projects IProject gradle1 = WorkspaceHelper.getProject("gradle1"); assertNull(gradle1); IProject gradle2 = WorkspaceHelper.getProject("gradle2"); @@ -174,7 +174,7 @@ public void testDisableGradleWrapper() throws Exception { assertEquals(distribution.getClass(), FixedVersionGradleDistribution.class); assertEquals(((FixedVersionGradleDistribution) distribution).getVersion(), requiredVersion); List projects = importProjects("eclipse/eclipsegradle"); - assertEquals(2, projects.size());//default + 1 eclipse projects + assertEquals(1, projects.size()); // 1 eclipse project IProject eclipse = WorkspaceHelper.getProject("eclipsegradle"); assertNotNull(eclipse); assertTrue(eclipse.getName() + " does not have the Gradle nature", ProjectUtils.isGradleProject(eclipse)); @@ -193,7 +193,7 @@ public void testGradleUserHome() throws Exception { gradleUserHome.deleteOnExit(); JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setGradleUserHome(gradleUserHome.getAbsolutePath()); List projects = importProjects("gradle/simple-gradle"); - assertEquals(2, projects.size());//default + 1 eclipse projects + assertEquals(1, projects.size()); // 1 eclipse project IProject project = WorkspaceHelper.getProject("simple-gradle"); assertNotNull(project); assertTrue(project.getName() + " does not have the Gradle nature", ProjectUtils.isGradleProject(project)); @@ -267,7 +267,7 @@ public void testDisableImportGradle() throws Exception { try { JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setImportGradleEnabled(false); List projects = importProjects("eclipse/eclipsegradle"); - assertEquals(2, projects.size());//default + 1 eclipse projects + assertEquals(1, projects.size()); // 1 eclipse projects IProject eclipse = WorkspaceHelper.getProject("eclipse"); assertNotNull(eclipse); assertFalse(eclipse.getName() + " has the Gradle nature", ProjectUtils.isGradleProject(eclipse)); @@ -487,7 +487,7 @@ public void testSubprojects() throws Exception { // force overrideWorkspace JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setGradleArguments(List.of("--stacktrace")); List projects = importProjects("gradle/subprojects"); - assertEquals(4, projects.size());//default + 3 gradle projects + assertEquals(3, projects.size()); // 3 gradle projects IProject root = WorkspaceHelper.getProject("subprojects"); assertIsGradleProject(root); IProject project1 = WorkspaceHelper.getProject("project1"); @@ -536,7 +536,7 @@ public void testSubprojects() throws Exception { @Test public void importGradleKtsProject() throws Exception { List projects = importProjects("gradle/kradle"); - assertEquals(2, projects.size());//default + gradle kts projects + assertEquals(1, projects.size()); // gradle kts projects IProject kradle = WorkspaceHelper.getProject("kradle"); assertIsGradleProject(kradle); assertNoErrors(kradle); @@ -629,7 +629,7 @@ public void testProtoBufSupportChanged() throws Exception { @Test public void testNameConflictProject() throws Exception { List projects = importProjects("gradle/nameConflict"); - assertEquals(3, projects.size()); + assertEquals(2, projects.size()); IProject root = WorkspaceHelper.getProject("nameConflict"); assertIsGradleProject(root); IProject subProject = WorkspaceHelper.getProject("nameConflict-nameconflict"); @@ -641,7 +641,7 @@ public void testAndroidProjectSupport() throws Exception { try { this.preferences.setAndroidSupportEnabled(true); List projects = importProjects("gradle/android"); - assertEquals(3, projects.size()); + assertEquals(2, projects.size()); IProject androidAppProject = WorkspaceHelper.getProject("app"); assertNotNull(androidAppProject); IJavaProject javaProject = JavaCore.create(androidAppProject); @@ -684,7 +684,7 @@ public void testAndroidProjectSupportChanged() throws Exception { try { this.preferences.setAndroidSupportEnabled(true); List projects = importProjects("gradle/android"); - assertEquals(3, projects.size()); + assertEquals(2, projects.size()); IProject androidAppProject = WorkspaceHelper.getProject("app"); assertNotNull(androidAppProject); IJavaProject javaProject = JavaCore.create(androidAppProject); diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/MavenBuildSupportTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/MavenBuildSupportTest.java index 0c2a38d5a5..d34ce61b20 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/MavenBuildSupportTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/MavenBuildSupportTest.java @@ -130,7 +130,7 @@ public void testMultipleProjects() throws Exception { @Test public void testIgnoreInnerPomChanges() throws Exception { IProject project = importMavenProject("archetyped"); - assertEquals("The inner pom should not have been imported", 2, WorkspaceHelper.getAllProjects().size()); + assertEquals("The inner pom should not have been imported", 1, WorkspaceHelper.getAllProjects().size()); IFile innerPom = project.getFile("src/main/resources/archetype-resources/pom.xml"); @@ -229,7 +229,7 @@ public void testBatchImport() throws Exception { waitForBackgroundJobs(); assertTrue(ProjectUtils.isMavenProject(project)); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - assertEquals(root.getProjects().length, 14); + assertEquals(root.getProjects().length, 13); project = root.getProject("batchchild"); assertTrue(ProjectUtils.isMavenProject(project)); } diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/MavenProjectImporterTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/MavenProjectImporterTest.java index 9e2483046d..e368f674de 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/MavenProjectImporterTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/MavenProjectImporterTest.java @@ -92,7 +92,7 @@ public void testJavaImportExclusions() throws Exception { try { javaImportExclusions.add(PROJECT1_PATTERN); List projects = importProjects("maven/multi"); - assertEquals(2, projects.size());//default + project 2 + assertEquals(1, projects.size()); // project 2 IProject project1 = WorkspaceHelper.getProject("project1"); assertNull(project1); IProject project2 = WorkspaceHelper.getProject("project2"); @@ -134,7 +134,7 @@ public IProgressMonitor getProgressReporter(CancelChecker checker) { @Test public void testUnzippedSourceImportExclusions() throws Exception { List projects = importProjects("maven/unzipped-sources"); - assertEquals(Arrays.asList(ProjectsManager.getDefaultProject()), projects); + assertTrue(projects.isEmpty()); } @Test @@ -143,7 +143,7 @@ public void testDisableMaven() throws Exception { try { JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setImportMavenEnabled(false); List projects = importProjects("eclipse/eclipsemaven"); - assertEquals(2, projects.size());//default + 1 eclipse projects + assertEquals(1, projects.size()); // 1 eclipse projects IProject eclipse = WorkspaceHelper.getProject("eclipse"); assertNotNull(eclipse); assertFalse(eclipse.getName() + " has the Maven nature", ProjectUtils.isMavenProject(eclipse)); diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/MultiRootTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/MultiRootTest.java index d064173564..86a9d7bdf5 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/MultiRootTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/MultiRootTest.java @@ -40,7 +40,7 @@ public void testInitializeWithMultiFolders() throws Exception { { Collection folders = Arrays.asList(EclipseFolder, MavenFolder); importProjects(folders); - assertEquals(3, WorkspaceHelper.getAllProjects().size()); // includes the default project + assertEquals(2, WorkspaceHelper.getAllProjects().size()); assertNotNull(WorkspaceHelper.getProject("hello")); assertNotNull(WorkspaceHelper.getProject("salut")); } @@ -49,7 +49,7 @@ public void testInitializeWithMultiFolders() throws Exception { Collection folders = Arrays.asList(MavenMultiFolder, EclipseFolder); importProjects(folders); - assertEquals(4, WorkspaceHelper.getAllProjects().size()); // includes the default project + assertEquals(3, WorkspaceHelper.getAllProjects().size()); assertNotNull(WorkspaceHelper.getProject("hello")); assertNull(WorkspaceHelper.getProject("salut")); assertNotNull(WorkspaceHelper.getProject("project1")); @@ -62,7 +62,7 @@ public void testUpdateMultiFolders() throws Exception { { Collection folders = Arrays.asList(EclipseFolder, MavenFolder); importProjects(folders); - assertEquals(3, WorkspaceHelper.getAllProjects().size()); // includes the default project + assertEquals(2, WorkspaceHelper.getAllProjects().size()); assertNotNull(WorkspaceHelper.getProject("hello")); assertNotNull(WorkspaceHelper.getProject("salut")); } @@ -72,7 +72,7 @@ public void testUpdateMultiFolders() throws Exception { Collection toRemove = Arrays.asList(MavenFolder); updateProjects(toAdd, toRemove); - assertEquals(4, WorkspaceHelper.getAllProjects().size()); // includes the default project + assertEquals(3, WorkspaceHelper.getAllProjects().size()); assertNotNull(WorkspaceHelper.getProject("hello")); assertNull(WorkspaceHelper.getProject("salut")); assertNotNull(WorkspaceHelper.getProject("project1")); @@ -85,7 +85,7 @@ public void testUpdateMultiFolders() throws Exception { Collection toRemove = Arrays.asList(MavenMultiFolder); updateProjects(toAdd, toRemove); - assertEquals(3, WorkspaceHelper.getAllProjects().size()); // includes the default project + assertEquals(2, WorkspaceHelper.getAllProjects().size()); assertNotNull(WorkspaceHelper.getProject("hello")); assertNotNull(WorkspaceHelper.getProject("salut")); assertNull(WorkspaceHelper.getProject("project1")); @@ -98,7 +98,7 @@ public void testUpdateMultiFolders() throws Exception { Collection toRemove = Arrays.asList(EclipseFolder, MavenFolder); updateProjects(toAdd, toRemove); - assertEquals(2, WorkspaceHelper.getAllProjects().size()); // includes the default project + assertEquals(1, WorkspaceHelper.getAllProjects().size()); assertNull(WorkspaceHelper.getProject("hello")); assertNull(WorkspaceHelper.getProject("salut")); assertNotNull(WorkspaceHelper.getProject("simple-gradle")); diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/ProjectsManagerTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/ProjectsManagerTest.java index 5aff50c95b..bcc837b916 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/ProjectsManagerTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/ProjectsManagerTest.java @@ -242,10 +242,9 @@ public void testImportMavenSubModule() throws IOException, OperationCanceledExce IProject[] allProjects = ProjectUtils.getAllProjects(); Set expectedProjects = new HashSet<>(Arrays.asList( "module1", - "childmodule", - "jdt.ls-java-project" + "childmodule" )); - assertEquals(3, allProjects.length); + assertEquals(2, allProjects.length); for (IProject project : allProjects) { assertTrue(expectedProjects.contains(project.getName())); } @@ -268,10 +267,9 @@ public void testChangeImportedMavenSubModule() throws Exception { Set expectedProjects = new HashSet<>(Arrays.asList( "module1", "childmodule", - "module2", - "jdt.ls-java-project" + "module2" )); - assertEquals(4, allProjects.length); + assertEquals(3, allProjects.length); for (IProject project : allProjects) { assertTrue(expectedProjects.contains(project.getName())); } @@ -286,10 +284,9 @@ public void testChangeImportedMavenSubModule() throws Exception { expectedProjects = new HashSet<>(Arrays.asList( "module1", "childmodule", - "module3", - "jdt.ls-java-project" + "module3" )); - assertEquals(4, allProjects.length); + assertEquals(3, allProjects.length); for (IProject project : allProjects) { assertTrue(expectedProjects.contains(project.getName())); } @@ -307,12 +304,11 @@ public void testImportMixedProjects() throws IOException, OperationCanceledExcep projectsManager.initializeProjects(Collections.singleton(new org.eclipse.core.runtime.Path(projectDir.getAbsolutePath())), monitor); IProject[] allProjects = ProjectUtils.getAllProjects(); Set expectedProjects = new HashSet<>(Arrays.asList( - "jdt.ls-java-project", "hello", "salut", "simple-gradle" )); - assertEquals(4, allProjects.length); + assertEquals(3, allProjects.length); for (IProject project : allProjects) { assertTrue(expectedProjects.contains(project.getName())); } @@ -329,11 +325,10 @@ public void testImportMixedProjectsPartially() throws IOException, OperationCanc projectsManager.initializeProjects(Collections.singleton(new org.eclipse.core.runtime.Path(projectDir.getAbsolutePath())), monitor); IProject[] allProjects = ProjectUtils.getAllProjects(); Set expectedProjects = new HashSet<>(Arrays.asList( - "jdt.ls-java-project", "salut", "simple-gradle" )); - assertEquals(3, allProjects.length); + assertEquals(2, allProjects.length); for (IProject project : allProjects) { assertTrue(expectedProjects.contains(project.getName())); }