Thu, 07 Jun 2012 20:30:57 -0700
7170079: Adjustments to build-infra makefiles
Reviewed-by: ohair, ohrstrom, ihse, jonas
Contributed-by: jonas <jonas.oreland@oracle.com>, erikj <erik.joelsson@oracle.com>, ihse <magnus.ihse.bursie@oracle.com>, tgranat <torbjorn.granat@oracle.com>, ykantser <yekaterina.kantserova@oracle.com>
duke@1 | 1 | #!/bin/sh |
duke@1 | 2 | |
duke@1 | 3 | # |
jjg@874 | 4 | # Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 5 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 6 | # |
duke@1 | 7 | # This code is free software; you can redistribute it and/or modify it |
duke@1 | 8 | # under the terms of the GNU General Public License version 2 only, as |
duke@1 | 9 | # published by the Free Software Foundation. |
duke@1 | 10 | # |
duke@1 | 11 | # This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | # version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | # accompanied this code). |
duke@1 | 16 | # |
duke@1 | 17 | # You should have received a copy of the GNU General Public License version |
duke@1 | 18 | # 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | # |
ohair@554 | 21 | # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | # or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | # questions. |
duke@1 | 24 | # |
duke@1 | 25 | |
duke@1 | 26 | |
jjg@874 | 27 | # @test |
duke@1 | 28 | # @bug 4212732 |
duke@1 | 29 | # @summary Test handling of the Class-Path attribute in jar file manifests |
duke@1 | 30 | # @author Martin Buchholz |
duke@1 | 31 | # |
duke@1 | 32 | # @run shell Class-Path.sh |
duke@1 | 33 | |
duke@1 | 34 | # To run this test manually, simply do ./Class-Path.sh |
duke@1 | 35 | |
duke@1 | 36 | . ${TESTSRC-.}/Util.sh |
duke@1 | 37 | |
duke@1 | 38 | set -u |
duke@1 | 39 | |
duke@1 | 40 | Cleanup() { |
duke@1 | 41 | Sys rm -rf pkg Main.java Main.class Main.jar jars |
duke@1 | 42 | Sys rm -rf MANIFEST.MF A.jar B.zip |
duke@1 | 43 | } |
duke@1 | 44 | |
duke@1 | 45 | Cleanup |
duke@1 | 46 | Sys mkdir pkg |
duke@1 | 47 | |
duke@1 | 48 | #---------------------------------------------------------------- |
duke@1 | 49 | # Create mutually referential jar files |
duke@1 | 50 | #---------------------------------------------------------------- |
duke@1 | 51 | cat >pkg/A.java <<EOF |
duke@1 | 52 | package pkg; |
duke@1 | 53 | import pkg.B; |
duke@1 | 54 | public class A { |
duke@1 | 55 | public static int f() { return B.g(); } |
duke@1 | 56 | public static int g() { return 0; } |
duke@1 | 57 | } |
duke@1 | 58 | EOF |
duke@1 | 59 | |
duke@1 | 60 | cat >pkg/B.java <<EOF |
duke@1 | 61 | package pkg; |
duke@1 | 62 | import pkg.A; |
duke@1 | 63 | public class B { |
duke@1 | 64 | public static int f() { return A.g(); } |
duke@1 | 65 | public static int g() { return 0; } |
duke@1 | 66 | } |
duke@1 | 67 | EOF |
duke@1 | 68 | |
duke@1 | 69 | Sys "$javac" ${TESTTOOLVMOPTS} pkg/A.java pkg/B.java |
duke@1 | 70 | |
duke@1 | 71 | MkManifestWithClassPath "B.zip" |
duke@1 | 72 | Sys "$jar" cmf MANIFEST.MF A.jar pkg/A.class |
duke@1 | 73 | |
duke@1 | 74 | MkManifestWithClassPath "A.jar" |
duke@1 | 75 | Sys "$jar" cmf MANIFEST.MF B.zip pkg/B.class |
duke@1 | 76 | |
duke@1 | 77 | cat >Main.java <<EOF |
duke@1 | 78 | import pkg.*; |
duke@1 | 79 | public class Main { |
duke@1 | 80 | public static void main(String []a) { System.exit(A.f() + B.f()); } |
duke@1 | 81 | } |
duke@1 | 82 | EOF |
duke@1 | 83 | |
duke@1 | 84 | Success "$javac" ${TESTTOOLVMOPTS} -cp "A.jar" Main.java |
duke@1 | 85 | Success "$javac" ${TESTTOOLVMOPTS} -cp "B.zip" Main.java |
duke@1 | 86 | Success "$java" ${TESTVMOPTS} -cp "A.jar${PS}." Main |
duke@1 | 87 | Success "$java" ${TESTVMOPTS} -cp "B.zip${PS}." Main |
duke@1 | 88 | |
duke@1 | 89 | #---------------------------------------------------------------- |
duke@1 | 90 | # Jar file Class-Path expanded only for jars found on user class path |
duke@1 | 91 | #---------------------------------------------------------------- |
duke@1 | 92 | Sys mkdir jars |
duke@1 | 93 | Sys mv A.jar B.zip jars/. |
duke@1 | 94 | Success "$javac" ${TESTTOOLVMOPTS} -cp "jars/A.jar" Main.java |
duke@1 | 95 | Success "$java" ${TESTVMOPTS} -cp "jars/A.jar${PS}." Main |
duke@1 | 96 | |
duke@1 | 97 | Success "$javac" ${TESTTOOLVMOPTS} -cp "jars/B.zip" Main.java |
duke@1 | 98 | Success "$java" ${TESTVMOPTS} -cp "jars/B.zip${PS}." Main |
duke@1 | 99 | |
duke@1 | 100 | Success "$javac" ${TESTTOOLVMOPTS} -extdirs "jars" -cp None Main.java |
duke@1 | 101 | Success "$javac" ${TESTTOOLVMOPTS} -Djava.ext.dirs="jars" -cp None Main.java |
duke@1 | 102 | Success "$java" ${TESTVMOPTS} -Djava.ext.dirs="jars" -cp . Main |
duke@1 | 103 | |
duke@1 | 104 | Success "$javac" ${TESTTOOLVMOPTS} -endorseddirs "jars" -cp None Main.java |
duke@1 | 105 | Success "$javac" ${TESTTOOLVMOPTS} -Djava.endorsed.dirs="jars" -cp None Main.java |
duke@1 | 106 | Success "$java" ${TESTVMOPTS} -Djava.endorsed.dirs="jars" -cp . Main |
duke@1 | 107 | |
duke@1 | 108 | Failure "$java" ${TESTVMOPTS} -Xbootclasspath/p:"jars/A.jar" -cp . Main |
duke@1 | 109 | Failure "$java" ${TESTVMOPTS} -Xbootclasspath/a:"jars/B.zip" -cp . Main |
duke@1 | 110 | Failure "$javac" ${TESTTOOLVMOPTS} -Xbootclasspath/p:"jars/A.jar" -cp None Main.java |
duke@1 | 111 | Failure "$javac" ${TESTTOOLVMOPTS} -Xbootclasspath/a:"jars/B.zip" -cp None Main.java |
duke@1 | 112 | Sys mv jars/A.jar jars/B.zip . |
duke@1 | 113 | |
duke@1 | 114 | MkManifestWithClassPath "A.jar" |
duke@1 | 115 | echo "Main-Class: Main" >> MANIFEST.MF |
duke@1 | 116 | Sys "$jar" cmf MANIFEST.MF Main.jar Main.class |
duke@1 | 117 | |
duke@1 | 118 | Success "$java" ${TESTVMOPTS} -jar Main.jar |
duke@1 | 119 | |
duke@1 | 120 | MkManifestWithClassPath "." |
duke@1 | 121 | Sys "$jar" cmf MANIFEST.MF A.jar pkg/A.class |
duke@1 | 122 | |
duke@1 | 123 | Success "$javac" ${TESTTOOLVMOPTS} -cp "A.jar" Main.java |
duke@1 | 124 | Success "$java" ${TESTVMOPTS} -jar Main.jar |
duke@1 | 125 | |
duke@1 | 126 | MkManifestWithClassPath "" |
duke@1 | 127 | Sys "$jar" cmf MANIFEST.MF A.jar pkg/A.class |
duke@1 | 128 | |
duke@1 | 129 | Failure "$javac" ${TESTTOOLVMOPTS} -cp "A.jar" Main.java |
duke@1 | 130 | Failure "$java" ${TESTVMOPTS} -jar Main.jar |
duke@1 | 131 | |
duke@1 | 132 | #---------------------------------------------------------------- |
duke@1 | 133 | # Test new flag -e (application entry point) |
duke@1 | 134 | #---------------------------------------------------------------- |
duke@1 | 135 | |
duke@1 | 136 | cat > Hello.java <<EOF |
duke@1 | 137 | import pkg.*; |
duke@1 | 138 | public class Hello { |
duke@1 | 139 | public static void main(String []a) { System.out.println("Hello World!"); } |
duke@1 | 140 | } |
duke@1 | 141 | EOF |
duke@1 | 142 | |
duke@1 | 143 | cat > Bye.java <<EOF |
duke@1 | 144 | import pkg.*; |
duke@1 | 145 | public class Bye { |
duke@1 | 146 | public static void main(String []a) { System.out.println("Good Bye!"); } |
duke@1 | 147 | } |
duke@1 | 148 | EOF |
duke@1 | 149 | |
duke@1 | 150 | Success "$javac" ${TESTTOOLVMOPTS} Hello.java Bye.java |
duke@1 | 151 | |
duke@1 | 152 | # test jar creation without manifest |
duke@1 | 153 | # |
duke@1 | 154 | Success "$jar" cfe "Hello.jar" "Hello" Hello.class |
duke@1 | 155 | Success "$java" ${TESTVMOPTS} -jar Hello.jar |
duke@1 | 156 | |
duke@1 | 157 | # test for overriding the manifest during jar creation |
duke@1 | 158 | # |
duke@1 | 159 | echo "Main-Class: Hello" >> MANIFEST.MF |
duke@1 | 160 | |
duke@1 | 161 | # test for error: " 'e' flag and manifest with the 'Main-Class' |
duke@1 | 162 | # attribute cannot be specified together, during creation |
duke@1 | 163 | Failure "$jar" cmfe MANIFEST.MF "Bye.jar" "Bye" Bye.class |
duke@1 | 164 | |
duke@1 | 165 | # test for overriding the manifest when updating the jar |
duke@1 | 166 | # |
duke@1 | 167 | Success "$jar" cfe "greetings.jar" "Hello" Hello.class |
duke@1 | 168 | Success "$jar" ufe "greetings.jar" "Bye" Bye.class |
duke@1 | 169 | Success "$java" ${TESTVMOPTS} -jar greetings.jar |
duke@1 | 170 | |
duke@1 | 171 | # test for error: " 'e' flag and manifest with the 'Main-Class' |
duke@1 | 172 | # attribute cannot be specified together, during update |
duke@1 | 173 | Failure "$jar" umfe MANIFEST.MF "greetings.jar" "Hello" |
duke@1 | 174 | |
duke@1 | 175 | # test jar updation when there are no inputfiles |
duke@1 | 176 | # |
duke@1 | 177 | Success "$jar" ufe "Hello.jar" "Bye" |
duke@1 | 178 | Failure "$java" ${TESTVMOPTS} -jar Hello.jar |
duke@1 | 179 | Success "$jar" umf MANIFEST.MF "Hello.jar" |
duke@1 | 180 | |
duke@1 | 181 | # test creating jar when the to-be-archived files |
duke@1 | 182 | # do not contain the specified main class, there is no check done |
duke@1 | 183 | # for the presence of the main class, so the test will pass |
duke@1 | 184 | # |
duke@1 | 185 | Success "$jar" cfe "Hello.jar" "Hello" Bye.class |
duke@1 | 186 | |
jjg@874 | 187 | # Jar creation and update when there is no manifest and inputfiles |
jjg@874 | 188 | # specified |
duke@1 | 189 | Failure "$jar" cvf "A.jar" |
duke@1 | 190 | Failure "$jar" uvf "A.jar" |
duke@1 | 191 | |
duke@1 | 192 | # error: no such file or directory |
duke@1 | 193 | Failure "$jar" cvf "A.jar" non-existing.file |
duke@1 | 194 | Failure "$jar" uvf "A.jar" non-existing.file |
duke@1 | 195 | |
duke@1 | 196 | Cleanup |
duke@1 | 197 | |
duke@1 | 198 | Bottom Line |