Wed, 23 Oct 2013 07:50:04 +0200
8026861: Wrong LineNumberTable for variable declarations in lambdas
Summary: Setting or correcting positions for many trees produced by LambdaToMethod.
Reviewed-by: vromero, rfield
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 {
116 // for i in 1 2 3; do
117 // if test ! -d ext${i}; then mkdir ext${i}; fi
118 // cp ${TESTSRC}${FS}ext${i}${FS}*.jar ext${i}
119 // done
120 sun.tools.jar.Main jarGenerator =
121 new sun.tools.jar.Main(System.out, System.err, "jar");
123 ToolBox.JavaToolArgs javacParams =
124 new ToolBox.JavaToolArgs()
125 .setOptions(ouputDirParam)
126 .setSources(ExtDirTestClass1Src);
127 ToolBox.javac(javacParams);
129 ToolBox.writeFile(Paths.get("pkg1", "MANIFEST.MF"), jar1Manifest);
130 jarGenerator.run(new String[] {"cfm", "pkg1.jar", "pkg1/MANIFEST.MF",
131 "pkg1/ExtDirTestClass1.class"});
133 javacParams.setSources(ExtDirTestClass2Src);
134 ToolBox.javac(javacParams);
136 ToolBox.writeFile(Paths.get("pkg2", "MANIFEST.MF"), jar2Manifest);
137 jarGenerator.run(new String[] {"cfm", "pkg2.jar", "pkg2/MANIFEST.MF",
138 "pkg2/ExtDirTestClass2.class"});
140 ToolBox.copyFile(Paths.get("ext1", "pkg1.jar"), Paths.get("pkg1.jar"));
141 ToolBox.copyFile(Paths.get("ext2", "pkg2.jar"), Paths.get("pkg2.jar"));
142 ToolBox.copyFile(Paths.get("ext3", "pkg1.jar"), Paths.get("pkg1.jar"));
143 ToolBox.copyFile(Paths.get("ext3", "pkg2.jar"), Paths.get("pkg2.jar"));
145 Files.delete(Paths.get("pkg1.jar"));
146 Files.delete(Paths.get("pkg2.jar"));
148 Files.delete(Paths.get("pkg1", "ExtDirTestClass1.class"));
149 Files.delete(Paths.get("pkg1", "MANIFEST.MF"));
150 Files.delete(Paths.get("pkg1"));
151 Files.delete(Paths.get("pkg2", "ExtDirTestClass2.class"));
152 Files.delete(Paths.get("pkg2", "MANIFEST.MF"));
153 Files.delete(Paths.get("pkg2"));
154 }
156 void compileWithExtDirs() throws Exception {
158 //"$javac" ${TESTTOOLVMOPTS} -d . -extdirs ext1 "${TESTSRC}${FS}ExtDirTest_1.java"
159 ToolBox.JavaToolArgs params =
160 new ToolBox.JavaToolArgs()
161 .setOptions("-d", ".", "-extdirs", "ext1")
162 .setSources(ExtDirTest_1Src);
163 ToolBox.javac(params);
165 //"$javac" ${TESTTOOLVMOPTS} -d . -extdirs ext1${PS}ext2 "${TESTSRC}${FS}ExtDirTest_2.java"
166 params.setOptions("-d", ".", "-extdirs", "ext1" + File.pathSeparator + "ext2")
167 .setSources(ExtDirTest_2Src);
168 ToolBox.javac(params);
170 //"$javac" ${TESTTOOLVMOPTS} -d . -extdirs ext3 "${TESTSRC}${FS}ExtDirTest_3.java"
171 params.setOptions("-d", ".", "-extdirs", "ext3")
172 .setSources(ExtDirTest_3Src);
173 ToolBox.javac(params);
174 }
176 }