Sat, 22 Dec 2018 13:10:38 -0800
Added tag jdk8u202-b25 for changeset 15d8c732039b
1 /*
2 * Copyright (c) 2013, 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 */
24 /*
25 * @test
26 * @bug 4204897 4256097 4785453 4863609
27 * @summary Test that '.jar' files in -extdirs are found.
28 * @library /tools/javac/lib
29 * @build ToolBox
30 * @run main ExtDirTest
31 */
33 import java.io.File;
34 import java.nio.file.Files;
35 import java.nio.file.Paths;
36 import java.util.Arrays;
37 import java.util.List;
39 //original test: test/tools/javac/ExtDirs/ExtDirs.sh
40 public class ExtDirTest {
42 private static final String ExtDirTestClass1Src =
43 "package pkg1;\n" +
44 "\n" +
45 "public class ExtDirTestClass1 {}";
47 private static final String ExtDirTestClass2Src =
48 "package pkg2;\n" +
49 "\n" +
50 "public class ExtDirTestClass2 {}";
52 private static final String ExtDirTest_1Src =
53 "import pkg1.*;\n" +
54 "\n" +
55 "public class ExtDirTest_1 {\n" +
56 " ExtDirTestClass1 x;\n" +
57 "}";
59 private static final String ExtDirTest_2Src =
60 "import pkg1.*;\n" +
61 "import pkg2.*;\n" +
62 "\n" +
63 "public class ExtDirTest_2 {\n" +
64 " ExtDirTestClass1 x;\n" +
65 " ExtDirTestClass2 y;\n" +
66 "}";
68 private static final String ExtDirTest_3Src =
69 "import pkg1.*;\n" +
70 "import pkg2.*;\n" +
71 "\n" +
72 "public class ExtDirTest_3 {\n" +
73 " ExtDirTestClass1 x;\n" +
74 " ExtDirTestClass2 y;\n" +
75 "}";
77 private static final String jar1Manifest =
78 "Manifest-Version: 1.0\n" +
79 "\n" +
80 "Name: pkg1/ExtDirTestClass1.class\n" +
81 "Digest-Algorithms: SHA MD5 \n" +
82 "SHA-Digest: 9HEcO9LJmND3cvOlq/AbUsbD9S0=\n" +
83 "MD5-Digest: hffPBwfqcUcnEdNv4PXu1Q==\n" +
84 "\n" +
85 "Name: pkg1/ExtDirTestClass1.java\n" +
86 "Digest-Algorithms: SHA MD5 \n" +
87 "SHA-Digest: 2FQVe6w3n2Ma1ACYpe8a988EBU8=\n" +
88 "MD5-Digest: /Ivr4zVI9MSM26NmqWtZpQ==\n";
90 private static final String jar2Manifest =
91 "Manifest-Version: 1.0\n" +
92 "\n" +
93 "Name: pkg2/ExtDirTestClass2.class\n" +
94 "Digest-Algorithms: SHA MD5 \n" +
95 "SHA-Digest: elbPaqWf8hjj1+ZkkdW3PGTsilo=\n" +
96 "MD5-Digest: 57Nn0e2t1yEQfu/4kSw8yg==\n" +
97 "\n" +
98 "Name: pkg2/ExtDirTestClass2.java\n" +
99 "Digest-Algorithms: SHA MD5 \n" +
100 "SHA-Digest: ILJOhwHg5US+yuw1Sc1d+Avu628=\n" +
101 "MD5-Digest: j8wnz8wneEcuJ/gjXBBQNA==\n";
103 List<String> ouputDirParam = Arrays.asList("-d", ".");
105 public static void main(String args[]) throws Exception {
106 new ExtDirTest().run();
107 }
109 void run() throws Exception {
110 createJars();
111 compileWithExtDirs();
112 }
114 void createJars() throws Exception {
115 sun.tools.jar.Main jarGenerator =
116 new sun.tools.jar.Main(System.out, System.err, "jar");
118 ToolBox.JavaToolArgs javacParams =
119 new ToolBox.JavaToolArgs()
120 .setOptions(ouputDirParam)
121 .setSources(ExtDirTestClass1Src);
122 ToolBox.javac(javacParams);
124 ToolBox.writeFile(Paths.get("pkg1", "MANIFEST.MF"), jar1Manifest);
125 jarGenerator.run(new String[] {"cfm", "pkg1.jar", "pkg1/MANIFEST.MF",
126 "pkg1/ExtDirTestClass1.class"});
128 javacParams.setSources(ExtDirTestClass2Src);
129 ToolBox.javac(javacParams);
131 ToolBox.writeFile(Paths.get("pkg2", "MANIFEST.MF"), jar2Manifest);
132 jarGenerator.run(new String[] {"cfm", "pkg2.jar", "pkg2/MANIFEST.MF",
133 "pkg2/ExtDirTestClass2.class"});
135 ToolBox.copyFile(Paths.get("ext1", "pkg1.jar"), Paths.get("pkg1.jar"));
136 ToolBox.copyFile(Paths.get("ext2", "pkg2.jar"), Paths.get("pkg2.jar"));
137 ToolBox.copyFile(Paths.get("ext3", "pkg1.jar"), Paths.get("pkg1.jar"));
138 ToolBox.copyFile(Paths.get("ext3", "pkg2.jar"), Paths.get("pkg2.jar"));
140 Files.delete(Paths.get("pkg1.jar"));
141 Files.delete(Paths.get("pkg2.jar"));
143 Files.delete(Paths.get("pkg1", "ExtDirTestClass1.class"));
144 Files.delete(Paths.get("pkg1", "MANIFEST.MF"));
145 Files.delete(Paths.get("pkg1"));
146 Files.delete(Paths.get("pkg2", "ExtDirTestClass2.class"));
147 Files.delete(Paths.get("pkg2", "MANIFEST.MF"));
148 Files.delete(Paths.get("pkg2"));
149 }
151 void compileWithExtDirs() throws Exception {
153 //javac -extdirs ext1 ExtDirTest_1.java
154 ToolBox.JavaToolArgs params =
155 new ToolBox.JavaToolArgs()
156 .setOptions("-d", ".", "-extdirs", "ext1")
157 .setSources(ExtDirTest_1Src);
158 ToolBox.javac(params);
160 //javac -extdirs ext1:ext2 ExtDirTest_2.java
161 params.setOptions("-d", ".", "-extdirs", "ext1" + File.pathSeparator + "ext2")
162 .setSources(ExtDirTest_2Src);
163 ToolBox.javac(params);
165 //javac -extdirs ext3 ExtDirTest_3.java
166 params.setOptions("-d", ".", "-extdirs", "ext3")
167 .setSources(ExtDirTest_3Src);
168 ToolBox.javac(params);
169 }
171 }