Path: blob/master/test/jdk/tools/launcher/TestMainWithoutEnclosing.java
41144 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.io.File;24import java.io.IOException;25import java.util.ArrayList;26import java.util.List;2728/**29* @test30* @bug 807626431* @summary Launching app shouldn't require enclosing class for the main class.32* @modules jdk.compiler33* jdk.zipfs34* @compile TestMainWithoutEnclosing.java35* @run main TestMainWithoutEnclosing36*/37public final class TestMainWithoutEnclosing extends TestHelper {3839static final String EnclosingName = "Enclosing";4041static void createJarFile(File testJar) throws IOException {42List<String> scratch = new ArrayList<>();43scratch.add("public class Enclosing {");44scratch.add(" public static final class Main {");45scratch.add(" public static void main(String... args) {");46scratch.add(" System.out.println(\"Hello World\");");47scratch.add(" }");48scratch.add(" }");49scratch.add("}");50File enclosingFile = new File(EnclosingName + ".java");51createFile(enclosingFile, scratch);52compile(enclosingFile.getName());53// avoid side effects remove the Enclosing class54getClassFile(enclosingFile).delete();55createJar("cvfe", testJar.getName(), EnclosingName + "$Main",56EnclosingName + "$Main" + ".class");57// remove extraneous files in the current directory58new File(EnclosingName + "$Main" + ".class").delete();59}6061public static void main(String... args) throws IOException {62File testJarFile = new File("test.jar");63createJarFile(testJarFile);64TestResult tr = doExec(javaCmd, "-jar", testJarFile.getName());65if (!tr.isOK()) {66System.out.println(tr);67throw new RuntimeException("test returned non-positive value");68}69if (!tr.contains("Hello World")) {70System.out.println(tr);71throw new RuntimeException("expected output not found");72}73}74}757677