Skip to content

Commit

Permalink
Throw error when absolute path is specified.
Browse files Browse the repository at this point in the history
Signed-off-by: Sheng Chen <[email protected]>
  • Loading branch information
jdneo committed Mar 2, 2021
1 parent 54640f4 commit c652d71
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,19 @@ public static List<IPath> getSourcePaths(List<String> 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<IPath> 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<IPath> getExcludingPath(IJavaProject javaProject, IPath rootPath, IFolder workspaceLinkFolder) throws CoreException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit c652d71

Please sign in to comment.