1 /* 2 * Copyright (c) 2004, 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 5046815 27 * @summary Test that RMIServer.getVersion() reflects the JDK version when 28 * JMX is bundled into the Java platform and the application is run with a 29 * security manager and the test codebase has the java permission to read 30 * the "java.runtime.version" system property. 31 * @author Luis-Miguel Alventosa, Joel Feraud 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 60 // Get Java Home 61 String javaHome = System.getProperty("java.home"); 62 63 // Get test src 64 // 65 String testSrc = System.getProperty("test.src"); 66 67 // Get test classes 68 String testClasses = System.getProperty("test.classes"); 69 70 // Build command string 71 String command = 72 javaHome + File.separator + "bin" + File.separator + "java " + 73 " -classpath " + testClasses + 74 " -Djava.security.manager -Djava.security.policy==" + testSrc + 75 File.separator + "policy -Dtest.classes=" + testClasses + 76 " ImplVersionCommand " + System.getProperty("java.runtime.version"); 77 System.out.println("ImplVersionCommand Exec Command = " + command); 78 79 // Exec command 80 Process proc = Runtime.getRuntime().exec(command); 81 new ImplVersionReader(proc, proc.getInputStream()).start(); 82 new ImplVersionReader(proc, proc.getErrorStream()).start(); 83 int exitValue = proc.waitFor(); 84 85 System.out.println("ImplVersionCommand Exit Value = " + 86 exitValue); 87 if (exitValue != 0) { 88 System.out.println("TEST FAILED: Incorrect exit value " + 89 "from ImplVersionCommand"); 90 System.exit(exitValue); 91 } 92 // Test OK! 93 System.out.println("Bye! Bye!"); 94 } catch (Exception e) { 95 System.out.println("Unexpected exception caught = " + e); 96 e.printStackTrace(); 97 System.exit(1); 98 } 99 } 100 }