Mercurial > hg > truffle
comparison test/runtime/CheckEndorsedAndExtDirs/EndorsedExtDirs.java @ 20684:c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
Reviewed-by: hseigel, ccheung
author | mchung |
---|---|
date | Tue, 02 Dec 2014 08:42:50 -0800 |
parents | fa6adc194d48 |
children | 28f116adb50c |
comparison
equal
deleted
inserted
replaced
20682:b12418b0d05c | 20684:c03d85ef5e6a |
---|---|
24 /* | 24 /* |
25 * @test | 25 * @test |
26 * @bug 8064667 | 26 * @bug 8064667 |
27 * @summary Sanity test for -XX:+CheckEndorsedAndExtDirs | 27 * @summary Sanity test for -XX:+CheckEndorsedAndExtDirs |
28 * @library /testlibrary | 28 * @library /testlibrary |
29 * @run main/othervm -XX:+CheckEndorsedAndExtDirs EndorsedExtDirs | 29 * @run main/othervm EndorsedExtDirs |
30 */ | 30 */ |
31 | 31 |
32 import com.oracle.java.testlibrary.*; | 32 import com.oracle.java.testlibrary.*; |
33 import java.io.File; | |
34 import java.io.IOException; | |
35 import java.nio.file.attribute.BasicFileAttributes; | |
36 import java.nio.file.Files; | |
37 import java.nio.file.Path; | |
38 import java.nio.file.Paths; | |
33 import java.util.ArrayList; | 39 import java.util.ArrayList; |
34 import java.util.List; | 40 import java.util.List; |
35 | 41 |
36 public class EndorsedExtDirs { | 42 public class EndorsedExtDirs { |
37 static final String cpath = System.getProperty("test.classes", "."); | 43 static final String cpath = System.getProperty("test.classes", "."); |
38 public static void main(String arg[]) throws Exception { | 44 public static void main(String arg[]) throws Exception { |
39 fatalError("-XX:+CheckEndorsedAndExtDirs", "-Djava.endorsed.dirs=foo"); | 45 fatalError("-XX:+CheckEndorsedAndExtDirs", "-Djava.endorsed.dirs=foo"); |
40 fatalError("-XX:+CheckEndorsedAndExtDirs", "-Djava.ext.dirs=bar"); | 46 fatalError("-XX:+CheckEndorsedAndExtDirs", "-Djava.ext.dirs=bar"); |
47 testNonEmptySystemExtDirs(); | |
41 } | 48 } |
42 | 49 |
43 static void fatalError(String... args) throws Exception { | 50 static void testNonEmptySystemExtDirs() throws Exception { |
51 String home = System.getProperty("java.home"); | |
52 Path ext = Paths.get(home, "lib", "ext"); | |
53 String extDirs = System.getProperty("java.ext.dirs"); | |
54 String[] dirs = extDirs.split(File.pathSeparator); | |
55 long count = 0; | |
56 for (String d : dirs) { | |
57 Path path = Paths.get(d); | |
58 if (Files.notExists(path) || path.equals(ext)) continue; | |
59 count += Files.find(path, 1, (Path p, BasicFileAttributes attr) | |
60 -> p.getFileName().toString().endsWith(".jar")) | |
61 .count(); | |
62 } | |
63 if (count > 0) { | |
64 fatalError("-XX:+CheckEndorsedAndExtDirs"); | |
65 } | |
66 } | |
67 | |
68 static ProcessBuilder newProcessBuilder(String... args) { | |
44 List<String> commands = new ArrayList<>(); | 69 List<String> commands = new ArrayList<>(); |
45 String java = System.getProperty("java.home") + "/bin/java"; | 70 String java = System.getProperty("java.home") + "/bin/java"; |
46 commands.add(java); | 71 commands.add(java); |
47 for (String s : args) { | 72 for (String s : args) { |
48 commands.add(s); | 73 commands.add(s); |
49 } | 74 } |
50 commands.add("-cp"); | 75 commands.add("-cp"); |
51 commands.add(cpath); | 76 commands.add(cpath); |
52 commands.add("EndorsedExtDirs"); | 77 commands.add("EndorsedExtDirs"); |
53 | 78 |
54 System.out.println("Launching " + commands); | 79 System.out.println("Process " + commands); |
55 ProcessBuilder pb = new ProcessBuilder(commands); | 80 return new ProcessBuilder(commands); |
81 } | |
82 | |
83 static void fatalError(String... args) throws Exception { | |
84 fatalError(newProcessBuilder(args)); | |
85 } | |
86 | |
87 static void fatalError(ProcessBuilder pb) throws Exception { | |
56 OutputAnalyzer output = new OutputAnalyzer(pb.start()); | 88 OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
57 output.shouldContain("Could not create the Java Virtual Machine"); | 89 output.shouldContain("Could not create the Java Virtual Machine"); |
58 output.shouldHaveExitValue(1); | 90 output.shouldHaveExitValue(1); |
59 } | 91 } |
60 } | 92 } |