Felix Yang | 519a6f9 | 2014-12-29 15:24:54 -0800 | [diff] [blame] | 1 | /* |
| 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 Chung | 53a97cb | 2015-05-28 10:54:48 -0700 | [diff] [blame] | 27 | * @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 Yang | 519a6f9 | 2014-12-29 15:24:54 -0800 | [diff] [blame] | 32 | * @build TestLibrary |
Felix Yang | 519a6f9 | 2014-12-29 15:24:54 -0800 | [diff] [blame] | 33 | * @run main IIOPCompilation |
Mandy Chung | e2a0ff3 | 2016-08-10 15:51:25 -0700 | [diff] [blame] | 34 | * |
| 35 | * @summary Compiles a PortableRemoteObject with rmic -iiop and ensures that stub and tie classes are generated. |
Felix Yang | 519a6f9 | 2014-12-29 15:24:54 -0800 | [diff] [blame] | 36 | * @author Felix Yang |
| 37 | * |
| 38 | */ |
| 39 | import java.io.File; |
| 40 | import java.io.FileNotFoundException; |
| 41 | import java.io.IOException; |
| 42 | import java.rmi.RemoteException; |
| 43 | import java.util.Arrays; |
| 44 | import java.util.List; |
| 45 | |
| 46 | import javax.rmi.PortableRemoteObject; |
| 47 | |
| 48 | public 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 | |
| 96 | interface Dummy extends java.rmi.Remote { |
| 97 | } |
| 98 | |
| 99 | class DummyImpl extends PortableRemoteObject implements Dummy { |
| 100 | public DummyImpl() throws RemoteException { |
| 101 | } |
| 102 | } |