8166286: jmod fails on symlink to directory

Reviewed-by: jlaskey, alanb
This commit is contained in:
Athijegannathan Sundararajan 2016-11-07 11:33:31 +05:30
parent 5fb366ed4f
commit 9b789e7327
4 changed files with 85 additions and 1 deletions

View File

@ -47,6 +47,7 @@ import java.lang.module.ResolutionException;
import java.lang.module.ResolvedModule;
import java.net.URI;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitOption;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
@ -633,7 +634,8 @@ public class JmodTask {
void processSection(JmodOutputStream out, Section section, Path top)
throws IOException
{
Files.walkFileTree(top, new SimpleFileVisitor<Path>() {
Files.walkFileTree(top, Set.of(FileVisitOption.FOLLOW_LINKS),
Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
throws IOException

View File

@ -28,6 +28,7 @@
* jdk.jlink
* @build jdk.testlibrary.FileUtils CompilerUtils
* @run testng JmodTest
* @bug 8142968
* @summary Basic test for jmod
*/
@ -85,6 +86,31 @@ public class JmodTest {
Files.createDirectories(MODS_DIR);
}
// JDK-8166286 - jmod fails on symlink to directory
@Test
public void testSymlinks() throws IOException {
Path apaDir = EXPLODED_DIR.resolve("apa");
Path classesDir = EXPLODED_DIR.resolve("apa").resolve("classes");
assertTrue(compileModule("apa", classesDir));
Path libDir = apaDir.resolve("lib");
createFiles(libDir, List.of("foo/bar/libfoo.so"));
try {
Path link = Files.createSymbolicLink(
libDir.resolve("baz"), libDir.resolve("foo").toAbsolutePath());
assertTrue(Files.exists(link));
} catch (UnsupportedOperationException uoe) {
// OS does not support symlinks. Nothing to test!
return;
}
Path jmod = MODS_DIR.resolve("apa.jmod");
jmod("create",
"--libs=", libDir.toString(),
"--class-path", classesDir.toString(),
jmod.toString())
.assertSuccess();
}
@Test
public void testList() throws IOException {
String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString();

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.test.apa;
public class Apa { }

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
module apa {
exports jdk.test.apa;
}