Skip to content

Commit

Permalink
Fixes java.getPackageData for modules with long name (#791)
Browse files Browse the repository at this point in the history
Signed-off-by: Frederik Claus <[email protected]>
Co-authored-by: Sheng Chen <[email protected]>
  • Loading branch information
fvclaus and jdneo authored Oct 8, 2023
1 parent 0ec45cc commit b3d964b
Show file tree
Hide file tree
Showing 20 changed files with 538 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 @@ -14,11 +14,11 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
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;
Expand Down Expand Up @@ -577,26 +577,21 @@ 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;
}

// 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;
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));
}
return project;

// This must be an invisible project.
// There might be more than one way to access it, but all containers should link to the same project.
return containers[0].getProject();
}
return null;
}

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

0 comments on commit b3d964b

Please sign in to comment.