blob: 96f30e96e150a7df3b6d117c0811215461d961d8 [file] [log] [blame]
Felix Yang519a6f92014-12-29 15:24:54 -08001/*
2 * Copyright (c) 2014, 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 8065957
26 * @library ../../../../java/rmi/testlibrary
Mandy Chung53a97cb2015-05-28 10:54:48 -070027 * @modules java.corba
28 * java.rmi/sun.rmi.registry
29 * java.rmi/sun.rmi.server
30 * java.rmi/sun.rmi.transport
31 * java.rmi/sun.rmi.transport.tcp
Felix Yang519a6f92014-12-29 15:24:54 -080032 * @build TestLibrary
Felix Yang519a6f92014-12-29 15:24:54 -080033 * @run main IIOPCompilation
Mandy Chunge2a0ff32016-08-10 15:51:25 -070034 *
35 * @summary Compiles a PortableRemoteObject with rmic -iiop and ensures that stub and tie classes are generated.
Felix Yang519a6f92014-12-29 15:24:54 -080036 * @author Felix Yang
37 *
38 */
39import java.io.File;
40import java.io.FileNotFoundException;
41import java.io.IOException;
42import java.rmi.RemoteException;
43import java.util.Arrays;
44import java.util.List;
45
46import javax.rmi.PortableRemoteObject;
47
48public class IIOPCompilation {
49
50 public static void main(String args[]) throws IOException, InterruptedException {
51 IIOPCompilation test = new IIOPCompilation();
52 test.doTest();
53 }
54
55 private void doTest() throws IOException, InterruptedException {
56 String className = DummyImpl.class.getName();
57 int exitCode = runRmic(className);
58 if (exitCode != 0) {
59 throw new RuntimeException("Rmic failed. The exit code is " + exitCode);
60 }
61
62 // Check the stub class generated correctly
63 String stubFile = "_" + Dummy.class.getName() + "_Stub.class";
64 assertFileExists(stubFile);
65
66 // Check the tie class generated correctly
67 String tieFile = "_" + className + "_Tie.class";
68 assertFileExists(tieFile);
69 }
70
71 private void assertFileExists(String fileName) throws FileNotFoundException {
72 if (!new File(fileName).exists()) {
73 throw new FileNotFoundException(fileName + " doesn't exist!");
74 }
75 }
76
77 private int runRmic(String classname) throws IOException, InterruptedException {
78 String rmicProgramStr = TestLibrary.getProperty("java.home", "") + File.separator + "bin" + File.separator + "rmic";
79 String testClasses = TestLibrary.getProperty("test.classes", "");
80 List<String> command = Arrays.asList(rmicProgramStr, "-iiop", "-classpath", testClasses, classname);
81 System.out.println("Running command: " + command);
82
83 Process p = null;
84 try {
85 p = new ProcessBuilder(command).inheritIO().start();
86 p.waitFor();
87 return p.exitValue();
88 } finally {
89 if (p != null && p.isAlive()) {
90 p.destroy();
91 }
92 }
93 }
94}
95
96interface Dummy extends java.rmi.Remote {
97}
98
99class DummyImpl extends PortableRemoteObject implements Dummy {
100 public DummyImpl() throws RemoteException {
101 }
102}