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 1 commit
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,11 +19,13 @@
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;

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);

fvclaus marked this conversation as resolved.
Show resolved Hide resolved
Optional<IContainer> maybeProject = Arrays.stream(containers).filter(container -> container instanceof IProject).findFirst();
if (maybeProject.isPresent()) {
return (IProject) maybeProject.get();
fvclaus marked this conversation as resolved.
Show resolved Hide resolved
} else {
String invisibleProjectName = ProjectUtils.getWorkspaceInvisibleProjectName(FileUtil.toPath(uri).removeTrailingSeparator());
jdneo marked this conversation as resolved.
Show resolved Hide resolved
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