test/tools/javac/synthesize/Main.java

changeset 86
3437676858e3
child 117
24a47c3062fe
equal deleted inserted replaced
83:37470f5ea179 86:3437676858e3
1 /*
2 * Copyright 2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24 /*
25 * @test
26 * @bug 6627364 6627366
27 * @summary Synthesize important classes if they are missing from the (boot)classpath
28 */
29
30 import java.io.*;
31 import java.util.*;
32
33 public class Main
34 {
35 File testSrc = new File(System.getProperty("test.src"));
36
37 public static void main(String[] args) throws Exception {
38 new Main().run();
39 }
40
41 public void run() throws Exception {
42
43 // compile with standard bootclasspath
44 compile(true, "Test.java");
45
46 // compile with various missing system classes
47
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 );
59
60 List<String> extra_files = Arrays.asList(
61 "Double.java",
62 "Float.java",
63 "Cloneable.java",
64 "Serializable.java"
65 );
66
67 List<String> files = new ArrayList<String>();
68 files.addAll(base_files);
69 files.add("Test.java");
70
71 compile(false, files);
72
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 }
81
82 if (errors > 0)
83 throw new Exception(errors + " errors occurred");
84 }
85
86 void compile(boolean stdBootClassPath, String... files) {
87 compile(stdBootClassPath, Arrays.asList(files));
88 }
89
90 void compile(boolean stdBootClassPath, List<String> files) {
91 File empty = new File("empty");
92 empty.mkdirs();
93
94 List<String> args = new ArrayList<String>();
95 args.add("-classpath");
96 args.add("empty");
97
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());
106
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();
114
115 if (rc != 0)
116 errors++;
117 }
118
119 private int errors;
120 }
121
122

mercurial