diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/LinkResourceUtil.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/LinkResourceUtil.java
new file mode 100644
index 0000000000..d06764e061
--- /dev/null
+++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/LinkResourceUtil.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2023 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************/
+package org.eclipse.jdt.ls.core.internal.managers;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.nio.file.StandardOpenOption;
+import java.nio.file.attribute.BasicFileAttributeView;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.time.Instant;
+
+import org.eclipse.core.internal.preferences.EclipsePreferences;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.IJavaProject;
+
+class LinkResourceUtil {
+
+ private static final IPath METADATA_FOLDER_PATH = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(".projects");
+
+ private static boolean isNewer(Path file, Instant instant) throws CoreException {
+ try {
+ BasicFileAttributes attributes = Files.getFileAttributeView(file, BasicFileAttributeView.class).readAttributes();
+ return attributes.creationTime().toInstant().isAfter(instant);
+ } catch (IOException ex) {
+ throw new CoreException(Status.error(ex.getMessage(), ex));
+ }
+ }
+
+ /**
+ * Get the redirected path of the input path. The path will be redirected to
+ * the workspace's metadata folder ({@link LinkResourceUtil#METADATA_FOLDER_PATH}).
+ * @param projectName name of the project.
+ * @param path path needs to be redirected.
+ * @return the redirected path.
+ */
+ private static IPath getMetaDataFilePath(String projectName, IPath path) {
+ if (path.segmentCount() == 1) {
+ return METADATA_FOLDER_PATH.append(projectName).append(path);
+ }
+
+ String lastSegment = path.lastSegment();
+ if (IProjectDescription.DESCRIPTION_FILE_NAME.equals(lastSegment)) {
+ return METADATA_FOLDER_PATH.append(projectName).append(lastSegment);
+ }
+
+ return null;
+ }
+
+ private static void linkFolderIfNewer(IFolder settingsFolder, Instant instant) throws CoreException {
+ if (settingsFolder.isLinked()) {
+ return;
+ }
+ if (settingsFolder.exists() && !isNewer(settingsFolder.getLocation().toPath(), instant)) {
+ return;
+ }
+ if (!settingsFolder.exists()) {
+ // not existing yet, create link
+ File diskFolder = getMetaDataFilePath(settingsFolder.getProject().getName(), settingsFolder.getProjectRelativePath()).toFile();
+ diskFolder.mkdirs();
+ settingsFolder.createLink(diskFolder.toURI(), IResource.NONE, new NullProgressMonitor());
+ } else if (isNewer(settingsFolder.getLocation().toPath(), instant)) {
+ // already existing but not existing before import: move then link
+ File sourceFolder = settingsFolder.getLocation().toFile();
+ File targetFolder = getMetaDataFilePath(settingsFolder.getProject().getName(), settingsFolder.getProjectRelativePath()).toFile();
+ File parentTargetFolder = targetFolder.getParentFile();
+ if (!parentTargetFolder.isDirectory()) {
+ parentTargetFolder.mkdirs();
+ }
+ sourceFolder.renameTo(targetFolder);
+ settingsFolder.createLink(targetFolder.toURI(), IResource.REPLACE, new NullProgressMonitor());
+ }
+ }
+
+ private static void linkFileIfNewer(IFile metadataFile, Instant instant, String ifEmpty) throws CoreException {
+ if (metadataFile.isLinked()) {
+ return;
+ }
+ if (metadataFile.exists() && !isNewer(metadataFile.getLocation().toPath(), instant)) {
+ return;
+ }
+ File targetFile = getMetaDataFilePath(metadataFile.getProject().getName(), metadataFile.getProjectRelativePath()).toFile();
+ targetFile.getParentFile().mkdirs();
+ try {
+ if (metadataFile.exists()) {
+ Files.move(metadataFile.getLocation().toFile().toPath(), targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
+ } else {
+ Files.writeString(targetFile.toPath(), ifEmpty != null ? ifEmpty : "", StandardOpenOption.CREATE);
+ }
+ } catch (IOException ex) {
+ throw new CoreException(Status.error(ex.getMessage(), ex));
+ }
+ metadataFile.createLink(targetFile.toURI(), IResource.REPLACE, new NullProgressMonitor());
+ }
+
+ public static void linkMetadataResourcesIfNewer(IProject project, Instant instant) throws CoreException {
+ linkFileIfNewer(project.getFile(IProjectDescription.DESCRIPTION_FILE_NAME), instant, null);
+ linkFolderIfNewer(project.getFolder(EclipsePreferences.DEFAULT_PREFERENCES_DIRNAME), instant);
+ linkFileIfNewer(project.getFile(IJavaProject.CLASSPATH_FILE_NAME), instant, null);
+ linkFileIfNewer(project.getFile(".factorypath"), instant, "");
+ }
+
+}
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 e04e83f4f6..31278abe6d 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
@@ -17,16 +17,19 @@
import java.io.File;
import java.net.URI;
+import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
+import java.util.Set;
import java.util.TreeMap;
-import java.util.Map.Entry;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -145,6 +148,8 @@ private void updateEncoding(IProgressMonitor monitor) throws CoreException {
protected void importProjects(Collection rootPaths, IProgressMonitor monitor) throws CoreException, OperationCanceledException {
SubMonitor subMonitor = SubMonitor.convert(monitor, rootPaths.size() * 100);
MultiStatus importStatusCollection = new MultiStatus(IConstants.PLUGIN_ID, -1, "Failed to import projects", null);
+ IProject[] alreadyExistingProjects = ProjectsManager.getWorkspaceRoot().getProjects();
+ Instant importSessionStart = Instant.now();
for (IPath rootPath : rootPaths) {
File rootFolder = rootPath.toFile();
try {
@@ -163,6 +168,18 @@ protected void importProjects(Collection rootPaths, IProgressMonitor moni
JavaLanguageServerPlugin.logException("Failed to import projects", e);
}
}
+ if (!generatesMetadataFilesAtProjectRoot()) {
+ Set newProjects = new HashSet<>(Arrays.asList(getWorkspaceRoot().getProjects()));
+ newProjects.removeAll(Arrays.asList(alreadyExistingProjects));
+ for (IProject project : newProjects) {
+ try {
+ LinkResourceUtil.linkMetadataResourcesIfNewer(project, importSessionStart);
+ } catch (CoreException e) {
+ importStatusCollection.add(e.getStatus());
+ JavaLanguageServerPlugin.logException("Failed to import projects", e);
+ }
+ }
+ }
if (!importStatusCollection.isOK()) {
throw new CoreException(importStatusCollection);
}
@@ -349,10 +366,29 @@ public static IProject createJavaProject(IProject project, IProgressMonitor moni
return createJavaProject(project, null, "src", "bin", monitor);
}
+ /*
+ * ⚠ These value is duplicated in ProjectsManager as both bundles must remain independent,
+ * but the same dir should be used for .project or .settings/.classpath.
+ * So when updating one, think about updating the other.
+ */
+ public static final String GENERATES_METADATA_FILES_AT_PROJECT_ROOT = "java.import.generatesMetadataFilesAtProjectRoot";
+
+ /**
+ * Check whether the metadata files needs to be generated at project root.
+ */
+ public static boolean generatesMetadataFilesAtProjectRoot() {
+ String property = System.getProperty(GENERATES_METADATA_FILES_AT_PROJECT_ROOT);
+ if (property == null) {
+ return true;
+ }
+ return Boolean.parseBoolean(property);
+ }
+
public static IProject createJavaProject(IProject project, IPath projectLocation, String src, String bin, IProgressMonitor monitor) throws CoreException, OperationCanceledException {
if (project.exists()) {
return project;
}
+ Instant creationRequestInstant = Instant.now();
JavaLanguageServerPlugin.logInfo("Creating the Java project " + project.getName());
//Create project
IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(project.getName());
@@ -400,6 +436,10 @@ public static IProject createJavaProject(IProject project, IPath projectLocation
//Add JVM to project class path
javaProject.setRawClasspath(classpaths.toArray(new IClasspathEntry[0]), monitor);
+ if (!generatesMetadataFilesAtProjectRoot()) {
+ LinkResourceUtil.linkMetadataResourcesIfNewer(project, creationRequestInstant);
+ }
+
JavaLanguageServerPlugin.logInfo("Finished creating the Java project " + project.getName());
return project;
}
@@ -434,6 +474,7 @@ public IStatus runInWorkspace(IProgressMonitor monitor) {
updateEncoding(monitor);
project.deleteMarkers(BUILD_FILE_MARKER_TYPE, false, IResource.DEPTH_ONE);
long elapsed = System.currentTimeMillis() - start;
+ replaceLinkedMetadataWithLocal(project);
JavaLanguageServerPlugin.logInfo("Updated " + projectName + " in " + elapsed + " ms");
} catch (Exception e) {
String msg = "Error updating " + projectName;
@@ -641,6 +682,13 @@ public void reportProjectsStatus() {
JavaLanguageServerPlugin.sendStatus(ServiceStatus.ProjectStatus, "OK");
}
}
+
+ private void replaceLinkedMetadataWithLocal(IProject p) throws CoreException {
+ if (new File(p.getLocation().toFile(), IJavaProject.CLASSPATH_FILE_NAME).exists() &&
+ p.getFile(IJavaProject.CLASSPATH_FILE_NAME).isLinked()) {
+ p.getFile(IJavaProject.CLASSPATH_FILE_NAME).delete(false, false, null);
+ }
+ }
class UpdateProjectsWorkspaceJob extends WorkspaceJob {
diff --git a/org.eclipse.jdt.ls.filesystem/.classpath b/org.eclipse.jdt.ls.filesystem/.classpath
deleted file mode 100644
index 5508535a40..0000000000
--- a/org.eclipse.jdt.ls.filesystem/.classpath
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
diff --git a/org.eclipse.jdt.ls.filesystem/.project b/org.eclipse.jdt.ls.filesystem/.project
deleted file mode 100644
index d34fd35ec5..0000000000
--- a/org.eclipse.jdt.ls.filesystem/.project
+++ /dev/null
@@ -1,45 +0,0 @@
-
-
- org.eclipse.jdt.ls.filesystem
-
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
- org.eclipse.pde.ManifestBuilder
-
-
-
-
- org.eclipse.pde.SchemaBuilder
-
-
-
-
- org.eclipse.m2e.core.maven2Builder
-
-
-
-
-
- org.eclipse.m2e.core.maven2Nature
- org.eclipse.pde.PluginNature
- org.eclipse.jdt.core.javanature
-
-
-
- 1675270185050
-
- 30
-
- org.eclipse.core.resources.regexFilterMatcher
- node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__
-
-
-
-
diff --git a/org.eclipse.jdt.ls.filesystem/.settings/org.eclipse.core.resources.prefs b/org.eclipse.jdt.ls.filesystem/.settings/org.eclipse.core.resources.prefs
deleted file mode 100644
index 99f26c0203..0000000000
--- a/org.eclipse.jdt.ls.filesystem/.settings/org.eclipse.core.resources.prefs
+++ /dev/null
@@ -1,2 +0,0 @@
-eclipse.preferences.version=1
-encoding/=UTF-8
diff --git a/org.eclipse.jdt.ls.filesystem/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.jdt.ls.filesystem/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index 62ef3488cc..0000000000
--- a/org.eclipse.jdt.ls.filesystem/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,9 +0,0 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
-org.eclipse.jdt.core.compiler.compliance=17
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
-org.eclipse.jdt.core.compiler.release=enabled
-org.eclipse.jdt.core.compiler.source=17
diff --git a/org.eclipse.jdt.ls.filesystem/.settings/org.eclipse.m2e.core.prefs b/org.eclipse.jdt.ls.filesystem/.settings/org.eclipse.m2e.core.prefs
deleted file mode 100644
index f897a7f1cb..0000000000
--- a/org.eclipse.jdt.ls.filesystem/.settings/org.eclipse.m2e.core.prefs
+++ /dev/null
@@ -1,4 +0,0 @@
-activeProfiles=
-eclipse.preferences.version=1
-resolveWorkspaceProjects=true
-version=1
diff --git a/org.eclipse.jdt.ls.filesystem/META-INF/MANIFEST.MF b/org.eclipse.jdt.ls.filesystem/META-INF/MANIFEST.MF
deleted file mode 100644
index 60849571ac..0000000000
--- a/org.eclipse.jdt.ls.filesystem/META-INF/MANIFEST.MF
+++ /dev/null
@@ -1,16 +0,0 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-SymbolicName: org.eclipse.jdt.ls.filesystem;singleton:=true
-Bundle-Name: %Bundle-Name
-Bundle-Version: 1.30.0.qualifier
-Export-Package: org.eclipse.jdt.ls.core.internal.filesystem;x-friends:="org.eclipse.jdt.ls.tests"
-Bundle-Localization: plugin
-Bundle-Activator: org.eclipse.jdt.ls.core.internal.filesystem.JDTLSFilesystemActivator
-Bundle-Vendor: %Bundle-Vendor
-Require-Bundle: org.eclipse.core.runtime,
- org.eclipse.core.filesystem;bundle-version="1.9.500",
- org.eclipse.core.resources;bundle-version="3.18.100",
- org.eclipse.jdt.core;bundle-version="3.32.0"
-Bundle-RequiredExecutionEnvironment: JavaSE-17
-Automatic-Module-Name: org.eclipse.jdt.ls.application
-Bundle-ActivationPolicy: lazy
diff --git a/org.eclipse.jdt.ls.filesystem/build.properties b/org.eclipse.jdt.ls.filesystem/build.properties
deleted file mode 100644
index 0dc34f7833..0000000000
--- a/org.eclipse.jdt.ls.filesystem/build.properties
+++ /dev/null
@@ -1,6 +0,0 @@
-source.. = src/
-output.. = bin/
-bin.includes = META-INF/,\
- .,\
- plugin.xml,\
- plugin.properties
diff --git a/org.eclipse.jdt.ls.filesystem/plugin.properties b/org.eclipse.jdt.ls.filesystem/plugin.properties
deleted file mode 100644
index 1f57838980..0000000000
--- a/org.eclipse.jdt.ls.filesystem/plugin.properties
+++ /dev/null
@@ -1,14 +0,0 @@
-###############################################################################
-# Copyright (c) 2016-2017 Red Hat Inc. and others.
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Eclipse Public License 2.0
-# which accompanies this distribution, and is available at
-# https://www.eclipse.org/legal/epl-2.0/
-#
-# SPDX-License-Identifier: EPL-2.0
-#
-# Contributors:
-# Red Hat Inc. - initial API and implementation
-###############################################################################
-Bundle-Vendor = Eclipse.org
-Bundle-Name = JDT Language Server - Core
\ No newline at end of file
diff --git a/org.eclipse.jdt.ls.filesystem/plugin.xml b/org.eclipse.jdt.ls.filesystem/plugin.xml
deleted file mode 100644
index 986a53bee5..0000000000
--- a/org.eclipse.jdt.ls.filesystem/plugin.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
diff --git a/org.eclipse.jdt.ls.filesystem/pom.xml b/org.eclipse.jdt.ls.filesystem/pom.xml
deleted file mode 100644
index 17e4f7fd71..0000000000
--- a/org.eclipse.jdt.ls.filesystem/pom.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
- 4.0.0
-
- org.eclipse.jdt.ls
- parent
- 1.30.0-SNAPSHOT
-
- org.eclipse.jdt.ls.filesystem
- eclipse-plugin
- ${base.name} :: Filesystem
-
diff --git a/org.eclipse.jdt.ls.filesystem/src/org/eclipse/jdt/ls/core/internal/filesystem/JDTLSFilesystemActivator.java b/org.eclipse.jdt.ls.filesystem/src/org/eclipse/jdt/ls/core/internal/filesystem/JDTLSFilesystemActivator.java
deleted file mode 100644
index 6b930e88fc..0000000000
--- a/org.eclipse.jdt.ls.filesystem/src/org/eclipse/jdt/ls/core/internal/filesystem/JDTLSFilesystemActivator.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package org.eclipse.jdt.ls.core.internal.filesystem;
-
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-
-/*******************************************************************************
- * Copyright (c) 2022 Red Hat Inc. and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *******************************************************************************/
-public class JDTLSFilesystemActivator implements BundleActivator {
-
- private static BundleContext context;
-
- static BundleContext getContext() {
- return context;
- }
-
- public void start(BundleContext bundleContext) throws Exception {
- JDTLSFilesystemActivator.context = bundleContext;
- }
-
- public void stop(BundleContext bundleContext) throws Exception {
- JDTLSFilesystemActivator.context = null;
- }
-
-}
diff --git a/org.eclipse.jdt.ls.filesystem/src/org/eclipse/jdt/ls/core/internal/filesystem/JLSFile.java b/org.eclipse.jdt.ls.filesystem/src/org/eclipse/jdt/ls/core/internal/filesystem/JLSFile.java
deleted file mode 100644
index f5770486f3..0000000000
--- a/org.eclipse.jdt.ls.filesystem/src/org/eclipse/jdt/ls/core/internal/filesystem/JLSFile.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2021 Microsoft Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Microsoft Corporation
- *******************************************************************************/
-
-package org.eclipse.jdt.ls.core.internal.filesystem;
-
-import java.io.File;
-import java.util.Arrays;
-import java.util.LinkedHashSet;
-import java.util.Set;
-
-import org.eclipse.core.filesystem.IFileStore;
-import org.eclipse.core.internal.filesystem.local.LocalFile;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Path;
-
-/**
- * JDT.LS's own implementation of files in the local operating system's file system.
- * The instance of this class will be returned by {@link JLSFileSystem}.
- */
-public class JLSFile extends LocalFile {
-
- public JLSFile(File file) {
- super(file);
- }
-
- /**
- * {@inheritDoc}
- *
- *
- * Since the metadata files may be redirected into the workspace,
- * we override the method to make sure those files are not missed.
- *
- */
- @Override
- public String[] childNames(int options, IProgressMonitor monitor) {
- String[] childNames = super.childNames(options, monitor);
- if (JLSFsUtils.generatesMetadataFilesAtProjectRoot()) {
- return childNames;
- }
-
- IPath filePath = new Path(this.filePath);
- String projectName = JLSFsUtils.getProjectNameIfLocationIsProjectRoot(filePath);
- if (projectName == null) {
- return childNames;
- }
-
- Set childNameSet = new LinkedHashSet<>(Arrays.asList(childNames));
- for (String fileName : JLSFsUtils.METADATA_NAMES) {
- if (!childNameSet.contains(fileName) &&
- JLSFsUtils.METADATA_FOLDER_PATH.append(projectName).append(fileName).toFile().exists()) {
- childNameSet.add(fileName);
- }
- }
-
- return childNameSet.toArray(String[]::new);
- }
-
- @Override
- public IFileStore getChild(String name) {
- IPath path = new Path(this.filePath).append(name);
- if (JLSFsUtils.shouldStoreInMetadataArea(path)) {
- IPath containerPath = JLSFsUtils.getContainerPath(path);
- String projectName = JLSFsUtils.getProjectNameIfLocationIsProjectRoot(containerPath);
- if (projectName == null) {
- return new JLSFile(new File(file, name));
- }
- IPath redirectedPath = JLSFsUtils.getMetaDataFilePath(projectName, new Path(name));
- if (redirectedPath != null) {
- return new JLSFile(redirectedPath.toFile());
- }
- }
-
- return new JLSFile(new File(file, name));
- }
-
- @Override
- public IFileStore getFileStore(IPath path) {
- IPath fullPath = new Path(this.filePath).append(path);
- if (JLSFsUtils.shouldStoreInMetadataArea(fullPath)) {
- IPath containerPath = JLSFsUtils.getContainerPath(fullPath);
- String projectName = JLSFsUtils.getProjectNameIfLocationIsProjectRoot(containerPath);
- if (projectName == null) {
- return new JLSFile(fullPath.toFile());
- }
- IPath redirectedPath = JLSFsUtils.getMetaDataFilePath(projectName, path);
- if (redirectedPath != null) {
- return new JLSFile(redirectedPath.toFile());
- }
- }
-
- return new JLSFile(fullPath.toFile());
- }
-}
diff --git a/org.eclipse.jdt.ls.filesystem/src/org/eclipse/jdt/ls/core/internal/filesystem/JLSFileSystem.java b/org.eclipse.jdt.ls.filesystem/src/org/eclipse/jdt/ls/core/internal/filesystem/JLSFileSystem.java
deleted file mode 100644
index 7e0d8682c7..0000000000
--- a/org.eclipse.jdt.ls.filesystem/src/org/eclipse/jdt/ls/core/internal/filesystem/JLSFileSystem.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2021 Microsoft Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Microsoft Corporation
- *******************************************************************************/
-
-package org.eclipse.jdt.ls.core.internal.filesystem;
-
-import java.net.URI;
-import java.nio.file.Paths;
-
-import org.eclipse.core.filesystem.IFileStore;
-import org.eclipse.core.internal.filesystem.local.LocalFileSystem;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-
-/**
- * JDT.LS's own implementation of file system to handle the 'file' scheme uri.
- * The purpose of this implementation is to allow the project metadata files (.project, .classpath, .settings/)
- * can be persisted out of the project root.
- */
-public class JLSFileSystem extends LocalFileSystem {
-
- @Override
- public IFileStore getStore(IPath path) {
- if (JLSFsUtils.shouldStoreInMetadataArea(path)) {
- IPath containerPath = JLSFsUtils.getContainerPath(path);
- String projectName = JLSFsUtils.getProjectNameIfLocationIsProjectRoot(containerPath);
- if (projectName == null) {
- return new JLSFile(path.toFile());
- }
- IPath redirectedPath = JLSFsUtils.getMetaDataFilePath(projectName, path);
- if (redirectedPath != null) {
- return new JLSFile(redirectedPath.toFile());
- }
- }
- return new JLSFile(path.toFile());
- }
-
- @Override
- public IFileStore getStore(URI uri) {
- IPath path = filePathFromURI(uri.toString());
- return path == null ? super.getStore(uri) : getStore(path);
- }
-
- public static IPath filePathFromURI(String uriStr) {
- URI uri = URI.create(uriStr);
- return "file".equals(uri.getScheme()) ?
- Path.fromOSString(Paths.get(uri).toString()) :
- null;
- }
-
-}
diff --git a/org.eclipse.jdt.ls.filesystem/src/org/eclipse/jdt/ls/core/internal/filesystem/JLSFsUtils.java b/org.eclipse.jdt.ls.filesystem/src/org/eclipse/jdt/ls/core/internal/filesystem/JLSFsUtils.java
deleted file mode 100644
index b898ccda93..0000000000
--- a/org.eclipse.jdt.ls.filesystem/src/org/eclipse/jdt/ls/core/internal/filesystem/JLSFsUtils.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2021-2022 Microsoft Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Microsoft Corporation
- *******************************************************************************/
-
-package org.eclipse.jdt.ls.core.internal.filesystem;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Objects;
-import java.util.Set;
-
-import org.eclipse.core.internal.preferences.EclipsePreferences;
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.jdt.core.IJavaProject;
-
-/**
- * Utilities of the file system implementation.
- */
-public class JLSFsUtils {
- private JLSFsUtils() {}
-
- static final IPath METADATA_FOLDER_PATH = ResourcesPlugin.getPlugin().getStateLocation().append(".projects");
-
- /**
- * The system property key to specify the file system mode.
- */
- static final String GENERATES_METADATA_FILES_AT_PROJECT_ROOT = "java.import.generatesMetadataFilesAtProjectRoot";
-
- static final String FACTORY_PATH = ".factorypath";
-
- /**
- * The metadata files
- */
- static final Set METADATA_NAMES = new HashSet<>(Arrays.asList(
- IProjectDescription.DESCRIPTION_FILE_NAME,
- EclipsePreferences.DEFAULT_PREFERENCES_DIRNAME,
- IJavaProject.CLASSPATH_FILE_NAME,
- FACTORY_PATH
- ));
-
- /**
- * Determine whether the resource should be stored in workspace's metadata folder.
- *
- * The file will be stored in workspace's metadata folder when following conditions meet:
- *
- * - The system property shows that it's allowed to store them in workspace.
- * - The file belongs to the metadata file defined in {@link JLSFsUtils#METADATA_NAMES}.
- * - The project's root path does not contain the metadata file with the same name.
- *
- *
- *
- * @param location the path of the resource.
- * @return whether the resource needs to be stored in workspace's metadata folder.
- */
- static boolean shouldStoreInMetadataArea(IPath location) {
- if (generatesMetadataFilesAtProjectRoot()) {
- return false;
- }
-
- if (!isProjectMetadataFile(location)) {
- return false;
- }
-
- // do not redirect if the file already exists on disk
- if (location.toFile().exists()) {
- return false;
- } else if (location.lastSegment().endsWith(EclipsePreferences.PREFS_FILE_EXTENSION)) {
- location = location.removeLastSegments(1);
- return !location.toFile().exists();
- }
-
- return true;
- }
-
- /**
- * Check whether the given location points to a metadata file.
- * @param location file location.
- * @return whether the given location points to a metadata file.
- */
- static boolean isProjectMetadataFile(IPath location) {
- if (location == null || location.segmentCount() < 2) {
- return false;
- }
-
- if (location.lastSegment().endsWith(EclipsePreferences.PREFS_FILE_EXTENSION)) {
- location = location.removeLastSegments(1);
- }
-
- if (location.segmentCount() < 2) {
- return false;
- }
-
- if (!METADATA_NAMES.contains(location.lastSegment())) {
- return false;
- }
-
- return true;
- }
-
- /**
- * Get the container path of the given file path.
- * If the file path is a preferences file, the grand-parent container will be returned.
- * @param filePath the file path.
- */
- static IPath getContainerPath(IPath filePath) {
- if (filePath.lastSegment().endsWith(EclipsePreferences.PREFS_FILE_EXTENSION)) {
- filePath = filePath.removeLastSegments(1);
- }
- return filePath.removeLastSegments(1);
- }
-
- /**
- * Get the project name if the given path is a project root, or null
if
- * no project root can match the path.
- * @param location the location path.
- * @return The project name
- */
- static String getProjectNameIfLocationIsProjectRoot(IPath location) {
- IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(IContainer.INCLUDE_HIDDEN);
- for (IProject project : projects) {
- IPath projectLocation = project.getLocation();
- if (Objects.equals(projectLocation, location)) {
- return project.getName();
- }
- }
- return null;
- }
-
- /**
- * Get the redirected path of the input path. The path will be redirected to
- * the workspace's metadata folder ({@link JLSFsUtils#METADATA_FOLDER_PATH}).
- * @param projectName name of the project.
- * @param path path needs to be redirected.
- * @return the redirected path.
- */
- static IPath getMetaDataFilePath(String projectName, IPath path) {
- if (path.segmentCount() == 1) {
- return METADATA_FOLDER_PATH.append(projectName).append(path);
- }
-
- String lastSegment = path.lastSegment();
- if (METADATA_NAMES.contains(lastSegment)) {
- return METADATA_FOLDER_PATH.append(projectName).append(lastSegment);
- } else if (lastSegment.endsWith(EclipsePreferences.PREFS_FILE_EXTENSION)) {
- return METADATA_FOLDER_PATH.append(projectName)
- .append(EclipsePreferences.DEFAULT_PREFERENCES_DIRNAME)
- .append(lastSegment);
- }
-
- return null;
- }
-
- /**
- * Check whether the metadata files needs to be generated at project root.
- */
- public static boolean generatesMetadataFilesAtProjectRoot() {
- String property = System.getProperty(GENERATES_METADATA_FILES_AT_PROJECT_ROOT);
- if (property == null) {
- return true;
- }
- return Boolean.parseBoolean(property);
- }
-}
diff --git a/org.eclipse.jdt.ls.product/languageServer.product b/org.eclipse.jdt.ls.product/languageServer.product
index 3b97b4ff3b..bd56c391f1 100644
--- a/org.eclipse.jdt.ls.product/languageServer.product
+++ b/org.eclipse.jdt.ls.product/languageServer.product
@@ -54,7 +54,6 @@
-
diff --git a/org.eclipse.jdt.ls.product/syntaxServer.product b/org.eclipse.jdt.ls.product/syntaxServer.product
index b4eed3bd6d..abb42d1cee 100644
--- a/org.eclipse.jdt.ls.product/syntaxServer.product
+++ b/org.eclipse.jdt.ls.product/syntaxServer.product
@@ -27,7 +27,6 @@
-
@@ -48,7 +47,6 @@
-
diff --git a/org.eclipse.jdt.ls.tests/META-INF/MANIFEST.MF b/org.eclipse.jdt.ls.tests/META-INF/MANIFEST.MF
index e6fca9cf30..09a3a3972e 100644
--- a/org.eclipse.jdt.ls.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.ls.tests/META-INF/MANIFEST.MF
@@ -33,7 +33,6 @@ Require-Bundle: org.eclipse.jdt.ls.core,
org.eclipse.jdt.apt.pluggable.core,
org.eclipse.m2e.apt.core,
org.eclipse.buildship.core,
- org.mockito.mockito-core;bundle-version="4.3.1",
- org.eclipse.jdt.ls.filesystem;bundle-version="1.0.0"
+ org.mockito.mockito-core;bundle-version="4.3.1"
Bundle-Vendor: %Bundle-Vendor
Bundle-Activator: org.eclipse.jdt.ls.core.internal.JavaLanguageServerTestPlugin
diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/filesystem/EclipseProjectMetadataFileTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/filesystem/EclipseProjectMetadataFileTest.java
index db3d5f70a9..219fa6b681 100644
--- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/filesystem/EclipseProjectMetadataFileTest.java
+++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/filesystem/EclipseProjectMetadataFileTest.java
@@ -14,6 +14,7 @@
package org.eclipse.jdt.ls.core.internal.filesystem;
import static org.eclipse.jdt.ls.core.internal.WorkspaceHelper.getProject;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -21,6 +22,7 @@
import java.io.File;
import java.util.Arrays;
import java.util.Collection;
+import java.util.List;
import org.eclipse.core.internal.preferences.EclipsePreferences;
import org.eclipse.core.internal.utils.FileUtil;
@@ -32,7 +34,9 @@
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.ls.core.internal.ProjectUtils;
import org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest;
+import org.eclipse.jdt.ls.core.internal.managers.ProjectsManager;
import org.eclipse.jdt.ls.core.internal.managers.ProjectsManager.CHANGE_TYPE;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -52,7 +56,12 @@ public static Collection data(){
@Before
public void setUp() {
- System.setProperty(JLSFsUtils.GENERATES_METADATA_FILES_AT_PROJECT_ROOT, fsMode);
+ System.setProperty(ProjectsManager.GENERATES_METADATA_FILES_AT_PROJECT_ROOT, fsMode);
+ }
+
+ @After
+ public void checkNoError() {
+ assertEquals(List.of(), logListener.getErrors());
}
@Test
@@ -67,16 +76,15 @@ public void testMetadataFileLocation() throws Exception {
IPath projectDescriptionPath = FileUtil.toPath(projectDescription.getLocationURI());
assertTrue(projectDescriptionPath.toFile().exists());
assertTrue(project.getLocation().isPrefixOf(projectDescriptionPath));
+ assertTrue(new File(project.getLocation().toFile(), IProjectDescription.DESCRIPTION_FILE_NAME).exists());
IFile classpath = project.getFile(IJavaProject.CLASSPATH_FILE_NAME);
- // workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
- IPath classpathPath = FileUtil.toPath(classpath.getLocationURI());
+ IPath classpathPath = classpath.getLocation();
assertTrue(classpathPath.toFile().exists());
assertTrue(project.getLocation().isPrefixOf(classpathPath));
IFile preferencesFile = project.getFile(EclipsePreferences.DEFAULT_PREFERENCES_DIRNAME);
- // workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
- IPath preferencesPath = FileUtil.toPath(preferencesFile.getLocationURI());
+ IPath preferencesPath = preferencesFile.getLocation();
assertTrue(preferencesPath.toFile().exists());
assertTrue(project.getLocation().isPrefixOf(preferencesPath));
}
@@ -87,9 +95,8 @@ public void testDeleteClasspath() throws Exception {
importProjects("eclipse/" + name);
IProject project = getProject(name);
assertNotNull(project);
- // workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
IFile dotClasspath = project.getFile(IJavaProject.CLASSPATH_FILE_NAME);
- File file = FileUtil.toPath(dotClasspath.getLocationURI()).toFile();
+ File file = dotClasspath.getLocation().toFile();
assertTrue(file.exists());
file.delete();
projectsManager.fileChanged(file.toPath().toUri().toString(), CHANGE_TYPE.DELETED);
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..37511906b3 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
@@ -23,6 +23,7 @@
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import org.eclipse.buildship.core.internal.CorePlugin;
@@ -41,6 +42,7 @@
import org.eclipse.jdt.ls.core.internal.ResourceUtils;
import org.eclipse.jdt.ls.core.internal.WorkspaceHelper;
import org.eclipse.jdt.ls.core.internal.managers.AbstractGradleBasedTest;
+import org.eclipse.jdt.ls.core.internal.managers.ProjectsManager;
import org.eclipse.jdt.ls.core.internal.managers.ProjectsManager.CHANGE_TYPE;
import org.eclipse.jdt.ls.core.internal.preferences.Preferences.FeatureStatus;
import org.junit.Before;
@@ -62,7 +64,7 @@ public static Collection data(){
@Before
public void setup() throws Exception {
- System.setProperty(JLSFsUtils.GENERATES_METADATA_FILES_AT_PROJECT_ROOT, fsMode);
+ System.setProperty(ProjectsManager.GENERATES_METADATA_FILES_AT_PROJECT_ROOT, fsMode);
}
@Test
@@ -77,33 +79,35 @@ public void testMetadataFileLocation() throws Exception {
// workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
IPath projectDescriptionPath = FileUtil.toPath(projectDescription.getLocationURI());
assertTrue(projectDescriptionPath.toFile().exists());
- assertEquals(project.getLocation().isPrefixOf(projectDescriptionPath), JLSFsUtils.generatesMetadataFilesAtProjectRoot());
+ assertEquals(project.getLocation().isPrefixOf(projectDescriptionPath), ProjectsManager.generatesMetadataFilesAtProjectRoot());
+ assertEquals(ProjectsManager.generatesMetadataFilesAtProjectRoot(), new File(project.getLocation().toFile(), IProjectDescription.DESCRIPTION_FILE_NAME).exists());
IFile preferencesFile = project.getFile(EclipsePreferences.DEFAULT_PREFERENCES_DIRNAME);
- // workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
- IPath preferencesPath = FileUtil.toPath(preferencesFile.getLocationURI());
+ IPath preferencesPath = preferencesFile.getLocation();
assertTrue(preferencesPath.toFile().exists());
- assertEquals(project.getLocation().isPrefixOf(preferencesPath), JLSFsUtils.generatesMetadataFilesAtProjectRoot());
+ assertEquals(project.getLocation().isPrefixOf(preferencesPath), ProjectsManager.generatesMetadataFilesAtProjectRoot());
+ assertEquals(ProjectsManager.generatesMetadataFilesAtProjectRoot(), new File(project.getLocation().toFile(), EclipsePreferences.DEFAULT_PREFERENCES_DIRNAME).exists());
// then we check the sub-module
project = WorkspaceHelper.getProject("app");
projectDescription = project.getFile(IProjectDescription.DESCRIPTION_FILE_NAME);
- // workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
- projectDescriptionPath = FileUtil.toPath(projectDescription.getLocationURI());
+ projectDescriptionPath = projectDescription.getLocation();
assertTrue(projectDescriptionPath.toFile().exists());
- assertEquals(project.getLocation().isPrefixOf(projectDescriptionPath), JLSFsUtils.generatesMetadataFilesAtProjectRoot());
+ assertEquals(project.getLocation().isPrefixOf(projectDescriptionPath), ProjectsManager.generatesMetadataFilesAtProjectRoot());
+ assertEquals(project.getLocation().append(IProjectDescription.DESCRIPTION_FILE_NAME).toFile().exists(), ProjectsManager.generatesMetadataFilesAtProjectRoot());
+ assertEquals(ProjectsManager.generatesMetadataFilesAtProjectRoot(), new File(project.getLocation().toFile(), IProjectDescription.DESCRIPTION_FILE_NAME).exists());
IFile classpath = project.getFile(IJavaProject.CLASSPATH_FILE_NAME);
- // workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
- IPath classpathPath = FileUtil.toPath(classpath.getLocationURI());
+ IPath classpathPath = classpath.getLocation();
assertTrue(classpathPath.toFile().exists());
- assertEquals(project.getLocation().isPrefixOf(classpathPath), JLSFsUtils.generatesMetadataFilesAtProjectRoot());
+ assertEquals(project.getLocation().isPrefixOf(classpathPath), ProjectsManager.generatesMetadataFilesAtProjectRoot());
+ assertEquals(ProjectsManager.generatesMetadataFilesAtProjectRoot(), new File(project.getLocation().toFile(), IJavaProject.CLASSPATH_FILE_NAME).exists());
preferencesFile = project.getFile(EclipsePreferences.DEFAULT_PREFERENCES_DIRNAME);
- // workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
- preferencesPath = FileUtil.toPath(preferencesFile.getLocationURI());
+ preferencesPath = preferencesFile.getLocation();
assertTrue(preferencesPath.toFile().exists());
- assertEquals(project.getLocation().isPrefixOf(preferencesPath), JLSFsUtils.generatesMetadataFilesAtProjectRoot());
+ assertEquals(project.getLocation().isPrefixOf(preferencesPath), ProjectsManager.generatesMetadataFilesAtProjectRoot());
+ assertEquals(ProjectsManager.generatesMetadataFilesAtProjectRoot(), new File(project.getLocation().toFile(), EclipsePreferences.DEFAULT_PREFERENCES_DIRNAME).exists());
}
@Test
@@ -115,7 +119,7 @@ public void testMetadataFileLocation2() throws Exception {
waitForBackgroundJobs();
List markers = ResourceUtils.findMarkers(project, IMarker.SEVERITY_ERROR);
- assertTrue(markers.isEmpty());
+ assertEquals(Collections.emptyList(), markers);
}
@Test
@@ -149,8 +153,7 @@ public void testDeleteClasspath() throws Exception {
assertIsJavaProject(project);
assertIsGradleProject(project);
IFile dotClasspath = project.getFile(IJavaProject.CLASSPATH_FILE_NAME);
- // workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
- File file = FileUtil.toPath(dotClasspath.getLocationURI()).toFile();
+ File file = dotClasspath.getLocation().toFile();
assertTrue(file.exists());
file.delete();
projectsManager.fileChanged(file.toPath().toUri().toString(), CHANGE_TYPE.DELETED);
diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/filesystem/InvisibleProjectMetadataFileTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/filesystem/InvisibleProjectMetadataFileTest.java
index 2204ec78a3..cfc85bd527 100644
--- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/filesystem/InvisibleProjectMetadataFileTest.java
+++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/filesystem/InvisibleProjectMetadataFileTest.java
@@ -19,17 +19,13 @@
import java.util.Arrays;
import java.util.Collection;
-import org.eclipse.core.internal.preferences.EclipsePreferences;
-import org.eclipse.core.internal.utils.FileUtil;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.ls.core.internal.TestVMType;
import org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest;
+import org.eclipse.jdt.ls.core.internal.managers.ProjectsManager;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -49,31 +45,7 @@ public static Collection data(){
@Before
public void setUp() {
- System.setProperty(JLSFsUtils.GENERATES_METADATA_FILES_AT_PROJECT_ROOT, fsMode);
- }
-
- @Test
- public void testMetadataFileLocation() throws Exception {
- IProject project = copyAndImportFolder("singlefile/simple", "src/App.java");
- assertTrue(project.exists());
-
- IFile projectDescription = project.getFile(IProjectDescription.DESCRIPTION_FILE_NAME);
- // workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
- IPath projectDescriptionPath = FileUtil.toPath(projectDescription.getLocationURI());
- assertTrue(projectDescriptionPath.toFile().exists());
- assertEquals(project.getLocation().isPrefixOf(projectDescriptionPath), JLSFsUtils.generatesMetadataFilesAtProjectRoot());
-
- IFile classpath = project.getFile(IJavaProject.CLASSPATH_FILE_NAME);
- // workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
- IPath classpathPath = FileUtil.toPath(classpath.getLocationURI());
- assertTrue(classpathPath.toFile().exists());
- assertEquals(project.getLocation().isPrefixOf(classpathPath), JLSFsUtils.generatesMetadataFilesAtProjectRoot());
-
- IFile preferencesFile = project.getFile(EclipsePreferences.DEFAULT_PREFERENCES_DIRNAME);
- // workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
- IPath preferencesPath = FileUtil.toPath(preferencesFile.getLocationURI());
- assertTrue(preferencesPath.toFile().exists());
- assertEquals(project.getLocation().isPrefixOf(preferencesPath), JLSFsUtils.generatesMetadataFilesAtProjectRoot());
+ System.setProperty(ProjectsManager.GENERATES_METADATA_FILES_AT_PROJECT_ROOT, fsMode);
}
@Test
diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/filesystem/JLSFsUtilsTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/filesystem/JLSFsUtilsTest.java
index 51699f796a..afb55e0ca8 100644
--- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/filesystem/JLSFsUtilsTest.java
+++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/filesystem/JLSFsUtilsTest.java
@@ -16,23 +16,24 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import org.eclipse.jdt.ls.core.internal.managers.ProjectsManager;
import org.junit.Test;
public class JLSFsUtilsTest {
@Test
public void testGeneratesMetadataFilesAtProjectRoot() {
- System.setProperty(JLSFsUtils.GENERATES_METADATA_FILES_AT_PROJECT_ROOT, "true");
- assertTrue(JLSFsUtils.generatesMetadataFilesAtProjectRoot());
+ System.setProperty(ProjectsManager.GENERATES_METADATA_FILES_AT_PROJECT_ROOT, "true");
+ assertTrue(ProjectsManager.generatesMetadataFilesAtProjectRoot());
}
@Test
public void testNotGeneratesMetadataFilesAtProjectRoot() {
- System.setProperty(JLSFsUtils.GENERATES_METADATA_FILES_AT_PROJECT_ROOT, "false");
- assertFalse(JLSFsUtils.generatesMetadataFilesAtProjectRoot());
+ System.setProperty(ProjectsManager.GENERATES_METADATA_FILES_AT_PROJECT_ROOT, "false");
+ assertFalse(ProjectsManager.generatesMetadataFilesAtProjectRoot());
}
@Test
public void testGeneratesMetadataFilesAtProjectRootWhenNotSet() {
- assertTrue(JLSFsUtils.generatesMetadataFilesAtProjectRoot());
+ assertTrue(ProjectsManager.generatesMetadataFilesAtProjectRoot());
}
}
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..c15f64a24a 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
@@ -26,7 +26,6 @@
import org.apache.commons.io.FileUtils;
import org.eclipse.core.internal.preferences.EclipsePreferences;
-import org.eclipse.core.internal.utils.FileUtil;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
@@ -36,6 +35,7 @@
import org.eclipse.jdt.ls.core.internal.ResourceUtils;
import org.eclipse.jdt.ls.core.internal.WorkspaceHelper;
import org.eclipse.jdt.ls.core.internal.managers.AbstractMavenBasedTest;
+import org.eclipse.jdt.ls.core.internal.managers.ProjectsManager;
import org.eclipse.jdt.ls.core.internal.managers.ProjectsManager.CHANGE_TYPE;
import org.junit.Before;
import org.junit.Test;
@@ -60,7 +60,7 @@ public static Collection data(){
@Before
public void setup() throws Exception {
- System.setProperty(JLSFsUtils.GENERATES_METADATA_FILES_AT_PROJECT_ROOT, fsMode);
+ System.setProperty(ProjectsManager.GENERATES_METADATA_FILES_AT_PROJECT_ROOT, fsMode);
}
@Test
@@ -72,21 +72,24 @@ public void testMetadataFileLocation() throws Exception {
IFile projectDescription = project.getFile(IProjectDescription.DESCRIPTION_FILE_NAME);
// workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
- IPath projectDescriptionPath = FileUtil.toPath(projectDescription.getLocationURI());
+ IPath projectDescriptionPath = projectDescription.getLocation();
assertTrue(projectDescriptionPath.toFile().exists());
- assertEquals(project.getLocation().isPrefixOf(projectDescriptionPath), JLSFsUtils.generatesMetadataFilesAtProjectRoot());
+ assertEquals(project.getLocation().isPrefixOf(projectDescriptionPath), ProjectsManager.generatesMetadataFilesAtProjectRoot());
+ assertEquals(project.getLocation().append(IProjectDescription.DESCRIPTION_FILE_NAME).toFile().exists(), ProjectsManager.generatesMetadataFilesAtProjectRoot());
+ assertEquals(ProjectsManager.generatesMetadataFilesAtProjectRoot(), new File(project.getLocation().toFile(), IProjectDescription.DESCRIPTION_FILE_NAME).exists());
IFile classpath = project.getFile(IJavaProject.CLASSPATH_FILE_NAME);
- // workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
- IPath classpathPath = FileUtil.toPath(classpath.getLocationURI());
+ IPath classpathPath = classpath.getLocation();
assertTrue(classpathPath.toFile().exists());
- assertEquals(project.getLocation().isPrefixOf(classpathPath), JLSFsUtils.generatesMetadataFilesAtProjectRoot());
+ assertEquals(project.getLocation().isPrefixOf(classpathPath), ProjectsManager.generatesMetadataFilesAtProjectRoot());
+ assertEquals(ProjectsManager.generatesMetadataFilesAtProjectRoot(), new File(project.getLocation().toFile(), IJavaProject.CLASSPATH_FILE_NAME).exists());
IFile preferencesFile = project.getFile(EclipsePreferences.DEFAULT_PREFERENCES_DIRNAME);
// workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
- IPath preferencesPath = FileUtil.toPath(preferencesFile.getLocationURI());
+ IPath preferencesPath = preferencesFile.getLocation();
assertTrue(preferencesPath.toFile().exists());
- assertEquals(project.getLocation().isPrefixOf(preferencesPath), JLSFsUtils.generatesMetadataFilesAtProjectRoot());
+ assertEquals(project.getLocation().isPrefixOf(preferencesPath), ProjectsManager.generatesMetadataFilesAtProjectRoot());
+ assertEquals(ProjectsManager.generatesMetadataFilesAtProjectRoot(), new File(project.getLocation().toFile(), EclipsePreferences.DEFAULT_PREFERENCES_DIRNAME).exists());
}
@Test
@@ -117,7 +120,7 @@ public void testInvalidProject() throws Exception {
IFile projectFile = invalid.getFile(IProjectDescription.DESCRIPTION_FILE_NAME);
assertTrue(projectFile.exists());
// workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
- File file = FileUtil.toPath(projectFile.getLocationURI()).toFile();
+ File file = projectFile.getLocation().toFile();
invalid.close(new NullProgressMonitor());
assertTrue(file.exists());
file.delete();
@@ -136,8 +139,7 @@ public void testDeleteClasspath() throws Exception {
assertIsJavaProject(project);
assertIsMavenProject(project);
IFile dotClasspath = project.getFile(IJavaProject.CLASSPATH_FILE_NAME);
- // workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
- File file = FileUtil.toPath(dotClasspath.getLocationURI()).toFile();
+ File file = dotClasspath.getLocation().toFile();
assertTrue(file.exists());
file.delete();
projectsManager.fileChanged(file.toPath().toUri().toString(), CHANGE_TYPE.DELETED);
@@ -156,46 +158,40 @@ public void testFactoryPathFileLocation() throws Exception {
IFile projectDescription = project.getFile(IProjectDescription.DESCRIPTION_FILE_NAME);
// workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
- IPath projectDescriptionPath = FileUtil.toPath(projectDescription.getLocationURI());
+ IPath projectDescriptionPath = projectDescription.getLocation();
assertTrue(projectDescriptionPath.toFile().exists());
- assertEquals(project.getLocation().isPrefixOf(projectDescriptionPath), JLSFsUtils.generatesMetadataFilesAtProjectRoot());
+ assertEquals(project.getLocation().isPrefixOf(projectDescriptionPath), ProjectsManager.generatesMetadataFilesAtProjectRoot());
IFile classpath = project.getFile(IJavaProject.CLASSPATH_FILE_NAME);
- // workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
- IPath classpathPath = FileUtil.toPath(classpath.getLocationURI());
+ IPath classpathPath = classpath.getLocation();
assertTrue(classpathPath.toFile().exists());
- assertEquals(project.getLocation().isPrefixOf(classpathPath), JLSFsUtils.generatesMetadataFilesAtProjectRoot());
+ assertEquals(project.getLocation().isPrefixOf(classpathPath), ProjectsManager.generatesMetadataFilesAtProjectRoot());
IFile preferencesFile = project.getFile(EclipsePreferences.DEFAULT_PREFERENCES_DIRNAME);
- // workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
- IPath preferencesPath = FileUtil.toPath(preferencesFile.getLocationURI());
+ IPath preferencesPath = preferencesFile.getLocation();
assertTrue(preferencesPath.toFile().exists());
- assertEquals(project.getLocation().isPrefixOf(preferencesPath), JLSFsUtils.generatesMetadataFilesAtProjectRoot());
+ assertEquals(project.getLocation().isPrefixOf(preferencesPath), ProjectsManager.generatesMetadataFilesAtProjectRoot());
- IFile factoryPathFile = project.getFile(JLSFsUtils.FACTORY_PATH);
- // workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
- IPath factoryPathFilePath = FileUtil.toPath(factoryPathFile.getLocationURI());
+ IFile factoryPathFile = project.getFile(".factorypath");
+ IPath factoryPathFilePath = factoryPathFile.getLocation();
assertTrue(factoryPathFilePath.toFile().exists());
- assertEquals(project.getLocation().isPrefixOf(factoryPathFilePath), JLSFsUtils.generatesMetadataFilesAtProjectRoot());
+ assertEquals(project.getLocation().isPrefixOf(factoryPathFilePath), ProjectsManager.generatesMetadataFilesAtProjectRoot());
}
@Test
public void testMultipleMetadataFile() throws Exception {
- if (JLSFsUtils.generatesMetadataFilesAtProjectRoot()) {
+ if (ProjectsManager.generatesMetadataFilesAtProjectRoot()) {
return;
}
String name = "quickstart2";
importProjects("maven/" + name);
IProject project = getProject(name);
IFile projectDescription = project.getFile(IProjectDescription.DESCRIPTION_FILE_NAME);
- // workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
- File projectDescriptionFile = FileUtil.toPath(projectDescription.getLocationURI()).toFile();
+ File projectDescriptionFile = projectDescription.getLocation().toFile();
IFile classpath = project.getFile(IJavaProject.CLASSPATH_FILE_NAME);
- // workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
- File classpathPathFile = FileUtil.toPath(classpath.getLocationURI()).toFile();
+ File classpathPathFile = classpath.getLocation().toFile();
IFile preferencesFile = project.getFile(EclipsePreferences.DEFAULT_PREFERENCES_DIRNAME);
- // workaround to get the correct path, see: https://github.com/eclipse/eclipse.jdt.ls/pull/1900
- File preferencesPathFile = FileUtil.toPath(preferencesFile.getLocationURI()).toFile();
+ File preferencesPathFile = preferencesFile.getLocation().toFile();
FileUtils.copyFile(projectDescriptionFile, project.getLocation().append(IProjectDescription.DESCRIPTION_FILE_NAME).toFile());
FileUtils.copyFile(classpathPathFile, project.getLocation().append(IJavaProject.CLASSPATH_FILE_NAME).toFile());
FileUtils.copyDirectory(preferencesPathFile, project.getLocation().append(EclipsePreferences.DEFAULT_PREFERENCES_DIRNAME).toFile());
diff --git a/pom.xml b/pom.xml
index eb63ad9127..8d10496ae6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -35,7 +35,6 @@
org.eclipse.jdt.ls.target
org.eclipse.jdt.ls.core
- org.eclipse.jdt.ls.filesystem
org.eclipse.jdt.ls.tests
org.eclipse.jdt.ls.logback.appender
org.eclipse.jdt.ls.tests.syntaxserver