1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/ExtDirs/ExtDirTest.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,171 @@ 1.4 +/* 1.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/* 1.28 + * @test 1.29 + * @bug 4204897 4256097 4785453 4863609 1.30 + * @summary Test that '.jar' files in -extdirs are found. 1.31 + * @library /tools/javac/lib 1.32 + * @build ToolBox 1.33 + * @run main ExtDirTest 1.34 + */ 1.35 + 1.36 +import java.io.File; 1.37 +import java.nio.file.Files; 1.38 +import java.nio.file.Paths; 1.39 +import java.util.Arrays; 1.40 +import java.util.List; 1.41 + 1.42 +//original test: test/tools/javac/ExtDirs/ExtDirs.sh 1.43 +public class ExtDirTest { 1.44 + 1.45 + private static final String ExtDirTestClass1Src = 1.46 + "package pkg1;\n" + 1.47 + "\n" + 1.48 + "public class ExtDirTestClass1 {}"; 1.49 + 1.50 + private static final String ExtDirTestClass2Src = 1.51 + "package pkg2;\n" + 1.52 + "\n" + 1.53 + "public class ExtDirTestClass2 {}"; 1.54 + 1.55 + private static final String ExtDirTest_1Src = 1.56 + "import pkg1.*;\n" + 1.57 + "\n" + 1.58 + "public class ExtDirTest_1 {\n" + 1.59 + " ExtDirTestClass1 x;\n" + 1.60 + "}"; 1.61 + 1.62 + private static final String ExtDirTest_2Src = 1.63 + "import pkg1.*;\n" + 1.64 + "import pkg2.*;\n" + 1.65 + "\n" + 1.66 + "public class ExtDirTest_2 {\n" + 1.67 + " ExtDirTestClass1 x;\n" + 1.68 + " ExtDirTestClass2 y;\n" + 1.69 + "}"; 1.70 + 1.71 + private static final String ExtDirTest_3Src = 1.72 + "import pkg1.*;\n" + 1.73 + "import pkg2.*;\n" + 1.74 + "\n" + 1.75 + "public class ExtDirTest_3 {\n" + 1.76 + " ExtDirTestClass1 x;\n" + 1.77 + " ExtDirTestClass2 y;\n" + 1.78 + "}"; 1.79 + 1.80 + private static final String jar1Manifest = 1.81 + "Manifest-Version: 1.0\n" + 1.82 + "\n" + 1.83 + "Name: pkg1/ExtDirTestClass1.class\n" + 1.84 + "Digest-Algorithms: SHA MD5 \n" + 1.85 + "SHA-Digest: 9HEcO9LJmND3cvOlq/AbUsbD9S0=\n" + 1.86 + "MD5-Digest: hffPBwfqcUcnEdNv4PXu1Q==\n" + 1.87 + "\n" + 1.88 + "Name: pkg1/ExtDirTestClass1.java\n" + 1.89 + "Digest-Algorithms: SHA MD5 \n" + 1.90 + "SHA-Digest: 2FQVe6w3n2Ma1ACYpe8a988EBU8=\n" + 1.91 + "MD5-Digest: /Ivr4zVI9MSM26NmqWtZpQ==\n"; 1.92 + 1.93 + private static final String jar2Manifest = 1.94 + "Manifest-Version: 1.0\n" + 1.95 + "\n" + 1.96 + "Name: pkg2/ExtDirTestClass2.class\n" + 1.97 + "Digest-Algorithms: SHA MD5 \n" + 1.98 + "SHA-Digest: elbPaqWf8hjj1+ZkkdW3PGTsilo=\n" + 1.99 + "MD5-Digest: 57Nn0e2t1yEQfu/4kSw8yg==\n" + 1.100 + "\n" + 1.101 + "Name: pkg2/ExtDirTestClass2.java\n" + 1.102 + "Digest-Algorithms: SHA MD5 \n" + 1.103 + "SHA-Digest: ILJOhwHg5US+yuw1Sc1d+Avu628=\n" + 1.104 + "MD5-Digest: j8wnz8wneEcuJ/gjXBBQNA==\n"; 1.105 + 1.106 + List<String> ouputDirParam = Arrays.asList("-d", "."); 1.107 + 1.108 + public static void main(String args[]) throws Exception { 1.109 + new ExtDirTest().run(); 1.110 + } 1.111 + 1.112 + void run() throws Exception { 1.113 + createJars(); 1.114 + compileWithExtDirs(); 1.115 + } 1.116 + 1.117 + void createJars() throws Exception { 1.118 + sun.tools.jar.Main jarGenerator = 1.119 + new sun.tools.jar.Main(System.out, System.err, "jar"); 1.120 + 1.121 + ToolBox.JavaToolArgs javacParams = 1.122 + new ToolBox.JavaToolArgs() 1.123 + .setOptions(ouputDirParam) 1.124 + .setSources(ExtDirTestClass1Src); 1.125 + ToolBox.javac(javacParams); 1.126 + 1.127 + ToolBox.writeFile(Paths.get("pkg1", "MANIFEST.MF"), jar1Manifest); 1.128 + jarGenerator.run(new String[] {"cfm", "pkg1.jar", "pkg1/MANIFEST.MF", 1.129 + "pkg1/ExtDirTestClass1.class"}); 1.130 + 1.131 + javacParams.setSources(ExtDirTestClass2Src); 1.132 + ToolBox.javac(javacParams); 1.133 + 1.134 + ToolBox.writeFile(Paths.get("pkg2", "MANIFEST.MF"), jar2Manifest); 1.135 + jarGenerator.run(new String[] {"cfm", "pkg2.jar", "pkg2/MANIFEST.MF", 1.136 + "pkg2/ExtDirTestClass2.class"}); 1.137 + 1.138 + ToolBox.copyFile(Paths.get("ext1", "pkg1.jar"), Paths.get("pkg1.jar")); 1.139 + ToolBox.copyFile(Paths.get("ext2", "pkg2.jar"), Paths.get("pkg2.jar")); 1.140 + ToolBox.copyFile(Paths.get("ext3", "pkg1.jar"), Paths.get("pkg1.jar")); 1.141 + ToolBox.copyFile(Paths.get("ext3", "pkg2.jar"), Paths.get("pkg2.jar")); 1.142 + 1.143 + Files.delete(Paths.get("pkg1.jar")); 1.144 + Files.delete(Paths.get("pkg2.jar")); 1.145 + 1.146 + Files.delete(Paths.get("pkg1", "ExtDirTestClass1.class")); 1.147 + Files.delete(Paths.get("pkg1", "MANIFEST.MF")); 1.148 + Files.delete(Paths.get("pkg1")); 1.149 + Files.delete(Paths.get("pkg2", "ExtDirTestClass2.class")); 1.150 + Files.delete(Paths.get("pkg2", "MANIFEST.MF")); 1.151 + Files.delete(Paths.get("pkg2")); 1.152 + } 1.153 + 1.154 + void compileWithExtDirs() throws Exception { 1.155 + 1.156 +//javac -extdirs ext1 ExtDirTest_1.java 1.157 + ToolBox.JavaToolArgs params = 1.158 + new ToolBox.JavaToolArgs() 1.159 + .setOptions("-d", ".", "-extdirs", "ext1") 1.160 + .setSources(ExtDirTest_1Src); 1.161 + ToolBox.javac(params); 1.162 + 1.163 +//javac -extdirs ext1:ext2 ExtDirTest_2.java 1.164 + params.setOptions("-d", ".", "-extdirs", "ext1" + File.pathSeparator + "ext2") 1.165 + .setSources(ExtDirTest_2Src); 1.166 + ToolBox.javac(params); 1.167 + 1.168 +//javac -extdirs ext3 ExtDirTest_3.java 1.169 + params.setOptions("-d", ".", "-extdirs", "ext3") 1.170 + .setSources(ExtDirTest_3Src); 1.171 + ToolBox.javac(params); 1.172 + } 1.173 + 1.174 +}