langtools/test/tools/javac/options/modes/OptionModesTester.java
author jjg
Fri, 12 Aug 2016 17:45:31 -0700
changeset 40316 20b50a99fe8d
parent 36526 langtools/test/tools/javac/options/modes/Tester.java@3b41f1c69604
permissions -rw-r--r--
8052398: Uniqify test framework class names Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     1
/*
40316
20b50a99fe8d 8052398: Uniqify test framework class names
jjg
parents: 36526
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     4
 *
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     8
 *
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    13
 * accompanied this code).
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    14
 *
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    18
 *
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    21
 * questions.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    22
 */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    23
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    24
import com.sun.tools.javac.api.JavacTool;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    25
import com.sun.tools.javac.file.JavacFileManager;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    26
import com.sun.tools.javac.util.Context;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    27
import java.io.ByteArrayOutputStream;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    28
import java.io.FileWriter;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    29
import java.io.IOException;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    30
import java.io.PrintStream;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    31
import java.io.PrintWriter;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    32
import java.io.StringWriter;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34560
diff changeset
    33
import java.io.UncheckedIOException;
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    34
import java.lang.annotation.Annotation;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    35
import java.lang.annotation.Retention;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    36
import java.lang.annotation.RetentionPolicy;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    37
import java.lang.reflect.InvocationTargetException;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    38
import java.lang.reflect.Method;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    39
import java.nio.file.Files;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    40
import java.nio.file.Path;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    41
import java.nio.file.Paths;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    42
import java.util.ArrayList;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    43
import java.util.Arrays;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    44
import java.util.EnumMap;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    45
import java.util.Iterator;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    46
import java.util.List;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    47
import java.util.Map;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    48
import java.util.stream.Collectors;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    49
import javax.tools.JavaFileManager;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    50
import javax.tools.JavaFileObject;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    51
import javax.tools.StandardJavaFileManager;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    52
import javax.tools.ToolProvider;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    53
40316
20b50a99fe8d 8052398: Uniqify test framework class names
jjg
parents: 36526
diff changeset
    54
public class OptionModesTester {
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    55
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    56
    /** Marker annotation for test methods to be invoked by runTests. */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    57
    @Retention(RetentionPolicy.RUNTIME)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    58
    @interface Test { }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    59
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    60
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    61
     * Run all methods annotated with @Test, and throw an exception if any
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    62
     * errors are reported..
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    63
     * Typically called on a tester object in main()
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    64
     * @throws Exception if any errors occurred
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    65
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    66
    void runTests() throws Exception {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    67
        for (Method m: getClass().getDeclaredMethods()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    68
            Annotation a = m.getAnnotation(Test.class);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    69
            if (a != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    70
                try {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    71
                    out.println("Running test " + m.getName());
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    72
                    m.invoke(this);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    73
                } catch (InvocationTargetException e) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    74
                    Throwable cause = e.getCause();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    75
                    throw (cause instanceof Exception) ? ((Exception) cause) : e;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    76
                }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    77
                out.println();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    78
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    79
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    80
        if (errors > 0)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    81
            throw new Exception(errors + " errors occurred");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    82
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    83
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    84
    TestResult runMain(String[] opts, String[] files) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    85
        out.println("Main " + Arrays.toString(opts) + " " + Arrays.toString(files));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    86
        return run(new TestResult(opts), (tr, c, pw) -> {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    87
            com.sun.tools.javac.main.Main compiler =
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    88
                new com.sun.tools.javac.main.Main("javac", pw);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    89
            int rc = compiler.compile(join(opts, files), c).exitCode;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    90
            tr.setResult(rc);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    91
        });
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    92
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    93
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    94
    TestResult runCall(String[] opts, String[] files) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    95
        out.println("Call " + Arrays.toString(opts) + " " + Arrays.toString(files));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    96
        return run(new TestResult(opts), (tr, c, pw) -> {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    97
            boolean ok = JavacTool.create()
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    98
                    .getTask(pw, null, null, Arrays.asList(opts), null, getFiles(files), c)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    99
                    .call();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   100
            tr.setResult(ok);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   101
        });
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   102
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   103
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   104
    TestResult runParse(String[] opts, String[] files) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   105
        out.println("Parse " + Arrays.toString(opts) + " " + Arrays.toString(files));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   106
        return run(new TestResult(opts), (tr, c, pw) -> {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   107
            JavacTool.create()
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   108
                    .getTask(pw, null, null, Arrays.asList(opts), null, getFiles(files), c)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   109
                    .parse();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   110
            tr.setResult(true);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   111
        });
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   112
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   113
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   114
    TestResult runAnalyze(String[] opts, String[] files) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   115
        out.println("Analyze " + Arrays.toString(opts) + " " + Arrays.toString(files));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   116
        return run(new TestResult(opts), (tr, c, pw) -> {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   117
            JavacTool.create()
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   118
                    .getTask(pw, null, null, Arrays.asList(opts), null, getFiles(files), c)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   119
                    .analyze();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   120
            tr.setResult(true);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   121
        });
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   122
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   123
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   124
    interface Runnable {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   125
        void run(TestResult tr, Context c, PrintWriter pw) throws IOException;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   126
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   127
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   128
    TestResult run(TestResult tr, Runnable r) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   129
        StringWriter sw = new StringWriter();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   130
        PrintWriter pw = new PrintWriter(sw);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   131
        StreamOutput sysOut = new StreamOutput(System.out, System::setOut);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   132
        StreamOutput sysErr = new StreamOutput(System.err, System::setErr);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   133
        Context context = new Context();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   134
        JavacFileManager.preRegister(context);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   135
        try {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   136
            r.run(tr, context, pw);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   137
        } catch (IllegalArgumentException | IllegalStateException | IOException e) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   138
            tr.setThrown(e);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   139
        } finally {
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 26264
diff changeset
   140
            try {
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 26264
diff changeset
   141
                ((JavacFileManager) context.get(JavaFileManager.class)).close();
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 26264
diff changeset
   142
            } catch (IOException e) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34560
diff changeset
   143
                throw new UncheckedIOException(e);
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 26264
diff changeset
   144
            }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34560
diff changeset
   145
            tr.setLogs(sw.toString(), sysOut.close(), sysErr.close());
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   146
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   147
        tr.setContext(context);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   148
        tr.show();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   149
        return tr;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   150
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   151
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   152
    enum Log { DIRECT, STDOUT, STDERR };
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   153
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   154
    class TestResult {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   155
        final List<String> args;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   156
        Throwable thrown;
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 26264
diff changeset
   157
        List<Throwable> suppressed = new ArrayList<>();
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   158
        Object rc; // Number or Boolean
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   159
        Map<Log, String> logs;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   160
        Context context;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   161
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   162
        TestResult(String... args) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   163
            this.args = Arrays.asList(args);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   164
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   165
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   166
        TestResult(List<String> args, Iterable<? extends JavaFileObject> files) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   167
            this.args = new ArrayList<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   168
            this.args.addAll(args);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   169
            for (JavaFileObject f: files)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   170
                this.args.add(f.getName());
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   171
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   172
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   173
        void setResult(int rc) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   174
            this.rc = rc;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   175
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   176
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   177
        void setResult(boolean ok) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   178
            this.rc = ok ? 0 : 1;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   179
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   180
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 26264
diff changeset
   181
        void setSuppressed(Throwable thrown) {
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 26264
diff changeset
   182
            this.suppressed.add(thrown);
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 26264
diff changeset
   183
        }
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 26264
diff changeset
   184
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   185
        void setThrown(Throwable thrown) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   186
            this.thrown = thrown;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   187
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   188
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   189
        void setLogs(String direct, String stdOut, String stdErr) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   190
            logs = new EnumMap<>(Log.class);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   191
            logs.put(Log.DIRECT, direct);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   192
            logs.put(Log.STDOUT, stdOut);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   193
            logs.put(Log.STDERR, stdErr);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   194
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   195
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   196
        void setContext(Context context) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   197
            this.context = context;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   198
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   199
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   200
        final void show() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   201
            String NL = System.getProperty("line.separator");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   202
            boolean needSep = false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   203
            if (rc != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   204
                out.print("rc:" + rc);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   205
                needSep = true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   206
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   207
            if (thrown != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   208
                if (needSep) out.print("; ");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   209
                out.print("thrown:" + thrown);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   210
                needSep = true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   211
            }
34560
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 26264
diff changeset
   212
            if (!suppressed.isEmpty()) {
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 26264
diff changeset
   213
                if (needSep) out.print("; ");
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 26264
diff changeset
   214
                out.print("suppressed:" + suppressed);
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 26264
diff changeset
   215
                needSep = true;
b6a567b677f7 8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents: 26264
diff changeset
   216
            }
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   217
            if (needSep)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   218
                out.println();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   219
            logs.forEach((k, v) -> {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   220
                if (!v.isEmpty()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   221
                    out.println("javac/" + k + ":");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   222
                    if (v.endsWith(NL))
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   223
                        out.print(v);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   224
                    else
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   225
                        out.println(v);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   226
                }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   227
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   228
            });
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   229
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   230
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   231
        TestResult checkOK() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   232
            if (thrown != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   233
                error("unexpected exception thrown: " + thrown);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   234
            } else if (rc == null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   235
                error("no result set");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   236
            } else if (rc != (Integer) 0 && rc != (Boolean) true) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   237
                error("compilation failed unexpectedly; rc=" + rc);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   238
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   239
            return this;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   240
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   241
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   242
        TestResult checkResult(int expect) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   243
            if (thrown != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   244
                error("unexpected exception thrown: " + thrown);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   245
            } else if (rc != (Integer) expect) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   246
                error("unexpected result: " + rc +", expected:" + expect);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   247
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   248
            return this;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   249
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   250
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   251
        TestResult checkResult(boolean expect) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   252
            if (thrown != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   253
                error("unexpected exception thrown: " + thrown);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   254
            } else if (rc != (Integer) (expect ? 0 : 1)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   255
                error("unexpected result: " + rc +", expected:" + expect);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   256
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   257
            return this;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   258
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   259
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   260
        TestResult checkLog(String... expects) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   261
            return checkLog(Log.DIRECT, expects);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   262
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   263
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   264
        TestResult checkLog(Log l, String... expects) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   265
            for (String e: expects) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   266
                if (!logs.get(l).contains(e))
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   267
                    error("expected string not found: " + e);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   268
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   269
            return this;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   270
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   271
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   272
        TestResult checkIllegalArgumentException() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   273
            return checkThrown(IllegalArgumentException.class);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   274
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   275
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   276
        TestResult checkIllegalStateException() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   277
            return checkThrown(IllegalStateException.class);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   278
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   279
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   280
        TestResult checkThrown(Class<? extends Throwable> t) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   281
            if (thrown == null)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   282
                error("expected exception not thrown: " + t);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   283
            else if (!t.isAssignableFrom(thrown.getClass()))
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   284
                error("unexpected exception thrown: " + thrown + ";  expected: " + t);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   285
            return this;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   286
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   287
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   288
        TestResult checkClass(String name) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   289
            Path p = getOutDir().resolve(name.replace(".", "/") + ".class");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   290
            if (!Files.exists(p))
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   291
                error("expected class not found: " + name + " (" + p + ")");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   292
            return this;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   293
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   294
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   295
        Path getOutDir() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   296
            Iterator<String> iter = args.iterator();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   297
            while (iter.hasNext()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   298
                if (iter.next().equals("-d")) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   299
                    return Paths.get(iter.next());
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   300
                }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   301
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   302
            return null;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   303
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   304
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   305
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   306
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   307
     * Utility class to simplify the handling of temporarily setting a
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   308
     * new stream for System.out or System.err.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   309
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   310
    private static class StreamOutput {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   311
        // functional interface to set a stream.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   312
        private interface Initializer {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   313
            void set(PrintStream s);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   314
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   315
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   316
        private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   317
        private final PrintStream ps = new PrintStream(baos);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   318
        private final PrintStream prev;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   319
        private final Initializer init;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   320
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   321
        StreamOutput(PrintStream s, Initializer init) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   322
            prev = s;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   323
            init.set(ps);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   324
            this.init = init;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   325
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   326
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   327
        String close() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   328
            init.set(prev);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   329
            ps.close();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   330
            return baos.toString();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   331
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   332
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   333
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   334
    List<JavaFileObject> getFiles(String... paths) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   335
        List<JavaFileObject> files = new ArrayList<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   336
        for (JavaFileObject f : fm.getJavaFileObjects(paths))
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   337
            files.add(f);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   338
        return files;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   339
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   340
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   341
    String toString(List<JavaFileObject> files) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   342
        return files.stream().map(f -> f.getName()).collect(Collectors.toList()).toString();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   343
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   344
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   345
    void mkdirs(String path) throws IOException {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   346
        Files.createDirectories(Paths.get(path));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   347
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   348
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   349
    void writeFile(String path, String body) throws IOException {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   350
        Path p = Paths.get(path);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   351
        if (p.getParent() != null)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   352
            Files.createDirectories(p.getParent());
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   353
        try (FileWriter w = new FileWriter(path)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   354
            w.write(body);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   355
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   356
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   357
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   358
    String[] join(String[] a, String[] b) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   359
        String[] result = new String[a.length + b.length];
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   360
        System.arraycopy(a, 0, result, 0, a.length);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   361
        System.arraycopy(b, 0, result, a.length, b.length);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   362
        return result;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   363
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   364
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   365
    void error(String message) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   366
        out.print(">>>>> ");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   367
        out.println(message);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   368
        errors++;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   369
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   370
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   371
    StandardJavaFileManager fm =
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   372
            ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   373
    PrintStream out = System.err;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   374
    int errors;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   375
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   376
}