1/*
2 * Copyright (c) 2014, 2016, 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 8060206 8067366
27 * @library /lib/testlibrary
28 * @summary Extension mechanism is removed
29 */
30
31import jdk.testlibrary.ProcessTools;
32
33import java.lang.Integer;
34import java.util.stream.Stream;
35
36public class ExtDirs {
37    private static String TEST_CLASSES = System.getProperty("test.classes", ".");
38
39    private static String[] VALUES = new String[] {
40            null,
41            "",
42            "\"\""
43    };
44
45    public static void main(String... args) throws Exception {
46        String value = System.getProperty("java.ext.dirs");
47        System.out.format("java.ext.dirs = '%s'%n", value);
48        if (args.length > 0) {
49            int index = Integer.valueOf(args[0]);
50            String expectedValue = VALUES[index];
51            if (!(expectedValue == value ||
52                    (value != null && value.isEmpty()) ||
53                    (expectedValue != null & expectedValue.equals(value)))) {
54                throw new RuntimeException("java.ext.dirs (" +
55                        value + ") != " + expectedValue);
56            }
57            // launched by subprocess.
58            return;
59        }
60
61        if (value != null) {
62            throw new RuntimeException("java.ext.dirs not removed: " + value);
63        }
64
65        fatalError(0, "-Djava.ext.dirs=foo");
66        start(0);
67        start(1, "-Djava.ext.dirs=");
68        start(2, "-Djava.ext.dirs=\"\"");
69    }
70
71    static String[] launchOptions(int testParam, String... args) {
72        return Stream.concat(Stream.of(args),
73                             Stream.of("-cp", TEST_CLASSES, "ExtDirs",
74                                       String.valueOf(testParam)))
75                     .toArray(String[]::new);
76    }
77
78    static void start(int testParam, String... args) throws Exception {
79        ProcessTools.executeTestJava(launchOptions(testParam, args))
80                    .shouldHaveExitValue(0);
81    }
82
83    static void fatalError(int testParam, String... args) throws Exception {
84        ProcessTools.executeTestJava(launchOptions(testParam, args))
85                    .stderrShouldContain("Could not create the Java Virtual Machine");
86    }
87}
88