1/* 2 * Copyright (c) 2014, 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 8178017 27 * @summary JDK 9 change to symlink handling causes misleading 28 * class.public.should.be.in.file diagnostic 29 * @library /tools/lib 30 * @modules jdk.compiler/com.sun.tools.javac.api 31 * jdk.compiler/com.sun.tools.javac.main 32 * @build toolbox.JavacTask toolbox.TestRunner toolbox.ToolBox 33 * @run main SymLinkTest 34 */ 35 36import java.io.IOException; 37import java.nio.file.FileSystemException; 38import java.nio.file.Files; 39import java.nio.file.Path; 40import java.nio.file.Paths; 41 42import toolbox.JavacTask; 43import toolbox.TestRunner; 44import toolbox.TestRunner.Test; 45import toolbox.ToolBox; 46 47public class SymLinkTest extends TestRunner { 48 public static void main(String... args) throws Exception { 49 new SymLinkTest().runTests(m -> new Object[] { Paths.get(m.getName()) }); 50 } 51 52 private final ToolBox tb = new ToolBox(); 53 54 public SymLinkTest() { 55 super(System.err); 56 } 57 58 @Test 59 public void testgetKind(Path base) throws IOException { 60 test(base, "SOURCE"); 61 } 62 63 @Test 64 public void testSymLink(Path base) throws IOException { 65 test(base, "SOURCE.java"); 66 } 67 68 void test(Path base, String name) throws IOException { 69 Path file = base.resolve(name); 70 Path javaFile = base.resolve("HelloWorld.java"); 71 tb.writeFile(file, 72 "public class HelloWorld {\n" 73 + " public static void main(String... args) {\n" 74 + " System.err.println(\"Hello World!\");\n" 75 + " }\n" 76 + "}"); 77 78 try { 79 Files.createSymbolicLink(javaFile, file.getFileName()); 80 } catch (FileSystemException fse) { 81 System.err.println("warning: test passes vacuously, sym-link could not be created"); 82 System.err.println(fse.getMessage()); 83 return; 84 } 85 86 Path classes = Files.createDirectories(base.resolve("classes")); 87 new JavacTask(tb) 88 .outdir(classes) 89 .files(javaFile) 90 .run() 91 .writeAll(); 92 } 93} 94 95