Skip to content

Commit

Permalink
Modify the JMOD related tests to work with JDKs that don't include JM…
Browse files Browse the repository at this point in the history
…OD files (#3587)

Also, fix the ClasspathJmod to work for resources inside the workspace
as well.

#3587
  • Loading branch information
jarthana authored Jan 28, 2025
1 parent ca77e4c commit 8a71d44
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.util.Map;
import java.util.regex.Pattern;
import junit.framework.Test;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
Expand Down Expand Up @@ -783,6 +785,10 @@ public void testSystemLibAsJMod() throws Exception {
IPath path = rawClasspath[i].getPath();
if (path.lastSegment().equals("jrt-fs.jar")) {
path = path.removeLastSegments(2).append("jmods").append("java.base.jmod");
if (path.toFile().exists()) {
// No jmod files in JDK? This test is not applicable
return;
}
IClasspathEntry newEntry = newModularLibraryEntry(path, rawClasspath[i].getSourceAttachmentPath(), new Path("java.base"));
rawClasspath[i] = newEntry;
}
Expand Down Expand Up @@ -838,6 +844,10 @@ public void test515342b() throws Exception {
IPath path = rawClasspath[i].getPath();
if (path.lastSegment().equals("jrt-fs.jar")) {
path = path.removeLastSegments(2).append("jmods").append("java.base.jmod");
if (!path.toFile().exists()) {
// No jmod files? Then this test is not applicable
return;
}
IClasspathEntry newEntry = newModularLibraryEntry(path, rawClasspath[i].getSourceAttachmentPath(), new Path("java.base"));
rawClasspath[i] = newEntry;
}
Expand Down Expand Up @@ -1430,6 +1440,11 @@ private IJavaProject createJavaProjectWithBaseSql() throws CoreException {
IPath path = rawClasspath[i].getPath();
if (path.lastSegment().equals("jrt-fs.jar")) {
path = path.removeLastSegments(2).append("jmods").append("java.base.jmod");
if (!path.toFile().exists()) {
// No jmod files? Just proceed with the jrt-fs.
newClasspath[i] = rawClasspath[i];
continue;
}
IClasspathEntry newEntry = JavaCore.newLibraryEntry(path, rawClasspath[i].getSourceAttachmentPath(), new Path("java.base"));
newClasspath[i] = newEntry;
path = path.removeLastSegments(2).append("jmods").append("java.sql.jmod");
Expand Down Expand Up @@ -1601,6 +1616,10 @@ public void test530024_001() throws Exception {
if (path.lastSegment().equals("jrt-fs.jar")) {
jdkRootPath = path.removeLastSegments(2);
path = jdkRootPath.append("jmods").append("java.base.jmod");
if (!path.toFile().exists()) {
// No jmod files? Then this test is not applicable
return;
}
IClasspathEntry newEntry = newModularLibraryEntry(path, rawClasspath[i].getSourceAttachmentPath(), new Path("java.base"));
rawClasspath[i] = newEntry;
}
Expand Down Expand Up @@ -1725,4 +1744,12 @@ public void test530653() throws CoreException, IOException {
deleteProject("Java9Elements");
}
}
public void testGH3549() throws CoreException, IOException {
IJavaProject project = setUpJavaProject("JModTests", "17");
waitForManualRefresh();
waitForAutoBuild();
project.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
IMarker[] markers = project.getProject().findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
assertMarkers("unexpected markers", "mod.c cannot be resolved to a module", markers);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2662,6 +2662,10 @@ public void testSystemLibAsJMod() throws CoreException {
IPath path = rawClasspath[i].getPath();
if (path.lastSegment().equals("jrt-fs.jar")) {
path = path.removeLastSegments(2).append("jmods").append("java.base.jmod");
if (!path.toFile().exists()) {
// No jmod? Then this test is not applicable.
return;
}
IClasspathEntry newEntry = JavaCore.newLibraryEntry(path, rawClasspath[i].getSourceAttachmentPath(), new Path("java.base"));
rawClasspath[i] = newEntry;
}
Expand Down Expand Up @@ -2698,6 +2702,10 @@ public void testSystemLibAsJMod_2() throws CoreException {
IPath path = rawClasspath[i].getPath();
if (path.lastSegment().equals("jrt-fs.jar")) {
path = path.removeLastSegments(2).append("jmods").append("java.base.jmod");
if (!path.toFile().exists()) {
// No jmod? Then this test is not applicable.
return;
}
IClasspathAttribute[] attributes = {
JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true") };
IClasspathEntry newEntry = JavaCore.newLibraryEntry(path, rawClasspath[i].getSourceAttachmentPath(),
Expand Down
11 changes: 11 additions & 0 deletions org.eclipse.jdt.core.tests.model/workspace/JModTests/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="var" path="JCL_17_LIB" sourcepath="JCL_17_SRC" rootpath="JCL_SRCROOT"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="jmods/mod.a.jmod">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions org.eclipse.jdt.core.tests.model/workspace/JModTests/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>mod.b</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module mod.b {
requires mod.a;
requires mod.c;
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ public static ClasspathLocation forLibrary(String libraryPathname, AccessRuleSet

public static ClasspathLocation forLibrary(IFile library, AccessRuleSet accessRuleSet, IPath annotationsPath,
boolean isOnModulePath, String compliance) {
IPath location = library.getLocation();
String libraryPathname = location == null? library.getFullPath().toPortableString() : location.toOSString();
if (Util.archiveFormat(libraryPathname) == Util.JMOD_FILE) {
return new ClasspathJMod(libraryPathname, 0, accessRuleSet, annotationsPath);
}
return (CompilerOptions.versionToJdkLevel(compliance) < ClassFileConstants.JDK9) ?
new ClasspathJar(library, accessRuleSet, annotationsPath, isOnModulePath) :
new ClasspathMultiReleaseJar(library, accessRuleSet, annotationsPath, isOnModulePath, compliance);
Expand Down

0 comments on commit 8a71d44

Please sign in to comment.