Skip to content

Commit

Permalink
Fixes java.getPackageData for modules with long name
Browse files Browse the repository at this point in the history
Fixes microsoft#788

Signed-off-by: Frederik Claus <[email protected]>
  • Loading branch information
fvclaus committed Sep 28, 2023
1 parent 2ba3227 commit 25cb1a2
Show file tree
Hide file tree
Showing 20 changed files with 539 additions and 240 deletions.
22 changes: 20 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,36 @@
"outFiles": [ "${workspaceFolder}/dist/**/*.js" ],
"preLaunchTask": "npm: compile"
},
{
"name": "Extension Tests - Multi Module Project",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"${workspaceFolder}/test/multi-module/",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/dist/test/multi-module-suite/index"
],
"sourceMaps": true,
"outFiles": [ "${workspaceFolder}/dist/**/*.js" ],
"preLaunchTask": "npm: compile"
},
{
"name": "Debug UI Command Tests",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/vscode-extension-tester/out/cli.js",
"args": [
"setup-and-run",
// If not set, will use the current version of vscode. Find a way not to hardcode this value.
"--code_version=1.77.0",
"${workspaceFolder}/dist/test/ui/command.test.js",
],
// To debug the test code, you must set --mode=development inside the vscode:prepublish task. Find a better way to do this.
"sourceMaps": true,
"outFiles": [ "${workspaceFolder}/dist/**/*.js" ],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"preLaunchTask": "npm: compile"
// No need to compile the code, vscode:prepublish task that compiles the code is run by vscode-extension-tester
},
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.core.internal.utils.FileUtil;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
Expand Down Expand Up @@ -577,26 +579,20 @@ private static Object[] findJarDirectoryChildren(JarEntryDirectory directory, St

public static IProject getProject(String projectUri) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IContainer[] containers = root.findContainersForLocationURI(JDTUtils.toURI(projectUri));

if (containers.length == 0) {
return null;
}

// For multi-module scenario, findContainersForLocationURI API may return a container array,
// put the result from the nearest project in front.
Arrays.sort(containers, (Comparator<IContainer>) (IContainer a, IContainer b) -> {
return a.getFullPath().toPortableString().length() - b.getFullPath().toPortableString().length();
});

for (IContainer container : containers) {
IProject project = container.getProject();
if (!project.exists()) {
return null;
URI uri = JDTUtils.toURI(projectUri);
IContainer[] containers = root.findContainersForLocationURI(uri);

Optional<IContainer> maybeProject = Arrays.stream(containers).filter(container -> container instanceof IProject).findFirst();
if (maybeProject.isPresent()) {
return (IProject) maybeProject.get();
} else {
String invisibleProjectName = ProjectUtils.getWorkspaceInvisibleProjectName(FileUtil.toPath(uri).removeTrailingSeparator());
IProject invisibleProject = root.getProject(invisibleProjectName);
if (!invisibleProject.exists()) {
throw new IllegalArgumentException(projectUri + " is neither a Java nor an invisible project.");
}
return project;
return invisibleProject;
}
return null;
}

public static IJavaProject getJavaProject(String projectUri) {
Expand Down
Loading

0 comments on commit 25cb1a2

Please sign in to comment.