Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/util/ResourceBundle/Control/MissingResourceCauseTestRun.java
41155 views
1
/*
2
* Copyright (c) 2007, 2019, 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
/*
25
* @test
26
* @bug 4354216 8213127
27
* @summary Test for the cause support when throwing a
28
* MissingResourceBundle. (This test exists under
29
* ResourceBundle/Control because bad resource bundle data can be
30
* shared with other test cases.)
31
* @library /test/lib
32
* @build jdk.test.lib.JDKToolLauncher
33
* jdk.test.lib.Utils
34
* jdk.test.lib.process.ProcessTools
35
* MissingResourceCauseTest
36
* NonResourceBundle
37
* PrivateConstructorRB
38
* AbstractRB
39
* BadStaticInitRB
40
* NoNoArgConstructorRB
41
* @run main MissingResourceCauseTestRun
42
*/
43
44
import java.io.File;
45
import java.io.FileWriter;
46
import java.nio.file.Files;
47
import java.nio.file.Path;
48
import java.nio.file.Paths;
49
50
import jdk.test.lib.JDKToolLauncher;
51
import jdk.test.lib.Utils;
52
import jdk.test.lib.process.ProcessTools;
53
54
public class MissingResourceCauseTestRun {
55
public static void main(String[] args) throws Throwable {
56
Path path = Paths.get("UnreadableRB.properties");
57
Files.deleteIfExists(path);
58
try {
59
writeFile(path);
60
runCmd();
61
} finally {
62
deleteFile(path);
63
}
64
}
65
66
/**
67
* Create an unreadable properties file
68
*/
69
private static void writeFile(Path path) throws Throwable {
70
String str = "type=unreadable";
71
Files.createFile(path);
72
try (FileWriter fw = new FileWriter(path.toString())) {
73
fw.write(str);
74
}
75
ProcessTools.executeCommand("chmod", "000", path.toString())
76
.outputTo(System.out)
77
.errorTo(System.out)
78
.shouldHaveExitValue(0);
79
}
80
81
private static void runCmd() throws Throwable {
82
// Class files are in Utils.TEST_CLASSES
83
// MalformedDataRB_en.properties is in Utils.TEST_SRC
84
// UnreadableRB.properties is in current directory
85
String cp = Utils.TEST_CLASSES + File.pathSeparator + Utils.TEST_SRC
86
+ File.pathSeparator + ".";
87
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("java");
88
launcher.addToolArg("-ea")
89
.addToolArg("-esa")
90
.addToolArg("-cp")
91
.addToolArg(cp)
92
.addToolArg("MissingResourceCauseTest");
93
94
int exitCode = ProcessTools.executeCommand(launcher.getCommand())
95
.getExitValue();
96
if (exitCode != 0) {
97
throw new RuntimeException("Execution of the test failed. "
98
+ "Unexpected exit code: " + exitCode);
99
}
100
}
101
102
private static void deleteFile(Path path) throws Throwable {
103
if(path.toFile().exists()) {
104
ProcessTools.executeCommand("chmod", "666", path.toString())
105
.outputTo(System.out)
106
.errorTo(System.out)
107
.shouldHaveExitValue(0);
108
Files.delete(path);
109
}
110
}
111
}
112
113