author | lana |
Thu, 02 Jun 2016 21:14:26 +0000 | |
changeset 38627 | 6dea0d12ee02 |
parent 30467 | 075f4f160f19 |
child 45944 | 882cea808912 |
permissions | -rw-r--r-- |
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. |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
33 |
* @compile TestMainWithoutEnclosing.java |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
34 |
* @run main TestMainWithoutEnclosing |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
35 |
*/ |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
36 |
public final class TestMainWithoutEnclosing extends TestHelper { |
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 |
static final String EnclosingName = "Enclosing"; |
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 void createJarFile(File testJar) throws IOException { |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
41 |
List<String> scratch = new ArrayList<>(); |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
42 |
scratch.add("public class Enclosing {"); |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
43 |
scratch.add(" public static final class Main {"); |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
44 |
scratch.add(" public static void main(String... args) {"); |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
45 |
scratch.add(" System.out.println(\"Hello World\");"); |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
46 |
scratch.add(" }"); |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
47 |
scratch.add(" }"); |
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 |
File enclosingFile = new File(EnclosingName + ".java"); |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
50 |
createFile(enclosingFile, scratch); |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
51 |
compile(enclosingFile.getName()); |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
52 |
// avoid side effects remove the Enclosing class |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
53 |
getClassFile(enclosingFile).delete(); |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
54 |
createJar("cvfe", testJar.getName(), EnclosingName + "$Main", |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
55 |
EnclosingName + "$Main" + ".class"); |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
56 |
// remove extraneous files in the current directory |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
57 |
new File(EnclosingName + "$Main" + ".class").delete(); |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
58 |
} |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
59 |
|
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
60 |
public static void main(String... args) throws IOException { |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
61 |
File testJarFile = new File("test.jar"); |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
62 |
createJarFile(testJarFile); |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
63 |
TestResult tr = doExec(javaCmd, "-jar", testJarFile.getName()); |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
64 |
if (!tr.isOK()) { |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
65 |
System.out.println(tr); |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
66 |
throw new RuntimeException("test returned non-positive value"); |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
67 |
} |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
68 |
if (!tr.contains("Hello World")) { |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
69 |
System.out.println(tr); |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
70 |
throw new RuntimeException("expected output not found"); |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
71 |
} |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
72 |
} |
075f4f160f19
8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents:
diff
changeset
|
73 |
} |