1 # 2 # Copyright (c) 2007, 2010, 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 #!/bin/sh 25 # @test 26 # @bug 6473331 6485027 6934615 27 # @summary Test handling of the Class-Path attribute in jar file manifests 28 # for the rmic tool 29 # @author Andrey Ozerov 30 # 31 # @run shell run.sh 32 33 # To run this test manually, simply do ./run.sh 34 35 . ${TESTSRC-.}/Util.sh 36 37 set -u 38 39 Cleanup() { 40 Sys rm -rf pkg Main.java MainI.java Main.class MainI.class Main_Stub.class 41 Sys rm -rf jars MANIFEST.MF A.jar B.zip 42 } 43 44 Cleanup 45 Sys mkdir pkg 46 47 #---------------------------------------------------------------- 48 # Create mutually referential jar files 49 #---------------------------------------------------------------- 50 cat >pkg/A.java <<EOF 51 package pkg; 52 public class A implements java.io.Serializable { 53 public int f(B b) { return b.g(); } 54 public int g() { return 0; } 55 } 56 EOF 57 58 cat >pkg/B.java <<EOF 59 package pkg; 60 public class B implements java.io.Serializable { 61 public int f(A a) { return a.g(); } 62 public int g() { return 0; } 63 } 64 EOF 65 66 Sys "$javac" pkg/A.java pkg/B.java 67 68 # NOTE: Previously, some lines were commented out and alternative lines 69 # provided, to work around javac bug 6485027. That bug, and related rmic 70 # bug 6934615 have now been fixed, so most of the workarounds have been 71 # removed. However, javac still does not evaluate jar class paths on 72 # the bootclasspath, including -extdirs. 73 74 MkManifestWithClassPath "sub/B.zip" 75 Sys "$jar" cmf MANIFEST.MF A.jar pkg/A.class 76 77 MkManifestWithClassPath "../A.jar" 78 Sys "$jar" cmf MANIFEST.MF B.zip pkg/B.class 79 80 Sys rm -rf pkg 81 Sys mkdir jars 82 Sys mv A.jar jars/. 83 Sys mkdir jars/sub 84 Sys mv B.zip jars/sub/. 85 86 cat >MainI.java <<EOF 87 import pkg.*; 88 public interface MainI extends java.rmi.Remote { 89 public int doIt(A a, B b) throws java.rmi.RemoteException; 90 } 91 EOF 92 93 cat >Main.java <<EOF 94 import pkg.*; 95 import java.rmi.server.UnicastRemoteObject; 96 public class Main implements MainI { 97 public int doIt(A a, B b) { 98 return a.f(b) + b.f(a); 99 } 100 public static void main(String args[]) throws Exception { 101 Main impl = new Main(); 102 try { 103 MainI stub = (MainI) UnicastRemoteObject.exportObject(impl); 104 int result = stub.doIt(new A(), new B()); 105 System.exit(result); 106 } finally { 107 try { 108 UnicastRemoteObject.unexportObject(impl, true); 109 } catch (Exception e) { } 110 } 111 } 112 } 113 EOF 114 115 Success "$javac" -classpath "jars/A.jar" Main.java MainI.java 116 Success "$rmic" -classpath "jars/A.jar${PS}." Main 117 Success "$java" ${TESTVMOPTS} -classpath "jars/A.jar${PS}." Main 118 119 Sys rm -f Main.class MainI.class Main_Stub.class 120 121 Success "$javac" -classpath "jars/sub/B.zip" Main.java MainI.java 122 Success "$rmic" -classpath "jars/sub/B.zip${PS}." Main 123 Success "$java" ${TESTVMOPTS} -classpath "jars/sub/B.zip${PS}." Main 124 125 #Sys rm -f Main.class MainI.class Main_Stub.class 126 Sys rm -f Main_Stub.class # javac -extdirs workaround 127 128 #Success "$javac" -extdirs "jars" -classpath None Main.java MainI.java 129 Success "$rmic" -extdirs "jars" -classpath . Main 130 Success "$java" ${TESTVMOPTS} -Djava.ext.dirs="jars" -cp . Main 131 132 Sys rm -f Main_Stub.class 133 134 #Success "$javac" -extdirs "jars/sub" -classpath None Main.java MainI.java 135 Success "$rmic" -extdirs "jars/sub" -classpath . Main 136 Success "$java" ${TESTVMOPTS} -Djava.ext.dirs="jars/sub" -cp . Main 137 138 Cleanup 139 140 Bottom Line