test/tools/javac/Paths/Class-Path.sh

Thu, 25 Aug 2011 17:18:25 -0700

author
schien
date
Thu, 25 Aug 2011 17:18:25 -0700
changeset 1067
f497fac86cf9
parent 874
e0c16199b2e0
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag jdk8-b02 for changeset b3c059de2a61

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

mercurial