1 /* 2 * Copyright (c) 2003, 2015, 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 * @modules java.management 33 * @run clean ImplVersionTest ImplVersionCommand 34 * @run build ImplVersionTest ImplVersionCommand ImplVersionReader 35 * @run main ImplVersionTest 36 */ 37 38 import java.io.File; 39 import java.security.CodeSource; 40 import javax.management.MBeanServer; 41 42 public class ImplVersionTest { 43 44 public static void main(String[] args) { 45 try { 46 // Get OS name 47 // 48 String osName = System.getProperty("os.name"); 49 System.out.println("osName = " + osName); 50 if ("Windows 98".equals(osName)) { 51 // Disable this test on Win98 due to parsing 52 // errors (bad handling of white spaces) when 53 // J2SE is installed under "Program Files". 54 // 55 System.out.println("This test is disabled on Windows 98."); 56 System.out.println("Bye! Bye!"); 57 return; 58 } 59 // Get Java Home 60 // 61 String javaHome = System.getProperty("java.home"); 62 System.out.println("javaHome = " + javaHome); 63 // Get test src 64 // 65 String testSrc = System.getProperty("test.src"); 66 System.out.println("testSrc = " + testSrc); 67 // Get test classes 68 // 69 String testClasses = System.getProperty("test.classes"); 70 System.out.println("testClasses = " + testClasses); 71 // Get boot class path 72 // 73 boolean checkVersion = true; 74 String bootClassPath = System.getProperty("sun.boot.class.path"); 75 if (bootClassPath != null && 76 bootClassPath.indexOf("jmxri.jar") != -1) 77 checkVersion = false; 78 String command = 79 javaHome + File.separator + "bin" + File.separator + "java " + 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 }