changeset 16038:06195d1ca9ce

8166286: jmod fails on symlink to directory Reviewed-by: jlaskey, alanb
author sundar
date Mon, 07 Nov 2016 11:33:31 +0530
parents 7ee327a10059
children 736a5f3085b2
files src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java test/tools/jmod/JmodTest.java test/tools/jmod/src/apa/jdk/test/apa/Apa.java test/tools/jmod/src/apa/module-info.java
diffstat 4 files changed, 85 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java	Fri Nov 04 15:49:31 2016 -0700
+++ b/src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java	Mon Nov 07 11:33:31 2016 +0530
@@ -47,6 +47,7 @@
 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 @@
         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
--- a/test/tools/jmod/JmodTest.java	Fri Nov 04 15:49:31 2016 -0700
+++ b/test/tools/jmod/JmodTest.java	Mon Nov 07 11:33:31 2016 +0530
@@ -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 @@
         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();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/jmod/src/apa/jdk/test/apa/Apa.java	Mon Nov 07 11:33:31 2016 +0530
@@ -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 { }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/jmod/src/apa/module-info.java	Mon Nov 07 11:33:31 2016 +0530
@@ -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;
+}