Mercurial > hg > truffle
annotate test/runtime/CheckEndorsedAndExtDirs/EndorsedExtDirs.java @ 21115:db96f9915540
Merge
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Thu, 23 Apr 2015 22:09:27 -0700 |
parents | 28f116adb50c |
children |
rev | line source |
---|---|
20654 | 1 /* |
2 * Copyright (c) 2014, 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 8064667 | |
27 * @summary Sanity test for -XX:+CheckEndorsedAndExtDirs | |
28 * @library /testlibrary | |
20709
28f116adb50c
8067232: [TESTBUG] runtime/CheckEndorsedAndExtDirs/EndorsedExtDirs.java fails with ClassNotFoundException
mseledtsov
parents:
20684
diff
changeset
|
29 * @build com.oracle.java.testlibrary.* |
20684
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
30 * @run main/othervm EndorsedExtDirs |
20654 | 31 */ |
32 | |
33 import com.oracle.java.testlibrary.*; | |
20684
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
34 import java.io.File; |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
35 import java.io.IOException; |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
36 import java.nio.file.attribute.BasicFileAttributes; |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
37 import java.nio.file.Files; |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
38 import java.nio.file.Path; |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
39 import java.nio.file.Paths; |
20654 | 40 import java.util.ArrayList; |
41 import java.util.List; | |
42 | |
43 public class EndorsedExtDirs { | |
44 static final String cpath = System.getProperty("test.classes", "."); | |
45 public static void main(String arg[]) throws Exception { | |
46 fatalError("-XX:+CheckEndorsedAndExtDirs", "-Djava.endorsed.dirs=foo"); | |
47 fatalError("-XX:+CheckEndorsedAndExtDirs", "-Djava.ext.dirs=bar"); | |
20684
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
48 testNonEmptySystemExtDirs(); |
20654 | 49 } |
50 | |
20684
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
51 static void testNonEmptySystemExtDirs() throws Exception { |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
52 String home = System.getProperty("java.home"); |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
53 Path ext = Paths.get(home, "lib", "ext"); |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
54 String extDirs = System.getProperty("java.ext.dirs"); |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
55 String[] dirs = extDirs.split(File.pathSeparator); |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
56 long count = 0; |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
57 for (String d : dirs) { |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
58 Path path = Paths.get(d); |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
59 if (Files.notExists(path) || path.equals(ext)) continue; |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
60 count += Files.find(path, 1, (Path p, BasicFileAttributes attr) |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
61 -> p.getFileName().toString().endsWith(".jar")) |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
62 .count(); |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
63 } |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
64 if (count > 0) { |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
65 fatalError("-XX:+CheckEndorsedAndExtDirs"); |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
66 } |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
67 } |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
68 |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
69 static ProcessBuilder newProcessBuilder(String... args) { |
20654 | 70 List<String> commands = new ArrayList<>(); |
71 String java = System.getProperty("java.home") + "/bin/java"; | |
72 commands.add(java); | |
73 for (String s : args) { | |
74 commands.add(s); | |
75 } | |
76 commands.add("-cp"); | |
77 commands.add(cpath); | |
78 commands.add("EndorsedExtDirs"); | |
79 | |
20684
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
80 System.out.println("Process " + commands); |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
81 return new ProcessBuilder(commands); |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
82 } |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
83 |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
84 static void fatalError(String... args) throws Exception { |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
85 fatalError(newProcessBuilder(args)); |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
86 } |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
87 |
c03d85ef5e6a
8065765: Missing space in output message from -XX:+CheckEndorsedAndExtDirs
mchung
parents:
20654
diff
changeset
|
88 static void fatalError(ProcessBuilder pb) throws Exception { |
20654 | 89 OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
90 output.shouldContain("Could not create the Java Virtual Machine"); | |
91 output.shouldHaveExitValue(1); | |
92 } | |
93 } |