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