From e8fc65233221fb8960d568808e7006eddf958dec Mon Sep 17 00:00:00 2001 From: Stephan Herrmann Date: Thu, 17 Oct 2024 16:55:29 +0200 Subject: [PATCH] + Ensure ClasspathJrt initialized to fix eclipse-jdt/eclipse.jdt.ui#1722 + Fix test's getJCL15PlusLibraryIfNeeded() --- .../jdt/internal/compiler/batch/FileSystem.java | 8 +++++++- .../core/tests/model/AbstractJavaModelTests.java | 15 ++++++--------- .../jdt/core/tests/model/ClasspathTests.java | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/FileSystem.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/FileSystem.java index 3092e4af272..18b53b4fa9e 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/FileSystem.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/FileSystem.java @@ -292,7 +292,13 @@ public static Classpath getClasspath(String classpathName, String encoding, Acce return getClasspath(classpathName, encoding, false, accessRuleSet, null, options, release); } public static Classpath getJrtClasspath(String jdkHome, String encoding, AccessRuleSet accessRuleSet, Map options) { - return new ClasspathJrt(new File(convertPathSeparators(jdkHome)), true, accessRuleSet, null); + ClasspathJrt classpathJrt = new ClasspathJrt(new File(convertPathSeparators(jdkHome)), true, accessRuleSet, null); + try { + classpathJrt.initialize(); + } catch (IOException e) { + // Broken entry, but let clients have it anyway. + } + return classpathJrt; } public static Classpath getOlderSystemRelease(String jdkHome, String release, AccessRuleSet accessRuleSet) { return isJRE12Plus ? diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java index e3a808251f3..074f6b867f5 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java @@ -653,7 +653,7 @@ protected void addClassFolder(IJavaProject javaProject, String folderRelativePat } protected void addExternalLibrary(IJavaProject javaProject, String jarPath, String[] pathAndContents, String[] nonJavaResources, String compliance) throws Exception { - String[] claspath = getJCL15PlusLibraryIfNeeded(compliance); + String[] claspath = getJCLLibrary(compliance); org.eclipse.jdt.core.tests.util.Util.createJar(pathAndContents, nonJavaResources, jarPath, claspath, compliance); addLibraryEntry(javaProject, new Path(jarPath), true/*exported*/); } @@ -742,7 +742,7 @@ protected IProject createLibrary( IProject project = javaProject.getProject(); String projectLocation = project.getLocation().toOSString(); String jarPath = projectLocation + File.separator + jarName; - String[] claspath = getJCL15PlusLibraryIfNeeded(compliance); + String[] claspath = getJCLLibrary(compliance); org.eclipse.jdt.core.tests.util.Util.createJar(pathAndContents, nonJavaResources, jarPath, claspath, compliance, options); if (pathAndContents != null && pathAndContents.length != 0) { String sourceZipPath = projectLocation + File.separator + sourceZipName; @@ -2532,13 +2532,10 @@ public void ensureChildExists(IParent container, IJavaElement child) throws Java } } - protected String[] getJCL15PlusLibraryIfNeeded(String compliance) throws JavaModelException, IOException { - if (compliance.charAt(compliance.length()-1) >= '8' && (AbstractCompilerTest.getPossibleComplianceLevels() & AbstractCompilerTest.F_1_8) != 0) { - // ensure that the JCL 18 lib is setup (i.e. that the jclMin18.jar is copied) - setUpJCLClasspathVariables("1.8"); - return new String[] {getExternalJCLPathString("1.8")}; - } - return null; + protected String[] getJCLLibrary(String compliance) throws JavaModelException, IOException { + // ensure that the requested JCL lib is setup (i.e. that the jclMinXY.jar is copied) + setUpJCLClasspathVariables(compliance); + return new String[] {getExternalJCLPathString(compliance)}; } /** * Returns the specified compilation unit in the given project, root, and diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java index 9ed76bf0659..e7730d5cf26 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java @@ -7455,7 +7455,7 @@ public void testBug576735a() throws Exception { projectLocation + File.separator + "libMissing.jar"); // create another jar depending on libMissing.jar: - String[] classpath = getJCL15PlusLibraryIfNeeded("1.8"); + String[] classpath = getJCLLibrary("1.8"); classpath = Arrays.copyOf(classpath, classpath.length+1); classpath[classpath.length-1] = projectLocation + File.separator + "libMissing.jar"; Util.createJar(