Navigation Menu

Skip to content

Commit

Permalink
8267583: jmod fails on symlink to class file
Browse files Browse the repository at this point in the history
Reviewed-by: alanb
  • Loading branch information
sundararajana committed May 26, 2021
1 parent 083416d commit bf8d4a8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java
Expand Up @@ -674,7 +674,8 @@ Set<String> findPackages(List<Path> classpath) {
Set<String> findPackages(Path dir) {
try {
return Files.find(dir, Integer.MAX_VALUE,
((path, attrs) -> attrs.isRegularFile()))
((path, attrs) -> attrs.isRegularFile()),
FileVisitOption.FOLLOW_LINKS)
.map(dir::relativize)
.filter(path -> isResource(path.toString()))
.map(path -> toPackageName(path))
Expand Down
40 changes: 39 additions & 1 deletion test/jdk/tools/jmod/JmodTest.java
Expand Up @@ -98,7 +98,7 @@ public void buildExplodedModules() throws IOException {

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

Expand All @@ -119,6 +121,42 @@ public void testSymlinks() throws IOException {
"--class-path", classesDir.toString(),
jmod.toString())
.assertSuccess();
Files.delete(jmod);
}

// JDK-8267583 - jmod fails on symlink to class file
@Test
public void testFileSymlinks() throws IOException {
Path apaDir = EXPLODED_DIR.resolve("apa");
Path classesDir = EXPLODED_DIR.resolve("apa").resolve("classes");
assertTrue(compileModule("apa", classesDir));

Files.move(classesDir.resolve("module-info.class"),
classesDir.resolve("module-info.class1"));
Files.move(classesDir.resolve(Paths.get("jdk", "test", "apa", "Apa.class")),
classesDir.resolve("Apa.class1"));
try {
Path link = Files.createSymbolicLink(
classesDir.resolve("module-info.class"),
classesDir.resolve("module-info.class1").toAbsolutePath());
assertTrue(Files.exists(link));
link = Files.createSymbolicLink(
classesDir.resolve(Paths.get("jdk", "test", "apa", "Apa.class")),
classesDir.resolve("Apa.class1").toAbsolutePath());
assertTrue(Files.exists(link));
} catch (IOException|UnsupportedOperationException uoe) {
// OS does not support symlinks. Nothing to test!
System.out.println("Creating symlinks failed. Test passes vacuously.");
uoe.printStackTrace();
return;
}

Path jmod = MODS_DIR.resolve("apa.jmod");
jmod("create",
"--class-path", classesDir.toString(),
jmod.toString())
.assertSuccess();
Files.delete(jmod);
}

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

1 comment on commit bf8d4a8

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.