Skip to content

Commit bf8d4a8

Browse files
committedMay 26, 2021
8267583: jmod fails on symlink to class file
Reviewed-by: alanb
1 parent 083416d commit bf8d4a8

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed
 

‎src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,8 @@ Set<String> findPackages(List<Path> classpath) {
674674
Set<String> findPackages(Path dir) {
675675
try {
676676
return Files.find(dir, Integer.MAX_VALUE,
677-
((path, attrs) -> attrs.isRegularFile()))
677+
((path, attrs) -> attrs.isRegularFile()),
678+
FileVisitOption.FOLLOW_LINKS)
678679
.map(dir::relativize)
679680
.filter(path -> isResource(path.toString()))
680681
.map(path -> toPackageName(path))

‎test/jdk/tools/jmod/JmodTest.java

+39-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void buildExplodedModules() throws IOException {
9898

9999
// JDK-8166286 - jmod fails on symlink to directory
100100
@Test
101-
public void testSymlinks() throws IOException {
101+
public void testDirSymlinks() throws IOException {
102102
Path apaDir = EXPLODED_DIR.resolve("apa");
103103
Path classesDir = EXPLODED_DIR.resolve("apa").resolve("classes");
104104
assertTrue(compileModule("apa", classesDir));
@@ -110,6 +110,8 @@ public void testSymlinks() throws IOException {
110110
assertTrue(Files.exists(link));
111111
} catch (IOException|UnsupportedOperationException uoe) {
112112
// OS does not support symlinks. Nothing to test!
113+
System.out.println("Creating symlink failed. Test passes vacuously.");
114+
uoe.printStackTrace();
113115
return;
114116
}
115117

@@ -119,6 +121,42 @@ public void testSymlinks() throws IOException {
119121
"--class-path", classesDir.toString(),
120122
jmod.toString())
121123
.assertSuccess();
124+
Files.delete(jmod);
125+
}
126+
127+
// JDK-8267583 - jmod fails on symlink to class file
128+
@Test
129+
public void testFileSymlinks() throws IOException {
130+
Path apaDir = EXPLODED_DIR.resolve("apa");
131+
Path classesDir = EXPLODED_DIR.resolve("apa").resolve("classes");
132+
assertTrue(compileModule("apa", classesDir));
133+
134+
Files.move(classesDir.resolve("module-info.class"),
135+
classesDir.resolve("module-info.class1"));
136+
Files.move(classesDir.resolve(Paths.get("jdk", "test", "apa", "Apa.class")),
137+
classesDir.resolve("Apa.class1"));
138+
try {
139+
Path link = Files.createSymbolicLink(
140+
classesDir.resolve("module-info.class"),
141+
classesDir.resolve("module-info.class1").toAbsolutePath());
142+
assertTrue(Files.exists(link));
143+
link = Files.createSymbolicLink(
144+
classesDir.resolve(Paths.get("jdk", "test", "apa", "Apa.class")),
145+
classesDir.resolve("Apa.class1").toAbsolutePath());
146+
assertTrue(Files.exists(link));
147+
} catch (IOException|UnsupportedOperationException uoe) {
148+
// OS does not support symlinks. Nothing to test!
149+
System.out.println("Creating symlinks failed. Test passes vacuously.");
150+
uoe.printStackTrace();
151+
return;
152+
}
153+
154+
Path jmod = MODS_DIR.resolve("apa.jmod");
155+
jmod("create",
156+
"--class-path", classesDir.toString(),
157+
jmod.toString())
158+
.assertSuccess();
159+
Files.delete(jmod);
122160
}
123161

124162
// JDK-8170618 - jmod should validate if any exported or open package is missing

0 commit comments

Comments
 (0)
Please sign in to comment.