jjg@86: /* ohair@554: * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. jjg@86: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@86: * jjg@86: * This code is free software; you can redistribute it and/or modify it jjg@86: * under the terms of the GNU General Public License version 2 only, as jjg@86: * published by the Free Software Foundation. jjg@86: * jjg@86: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@86: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@86: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@86: * version 2 for more details (a copy is included in the LICENSE file that jjg@86: * accompanied this code). jjg@86: * jjg@86: * You should have received a copy of the GNU General Public License version jjg@86: * 2 along with this work; if not, write to the Free Software Foundation, jjg@86: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@86: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. jjg@86: */ jjg@86: jjg@86: /* jjg@86: * @test jjg@86: * @bug 6627364 6627366 jjg@86: * @summary Synthesize important classes if they are missing from the (boot)classpath jjg@86: */ jjg@86: jjg@86: import java.io.*; jjg@86: import java.util.*; jjg@86: jjg@86: public class Main jjg@86: { jjg@86: File testSrc = new File(System.getProperty("test.src")); jjg@86: jjg@86: public static void main(String[] args) throws Exception { jjg@86: new Main().run(); jjg@86: } jjg@86: jjg@86: public void run() throws Exception { jjg@86: jjg@86: // compile with standard bootclasspath jjg@86: compile(true, "Test.java"); jjg@86: jjg@86: // compile with various missing system classes jjg@86: jjg@86: List base_files = Arrays.asList( jjg@86: "Boolean.java", jjg@86: "Byte.java", jjg@86: "Character.java", jjg@86: "Integer.java", jjg@86: "Long.java", jjg@86: "Number.java", jjg@86: "Object.java", jjg@86: "Short.java", jjg@86: "Void.java" jjg@86: ); jjg@86: jjg@86: List extra_files = Arrays.asList( jjg@86: "Double.java", jjg@86: "Float.java", jjg@86: "Cloneable.java", jjg@86: "Serializable.java" jjg@86: ); jjg@86: jjg@86: List files = new ArrayList(); jjg@86: files.addAll(base_files); jjg@86: files.add("Test.java"); jjg@86: jjg@86: compile(false, files); jjg@86: jjg@86: for (String f: extra_files) { jjg@86: files = new ArrayList(); jjg@86: files.addAll(base_files); jjg@86: files.addAll(extra_files); jjg@86: files.remove(f); jjg@86: files.add("Test.java"); jjg@86: compile(false, files); jjg@86: } jjg@86: jjg@86: if (errors > 0) jjg@86: throw new Exception(errors + " errors occurred"); jjg@86: } jjg@86: jjg@86: void compile(boolean stdBootClassPath, String... files) { jjg@86: compile(stdBootClassPath, Arrays.asList(files)); jjg@86: } jjg@86: jjg@86: void compile(boolean stdBootClassPath, List files) { jjg@86: File empty = new File("empty"); jjg@86: empty.mkdirs(); jjg@86: jjg@86: List args = new ArrayList(); jjg@86: args.add("-classpath"); jjg@86: args.add("empty"); jjg@86: jjg@86: if (!stdBootClassPath) { jjg@86: args.add("-bootclasspath"); jjg@86: args.add("empty"); jjg@86: } jjg@86: args.add("-d"); jjg@86: args.add("."); jjg@86: for (String f: files) jjg@86: args.add(new File(testSrc, f).getPath()); jjg@86: jjg@86: System.out.println("Compile: " + args); jjg@86: StringWriter out = new StringWriter(); jjg@86: int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), jjg@86: new PrintWriter(out)); jjg@86: System.out.println(out.toString()); jjg@86: System.out.println("result: " + rc); jjg@86: System.out.println(); jjg@86: jjg@86: if (rc != 0) jjg@86: errors++; jjg@86: } jjg@86: jjg@86: private int errors; jjg@86: } jjg@86: jjg@86: