blob: 06ae701a6c2a02621b3661c2e5950b49238b4ef4 [file] [log] [blame]
anthonye95261e2012-04-24 20:39:40 +04001/*
2 * Copyright (c) 2012, 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 * see TestSpecialArgs.java
26 * bug 7131021
27 * summary Checks for environment variables set by the launcher
28 * author anthony.petrov@oracle.com: area=launcher
29 */
30
31public class EnvironmentVariables {
32 public static void main(String[] args) {
33 if (args.length != 2) {
34 throw new RuntimeException("ERROR: two command line arguments expected");
35 }
36
37 String name = args[0];
38 String expect = args[1];
39 String key = null;
40
41 if (!name.endsWith("*")) {
42 key = name;
43 } else {
44 name = name.split("\\*")[0];
45
46 for (String s : System.getenv().keySet()) {
47 if (s.startsWith(name)) {
48 if (key == null) {
49 key = s;
50 } else {
51 System.err.println("WARNING: more variables match: " + s);
52 }
53 }
54 }
55
56 if (key == null) {
57 throw new RuntimeException("ERROR: unable to find a match for: " + name);
58 }
59 }
60
61 System.err.println("Will check the variable named: '" + key +
62 "' expecting the value: '" + expect + "'");
63
64 if (!System.getenv().containsKey(key)) {
65 throw new RuntimeException("ERROR: the variable '" + key +
66 "' is not present in the environment");
67 }
68
69 if (!expect.equals(System.getenv().get(key))) {
70 throw new RuntimeException("ERROR: expected: '" + expect +
71 "', got: '" + System.getenv().get(key) + "'");
72 }
73 for (String x : args) {
74 System.err.print(x + " ");
75 }
76 System.err.println("-----> Passed!");
77 }
78}
79