Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/ImplementationVersion/ImplVersionTest.java
38838 views
/*1* Copyright (c) 2003, 2006, 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 JMX is bundled into the Java platform and the application28* is run with a security manager and the test codebase has the java permission29* to read the "java.runtime.version" system property.30* @author Luis-Miguel Alventosa31* @run clean ImplVersionTest ImplVersionCommand32* @run build ImplVersionTest ImplVersionCommand ImplVersionReader33* @run main ImplVersionTest34*/3536import java.io.File;37import java.security.CodeSource;38import javax.management.MBeanServer;3940public class ImplVersionTest {4142public static void main(String[] args) {43try {44// Get OS name45//46String osName = System.getProperty("os.name");47System.out.println("osName = " + osName);48if ("Windows 98".equals(osName)) {49// Disable this test on Win98 due to parsing50// errors (bad handling of white spaces) when51// J2SE is installed under "Program Files".52//53System.out.println("This test is disabled on Windows 98.");54System.out.println("Bye! Bye!");55return;56}57// Get Java Home58//59String javaHome = System.getProperty("java.home");60System.out.println("javaHome = " + javaHome);61// Get test src62//63String testSrc = System.getProperty("test.src");64System.out.println("testSrc = " + testSrc);65// Get test classes66//67String testClasses = System.getProperty("test.classes");68System.out.println("testClasses = " + testClasses);69// Get boot class path70//71boolean checkVersion = true;72String bootClassPath = System.getProperty("sun.boot.class.path");73if (bootClassPath != null &&74bootClassPath.indexOf("jmxri.jar") != -1)75checkVersion = false;76String command =77javaHome + File.separator + "bin" + File.separator + "java " +78" -Xbootclasspath/p:" + bootClassPath +79" -classpath " + testClasses +80" -Djava.security.manager -Djava.security.policy==" + testSrc +81File.separator + "policy -Dtest.classes=" + testClasses +82" ImplVersionCommand " +83System.getProperty("java.runtime.version") + " " + checkVersion;84System.out.println("ImplVersionCommand Exec Command = " +command);85Process proc = Runtime.getRuntime().exec(command);86new ImplVersionReader(proc, proc.getInputStream()).start();87new ImplVersionReader(proc, proc.getErrorStream()).start();88int exitValue = proc.waitFor();89System.out.println("ImplVersionCommand Exit Value = " +90exitValue);91if (exitValue != 0) {92System.out.println("TEST FAILED: Incorrect exit value " +93"from ImplVersionCommand");94System.exit(exitValue);95}96// Test OK!97//98System.out.println("Bye! Bye!");99} catch (Exception e) {100System.out.println("Unexpected exception caught = " + e);101e.printStackTrace();102System.exit(1);103}104}105}106107108