Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/tools/launcher/TestMainWithoutEnclosing.java
41144 views
1
/*
2
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import java.io.File;
25
import java.io.IOException;
26
import java.util.ArrayList;
27
import java.util.List;
28
29
/**
30
* @test
31
* @bug 8076264
32
* @summary Launching app shouldn't require enclosing class for the main class.
33
* @modules jdk.compiler
34
* jdk.zipfs
35
* @compile TestMainWithoutEnclosing.java
36
* @run main TestMainWithoutEnclosing
37
*/
38
public final class TestMainWithoutEnclosing extends TestHelper {
39
40
static final String EnclosingName = "Enclosing";
41
42
static void createJarFile(File testJar) throws IOException {
43
List<String> scratch = new ArrayList<>();
44
scratch.add("public class Enclosing {");
45
scratch.add(" public static final class Main {");
46
scratch.add(" public static void main(String... args) {");
47
scratch.add(" System.out.println(\"Hello World\");");
48
scratch.add(" }");
49
scratch.add(" }");
50
scratch.add("}");
51
File enclosingFile = new File(EnclosingName + ".java");
52
createFile(enclosingFile, scratch);
53
compile(enclosingFile.getName());
54
// avoid side effects remove the Enclosing class
55
getClassFile(enclosingFile).delete();
56
createJar("cvfe", testJar.getName(), EnclosingName + "$Main",
57
EnclosingName + "$Main" + ".class");
58
// remove extraneous files in the current directory
59
new File(EnclosingName + "$Main" + ".class").delete();
60
}
61
62
public static void main(String... args) throws IOException {
63
File testJarFile = new File("test.jar");
64
createJarFile(testJarFile);
65
TestResult tr = doExec(javaCmd, "-jar", testJarFile.getName());
66
if (!tr.isOK()) {
67
System.out.println(tr);
68
throw new RuntimeException("test returned non-positive value");
69
}
70
if (!tr.contains("Hello World")) {
71
System.out.println(tr);
72
throw new RuntimeException("expected output not found");
73
}
74
}
75
}
76
77