1 /*
   2  * Copyright (c) 1999, 2012, 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 /* @test
  25  * @bug 4236543
  26  * @summary rmic w/o -d should put class files in package directory
  27  * @author Dana Burns
  28  * @library ../../../../java/rmi/testlibrary
  29  *
  30  * @build StreamPipe
  31  * @run main/othervm RmicDefault
  32  */
  33 
  34 /*
  35  * Ensure that, in the absence of a -d argument, rmic will deposit
  36  * the generated class files in the package directory as opposed
  37  * to the old behaviour of depositing them in the local directory.
  38  * JavaTest/jtreg does not support setting the classpath yet, so do
  39  * the javac directly.
  40  */
  41 
  42 import java.io.File;
  43 import java.io.IOException;
  44 
  45 public class RmicDefault {
  46     public static void main(String args[]) throws Exception {
  47         String javahome = System.getProperty("java.home");
  48         String testclasses = System.getProperty("test.classes");
  49         String userDir = System.getProperty("user.dir");
  50 
  51         if (javahome.regionMatches(true, javahome.length() - 4,
  52                                    File.separator + "jre", 0, 4))
  53         {
  54             javahome = javahome.substring(0, javahome.length() - 4);
  55         }
  56 
  57         Process javacProcess = Runtime.getRuntime().exec(
  58             javahome + File.separator + "bin" + File.separator +
  59             "javac -d " + testclasses + " " +
  60             System.getProperty("test.src") + File.separator + "packagedir" +
  61             File.separator + "RmicMeImpl.java");
  62 
  63         StreamPipe.plugTogether(javacProcess.getInputStream(), System.out);
  64         StreamPipe.plugTogether(javacProcess.getErrorStream(), System.out);
  65 
  66         javacProcess.waitFor();
  67 
  68         Process rmicProcess = Runtime.getRuntime().exec(
  69             javahome + File.separator + "bin" + File.separator +
  70             "rmic -classpath " + testclasses + " packagedir.RmicMeImpl");
  71 
  72         StreamPipe.plugTogether(rmicProcess.getInputStream(), System.out);
  73         StreamPipe.plugTogether(rmicProcess.getErrorStream(), System.err);
  74 
  75         rmicProcess.waitFor();
  76 
  77         File stub = new File(userDir + File.separator + "packagedir" +
  78                              File.separator + "RmicMeImpl_Stub.class");
  79         if (!stub.exists()) {
  80             throw new RuntimeException("TEST FAILED: could not find stub");
  81         }
  82 
  83         System.err.println("TEST PASSED");
  84     }
  85 }