Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/remote/mandatory/version/ImplVersionTest.java
38867 views
/*1* Copyright (c) 2004, 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 504681526* @summary Test that RMIServer.getVersion() reflects the JDK version when27* JMX is bundled into the Java platform and the application is run with a28* security manager and the test codebase has the java permission to read29* the "java.runtime.version" system property.30* @author Luis-Miguel Alventosa, Joel Feraud31* @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}5758// Get Java Home59String javaHome = System.getProperty("java.home");6061// Get test src62//63String testSrc = System.getProperty("test.src");6465// Get test classes66String testClasses = System.getProperty("test.classes");6768// Get boot class path69String bootClassPath = System.getProperty("sun.boot.class.path");7071// Build command string72String command =73javaHome + File.separator + "bin" + File.separator + "java " +74" -Xbootclasspath/p:" + bootClassPath +75" -classpath " + testClasses +76" -Djava.security.manager -Djava.security.policy==" + testSrc +77File.separator + "policy -Dtest.classes=" + testClasses +78" ImplVersionCommand " + System.getProperty("java.runtime.version");79System.out.println("ImplVersionCommand Exec Command = " + command);8081// Exec command82Process proc = Runtime.getRuntime().exec(command);83new ImplVersionReader(proc, proc.getInputStream()).start();84new ImplVersionReader(proc, proc.getErrorStream()).start();85int exitValue = proc.waitFor();8687System.out.println("ImplVersionCommand Exit Value = " +88exitValue);89if (exitValue != 0) {90System.out.println("TEST FAILED: Incorrect exit value " +91"from ImplVersionCommand");92System.exit(exitValue);93}94// Test OK!95System.out.println("Bye! Bye!");96} catch (Exception e) {97System.out.println("Unexpected exception caught = " + e);98e.printStackTrace();99System.exit(1);100}101}102}103104105