4954N/A/*
4954N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
4954N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4954N/A *
4954N/A * This code is free software; you can redistribute it and/or modify it
4954N/A * under the terms of the GNU General Public License version 2 only, as
4954N/A * published by the Free Software Foundation.
4954N/A *
4954N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4954N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4954N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4954N/A * version 2 for more details (a copy is included in the LICENSE file that
4954N/A * accompanied this code).
4954N/A *
4954N/A * You should have received a copy of the GNU General Public License version
4954N/A * 2 along with this work; if not, write to the Free Software Foundation,
4954N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4954N/A *
4954N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4954N/A * or visit www.oracle.com if you need additional information or have any
4954N/A * questions.
4954N/A */
4954N/A
4954N/A/*
4954N/A * see TestSpecialArgs.java
4954N/A * bug 7131021
4954N/A * summary Checks for environment variables set by the launcher
4954N/A * author anthony.petrov@oracle.com: area=launcher
4954N/A */
4954N/A
4954N/Apublic class EnvironmentVariables {
4954N/A public static void main(String[] args) {
4954N/A if (args.length != 2) {
4954N/A throw new RuntimeException("ERROR: two command line arguments expected");
4954N/A }
4954N/A
4954N/A String name = args[0];
4954N/A String expect = args[1];
4954N/A String key = null;
4954N/A
4954N/A if (!name.endsWith("*")) {
4954N/A key = name;
4954N/A } else {
4954N/A name = name.split("\\*")[0];
4954N/A
4954N/A for (String s : System.getenv().keySet()) {
4954N/A if (s.startsWith(name)) {
4954N/A if (key == null) {
4954N/A key = s;
4954N/A } else {
4954N/A System.err.println("WARNING: more variables match: " + s);
4954N/A }
4954N/A }
4954N/A }
4954N/A
4954N/A if (key == null) {
4954N/A throw new RuntimeException("ERROR: unable to find a match for: " + name);
4954N/A }
4954N/A }
4954N/A
4954N/A System.err.println("Will check the variable named: '" + key +
4954N/A "' expecting the value: '" + expect + "'");
4954N/A
4954N/A if (!System.getenv().containsKey(key)) {
4954N/A throw new RuntimeException("ERROR: the variable '" + key +
4954N/A "' is not present in the environment");
4954N/A }
4954N/A
4954N/A if (!expect.equals(System.getenv().get(key))) {
4954N/A throw new RuntimeException("ERROR: expected: '" + expect +
4954N/A "', got: '" + System.getenv().get(key) + "'");
4954N/A }
4954N/A for (String x : args) {
4954N/A System.err.print(x + " ");
4954N/A }
4954N/A System.err.println("-----> Passed!");
4954N/A }
4954N/A}
4954N/A