Skip to content

Commit

Permalink
Address the comments
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 c652d71 commit 9c86b82
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ public static IClasspathEntry[] resolveClassPathEntries(IJavaProject javaProject
}
}

// Sort the source paths to make the parent folders come first
// Sort the source paths to make the child folders come first
Collections.sort(sourcePaths, new Comparator<IPath>() {
@Override
public int compare(IPath path1, IPath path2) {
return path1.toString().compareTo(path2.toString());
return path1.toString().compareTo(path2.toString()) * -1;
}
});

Expand All @@ -191,12 +191,6 @@ public int compare(IPath path1, IPath path2) {
break;
}

if (sourceEntry.getPath().isPrefixOf(currentPath)) {
JavaLanguageServerPlugin.logError("Skip source path: " + currentPath.toString() + ", since its parent path is already a source path");
canAddToSourceEntries = false;
break;
}

if (currentPath.isPrefixOf(sourceEntry.getPath())) {
exclusionPatterns.add(sourceEntry.getPath().makeRelativeTo(currentPath).addTrailingSeparator());
}
Expand Down Expand Up @@ -279,17 +273,11 @@ public static List<IPath> getSourcePaths(List<String> sourcePaths, IFolder works

public static List<IPath> getExcludingPath(IJavaProject javaProject, IPath rootPath, IFolder workspaceLinkFolder) throws CoreException {
if (rootPath == null) {
PreferenceManager preferenceManager = JavaLanguageServerPlugin.getPreferencesManager();
if (preferenceManager == null || preferenceManager.getPreferences() == null) {
throw new CoreException(new Status(IStatus.ERROR, IConstants.PLUGIN_ID, "Failed to get the preferences."));
}
Collection<IPath> rootPaths = preferenceManager.getPreferences().getRootPaths();
Optional<IPath> belongedRootPath = rootPaths.stream().filter(root -> root.isPrefixOf(workspaceLinkFolder.getLocation())).findFirst();
if (belongedRootPath.isEmpty()) {
throw new CoreException(new Status(IStatus.ERROR, IConstants.PLUGIN_ID, "Failed to find the belonging root of the linked folder: " + workspaceLinkFolder.toString()));
}
rootPath = ProjectUtils.findBelongedWorkspaceRoot(workspaceLinkFolder.getLocation());
}

rootPath = belongedRootPath.get();
if (rootPath == null) {
throw new CoreException(new Status(IStatus.ERROR, IConstants.PLUGIN_ID, "Failed to find the belonging root of the linked folder: " + workspaceLinkFolder.toString()));
}

final IPath root = rootPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public void preferencesChange(Preferences oldPreferences, Preferences newPrefere

try {
IFolder workspaceLinkFolder = javaProject.getProject().getFolder(ProjectUtils.WORKSPACE_LINK);
if (!workspaceLinkFolder.exists()) {
continue;
}
List<IPath> sourcePaths = InvisibleProjectImporter.getSourcePaths(newPreferences.getInvisibleProjectSourcePaths(), workspaceLinkFolder);
List<IPath> excludingPaths = InvisibleProjectImporter.getExcludingPath(javaProject, null, workspaceLinkFolder);
IPath outputPath = InvisibleProjectImporter.getOutputPath(javaProject, newPreferences.getInvisibleProjectOutputPath(), true /*isUpdate*/);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,9 @@ public void testSpecifyingNestedSourcePaths() throws Exception {
sourcePaths.add(entry.getPath().makeRelativeTo(linkFolder.getFullPath()).toString());
}
}
assertEquals(1, sourcePaths.size());
assertEquals(2, sourcePaths.size());
assertTrue(sourcePaths.contains("foo"));
assertTrue(sourcePaths.contains("foo/bar"));
}

@Test
Expand Down

0 comments on commit 9c86b82

Please sign in to comment.