ExtDirTest.java revision 3314:97ec97671022
1/* 2 * Copyright (c) 2013, 2016, 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 4204897 4256097 4785453 4863609 27 * @summary Test that '.jar' files in -extdirs are found. 28 * @library /tools/lib 29 * @modules jdk.compiler/com.sun.tools.javac.api 30 * jdk.compiler/com.sun.tools.javac.main 31 * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask 32 * @run main ExtDirTest 33 */ 34 35import java.io.File; 36 37import toolbox.JarTask; 38import toolbox.JavacTask; 39import toolbox.ToolBox; 40 41// Original test: test/tools/javac/ExtDirs/ExtDirs.sh 42public class ExtDirTest { 43 44 private static final String ExtDirTestClass1Src = 45 "package pkg1;\n" + 46 "\n" + 47 "public class ExtDirTestClass1 {}"; 48 49 private static final String ExtDirTestClass2Src = 50 "package pkg2;\n" + 51 "\n" + 52 "public class ExtDirTestClass2 {}"; 53 54 private static final String ExtDirTest_1Src = 55 "import pkg1.*;\n" + 56 "\n" + 57 "public class ExtDirTest_1 {\n" + 58 " ExtDirTestClass1 x;\n" + 59 "}"; 60 61 private static final String ExtDirTest_2Src = 62 "import pkg1.*;\n" + 63 "import pkg2.*;\n" + 64 "\n" + 65 "public class ExtDirTest_2 {\n" + 66 " ExtDirTestClass1 x;\n" + 67 " ExtDirTestClass2 y;\n" + 68 "}"; 69 70 private static final String ExtDirTest_3Src = 71 "import pkg1.*;\n" + 72 "import pkg2.*;\n" + 73 "\n" + 74 "public class ExtDirTest_3 {\n" + 75 " ExtDirTestClass1 x;\n" + 76 " ExtDirTestClass2 y;\n" + 77 "}"; 78 79 private static final String jar1Manifest = 80 "Manifest-Version: 1.0\n" + 81 "\n" + 82 "Name: pkg1/ExtDirTestClass1.class\n" + 83 "Digest-Algorithms: SHA MD5 \n" + 84 "SHA-Digest: 9HEcO9LJmND3cvOlq/AbUsbD9S0=\n" + 85 "MD5-Digest: hffPBwfqcUcnEdNv4PXu1Q==\n" + 86 "\n" + 87 "Name: pkg1/ExtDirTestClass1.java\n" + 88 "Digest-Algorithms: SHA MD5 \n" + 89 "SHA-Digest: 2FQVe6w3n2Ma1ACYpe8a988EBU8=\n" + 90 "MD5-Digest: /Ivr4zVI9MSM26NmqWtZpQ==\n"; 91 92 private static final String jar2Manifest = 93 "Manifest-Version: 1.0\n" + 94 "\n" + 95 "Name: pkg2/ExtDirTestClass2.class\n" + 96 "Digest-Algorithms: SHA MD5 \n" + 97 "SHA-Digest: elbPaqWf8hjj1+ZkkdW3PGTsilo=\n" + 98 "MD5-Digest: 57Nn0e2t1yEQfu/4kSw8yg==\n" + 99 "\n" + 100 "Name: pkg2/ExtDirTestClass2.java\n" + 101 "Digest-Algorithms: SHA MD5 \n" + 102 "SHA-Digest: ILJOhwHg5US+yuw1Sc1d+Avu628=\n" + 103 "MD5-Digest: j8wnz8wneEcuJ/gjXBBQNA==\n"; 104 105 public static void main(String args[]) throws Exception { 106 new ExtDirTest().run(); 107 } 108 109 private final ToolBox tb = new ToolBox(); 110 111 void run() throws Exception { 112 createJars(); 113 compileWithExtDirs(); 114 } 115 116 void createJars() throws Exception { 117 new JavacTask(tb) 118 .outdir(".") 119 .sources(ExtDirTestClass1Src) 120 .run(); 121 122 new JarTask(tb, "pkg1.jar") 123 .manifest(jar1Manifest) 124 .files("pkg1/ExtDirTestClass1.class") 125 .run(); 126 127 new JavacTask(tb) 128 .outdir(".") 129 .sources(ExtDirTestClass2Src) 130 .run(); 131 132 new JarTask(tb, "pkg2.jar") 133 .manifest(jar2Manifest) 134 .files("pkg2/ExtDirTestClass2.class") 135 .run(); 136 137 tb.createDirectories("ext1", "ext2", "ext3"); 138 tb.copyFile("pkg1.jar", "ext1"); 139 tb.copyFile("pkg2.jar", "ext2"); 140 tb.copyFile("pkg1.jar", "ext3"); 141 tb.copyFile("pkg2.jar", "ext3"); 142 143 tb.deleteFiles( 144 "pkg1.jar", 145 "pkg2.jar", 146 "pkg1/ExtDirTestClass1.class", 147 "pkg1", 148 "pkg2/ExtDirTestClass2.class", 149 "pkg2" 150 ); 151 } 152 153 void compileWithExtDirs() throws Exception { 154 new JavacTask(tb) 155 .outdir(".") 156 .options("-source", "8", 157 "-extdirs", "ext1") 158 .sources(ExtDirTest_1Src) 159 .run() 160 .writeAll(); 161 162 new JavacTask(tb) 163 .outdir(".") 164 .options("-source", "8", 165 "-extdirs", "ext1" + File.pathSeparator + "ext2") 166 .sources(ExtDirTest_2Src) 167 .run() 168 .writeAll(); 169 170 new JavacTask(tb) 171 .outdir(".") 172 .options("-source", "8", 173 "-extdirs", "ext3") 174 .sources(ExtDirTest_3Src) 175 .run() 176 .writeAll(); 177 } 178 179} 180