jdk/test/tools/launcher/EnvironmentVariables.java
author prr
Tue, 01 Jul 2014 10:20:56 -0700
changeset 25211 2476da7d73bf
parent 12527 22abaf748b5b
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12527
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
     1
/*
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
     4
 *
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
     7
 * published by the Free Software Foundation.
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
     8
 *
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    13
 * accompanied this code).
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    14
 *
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    18
 *
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    21
 * questions.
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    22
 */
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    23
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    24
/*
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    25
 * see TestSpecialArgs.java
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    26
 * bug 7131021
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    27
 * summary Checks for environment variables set by the launcher
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    28
 * author anthony.petrov@oracle.com: area=launcher
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    29
 */
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    30
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    31
public class EnvironmentVariables {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    32
    public static void main(String[] args) {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    33
        if (args.length != 2) {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    34
            throw new RuntimeException("ERROR: two command line arguments expected");
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    35
        }
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    36
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    37
        String name = args[0];
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    38
        String expect = args[1];
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    39
        String key = null;
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    40
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    41
        if (!name.endsWith("*")) {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    42
            key = name;
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    43
        } else {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    44
            name = name.split("\\*")[0];
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    45
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    46
            for (String s : System.getenv().keySet()) {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    47
                if (s.startsWith(name)) {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    48
                    if (key == null) {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    49
                        key = s;
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    50
                    } else {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    51
                        System.err.println("WARNING: more variables match: " + s);
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    52
                    }
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    53
                }
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    54
            }
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    55
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    56
            if (key == null) {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    57
                throw new RuntimeException("ERROR: unable to find a match for: " + name);
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    58
            }
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    59
        }
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    60
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    61
        System.err.println("Will check the variable named: '" + key +
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    62
                "' expecting the value: '" + expect + "'");
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    63
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    64
        if (!System.getenv().containsKey(key)) {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    65
            throw new RuntimeException("ERROR: the variable '" + key +
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    66
                    "' is not present in the environment");
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    67
        }
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    68
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    69
        if (!expect.equals(System.getenv().get(key))) {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    70
            throw new RuntimeException("ERROR: expected: '" + expect +
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    71
                    "', got: '" + System.getenv().get(key) + "'");
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    72
        }
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    73
        for (String x : args) {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    74
            System.err.print(x + " ");
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    75
        }
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    76
        System.err.println("-----> Passed!");
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    77
    }
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    78
}
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    79