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