langtools/test/tools/javac/file/LimitedImage.java
author jlahoda
Mon, 22 Aug 2016 09:59:43 +0200
changeset 40513 39b67170b045
child 40599 be40838eb215
permissions -rw-r--r--
8153391: an image created for \"jdk.compiler\" fails to run javac Summary: Improving errors produced by javac when the zipfs implementation is missing in the JDK image. Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40513
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
     1
/*
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
     4
 *
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
     8
 *
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    13
 * accompanied this code).
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    14
 *
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    18
 *
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    21
 * questions.
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    22
 */
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    23
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    24
/**
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    25
 * @test
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    26
 * @bug 8153391
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    27
 * @summary Verify javac behaves properly in absence of zip/jar FileSystemProvider
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    28
 * @library /tools/lib
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    29
 * @modules jdk.compiler/com.sun.tools.javac.api
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    30
 *          jdk.compiler/com.sun.tools.javac.main
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    31
 * @run main/othervm -limitmods jdk.compiler LimitedImage
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    32
 */
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    33
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    34
import java.io.IOException;
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    35
import java.nio.file.Path;
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    36
import java.nio.file.Paths;
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    37
import java.util.Arrays;
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    38
import java.util.List;
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    39
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    40
import toolbox.JavacTask;
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    41
import toolbox.JarTask;
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    42
import toolbox.Task.Expect;
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    43
import toolbox.Task.Mode;
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    44
import toolbox.Task.OutputKind;
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    45
import toolbox.ToolBox;
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    46
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    47
public class LimitedImage {
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    48
    public static void main(String... args) throws IOException {
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    49
        ToolBox tb = new ToolBox();
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    50
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    51
        //showing help should be OK
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    52
        new JavacTask(tb, Mode.CMDLINE)
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    53
                .options("--help")
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    54
                .run().writeAll();
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    55
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    56
        Path testSource = Paths.get("Test.java");
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    57
        tb.writeFile(testSource, "class Test {}");
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    58
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    59
        //when zip/jar FS is not needed, compilation should succeed
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    60
        new JavacTask(tb, Mode.CMDLINE)
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    61
                .classpath()
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    62
                .files(testSource)
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    63
                .outdir(".")
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    64
                .run()
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    65
                .writeAll();
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    66
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    67
        Path testJar = Paths.get("test.jar").toAbsolutePath();
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    68
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    69
        new JarTask(tb, testJar).run();
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    70
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    71
        List<String> actualOutput;
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    72
        List<String> expectedOutput = Arrays.asList(
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    73
                "- compiler.err.no.zipfs.for.archive: " + testJar.toString()
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    74
        );
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    75
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    76
        //check proper diagnostics when zip/jar FS not present:
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    77
        actualOutput = new JavacTask(tb, Mode.CMDLINE)
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    78
                .classpath(testJar)
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    79
                .options("-XDrawDiagnostics")
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    80
                .files(testSource)
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    81
                .outdir(".")
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    82
                .run(Expect.FAIL)
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    83
                .writeAll()
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    84
                .getOutputLines(OutputKind.DIRECT);
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    85
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    86
        if (!expectedOutput.equals(actualOutput)) {
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    87
            throw new AssertionError("Unexpected output: " + actualOutput);
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    88
        }
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    89
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    90
        actualOutput = new JavacTask(tb, Mode.CMDLINE)
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    91
                .sourcepath(testJar)
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    92
                .options("-XDrawDiagnostics")
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    93
                .files(testSource)
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    94
                .outdir(".")
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    95
                .run(Expect.FAIL)
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    96
                .writeAll()
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    97
                .getOutputLines(OutputKind.DIRECT);
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    98
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
    99
        if (!expectedOutput.equals(actualOutput)) {
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   100
            throw new AssertionError("Unexpected output: " + actualOutput);
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   101
        }
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   102
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   103
        actualOutput = new JavacTask(tb, Mode.CMDLINE)
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   104
                .options("-XDrawDiagnostics",
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   105
                         "--module-path", testJar.toString())
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   106
                .files(testSource)
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   107
                .outdir(".")
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   108
                .run(Expect.FAIL)
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   109
                .writeAll()
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   110
                .getOutputLines(OutputKind.DIRECT);
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   111
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   112
        if (!expectedOutput.equals(actualOutput)) {
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   113
            throw new AssertionError("Unexpected output: " + actualOutput);
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   114
        }
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   115
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   116
        expectedOutput = Arrays.asList(
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   117
                "- compiler.err.no.zipfs.for.archive: " + testJar.toString(),
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   118
                "1 error"
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   119
        );
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   120
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   121
        actualOutput = new JavacTask(tb, Mode.CMDLINE)
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   122
                .classpath()
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   123
                .options("-XDrawDiagnostics",
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   124
                         "--module-path", testJar.getParent().toString())
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   125
                .files(testSource)
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   126
                .outdir(".")
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   127
                .run(Expect.FAIL)
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   128
                .writeAll()
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   129
                .getOutputLines(OutputKind.DIRECT);
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   130
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   131
        if (!expectedOutput.equals(actualOutput)) {
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   132
            throw new AssertionError("Unexpected output: " + actualOutput);
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   133
        }
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   134
    }
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   135
39b67170b045 8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
diff changeset
   136
}