LinksTest.java revision 2734:b96d74fa60aa
1/* 2 * Copyright (c) 2013, 2014, 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 4266026 27 * @summary javac no longer follows symlinks 28 * @library /tools/lib 29 * @build ToolBox 30 * @run main LinksTest 31 */ 32 33import java.io.IOException; 34import java.nio.file.Files; 35import java.nio.file.Paths; 36 37// Original test: test/tools/javac/links/links.sh 38public class LinksTest { 39 40 private static final String BSrc = 41 "package a;\n" + 42 "\n" + 43 "public class B {}"; 44 45 private static final String TSrc = 46 "class T extends a.B {}"; 47 48 public static void main(String... args) throws Exception { 49 ToolBox tb = new ToolBox(); 50 tb.writeFile("tmp/B.java", BSrc); 51 52 // Try to set up a symbolic link for the test. 53 try { 54 Files.createSymbolicLink(Paths.get("a"), Paths.get("tmp")); 55 System.err.println("Created symbolic link"); 56 } catch (UnsupportedOperationException | IOException e) { 57 System.err.println("Problem creating symbolic link: " + e); 58 System.err.println("Test cannot continue; test passed by default"); 59 return; 60 } 61 62 // If symbolic link was successfully created, 63 // try a compilation that will use it. 64 tb.new JavacTask() 65 .sourcepath(".") 66 .outdir(".") 67 .sources(TSrc) 68 .run() 69 .writeAll(); 70 } 71 72} 73