Skip to content

Commit 4d6216b

Browse files
committed
Modify the JMOD related tests to work with JDKs that don't include JMOD
files. Also, fix the ClasspathJmod to work for resources inside the workspace as well.
1 parent 5a22a10 commit 4d6216b

File tree

7 files changed

+72
-0
lines changed

7 files changed

+72
-0
lines changed

org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/Java9ElementTests.java

+27
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.util.Map;
2727
import java.util.regex.Pattern;
2828
import junit.framework.Test;
29+
import org.eclipse.core.resources.IMarker;
30+
import org.eclipse.core.resources.IResource;
2931
import org.eclipse.core.resources.IncrementalProjectBuilder;
3032
import org.eclipse.core.runtime.CoreException;
3133
import org.eclipse.core.runtime.IPath;
@@ -783,6 +785,10 @@ public void testSystemLibAsJMod() throws Exception {
783785
IPath path = rawClasspath[i].getPath();
784786
if (path.lastSegment().equals("jrt-fs.jar")) {
785787
path = path.removeLastSegments(2).append("jmods").append("java.base.jmod");
788+
if (path.toFile().exists()) {
789+
// No jmod files in JDK? This test is not applicable
790+
return;
791+
}
786792
IClasspathEntry newEntry = newModularLibraryEntry(path, rawClasspath[i].getSourceAttachmentPath(), new Path("java.base"));
787793
rawClasspath[i] = newEntry;
788794
}
@@ -838,6 +844,10 @@ public void test515342b() throws Exception {
838844
IPath path = rawClasspath[i].getPath();
839845
if (path.lastSegment().equals("jrt-fs.jar")) {
840846
path = path.removeLastSegments(2).append("jmods").append("java.base.jmod");
847+
if (!path.toFile().exists()) {
848+
// No jmod files? Then this test is not applicable
849+
return;
850+
}
841851
IClasspathEntry newEntry = newModularLibraryEntry(path, rawClasspath[i].getSourceAttachmentPath(), new Path("java.base"));
842852
rawClasspath[i] = newEntry;
843853
}
@@ -1430,6 +1440,11 @@ private IJavaProject createJavaProjectWithBaseSql() throws CoreException {
14301440
IPath path = rawClasspath[i].getPath();
14311441
if (path.lastSegment().equals("jrt-fs.jar")) {
14321442
path = path.removeLastSegments(2).append("jmods").append("java.base.jmod");
1443+
if (!path.toFile().exists()) {
1444+
// No jmod files? Just proceed with the jrt-fs.
1445+
newClasspath[i] = rawClasspath[i];
1446+
continue;
1447+
}
14331448
IClasspathEntry newEntry = JavaCore.newLibraryEntry(path, rawClasspath[i].getSourceAttachmentPath(), new Path("java.base"));
14341449
newClasspath[i] = newEntry;
14351450
path = path.removeLastSegments(2).append("jmods").append("java.sql.jmod");
@@ -1601,6 +1616,10 @@ public void test530024_001() throws Exception {
16011616
if (path.lastSegment().equals("jrt-fs.jar")) {
16021617
jdkRootPath = path.removeLastSegments(2);
16031618
path = jdkRootPath.append("jmods").append("java.base.jmod");
1619+
if (!path.toFile().exists()) {
1620+
// No jmod files? Then this test is not applicable
1621+
return;
1622+
}
16041623
IClasspathEntry newEntry = newModularLibraryEntry(path, rawClasspath[i].getSourceAttachmentPath(), new Path("java.base"));
16051624
rawClasspath[i] = newEntry;
16061625
}
@@ -1725,4 +1744,12 @@ public void test530653() throws CoreException, IOException {
17251744
deleteProject("Java9Elements");
17261745
}
17271746
}
1747+
public void testGH3549() throws CoreException, IOException {
1748+
IJavaProject project = setUpJavaProject("JModTests", "17");
1749+
waitForManualRefresh();
1750+
waitForAutoBuild();
1751+
project.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
1752+
IMarker[] markers = project.getProject().findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
1753+
assertMarkers("unexpected markers", "mod.c cannot be resolved to a module", markers);
1754+
}
17281755
}

org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java

+8
Original file line numberDiff line numberDiff line change
@@ -2662,6 +2662,10 @@ public void testSystemLibAsJMod() throws CoreException {
26622662
IPath path = rawClasspath[i].getPath();
26632663
if (path.lastSegment().equals("jrt-fs.jar")) {
26642664
path = path.removeLastSegments(2).append("jmods").append("java.base.jmod");
2665+
if (!path.toFile().exists()) {
2666+
// No jmod? Then this test is not applicable.
2667+
return;
2668+
}
26652669
IClasspathEntry newEntry = JavaCore.newLibraryEntry(path, rawClasspath[i].getSourceAttachmentPath(), new Path("java.base"));
26662670
rawClasspath[i] = newEntry;
26672671
}
@@ -2698,6 +2702,10 @@ public void testSystemLibAsJMod_2() throws CoreException {
26982702
IPath path = rawClasspath[i].getPath();
26992703
if (path.lastSegment().equals("jrt-fs.jar")) {
27002704
path = path.removeLastSegments(2).append("jmods").append("java.base.jmod");
2705+
if (!path.toFile().exists()) {
2706+
// No jmod? Then this test is not applicable.
2707+
return;
2708+
}
27012709
IClasspathAttribute[] attributes = {
27022710
JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true") };
27032711
IClasspathEntry newEntry = JavaCore.newLibraryEntry(path, rawClasspath[i].getSourceAttachmentPath(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="var" path="JCL_17_LIB" sourcepath="JCL_17_SRC" rootpath="JCL_SRCROOT"/>
4+
<classpathentry kind="src" path="src"/>
5+
<classpathentry kind="lib" path="jmods/mod.a.jmod">
6+
<attributes>
7+
<attribute name="module" value="true"/>
8+
</attributes>
9+
</classpathentry>
10+
<classpathentry kind="output" path="bin"/>
11+
</classpath>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>mod.b</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module mod.b {
2+
requires mod.a;
3+
requires mod.c;
4+
}

org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathLocation.java

+5
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ public static ClasspathLocation forLibrary(String libraryPathname, AccessRuleSet
183183

184184
public static ClasspathLocation forLibrary(IFile library, AccessRuleSet accessRuleSet, IPath annotationsPath,
185185
boolean isOnModulePath, String compliance) {
186+
IPath location = library.getLocation();
187+
String libraryPathname = location == null? library.getFullPath().toPortableString() : location.toOSString();
188+
if (Util.archiveFormat(libraryPathname) == Util.JMOD_FILE) {
189+
return new ClasspathJMod(libraryPathname, 0, accessRuleSet, annotationsPath);
190+
}
186191
return (CompilerOptions.versionToJdkLevel(compliance) < ClassFileConstants.JDK9) ?
187192
new ClasspathJar(library, accessRuleSet, annotationsPath, isOnModulePath) :
188193
new ClasspathMultiReleaseJar(library, accessRuleSet, annotationsPath, isOnModulePath, compliance);

0 commit comments

Comments
 (0)