jdk/test/javax/management/remote/mandatory/version/ImplVersionTest.java
author lana
Thu, 26 Dec 2013 12:04:16 -0800
changeset 23010 6dadb192ad81
parent 5506 202f599c92aa
child 30376 2ccf2cf7ea48
permissions -rw-r--r--
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013 Summary: updated files with 2011, 2012 and 2013 years according to the file's last updated date Reviewed-by: tbell, lancea, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2004, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 5046815
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test that RMIServer.getVersion() reflects the JDK version when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * JMX is bundled into the Java platform and the application is run with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * security manager and the test codebase has the java permission to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * the "java.runtime.version" system property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @author Luis-Miguel Alventosa, Joel Feraud
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run clean ImplVersionTest ImplVersionCommand
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @run build ImplVersionTest ImplVersionCommand ImplVersionReader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @run main ImplVersionTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.security.CodeSource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class ImplVersionTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
            // Get OS name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
            String osName = System.getProperty("os.name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
            System.out.println("osName = " + osName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
            if ("Windows 98".equals(osName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                // Disable this test on Win98 due to parsing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                // errors (bad handling of white spaces) when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
                // J2SE is installed under "Program Files".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                System.out.println("This test is disabled on Windows 98.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                System.out.println("Bye! Bye!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            // Get Java Home
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            String javaHome = System.getProperty("java.home");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            // Get test src
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            String testSrc = System.getProperty("test.src");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            // Get test classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            String testClasses = System.getProperty("test.classes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            // Get boot class path
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            String bootClassPath = System.getProperty("sun.boot.class.path");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            // Build command string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            String command =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                javaHome + File.separator + "bin" + File.separator + "java " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                " -Xbootclasspath/p:" + bootClassPath +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                " -classpath " + testClasses +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                " -Djava.security.manager -Djava.security.policy==" + testSrc +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                File.separator + "policy -Dtest.classes=" + testClasses +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                " ImplVersionCommand " + System.getProperty("java.runtime.version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            System.out.println("ImplVersionCommand Exec Command = " + command);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            // Exec command
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            Process proc = Runtime.getRuntime().exec(command);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            new ImplVersionReader(proc, proc.getInputStream()).start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            new ImplVersionReader(proc, proc.getErrorStream()).start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            int exitValue = proc.waitFor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            System.out.println("ImplVersionCommand Exit Value = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                               exitValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            if (exitValue != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                System.out.println("TEST FAILED: Incorrect exit value " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                                   "from ImplVersionCommand");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                System.exit(exitValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            // Test OK!
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            System.out.println("Bye! Bye!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            System.out.println("Unexpected exception caught = " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
}