Mon, 19 Jun 2017 14:51:25 -0700
Added tag jdk8u151-b02 for changeset 732e1bab2660
1 /*
2 * Copyright (c) 2007, 2008, 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 6627364 6627366
27 * @summary Synthesize important classes if they are missing from the (boot)classpath
28 */
30 import java.io.*;
31 import java.util.*;
33 public class Main
34 {
35 File testSrc = new File(System.getProperty("test.src"));
37 public static void main(String[] args) throws Exception {
38 new Main().run();
39 }
41 public void run() throws Exception {
43 // compile with standard bootclasspath
44 compile(true, "Test.java");
46 // compile with various missing system classes
48 List<String> base_files = Arrays.asList(
49 "Boolean.java",
50 "Byte.java",
51 "Character.java",
52 "Integer.java",
53 "Long.java",
54 "Number.java",
55 "Object.java",
56 "Short.java",
57 "Void.java"
58 );
60 List<String> extra_files = Arrays.asList(
61 "Double.java",
62 "Float.java",
63 "Cloneable.java",
64 "Serializable.java"
65 );
67 List<String> files = new ArrayList<String>();
68 files.addAll(base_files);
69 files.add("Test.java");
71 compile(false, files);
73 for (String f: extra_files) {
74 files = new ArrayList<String>();
75 files.addAll(base_files);
76 files.addAll(extra_files);
77 files.remove(f);
78 files.add("Test.java");
79 compile(false, files);
80 }
82 if (errors > 0)
83 throw new Exception(errors + " errors occurred");
84 }
86 void compile(boolean stdBootClassPath, String... files) {
87 compile(stdBootClassPath, Arrays.asList(files));
88 }
90 void compile(boolean stdBootClassPath, List<String> files) {
91 File empty = new File("empty");
92 empty.mkdirs();
94 List<String> args = new ArrayList<String>();
95 args.add("-classpath");
96 args.add("empty");
98 if (!stdBootClassPath) {
99 args.add("-bootclasspath");
100 args.add("empty");
101 }
102 args.add("-d");
103 args.add(".");
104 for (String f: files)
105 args.add(new File(testSrc, f).getPath());
107 System.out.println("Compile: " + args);
108 StringWriter out = new StringWriter();
109 int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]),
110 new PrintWriter(out));
111 System.out.println(out.toString());
112 System.out.println("result: " + rc);
113 System.out.println();
115 if (rc != 0)
116 errors++;
117 }
119 private int errors;
120 }