test/tools/javac/policy/test1/Test1b.java

Tue, 23 Sep 2008 10:44:51 -0700

author
jjg
date
Tue, 23 Sep 2008 10:44:51 -0700
changeset 119
1e83972f53fb
child 554
9d9f26857129
permissions
-rw-r--r--

6420151: need to improve byfile compile policy to eliminate footprint issues
Reviewed-by: mcimadamore

jjg@119 1 /*
jjg@119 2 * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
jjg@119 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@119 4 *
jjg@119 5 * This code is free software; you can redistribute it and/or modify it
jjg@119 6 * under the terms of the GNU General Public License version 2 only, as
jjg@119 7 * published by the Free Software Foundation.
jjg@119 8 *
jjg@119 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@119 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@119 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@119 12 * version 2 for more details (a copy is included in the LICENSE file that
jjg@119 13 * accompanied this code).
jjg@119 14 *
jjg@119 15 * You should have received a copy of the GNU General Public License version
jjg@119 16 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@119 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@119 18 *
jjg@119 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
jjg@119 20 * CA 95054 USA or visit www.sun.com if you need additional information or
jjg@119 21 * have any questions.
jjg@119 22 */
jjg@119 23
jjg@119 24 /*
jjg@119 25 * @test 6420151
jjg@119 26 * @summary Compile a group of files and validate the set of class files produced
jjg@119 27 * @run main Test1b -XDcompilePolicy=byfile A.java B.java D.java
jjg@119 28 */
jjg@119 29
jjg@119 30 /*
jjg@119 31 * @test 6420151
jjg@119 32 * @summary Compile a group of files and validate the set of class files produced
jjg@119 33 * @run main Test1b -XDcompilePolicy=byfile A.java C.java D.java
jjg@119 34 */
jjg@119 35
jjg@119 36 /*
jjg@119 37 * @test 6420151
jjg@119 38 * @summary Compile a group of files and validate the set of class files produced
jjg@119 39 * @run main Test1b -XDcompilePolicy=simple A.java B.java D.java
jjg@119 40 */
jjg@119 41
jjg@119 42 /*
jjg@119 43 * @test 6420151
jjg@119 44 * @summary Compile a group of files and validate the set of class files produced
jjg@119 45 * @run main Test1b -XDcompilePolicy=simple A.java C.java D.java
jjg@119 46 */
jjg@119 47
jjg@119 48 // These test cases should be uncommented when the default compile policy is
jjg@119 49 // changed to "byfile". While the default policy is "bytodo", the test cases fail
jjg@119 50 ///*
jjg@119 51 // * @test 6420151
jjg@119 52 // * @summary Compile a group of files and validate the set of class files produced
jjg@119 53 // * @run main Test1b A.java B.java D.java
jjg@119 54 // */
jjg@119 55 //
jjg@119 56 ///*
jjg@119 57 // * @test 6420151
jjg@119 58 // * @summary Compile a group of files and validate the set of class files produced
jjg@119 59 // * @run main Test1b A.java C.java D.java
jjg@119 60 // */
jjg@119 61
jjg@119 62 // These test cases are retained for debugging; if uncommented, they show that
jjg@119 63 // to bytodo mode fails the "all or none" class file test
jjg@119 64 ///*
jjg@119 65 // * @test 6420151
jjg@119 66 // * @summary Compile a group of files and validate the set of class files produced
jjg@119 67 // * @run main Test1b -XDcompilePolicy=bytodo A.java B.java D.java
jjg@119 68 // */
jjg@119 69 //
jjg@119 70 ///*
jjg@119 71 // * @test 6420151
jjg@119 72 // * @summary Compile a group of files and validate the set of class files produced
jjg@119 73 // * @run main Test1b -XDcompilePolicy=bytodo A.java C.java D.java
jjg@119 74 // */
jjg@119 75
jjg@119 76 import java.io.File;
jjg@119 77 import java.io.PrintWriter;
jjg@119 78 import java.io.StringWriter;
jjg@119 79 import java.util.ArrayList;
jjg@119 80 import java.util.HashMap;
jjg@119 81 import java.util.List;
jjg@119 82 import java.util.Map;
jjg@119 83 import java.util.regex.Matcher;
jjg@119 84 import java.util.regex.Pattern;
jjg@119 85
jjg@119 86 public class Test1b
jjg@119 87 {
jjg@119 88 public static void main(String... args) throws Exception {
jjg@119 89 new Test1b().run(args);
jjg@119 90 }
jjg@119 91
jjg@119 92 void run(String... args) throws Exception {
jjg@119 93 File testSrcDir = new File(System.getProperty("test.src"));
jjg@119 94 File tmpClassDir = new File(".");
jjg@119 95 List<String> l = new ArrayList<String>();
jjg@119 96 l.add("-d");
jjg@119 97 l.add(tmpClassDir.getPath());
jjg@119 98 for (String a: args) {
jjg@119 99 if (a.endsWith(".java"))
jjg@119 100 l.add(new File(testSrcDir, a).getPath());
jjg@119 101 else
jjg@119 102 l.add(a);
jjg@119 103 }
jjg@119 104
jjg@119 105 StringWriter sw = new StringWriter();
jjg@119 106 int rc = com.sun.tools.javac.Main.compile(l.toArray(new String[l.size()]), new PrintWriter(sw));
jjg@119 107 System.err.println(sw);
jjg@119 108
jjg@119 109 Pattern p = Pattern.compile("([A-Z]+).*");
jjg@119 110 for (String name: tmpClassDir.list()) {
jjg@119 111 if (name.endsWith(".class")) {
jjg@119 112 Matcher m = p.matcher(name);
jjg@119 113 if (m.matches()) {
jjg@119 114 found(m.group(1), name);
jjg@119 115 }
jjg@119 116 }
jjg@119 117 }
jjg@119 118
jjg@119 119 // for all classes that might have been compiled, check that
jjg@119 120 // all the classes in the source file get generated, or none do.
jjg@119 121 check("A", 3);
jjg@119 122 check("B", 3);
jjg@119 123 check("C", 3);
jjg@119 124 check("D", 3);
jjg@119 125
jjg@119 126 if (errors > 0)
jjg@119 127 throw new Exception(errors + " errors");
jjg@119 128 }
jjg@119 129
jjg@119 130 void check(String prefix, int expect) {
jjg@119 131 List<String> names = map.get(prefix);
jjg@119 132 int found = (names == null ? 0 : names.size());
jjg@119 133 if (found == 0 || found == expect) {
jjg@119 134 System.err.println("Found " + found + " files for " + prefix + ": OK");
jjg@119 135 return;
jjg@119 136 }
jjg@119 137 error("Found " + found + " files for " + prefix + ": expected 0 or " + expect + " " + names);
jjg@119 138 }
jjg@119 139
jjg@119 140 void found(String prefix, String name) {
jjg@119 141 List<String> names = map.get(prefix);
jjg@119 142 if (names == null) {
jjg@119 143 names = new ArrayList<String>();
jjg@119 144 map.put(prefix, names);
jjg@119 145 }
jjg@119 146 names.add(name);
jjg@119 147 }
jjg@119 148
jjg@119 149 void error(String message) {
jjg@119 150 System.err.println(message);
jjg@119 151 errors++;
jjg@119 152 }
jjg@119 153
jjg@119 154 Map<String,List<String>> map = new HashMap<String,List<String>>();
jjg@119 155 int errors;
jjg@119 156 }

mercurial