1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/synthesize/Main.java Fri Aug 01 15:23:18 2008 -0700 1.3 @@ -0,0 +1,122 @@ 1.4 +/* 1.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + */ 1.26 + 1.27 +/* 1.28 + * @test 1.29 + * @bug 6627364 6627366 1.30 + * @summary Synthesize important classes if they are missing from the (boot)classpath 1.31 + */ 1.32 + 1.33 +import java.io.*; 1.34 +import java.util.*; 1.35 + 1.36 +public class Main 1.37 +{ 1.38 + File testSrc = new File(System.getProperty("test.src")); 1.39 + 1.40 + public static void main(String[] args) throws Exception { 1.41 + new Main().run(); 1.42 + } 1.43 + 1.44 + public void run() throws Exception { 1.45 + 1.46 + // compile with standard bootclasspath 1.47 + compile(true, "Test.java"); 1.48 + 1.49 + // compile with various missing system classes 1.50 + 1.51 + List<String> base_files = Arrays.asList( 1.52 + "Boolean.java", 1.53 + "Byte.java", 1.54 + "Character.java", 1.55 + "Integer.java", 1.56 + "Long.java", 1.57 + "Number.java", 1.58 + "Object.java", 1.59 + "Short.java", 1.60 + "Void.java" 1.61 + ); 1.62 + 1.63 + List<String> extra_files = Arrays.asList( 1.64 + "Double.java", 1.65 + "Float.java", 1.66 + "Cloneable.java", 1.67 + "Serializable.java" 1.68 + ); 1.69 + 1.70 + List<String> files = new ArrayList<String>(); 1.71 + files.addAll(base_files); 1.72 + files.add("Test.java"); 1.73 + 1.74 + compile(false, files); 1.75 + 1.76 + for (String f: extra_files) { 1.77 + files = new ArrayList<String>(); 1.78 + files.addAll(base_files); 1.79 + files.addAll(extra_files); 1.80 + files.remove(f); 1.81 + files.add("Test.java"); 1.82 + compile(false, files); 1.83 + } 1.84 + 1.85 + if (errors > 0) 1.86 + throw new Exception(errors + " errors occurred"); 1.87 + } 1.88 + 1.89 + void compile(boolean stdBootClassPath, String... files) { 1.90 + compile(stdBootClassPath, Arrays.asList(files)); 1.91 + } 1.92 + 1.93 + void compile(boolean stdBootClassPath, List<String> files) { 1.94 + File empty = new File("empty"); 1.95 + empty.mkdirs(); 1.96 + 1.97 + List<String> args = new ArrayList<String>(); 1.98 + args.add("-classpath"); 1.99 + args.add("empty"); 1.100 + 1.101 + if (!stdBootClassPath) { 1.102 + args.add("-bootclasspath"); 1.103 + args.add("empty"); 1.104 + } 1.105 + args.add("-d"); 1.106 + args.add("."); 1.107 + for (String f: files) 1.108 + args.add(new File(testSrc, f).getPath()); 1.109 + 1.110 + System.out.println("Compile: " + args); 1.111 + StringWriter out = new StringWriter(); 1.112 + int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), 1.113 + new PrintWriter(out)); 1.114 + System.out.println(out.toString()); 1.115 + System.out.println("result: " + rc); 1.116 + System.out.println(); 1.117 + 1.118 + if (rc != 0) 1.119 + errors++; 1.120 + } 1.121 + 1.122 + private int errors; 1.123 +} 1.124 + 1.125 +