From ead44c071fd2883ec3e00b3043a7ee5d062f64da Mon Sep 17 00:00:00 2001 From: Frederik Claus Date: Fri, 29 Sep 2023 00:36:50 +0200 Subject: [PATCH] Tries to fix ui-test --- .../microsoft/jdtls/ext/core/PackageCommand.java | 16 ++++++++++------ .../microsoft/jdtls/ext/core/ProjectCommand.java | 8 +++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/PackageCommand.java b/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/PackageCommand.java index 59f3848f..ef183ab4 100644 --- a/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/PackageCommand.java +++ b/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/PackageCommand.java @@ -25,6 +25,7 @@ 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; @@ -578,17 +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; - } + URI uri = JDTUtils.toURI(projectUri); + IContainer[] containers = root.findContainersForLocationURI(uri); Optional 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 invisibleProject; } - return null; } public static IJavaProject getJavaProject(String projectUri) { diff --git a/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/ProjectCommand.java b/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/ProjectCommand.java index 4ae20657..1c89a202 100644 --- a/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/ProjectCommand.java +++ b/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/ProjectCommand.java @@ -240,11 +240,9 @@ public static List getMainClasses(List arguments, IProgre } for (PackageNode project : projectList) { IJavaProject javaProject = PackageCommand.getJavaProject(project.getUri()); - if (javaProject != null) { - for (IPackageFragmentRoot packageFragmentRoot : javaProject.getAllPackageFragmentRoots()) { - if (!packageFragmentRoot.isArchive()) { - searchRoots.add(packageFragmentRoot); - } + for (IPackageFragmentRoot packageFragmentRoot : javaProject.getAllPackageFragmentRoots()) { + if (!packageFragmentRoot.isArchive()) { + searchRoots.add(packageFragmentRoot); } } }