Path: blob/master/test/jdk/javax/management/ImplementationVersion/ImplVersionTest.java
41149 views
/*1* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 484219626* @summary Test that there is no difference between the JMX version and the27* JDK version when the application is run with a security manager and the28* test codebase has the java permission to read the "java.runtime.version"29* system property.30* @author Luis-Miguel Alventosa31*32* @run clean ImplVersionTest ImplVersionCommand33* @run build ImplVersionTest ImplVersionCommand ImplVersionReader34* @run main ImplVersionTest35*/3637import java.io.File;3839public class ImplVersionTest {4041public static void main(String[] args) {42try {43// Get OS name44//45String osName = System.getProperty("os.name");46System.out.println("osName = " + osName);47if ("Windows 98".equals(osName)) {48// Disable this test on Win98 due to parsing49// errors (bad handling of white spaces) when50// J2SE is installed under "Program Files".51//52System.out.println("This test is disabled on Windows 98.");53System.out.println("Bye! Bye!");54return;55}56// Get Java Home57//58String javaHome = System.getProperty("java.home");59System.out.println("javaHome = " + javaHome);60// Get test src61//62String testSrc = System.getProperty("test.src");63System.out.println("testSrc = " + testSrc);64// Get test classes65//66String testClasses = System.getProperty("test.classes");67System.out.println("testClasses = " + testClasses);68// Get boot class path69//70String command =71javaHome + File.separator + "bin" + File.separator + "java " +72" -classpath " + testClasses +73" -Djava.security.manager -Djava.security.policy==" + testSrc +74File.separator + "policy -Dtest.classes=" + testClasses +75" ImplVersionCommand " +76System.getProperty("java.runtime.version");77System.out.println("ImplVersionCommand Exec Command = " +command);78Process proc = Runtime.getRuntime().exec(command);79new ImplVersionReader(proc, proc.getInputStream()).start();80new ImplVersionReader(proc, proc.getErrorStream()).start();81int exitValue = proc.waitFor();82System.out.println("ImplVersionCommand Exit Value = " +83exitValue);84if (exitValue != 0) {85System.out.println("TEST FAILED: Incorrect exit value " +86"from ImplVersionCommand");87System.exit(exitValue);88}89// Test OK!90//91System.out.println("Bye! Bye!");92} catch (Exception e) {93System.out.println("Unexpected exception caught = " + e);94e.printStackTrace();95System.exit(1);96}97}98}99100101