1 /* 2 * Copyright (c) 2007, 2016, 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 */ 23 24 /* 25 * @test 26 * @bug 6627364 6627366 27 * @summary Synthesize important classes if they are missing from the (boot)classpath 28 * @modules jdk.compiler 29 */ 30 31 import java.io.*; 32 import java.util.*; 33 34 public class Main 35 { 36 File testSrc = new File(System.getProperty("test.src")); 37 38 public static void main(String[] args) throws Exception { 39 new Main().run(); 40 } 41 42 public void run() throws Exception { 43 44 // compile with standard bootclasspath 45 compile(true, "Test.java"); 46 47 // compile with various missing system classes 48 49 List<String> base_files = Arrays.asList( 50 "Boolean.java", 51 "Byte.java", 52 "Character.java", 53 "Integer.java", 54 "Long.java", 55 "Number.java", 56 "Object.java", 57 "Short.java", 58 "Void.java" 59 ); 60 61 List<String> extra_files = Arrays.asList( 62 "Double.java", 63 "Float.java", 64 "Cloneable.java", 65 "Serializable.java" 66 ); 67 68 List<String> files = new ArrayList<String>(); 69 files.addAll(base_files); 70 files.add("Test.java"); 71 72 compile(false, files); 73 74 for (String f: extra_files) { 75 files = new ArrayList<String>(); 76 files.addAll(base_files); 77 files.addAll(extra_files); 78 files.remove(f); 79 files.add("Test.java"); 80 compile(false, files); 81 } 82 83 if (errors > 0) 84 throw new Exception(errors + " errors occurred"); 85 } 86 87 void compile(boolean stdBootClassPath, String... files) { 88 compile(stdBootClassPath, Arrays.asList(files)); 89 } 90 91 void compile(boolean stdBootClassPath, List<String> files) { 92 File empty = new File("empty"); 93 empty.mkdirs(); 94 95 // files to compile are in a separate directory from test to avoid 96 // confusing jtreg 97 File src = new File(testSrc, "src"); 98 99 List<String> args = new ArrayList<String>(); 100 args.add("-classpath"); 101 args.add("empty"); 102 103 if (stdBootClassPath) { 104 args.add("--patch-module"); 105 args.add("java.base=" + testSrc.getAbsolutePath()); 106 } else { 107 args.add("--system"); 108 args.add("none"); 109 files.add("module-info.java"); 110 } 111 112 113 args.add("-d"); 114 args.add("."); 115 116 for (String f: files) 117 args.add(new File(src, f).getPath()); 118 119 System.out.println("Compile: " + args); 120 StringWriter out = new StringWriter(); 121 int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), 122 new PrintWriter(out)); 123 System.out.println(out.toString()); 124 System.out.println("result: " + rc); 125 System.out.println(); 126 127 if (rc != 0) 128 errors++; 129 } 130 131 private int errors; 132 } 133 134