1 /*
   2  * Copyright (c) 2004, 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 5046815
  27  * @summary Test that RMIServer.getVersion() reflects the JDK version when
  28  * the Java platform and 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, 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 
  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 
  58             // Get Java Home
  59             String javaHome = System.getProperty("java.home");
  60 
  61             // Get test src
  62             //
  63             String testSrc = System.getProperty("test.src");
  64 
  65             // Get test classes
  66             String testClasses = System.getProperty("test.classes");
  67 
  68             // Build command string
  69             String command =
  70                 javaHome + File.separator + "bin" + File.separator + "java " +
  71                 " -classpath " + testClasses +
  72                 " -Djava.security.manager -Djava.security.policy==" + testSrc +
  73                 File.separator + "policy -Dtest.classes=" + testClasses +
  74                 " ImplVersionCommand " + System.getProperty("java.runtime.version");
  75             System.out.println("ImplVersionCommand Exec Command = " + command);
  76 
  77             // Exec command
  78             Process proc = Runtime.getRuntime().exec(command);
  79             new ImplVersionReader(proc, proc.getInputStream()).start();
  80             new ImplVersionReader(proc, proc.getErrorStream()).start();
  81             int exitValue = proc.waitFor();
  82 
  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             System.out.println("Bye! Bye!");
  92         } catch (Exception e) {
  93             System.out.println("Unexpected exception caught = " + e);
  94             e.printStackTrace();
  95             System.exit(1);
  96         }
  97     }
  98 }