Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes java.getPackageData for modules with long name #791

Merged
merged 8 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,6 +19,7 @@
import java.util.LinkedList;
fvclaus marked this conversation as resolved.
Show resolved Hide resolved
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;
Expand Down Expand Up @@ -577,26 +578,26 @@ 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));
URI uri = JDTUtils.toURI(projectUri);
IContainer[] containers = root.findContainersForLocationURI(uri);

if (containers.length == 0) {
return null;
}
Optional<IContainer> maybeProject = Arrays.stream(containers).filter(container -> container instanceof IProject).findFirst();
if (maybeProject.isPresent()) {
return (IProject) maybeProject.get();
} else {
if (containers.length == 0) {
throw new IllegalArgumentException(String.format("Did not find container for URI %s", projectUri));
}

// 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();
});
// This must be an invisible project. Third party extension could theoretically create invisible projects anywhere
// in the project hierarchy. We therefore pick the most specific path.
// See: https://github.com/microsoft/vscode-java-dependency/pull/791#discussion_r1349435426
Arrays.sort(containers, (Comparator<IContainer>) (IContainer a, IContainer b) -> {
return b.getFullPath().toPortableString().length() - a.getFullPath().toPortableString().length();
});

for (IContainer container : containers) {
IProject project = container.getProject();
if (!project.exists()) {
return null;
}
return project;
return containers[containers.length - 1].getProject();
}
return null;
}

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