Mon, 17 Oct 2016 21:20:17 -0700
8168115: Remove and retag jdk8u122-b03 in 8u repo
Reviewed-by: coffeys
1 /*
2 * Copyright (c) 2011, 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 7026509
27 * @summary Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations
28 */
30 import java.io.*;
31 import java.util.*;
32 import javax.tools.*;
33 import javax.tools.JavaCompiler.CompilationTask;
34 import com.sun.source.util.*;
36 public class TestJavacTask_Lock {
37 public static void main(String... args) throws Exception {
38 new TestJavacTask_Lock().run();
39 }
41 enum MethodKind {
42 CALL {
43 int test(CompilationTask t) {
44 boolean ok = t.call();
45 if (!ok)
46 throw new Error("compilation failed");
47 return 1;
48 }
49 },
50 PARSE {
51 int test(CompilationTask t) {
52 try {
53 ((JavacTask) t).parse();
54 return 1;
55 } catch (IOException ex) {
56 throw new Error(ex);
57 }
58 }
60 };
61 abstract int test(CompilationTask t);
62 }
64 JavaCompiler comp;
65 StandardJavaFileManager fm;
67 void run() throws Exception {
68 comp = ToolProvider.getSystemJavaCompiler();
69 fm = comp.getStandardFileManager(null, null, null);
71 for (MethodKind first: MethodKind.values()) {
72 for (MethodKind second: MethodKind.values()) {
73 test(first, second);
74 }
75 }
77 if (errors > 0)
78 throw new Exception(errors + " errors found");
79 }
81 void test(MethodKind first, MethodKind second) {
82 System.err.println("test: " + first + ", " + second);
83 File testSrc = new File(System.getProperty("test.src"));
84 String thisClassName = TestJavacTask_Lock.class.getName();
85 Iterable<? extends JavaFileObject> files =
86 fm.getJavaFileObjects(new File(testSrc, thisClassName + ".java"));
87 File tmpDir = new File(first + "_" + second);
88 tmpDir.mkdirs();
89 List<String> options = Arrays.asList( "-d", tmpDir.getPath() );
90 CompilationTask t = comp.getTask(null, fm, null, options, null, files);
92 try {
93 first.test(t);
94 second.test(t);
95 error("No exception thrown");
96 } catch (IllegalStateException e) {
97 System.err.println("Expected exception caught: " + e);
98 } catch (Exception e) {
99 error("Unexpected exception caught: " + e);
100 e.printStackTrace(System.err);
101 }
103 }
105 void error(String msg) {
106 System.err.println("Error: " + msg);
107 errors++;
108 }
110 int errors;
111 }