test/jdk/tools/launcher/TestMainWithoutEnclosing.java
author mr
Wed, 16 Jan 2019 16:27:21 -0800
changeset 53372 4003935e6e5f
parent 47216 71c04702a3d5
permissions -rw-r--r--
8216532: tools/launcher/Test7029048.java fails (Solaris) Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30467
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
     1
/*
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
     4
 *
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
     8
 *
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    13
 * accompanied this code).
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    14
 *
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    18
 *
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    21
 * questions.
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    22
 */
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    23
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    24
import java.io.File;
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    25
import java.io.IOException;
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    26
import java.util.ArrayList;
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    27
import java.util.List;
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    28
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    29
/**
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    30
 * @test
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    31
 * @bug 8076264
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    32
 * @summary Launching app shouldn't require enclosing class for the main class.
45944
882cea808912 8179292: a number of launcher tests fail when run with --limit-modules due to CNFE: javax.tools.ToolProvider
anazarov
parents: 30467
diff changeset
    33
 * @modules jdk.compiler
882cea808912 8179292: a number of launcher tests fail when run with --limit-modules due to CNFE: javax.tools.ToolProvider
anazarov
parents: 30467
diff changeset
    34
 *          jdk.zipfs
30467
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    35
 * @compile TestMainWithoutEnclosing.java
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    36
 * @run main TestMainWithoutEnclosing
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    37
 */
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    38
public final class TestMainWithoutEnclosing extends TestHelper {
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    39
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    40
    static final String EnclosingName = "Enclosing";
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    41
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    42
    static void createJarFile(File testJar) throws IOException {
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    43
        List<String> scratch = new ArrayList<>();
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    44
        scratch.add("public class Enclosing {");
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    45
        scratch.add("    public static final class Main {");
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    46
        scratch.add("        public static void main(String... args) {");
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    47
        scratch.add("            System.out.println(\"Hello World\");");
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    48
        scratch.add("        }");
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    49
        scratch.add("    }");
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    50
        scratch.add("}");
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    51
        File enclosingFile = new File(EnclosingName + ".java");
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    52
        createFile(enclosingFile, scratch);
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    53
        compile(enclosingFile.getName());
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    54
        // avoid side effects remove the Enclosing class
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    55
        getClassFile(enclosingFile).delete();
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    56
        createJar("cvfe", testJar.getName(), EnclosingName + "$Main",
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    57
                EnclosingName + "$Main" + ".class");
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    58
        // remove extraneous files in the current directory
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    59
        new File(EnclosingName + "$Main" + ".class").delete();
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    60
    }
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    61
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    62
    public static void main(String... args) throws IOException {
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    63
        File testJarFile = new File("test.jar");
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    64
        createJarFile(testJarFile);
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    65
        TestResult tr = doExec(javaCmd, "-jar", testJarFile.getName());
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    66
        if (!tr.isOK()) {
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    67
            System.out.println(tr);
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    68
            throw new RuntimeException("test returned non-positive value");
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    69
        }
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    70
        if (!tr.contains("Hello World")) {
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    71
            System.out.println(tr);
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    72
            throw new RuntimeException("expected output not found");
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    73
        }
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    74
    }
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff changeset
    75
}