langtools/test/tools/javac/api/T6430241.java
author avstepan
Tue, 19 May 2015 16:04:14 +0400
changeset 30655 d83f50188ca9
parent 27579 d1a63c99cdd5
child 30730 d3ce7619db2c
permissions -rw-r--r--
8080422: some docs cleanup for core libs Summary: some docs cleanup Reviewed-by: rriggs, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
     1
/*
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
     2
 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
     4
 *
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
     7
 * published by the Free Software Foundation.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
     8
 *
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    13
 * accompanied this code).
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    14
 *
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    18
 *
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    21
 * questions.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    22
 */
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    23
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    24
/*
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    25
 * @test
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    26
 * @bug 6430241
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    27
 * @summary Hard to disable symbol file feature through API
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    28
 * @library /tools/lib
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    29
 * @build ToolBox
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    30
 * @run main T6430241
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    31
 */
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    32
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    33
import java.io.*;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    34
import java.util.*;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    35
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    36
import javax.tools.*;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    37
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    38
import com.sun.source.util.JavacTask;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    39
import com.sun.tools.javac.api.JavacTool;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    40
import com.sun.tools.javac.file.JavacFileManager;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    41
import com.sun.tools.javac.util.Context;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    42
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    43
public class T6430241 {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    44
    public static void main(String... args) throws Exception {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    45
        new T6430241().run();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    46
    }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    47
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    48
    void run() throws Exception {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    49
        setup();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    50
        testCommandLine();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    51
        testSimpleAPI();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    52
        testTaskAPI();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    53
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    54
        if (errors > 0)
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    55
            throw new Exception(errors + " errors found");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    56
    }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    57
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    58
    void setup() throws Exception {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    59
        classesDir = new File("classes");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    60
        classesDir.mkdirs();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    61
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    62
        emptyDir = new File("empty");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    63
        emptyDir.mkdirs();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    64
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    65
        bootClassPath = createJar().getPath();
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    66
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    67
        File srcDir = new File("src");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    68
        String test = "import sun.misc.Unsafe; class Test { }";
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    69
        testFile = writeFile(srcDir, "Test.java", test);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    70
    }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    71
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    72
    //----- tests for command line invocation
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    73
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    74
    void testCommandLine() throws Exception {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    75
        testCommandLine(true);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    76
        testCommandLine(false, "-Xbootclasspath/p:" + emptyDir);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    77
        testCommandLine(false, "-Xbootclasspath:" + bootClassPath);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    78
        testCommandLine(false, "-Xbootclasspath/a:" + emptyDir);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    79
        testCommandLine(false, "-XDignore.symbol.file");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    80
        System.err.println();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    81
    }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    82
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    83
    void testCommandLine(boolean expectWarnings, String... opts) throws Exception {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    84
        System.err.println("test command line: " + Arrays.asList(opts));
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    85
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    86
        String[] args = initArgs(opts);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    87
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    88
        StringWriter sw = new StringWriter();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    89
        PrintWriter pw = new PrintWriter(sw);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    90
        int rc = com.sun.tools.javac.Main.compile(args, pw);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    91
        String out = showOutput(sw.toString());
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    92
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    93
        checkCompilationOK(rc);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    94
        checkOutput(out, expectWarnings);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    95
    }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    96
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    97
    //----- tests for simple API invocation
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    98
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
    99
    void testSimpleAPI() {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   100
        testSimpleAPI(true);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   101
        testSimpleAPI(false, "-Xbootclasspath/p:" + emptyDir);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   102
        testSimpleAPI(false, "-Xbootclasspath:" + bootClassPath);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   103
        testSimpleAPI(false, "-Xbootclasspath/a:" + emptyDir);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   104
        testSimpleAPI(false, "-XDignore.symbol.file");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   105
        System.err.println();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   106
    }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   107
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   108
    void testSimpleAPI(boolean expectWarnings, String... opts) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   109
        System.err.println("test simple API: " + Arrays.asList(opts));
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   110
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   111
        String[] args = initArgs(opts);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   112
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   113
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   114
        PrintStream ps = new PrintStream(baos);
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   115
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   116
        JavacTool tool = JavacTool.create();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   117
        int rc = tool.run(null, null, ps, args);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   118
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   119
        String out = showOutput(baos.toString());
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   120
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   121
        checkCompilationOK(rc);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   122
        checkOutput(out, expectWarnings);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   123
    }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   124
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   125
    //----- tests for CompilationTask API invocation
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   126
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   127
    void testTaskAPI() throws Exception {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   128
        List<File> bcp = new ArrayList<File>();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   129
        for (String f: bootClassPath.split(File.pathSeparator)) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   130
            if (!f.isEmpty())
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   131
                bcp.add(new File(f));
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   132
        }
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   133
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   134
        testTaskAPI(true, null);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   135
        testTaskAPI(false, bcp);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   136
        System.err.println();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   137
    }
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   138
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   139
    void testTaskAPI(boolean expectWarnings, Iterable<? extends File> pcp) throws Exception {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   140
        System.err.println("test task API: " + pcp);
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   141
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   142
        JavacTool tool = JavacTool.create();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   143
        try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   144
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   145
            if (pcp != null)
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   146
                fm.setLocation(StandardLocation.PLATFORM_CLASS_PATH, pcp);
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   147
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   148
            Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(testFile);
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   149
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   150
            StringWriter sw = new StringWriter();
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   151
            PrintWriter pw = new PrintWriter(sw);
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   152
            JavacTask task = tool.getTask(pw, fm, null, null, null, files);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   153
            boolean ok = task.call();
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   154
            String out = showOutput(sw.toString());
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   155
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   156
            checkCompilationOK(ok);
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   157
            checkOutput(out, expectWarnings);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   158
        }
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   159
    }
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   160
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   161
    //----- utility methods
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   162
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   163
    File createJar() throws IOException {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   164
        File f = new File("test.jar");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   165
        try (JavaFileManager fm = new JavacFileManager(new Context(), false, null)) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   166
            ToolBox tb = new ToolBox();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   167
            tb.new JarTask(f.getPath())
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   168
                .files(fm, StandardLocation.PLATFORM_CLASS_PATH, "java.lang.*", "sun.misc.*")
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   169
                .run();
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   170
        }
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   171
        return f;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   172
    }
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   173
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   174
    /**
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   175
     * Create a file with given content.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   176
     */
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   177
    File writeFile(File dir, String path, String content) throws IOException {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   178
        File f = new File(dir, path);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   179
        f.getParentFile().mkdirs();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   180
        FileWriter out = new FileWriter(f);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   181
        try {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   182
            out.write(content);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   183
        } finally {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   184
            out.close();
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   185
        }
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   186
        return f;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   187
    }
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   188
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   189
    /**
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   190
     * Initialize args for compilation with given opts.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   191
     * @return opts -d classesDir testFile
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   192
     */
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   193
    String[] initArgs(String[] opts) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   194
        List<String> args = new ArrayList<String>();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   195
        args.addAll(Arrays.asList(opts));
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   196
        args.add("-d");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   197
        args.add(classesDir.getPath());
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   198
        args.add(testFile.getPath());
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   199
        return args.toArray(new String[args.size()]);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   200
    }
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   201
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   202
    /**
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   203
     * Show output from compilation if non empty.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   204
     */
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   205
    String showOutput(String out) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   206
        if (!out.isEmpty())
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   207
            System.err.println(out);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   208
        return out;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   209
    }
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   210
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   211
    /**
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   212
     * Verify compilation succeeded.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   213
     */
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   214
    void checkCompilationOK(boolean ok) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   215
        if (!ok)
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   216
            error("compilation failed");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   217
    }
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   218
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   219
    /**
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   220
     * Verify compilation succeeded.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   221
     */
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   222
    void checkCompilationOK(int rc) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   223
        if (rc != 0)
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   224
            error("compilation failed, rc: " + rc);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   225
    }
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   226
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   227
    /**
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   228
     * Check whether output contains warnings if and only if warnings
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   229
     * are expected.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   230
     */
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   231
    void checkOutput(String out, boolean expectWarnings) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   232
        boolean foundWarnings = out.contains("warning");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   233
        if (foundWarnings) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   234
            if (!expectWarnings)
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   235
                error("unexpected warnings found");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   236
        } else {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   237
            if (expectWarnings)
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   238
                error("expected warnings not found");
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   239
        }
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   240
    }
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   241
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   242
    /**
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   243
     * Report an error.
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   244
     */
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   245
    void error(String msg) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   246
        System.err.println("error: " + msg);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   247
        errors++;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   248
    }
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   249
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   250
    String bootClassPath;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   251
    File classesDir;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   252
    File emptyDir;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   253
    File testFile;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   254
    int errors;
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 27319
diff changeset
   255
}