From f33095ffa3c162686fb3feb03c9e608b79e646f3 Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Mon, 22 Feb 2021 13:14:12 +0800 Subject: [PATCH] Throw error when absolute path is specified. Signed-off-by: Sheng Chen --- .../managers/InvisibleProjectImporter.java | 12 ++++++++++-- .../managers/InvisibleProjectImporterTest.java | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) 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 d68387c5c6..49680e4cda 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 @@ -262,11 +262,19 @@ public static List getSourcePaths(List sourcePaths, IFolder works return Collections.emptyList(); } - return sourcePaths.stream() + sourcePaths = sourcePaths.stream() .map(path -> path.trim()) .distinct() - .map(path -> workspaceLinkFolder.getFolder(path).getFullPath()) .collect(Collectors.toList()); + + List sourceList = new LinkedList<>(); + for (String sourcePath : sourcePaths) { + if (new org.eclipse.core.runtime.Path(sourcePath).isAbsolute()) { + throw new CoreException(new Status(IStatus.ERROR, IConstants.PLUGIN_ID, "The source path must be a relative path to the workspace.")); + } + sourceList.add(workspaceLinkFolder.getFolder(sourcePath).getFullPath()); + } + return sourceList; } public static List getExcludingPath(IJavaProject javaProject, IPath rootPath, IFolder workspaceLinkFolder) throws CoreException { diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/InvisibleProjectImporterTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/InvisibleProjectImporterTest.java index 3216eaa4fd..ab5dbdd316 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/InvisibleProjectImporterTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/InvisibleProjectImporterTest.java @@ -254,6 +254,14 @@ public void testSpecifyingOutputPathEqualToSourcePath() throws Exception { waitForBackgroundJobs(); } + @Test(expected = CoreException.class) + public void testSpecifyingAbsoluteOutputPath() throws Exception { + Preferences preferences = preferenceManager.getPreferences(); + preferences.setInvisibleProjectOutputPath(new File("projects").getAbsolutePath()); + copyAndImportFolder("singlefile/simple", "src/App.java"); + waitForBackgroundJobs(); + } + @Test public void testSpecifyingEmptyOutputPath() throws Exception { Preferences preferences = preferenceManager.getPreferences(); @@ -359,6 +367,14 @@ public void testSpecifyingRootAsSourcePaths() throws Exception { assertTrue(sourcePaths.contains("")); } + @Test(expected = CoreException.class) + public void testSpecifyingAbsoluteSourcePath() throws Exception { + Preferences preferences = preferenceManager.getPreferences(); + preferences.setInvisibleProjectSourcePaths(Arrays.asList(new File("projects").getAbsolutePath())); + copyAndImportFolder("singlefile/simple", "src/App.java"); + waitForBackgroundJobs(); + } + @Test public void testSpecifyingSourcePathsContainingOutputPath() throws Exception { Preferences preferences = preferenceManager.getPreferences();