langtools/test/tools/javac/TestPkgInfo.java
author jjg
Mon, 24 Jan 2011 16:38:56 -0800
changeset 8223 638daa596494
parent 6575 ae1798028008
child 19488 3d9b2d67f71f
permissions -rw-r--r--
6988106: javac report 'java.lang.IllegalMonitorStateException' Reviewed-by: ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6575
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
     1
/*
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
     4
 *
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
     8
 *
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    13
 * accompanied this code).
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    14
 *
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    18
 *
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    21
 * questions.
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    22
 */
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    23
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    24
/*
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    25
 * @test
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    26
 * @bug 6960424
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    27
 * @summary new option -Xpkginfo for better control of when package-info.class is generated
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    28
 */
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    29
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    30
import java.io.*;
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    31
import java.util.*;
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    32
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    33
public class TestPkgInfo {
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    34
    enum OptKind {
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    35
        NONE(null),
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    36
        ALWAYS("-Xpkginfo:always"),
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    37
        NONEMPTY("-Xpkginfo:nonempty"),
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    38
        LEGACY("-Xpkginfo:legacy");
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    39
        OptKind(String opt) { this.opt = opt; }
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    40
        final String opt;
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    41
    };
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    42
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    43
    public static void main(String... args) throws Exception {
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    44
        new TestPkgInfo().run(args);
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    45
    }
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    46
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    47
    public void run(String... args) throws Exception {
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    48
        boolean[] booleanValues = { false, true };
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    49
        for (OptKind ok: OptKind.values()) {
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    50
            for (boolean sr: booleanValues) {
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    51
                for (boolean cr: booleanValues) {
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    52
                    for (boolean rr: booleanValues) {
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    53
                        try {
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    54
                            test(ok, sr, cr, rr);
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    55
                        } catch (Exception e) {
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    56
                            error("Exception: " + e);
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    57
                        }
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    58
                        if (errors > 0) throw new AssertionError();
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    59
                    }
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    60
                }
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    61
            }
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    62
        }
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    63
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    64
        if (errors > 0)
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    65
            throw new Exception(errors + " errors occurred");
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    66
    }
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    67
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    68
    void test(OptKind ok, boolean sr, boolean cr, boolean rr) throws Exception {
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    69
        count++;
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    70
        System.err.println("Test " + count + ": ok:" + ok + " sr:" + sr + " cr:" + cr + " rr:" + rr);
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    71
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    72
        StringBuilder sb = new StringBuilder();
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    73
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    74
        // create annotated package statement with all combinations of retention policy
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    75
        if (sr) sb.append("@SR\n");
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    76
        if (cr) sb.append("@CR\n");
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    77
        if (rr) sb.append("@RR\n");
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    78
        sb.append("package p;\n");
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    79
        sb.append("\n");
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    80
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    81
        sb.append("import java.lang.annotation.*;\n");
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    82
        sb.append("@Retention(RetentionPolicy.SOURCE)  @interface SR { }\n");
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    83
        sb.append("@Retention(RetentionPolicy.CLASS)   @interface CR { }\n");
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    84
        sb.append("@Retention(RetentionPolicy.RUNTIME) @interface RR { }\n");
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    85
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    86
        // test specific tmp directory
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    87
        File tmpDir = new File("tmp.test" + count);
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    88
        File classesDir = new File(tmpDir, "classes");
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    89
        classesDir.mkdirs();
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    90
        File pkginfo_java = new File(new File(tmpDir, "src"), "package-info.java");
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    91
        writeFile(pkginfo_java, sb.toString());
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    92
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    93
        // build up list of options and files to be compiled
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    94
        List<String> opts = new ArrayList<String>();
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    95
        List<File> files = new ArrayList<File>();
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    96
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    97
        opts.add("-d");
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    98
        opts.add(classesDir.getPath());
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
    99
        if (ok.opt != null)
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   100
            opts.add(ok.opt);
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   101
        //opts.add("-verbose");
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   102
        files.add(pkginfo_java);
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   103
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   104
        compile(opts, files);
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   105
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   106
        File pkginfo_class = new File(new File(classesDir, "p"), "package-info.class");
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   107
        boolean exists = pkginfo_class.exists();
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   108
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   109
        boolean expected;
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   110
        switch (ok) {
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   111
            case ALWAYS:
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   112
                expected = true;
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   113
                break;
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   114
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   115
            case LEGACY:
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   116
            case NONE:
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   117
                expected = (sr || cr || rr ); // any annotation
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   118
                break;
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   119
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   120
            case NONEMPTY:
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   121
                expected = (cr || rr ); // any annotation in class file
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   122
                break;
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   123
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   124
            default:
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   125
                throw new IllegalStateException();
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   126
        }
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   127
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   128
        if (exists && !expected)
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   129
            error("package-info.class found but not expected");
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   130
        if (!exists && expected)
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   131
            error("package-info.class expected but not found");
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   132
    }
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   133
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   134
    /** Compile files with options provided. */
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   135
    void compile(List<String> opts, List<File> files) throws Exception {
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   136
        System.err.println("javac: " + opts + " " + files);
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   137
        List<String> args = new ArrayList<String>();
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   138
        args.addAll(opts);
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   139
        for (File f: files)
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   140
            args.add(f.getPath());
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   141
        StringWriter sw = new StringWriter();
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   142
        PrintWriter pw = new PrintWriter(sw);
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   143
        int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw);
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   144
        pw.flush();
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   145
        if (sw.getBuffer().length() > 0)
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   146
            System.err.println(sw.toString());
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   147
        if (rc != 0)
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   148
            throw new Exception("compilation failed: rc=" + rc);
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   149
    }
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   150
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   151
    /** Write a file with a given body. */
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   152
    void writeFile(File f, String body) throws Exception {
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   153
        if (f.getParentFile() != null)
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   154
            f.getParentFile().mkdirs();
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   155
        Writer out = new FileWriter(f);
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   156
        try {
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   157
            out.write(body);
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   158
        } finally {
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   159
            out.close();
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   160
        }
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   161
    }
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   162
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   163
    /** Report an error. */
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   164
    void error(String msg) {
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   165
        System.err.println("Error: " + msg);
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   166
        errors++;
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   167
    }
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   168
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   169
    /** Test case counter. */
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   170
    int count;
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   171
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   172
    /** Number of errors found. */
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   173
    int errors;
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
diff changeset
   174
}