1 /*
   2  * Copyright (c) 2003, 2006, 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 4842196
  27  * @summary Test that there is no difference between the JMX version and the
  28  * JDK version when JMX is bundled into the Java platform and the application
  29  * is run with a security manager and the test codebase has the java permission
  30  * to read the "java.runtime.version" system property.
  31  * @author Luis-Miguel Alventosa
  32  * @run clean ImplVersionTest ImplVersionCommand
  33  * @run build ImplVersionTest ImplVersionCommand ImplVersionReader
  34  * @run main ImplVersionTest
  35  */
  36 
  37 import java.io.File;
  38 import java.security.CodeSource;
  39 import javax.management.MBeanServer;
  40 
  41 public class ImplVersionTest {
  42 
  43     public static void main(String[] args) {
  44         try {
  45             // Get OS name
  46             //
  47             String osName = System.getProperty("os.name");
  48             System.out.println("osName = " + osName);
  49             if ("Windows 98".equals(osName)) {
  50                 // Disable this test on Win98 due to parsing
  51                 // errors (bad handling of white spaces) when
  52                 // J2SE is installed under "Program Files".
  53                 //
  54                 System.out.println("This test is disabled on Windows 98.");
  55                 System.out.println("Bye! Bye!");
  56                 return;
  57             }
  58             // Get Java Home
  59             //
  60             String javaHome = System.getProperty("java.home");
  61             System.out.println("javaHome = " + javaHome);
  62             // Get test src
  63             //
  64             String testSrc = System.getProperty("test.src");
  65             System.out.println("testSrc = " + testSrc);
  66             // Get test classes
  67             //
  68             String testClasses = System.getProperty("test.classes");
  69             System.out.println("testClasses = " + testClasses);
  70             // Get boot class path
  71             //
  72             boolean checkVersion = true;
  73             String bootClassPath = System.getProperty("sun.boot.class.path");
  74             if (bootClassPath != null &&
  75                 bootClassPath.indexOf("jmxri.jar") != -1)
  76                 checkVersion = false;
  77             String command =
  78                 javaHome + File.separator + "bin" + File.separator + "java " +
  79                 " -Xbootclasspath/p:" + bootClassPath +
  80                 " -classpath " + testClasses +
  81                 " -Djava.security.manager -Djava.security.policy==" + testSrc +
  82                 File.separator + "policy -Dtest.classes=" + testClasses +
  83                 " ImplVersionCommand " +
  84                 System.getProperty("java.runtime.version") + " " + checkVersion;
  85             System.out.println("ImplVersionCommand Exec Command = " +command);
  86             Process proc = Runtime.getRuntime().exec(command);
  87             new ImplVersionReader(proc, proc.getInputStream()).start();
  88             new ImplVersionReader(proc, proc.getErrorStream()).start();
  89             int exitValue = proc.waitFor();
  90             System.out.println("ImplVersionCommand Exit Value = " +
  91                                exitValue);
  92             if (exitValue != 0) {
  93                 System.out.println("TEST FAILED: Incorrect exit value " +
  94                                    "from ImplVersionCommand");
  95                 System.exit(exitValue);
  96             }
  97             // Test OK!
  98             //
  99             System.out.println("Bye! Bye!");
 100         } catch (Exception e) {
 101             System.out.println("Unexpected exception caught = " + e);
 102             e.printStackTrace();
 103             System.exit(1);
 104         }
 105     }
 106 }