1/* 2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/** 25 * @test 26 * @bug 8175990 27 * @summary source in symbolic link 28 * @library /tools/lib 29 * @modules 30 * jdk.compiler/com.sun.tools.javac.api 31 * jdk.compiler/com.sun.tools.javac.main 32 * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask ModuleTestBase 33 * @run main SourceInSymlinkTest 34 */ 35 36import java.nio.file.*; 37import javax.tools.*; 38 39import toolbox.JarTask; 40import toolbox.JavacTask; 41import toolbox.Task; 42import toolbox.ToolBox; 43 44public class SourceInSymlinkTest extends ModuleTestBase { 45 public static void main(String... args) throws Exception { 46 SourceInSymlinkTest t = new SourceInSymlinkTest(); 47 t.runTests(); 48 } 49 50 @Test 51 public void testModuleSourcePath(Path base) throws Exception { 52 Path src = base.resolve("src"); 53 Path src_m = src.resolve("m"); 54 tb.writeFile(src_m.resolve("module-info.java"), "module m { }"); 55 tb.writeJavaFiles(src_m, "package p; public class A{}"); 56 57 Path classes = base.resolve("classes"); 58 Files.createDirectories(classes); 59 60 new JavacTask(tb) 61 .options("--module-source-path", src.toString()) 62 .outdir(classes) 63 .files(src_m.resolve("p/A.java")) 64 .run() 65 .writeAll(); 66 67 checkFiles( 68 classes.resolve("m/module-info.class"), 69 classes.resolve("m/p/A.class")); 70 71 // ok normal case works, now create a symlink to the source 72 Path lsrc = base.resolve("link"); 73 Path lsrc_m = src.resolve("m"); 74 Path lclasses = base.resolve("link-out"); 75 Files.createDirectories(lclasses); 76 try { 77 Files.createSymbolicLink(lsrc, Paths.get("src")); 78 } catch (FileSystemException fse) { 79 System.err.println("warning: test passes vacuously, sym-link could not be created"); 80 System.err.println(fse.getMessage()); 81 return; 82 } 83 new JavacTask(tb) 84 .options("--module-source-path", lsrc.toString()) 85 .outdir(lclasses) 86 .files(lsrc_m.resolve("p/A.java")) 87 .run() 88 .writeAll(); 89 90 checkFiles( 91 lclasses.resolve("m/module-info.class"), 92 lclasses.resolve("m/p/A.class")); 93 94 } 95 96 void checkFiles(Path... files) throws Exception { 97 for (Path f: files) { 98 if (!Files.exists(f)) 99 throw new Exception("expected file not found: " + f); 100 } 101 } 102} 103