1 #!/bin/sh
   2 # @test MultipleJRE.sh
   3 # @bug 4811102 4953711 4955505 4956301 4991229 4998210 5018605 6387069 6733959
   4 # @build PrintVersion
   5 # @build UglyPrintVersion
   6 # @build ZipMeUp
   7 # @run shell MultipleJRE.sh
   8 # @summary Verify Multiple JRE version support has been removed
   9 # @author Joseph E. Kowalski
  10 
  11 #
  12 # Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
  13 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  14 #
  15 # This code is free software; you can redistribute it and/or modify it
  16 # under the terms of the GNU General Public License version 2 only, as
  17 # published by the Free Software Foundation.
  18 #
  19 # This code is distributed in the hope that it will be useful, but WITHOUT
  20 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  21 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  22 # version 2 for more details (a copy is included in the LICENSE file that
  23 # accompanied this code).
  24 #
  25 # You should have received a copy of the GNU General Public License version
  26 # 2 along with this work; if not, write to the Free Software Foundation,
  27 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  28 #
  29 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  30 # or visit www.oracle.com if you need additional information or have any
  31 # questions.
  32 #
  33 
  34 # Verify directory context variables are set
  35 if [ "${TESTJAVA}" = "" ]
  36 then
  37   echo "TESTJAVA not set.  Test cannot execute.  Failed."
  38   exit 1
  39 fi
  40 
  41 if [ "${COMPILEJAVA}" = "" ]; then
  42   COMPILEJAVA="${TESTJAVA}"
  43 fi
  44 
  45 if [ "${TESTSRC}" = "" ]
  46 then
  47   echo "TESTSRC not set.  Test cannot execute.  Failed."
  48   exit 1
  49 fi
  50 
  51 if [ "${TESTCLASSES}" = "" ]
  52 then
  53   echo "TESTCLASSES not set.  Test cannot execute.  Failed."
  54   exit 1
  55 fi
  56 
  57 JAVAEXE="$TESTJAVA/bin/java ${TESTVMOPTS}"
  58 JAVA="$TESTJAVA/bin/java ${TESTVMOPTS} -classpath $TESTCLASSES"
  59 JAR="$COMPILEJAVA/bin/jar ${TESTTOOLVMOPTS}"
  60 OS=`uname -s`;
  61 
  62 #
  63 # Tests whether we are on windows (true) or not.
  64 #
  65 IsWindows() {
  66     case "$OS" in
  67         Windows* | CYGWIN* )
  68             printf "true"
  69         ;;
  70         * )
  71             printf "false"
  72         ;;
  73     esac
  74 }
  75 
  76 #
  77 # Shell routine to test for the proper rejection of syntactically incorrect
  78 # version specifications.
  79 #
  80 TestSyntax() {
  81         mess="`$JAVA -version:\"$1\" -version 2>&1`"
  82         if [ $? -eq 0 ]; then
  83                 echo "Invalid version syntax $1 accepted"
  84                 exit 1
  85         fi
  86         prefix="`echo "$mess" | cut -d ' ' -f 1-3`"
  87         if [ "$prefix" != "Error: Syntax error" ]; then
  88                 echo "Unexpected error message for invalid syntax $1"
  89                 exit 1
  90         fi
  91 }
  92 
  93 #
  94 # Just as the name says.  We sprinkle these in the appropriate location
  95 # in the test file system and they just say who they are pretending to be.
  96 #
  97 CreateMockVM() {
  98         mkdir -p jdk/j2re$1/bin
  99         echo "#!/bin/sh"    > jdk/j2re$1/bin/java
 100         echo "echo \"$1\"" >> jdk/j2re$1/bin/java
 101         chmod +x jdk/j2re$1/bin/java
 102 }
 103 
 104 #
 105 # Constructs the jar file needed by these tests.
 106 #
 107 CreateJar() {
 108         mkdir -p META-INF
 109         echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF
 110         echo "Main-Class: PrintVersion" >> META-INF/MANIFEST.MF
 111         if [ "$1" != "" ]; then
 112                 echo "JRE-Version: $1" >> META-INF/MANIFEST.MF
 113         fi
 114         cp $TESTCLASSES/PrintVersion.class .
 115         $JAR $2cmf META-INF/MANIFEST.MF PrintVersion PrintVersion.class
 116 }
 117 
 118 #
 119 # Constructs a jar file using zip.
 120 #
 121 CreateZippyJar() {
 122         mkdir -p META-INF
 123         echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF
 124         echo "Main-Class: PrintVersion" >> META-INF/MANIFEST.MF
 125         if [ "$1" != "" ]; then
 126                 echo "JRE-Version: $1" >> META-INF/MANIFEST.MF
 127         fi
 128         cp $TESTCLASSES/PrintVersion.class .
 129         /usr/bin/zip $2 PrintVersion META-INF/MANIFEST.MF PrintVersion.class
 130 }
 131 
 132 #
 133 # Constructs a jar file with a Main-Class attribute of greater than
 134 # 80 characters to validate the continuation line processing.
 135 #
 136 # Make this just long enough to require two continuation lines.  Longer
 137 # paths take too much away from the restricted Windows maximum path length.
 138 # Note: see the variable UGLYCLASS and its check for path length.
 139 #
 140 # Make sure that 5018605 remains fixed by including additional sections
 141 # in the Manifest which contain the same names as those allowed in the
 142 # main section.
 143 #
 144 PACKAGE=reallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallylongpackagename
 145 UGLYCLASS=$TESTCLASSES/$PACKAGE/UglyPrintVersion.class
 146 CreateUglyJar() {
 147         mkdir -p META-INF
 148         echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF
 149         echo "Main-Class: $PACKAGE.UglyPrintVersion" >> META-INF/MANIFEST.MF
 150         if [ "$1" != "" ]; then
 151                 echo "JRE-Version: $1" >> META-INF/MANIFEST.MF
 152         fi
 153         echo "" >> META-INF/MANIFEST.MF
 154         echo "Name: NotToBeFound.class" >> META-INF/MANIFEST.MF
 155         echo "Main-Class: NotToBeFound" >> META-INF/MANIFEST.MF
 156         mkdir -p $PACKAGE
 157         cp $UGLYCLASS $PACKAGE
 158         $JAR $2cmf META-INF/MANIFEST.MF PrintVersion \
 159             $PACKAGE/UglyPrintVersion.class
 160 }
 161 
 162 #
 163 # Constructs a jar file with a fair number of "zip directory" entries and
 164 # the MANIFEST.MF entry at or near the end of that directory to validate
 165 # the ability to transverse that directory.
 166 #
 167 CreateFullJar() {
 168         mkdir -p META-INF
 169         echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF
 170         echo "Main-Class: PrintVersion" >> META-INF/MANIFEST.MF
 171         if [ "$1" != "" ]; then
 172             echo "JRE-Version: $1" >> META-INF/MANIFEST.MF
 173         fi
 174         cp $TESTCLASSES/PrintVersion.class .
 175         for i in 0 1 2 3 4 5 6 7 8 9 ; do
 176                 for j in 0 1 2 3 4 5 6 7 8 9 ; do
 177                         touch AfairlyLongNameEatsUpDirectorySpaceBetter$i$j
 178                 done
 179         done
 180         $JAR $2cMf PrintVersion PrintVersion.class AfairlyLong*
 181         $JAR $2umf META-INF/MANIFEST.MF PrintVersion
 182         rm -f AfairlyLong*
 183 }
 184 
 185 #
 186 # Creates a jar file with the attributes which caused the failure
 187 # described in 4991229.
 188 #
 189 # Generate a bunch of CENTAB entries, each of which is 64 bytes long
 190 # which practically guarentees we will hit the appropriate power of
 191 # two buffer (initially 1K).  Note that due to the perversity of
 192 # zip/jar files, the first entry gets extra stuff so it needs a
 193 # shorter name to compensate.
 194 #
 195 CreateAlignedJar() {
 196         mkdir -p META-INF
 197         echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF
 198         echo "Main-Class: PrintVersion" >> META-INF/MANIFEST.MF
 199         if [ "$1" != "" ]; then
 200             echo "JRE-Version: $1" >> META-INF/MANIFEST.MF
 201         fi
 202         cp $TESTCLASSES/PrintVersion.class .
 203         touch 57BytesSpecial
 204         for i in 0 1 2 3 4 5 6 7 8 9 ; do
 205                 for j in 0 1 2 3 4 5 6 7 8 9 ; do
 206                         touch 64BytesPerEntry-$i$j
 207                 done
 208         done
 209         $JAR $2cMf PrintVersion 57* 64* PrintVersion.class
 210         $JAR $2umf META-INF/MANIFEST.MF PrintVersion
 211         rm -f 57* 64*
 212 }
 213 
 214 #
 215 # Adds comments to a jar/zip file.  This serves two purposes:
 216 #
 217 #   1)  Make sure zip file comments (both per file and per archive) are
 218 #       properly processed and ignored.
 219 #
 220 #   2)  A long file comment creates a mondo "Central Directory" entry in
 221 #       the zip file. Such a "mondo" entry could also be due to a very
 222 #       long file name (path) or a long "Ext" entry, but adding the long
 223 #       comment is the easiest way.
 224 #
 225 MONDO=" Mondo comment line 00 is designed to take up space - lots and lots of space.  Mondo comment line 01 is designed to take up space - lots and lots of space.  Mondo comment line 02 is designed to take up space - lots and lots of space.  Mondo comment line 03 is designed to take up space - lots and lots of space.  Mondo comment line 04 is designed to take up space - lots and lots of space.  Mondo comment line 05 is designed to take up space - lots and lots of space.  Mondo comment line 06 is designed to take up space - lots and lots of space.  Mondo comment line 07 is designed to take up space - lots and lots of space.  Mondo comment line 08 is designed to take up space - lots and lots of space.  Mondo comment line 09 is designed to take up space - lots and lots of space.  Mondo comment line 0a is designed to take up space - lots and lots of space.  Mondo comment line 0b is designed to take up space - lots and lots of space.  Mondo comment line 0c is designed to take up space - lots and lots of space.  Mondo comment line 0d is designed to take up space - lots and lots of space.  Mondo comment line 0e is designed to take up space - lots and lots of space.  Mondo comment line 0f is designed to take up space - lots and lots of space.  Mondo comment line 10 is designed to take up space - lots and lots of space.  Mondo comment line 11 is designed to take up space - lots and lots of space.  Mondo comment line 12 is designed to take up space - lots and lots of space.  Mondo comment line 13 is designed to take up space - lots and lots of space.  Mondo comment line 14 is designed to take up space - lots and lots of space.  Mondo comment line 15 is designed to take up space - lots and lots of space.  Mondo comment line 16 is designed to take up space - lots and lots of space.  Mondo comment line 17 is designed to take up space - lots and lots of space.  Mondo comment line 18 is designed to take up space - lots and lots of space.  Mondo comment line 19 is designed to take up space - lots and lots of space.  Mondo comment line 1a is designed to take up space - lots and lots of space.  Mondo comment line 1b is designed to take up space - lots and lots of space.  Mondo comment line 1c is designed to take up space - lots and lots of space.  Mondo comment line 1d is designed to take up space - lots and lots of space.  Mondo comment line 1e is designed to take up space - lots and lots of space.  Mondo comment line 1f is designed to take up space - lots and lots of space.  Mondo comment line 20 is designed to take up space - lots and lots of space.  Mondo comment line 21 is designed to take up space - lots and lots of space.  Mondo comment line 22 is designed to take up space - lots and lots of space.  Mondo comment line 23 is designed to take up space - lots and lots of space.  Mondo comment line 24 is designed to take up space - lots and lots of space.  Mondo comment line 25 is designed to take up space - lots and lots of space.  Mondo comment line 26 is designed to take up space - lots and lots of space.  Mondo comment line 27 is designed to take up space - lots and lots of space.  Mondo comment line 28 is designed to take up space - lots and lots of space.  Mondo comment line 29 is designed to take up space - lots and lots of space.  Mondo comment line 2a is designed to take up space - lots and lots of space.  Mondo comment line 2b is designed to take up space - lots and lots of space.  Mondo comment line 2c is designed to take up space - lots and lots of space.  Mondo comment line 2d is designed to take up space - lots and lots of space.  Mondo comment line 2e is designed to take up space - lots and lots of space.  Mondo comment line 2f is designed to take up space - lots and lots of space.  Mondo comment line 30 is designed to take up space - lots and lots of space.  Mondo comment line 31 is designed to take up space - lots and lots of space.  Mondo comment line 32 is designed to take up space - lots and lots of space.  Mondo comment line 33 is designed to take up space - lots and lots of space.  Mondo comment line 34 is designed to take up space - lots and lots of space.  Mondo comment line 35 is designed to take up space - lots and lots of space.  Mondo comment line 36 is designed to take up space - lots and lots of space.  Mondo comment line 37 is designed to take up space - lots and lots of space.  Mondo comment line 38 is designed to take up space - lots and lots of space.  Mondo comment line 39 is designed to take up space - lots and lots of space.  Mondo comment line 3a is designed to take up space - lots and lots of space.  Mondo comment line 3b is designed to take up space - lots and lots of space.  Mondo comment line 3c is designed to take up space - lots and lots of space.  Mondo comment line 3d is designed to take up space - lots and lots of space.  Mondo comment line 3e is designed to take up space - lots and lots of space.  Mondo comment line 3f is designed to take up space - lots and lots of space.  Mondo comment line 40 is designed to take up space - lots and lots of space.  Mondo comment line 41 is designed to take up space - lots and lots of space.  Mondo comment line 42 is designed to take up space - lots and lots of space.  Mondo comment line 43 is designed to take up space - lots and lots of space.  Mondo comment line 44 is designed to take up space - lots and lots of space.  Mondo comment line 45 is designed to take up space - lots and lots of space.  Mondo comment line 46 is designed to take up space - lots and lots of space.  Mondo comment line 47 is designed to take up space - lots and lots of space.  Mondo comment line 48 is designed to take up space - lots and lots of space.  Mondo comment line 49 is designed to take up space - lots and lots of space.  Mondo comment line 4a is designed to take up space - lots and lots of space.  Mondo comment line 4b is designed to take up space - lots and lots of space.  Mondo comment line 4c is designed to take up space - lots and lots of space.  Mondo comment line 4d is designed to take up space - lots and lots of space.  Mondo comment line 4e is designed to take up space - lots and lots of space.  Mondo comment line 4f is designed to take up space - lots and lots of space.  Mondo comment line 50 is designed to take up space - lots and lots of space.  Mondo comment line 51 is designed to take up space - lots and lots of space.  Mondo comment line 52 is designed to take up space - lots and lots of space.  Mondo comment line 53 is designed to take up space - lots and lots of space.  Mondo comment line 54 is designed to take up space - lots and lots of space.  Mondo comment line 55 is designed to take up space - lots and lots of space.  Mondo comment line 56 is designed to take up space - lots and lots of space.  Mondo comment line 57 is designed to take up space - lots and lots of space.  Mondo comment line 58 is designed to take up space - lots and lots of space.  Mondo comment line 59 is designed to take up space - lots and lots of space.  Mondo comment line 5a is designed to take up space - lots and lots of space.  Mondo comment line 5b is designed to take up space - lots and lots of space.  Mondo comment line 5c is designed to take up space - lots and lots of space.  Mondo comment line 5d is designed to take up space - lots and lots of space.  Mondo comment line 5e is designed to take up space - lots and lots of space.  Mondo comment line 5f is designed to take up space - lots and lots of space.  Mondo comment line 60 is designed to take up space - lots and lots of space.  Mondo comment line 61 is designed to take up space - lots and lots of space.  Mondo comment line 62 is designed to take up space - lots and lots of space.  Mondo comment line 63 is designed to take up space - lots and lots of space.  Mondo comment line 64 is designed to take up space - lots and lots of space.  Mondo comment line 65 is designed to take up space - lots and lots of space.  Mondo comment line 66 is designed to take up space - lots and lots of space.  Mondo comment line 67 is designed to take up space - lots and lots of space.  Mondo comment line 68 is designed to take up space - lots and lots of space.  Mondo comment line 69 is designed to take up space - lots and lots of space.  Mondo comment line 6a is designed to take up space - lots and lots of space.  Mondo comment line 6b is designed to take up space - lots and lots of space.  Mondo comment line 6c is designed to take up space - lots and lots of space.  Mondo comment line 6d is designed to take up space - lots and lots of space.  Mondo comment line 6e is designed to take up space - lots and lots of space.  Mondo comment line 6f is designed to take up space - lots and lots of space.  Mondo comment line 70 is designed to take up space - lots and lots of space.  Mondo comment line 71 is designed to take up space - lots and lots of space.  Mondo comment line 72 is designed to take up space - lots and lots of space.  Mondo comment line 73 is designed to take up space - lots and lots of space.  Mondo comment line 74 is designed to take up space - lots and lots of space.  Mondo comment line 75 is designed to take up space - lots and lots of space.  Mondo comment line 76 is designed to take up space - lots and lots of space.  Mondo comment line 77 is designed to take up space - lots and lots of space.  Mondo comment line 78 is designed to take up space - lots and lots of space.  Mondo comment line 79 is designed to take up space - lots and lots of space.  Mondo comment line 7a is designed to take up space - lots and lots of space.  Mondo comment line 7b is designed to take up space - lots and lots of space.  Mondo comment line 7c is designed to take up space - lots and lots of space.  Mondo comment line 7d is designed to take up space - lots and lots of space.  Mondo comment line 7e is designed to take up space - lots and lots of space.  Mondo comment line 7f is designed to take up space - lots and lots of space.  Mondo comment line 80 is designed to take up space - lots and lots of space.  Mondo comment line 81 is designed to take up space - lots and lots of space.  Mondo comment line 82 is designed to take up space - lots and lots of space.  Mondo comment line 83 is designed to take up space - lots and lots of space.  Mondo comment line 84 is designed to take up space - lots and lots of space.  Mondo comment line 85 is designed to take up space - lots and lots of space.  Mondo comment line 86 is designed to take up space - lots and lots of space.  Mondo comment line 87 is designed to take up space - lots and lots of space.  Mondo comment line 88 is designed to take up space - lots and lots of space.  Mondo comment line 89 is designed to take up space - lots and lots of space.  Mondo comment line 8a is designed to take up space - lots and lots of space.  Mondo comment line 8b is designed to take up space - lots and lots of space.  Mondo comment line 8c is designed to take up space - lots and lots of space.  Mondo comment line 8d is designed to take up space - lots and lots of space.  Mondo comment line 8e is designed to take up space - lots and lots of space.  Mondo comment line 8f is designed to take up space - lots and lots of space.  Mondo comment line 90 is designed to take up space - lots and lots of space.  Mondo comment line 91 is designed to take up space - lots and lots of space.  Mondo comment line 92 is designed to take up space - lots and lots of space.  Mondo comment line 93 is designed to take up space - lots and lots of space.  Mondo comment line 94 is designed to take up space - lots and lots of space.  Mondo comment line 95 is designed to take up space - lots and lots of space.  Mondo comment line 96 is designed to take up space - lots and lots of space.  Mondo comment line 97 is designed to take up space - lots and lots of space.  Mondo comment line 98 is designed to take up space - lots and lots of space.  Mondo comment line 99 is designed to take up space - lots and lots of space.  Mondo comment line 9a is designed to take up space - lots and lots of space.  Mondo comment line 9b is designed to take up space - lots and lots of space.  Mondo comment line 9c is designed to take up space - lots and lots of space.  Mondo comment line 9d is designed to take up space - lots and lots of space.  Mondo comment line 9e is designed to take up space - lots and lots of space.  Mondo comment line 9f is designed to take up space - lots and lots of space.  Mondo comment line a0 is designed to take up space - lots and lots of space.  Mondo comment line a1 is designed to take up space - lots and lots of space.  Mondo comment line a2 is designed to take up space - lots and lots of space.  Mondo comment line a3 is designed to take up space - lots and lots of space.  Mondo comment line a4 is designed to take up space - lots and lots of space.  Mondo comment line a5 is designed to take up space - lots and lots of space.  Mondo comment line a6 is designed to take up space - lots and lots of space.  Mondo comment line a7 is designed to take up space - lots and lots of space.  Mondo comment line a8 is designed to take up space - lots and lots of space.  Mondo comment line a9 is designed to take up space - lots and lots of space.  Mondo comment line aa is designed to take up space - lots and lots of space.  Mondo comment line ab is designed to take up space - lots and lots of space.  Mondo comment line ac is designed to take up space - lots and lots of space.  Mondo comment line ad is designed to take up space - lots and lots of space.  Mondo comment line ae is designed to take up space - lots and lots of space.  Mondo comment line af is designed to take up space - lots and lots of space.  Mondo comment line b0 is designed to take up space - lots and lots of space.  Mondo comment line b1 is designed to take up space - lots and lots of space.  Mondo comment line b2 is designed to take up space - lots and lots of space.  Mondo comment line b3 is designed to take up space - lots and lots of space.  Mondo comment line b4 is designed to take up space - lots and lots of space.  Mondo comment line b5 is designed to take up space - lots and lots of space.  Mondo comment line b6 is designed to take up space - lots and lots of space.  Mondo comment line b7 is designed to take up space - lots and lots of space.  Mondo comment line b8 is designed to take up space - lots and lots of space.  Mondo comment line b9 is designed to take up space - lots and lots of space.  Mondo comment line ba is designed to take up space - lots and lots of space.  Mondo comment line bb is designed to take up space - lots and lots of space.  Mondo comment line bc is designed to take up space - lots and lots of space.  Mondo comment line bd is designed to take up space - lots and lots of space.  Mondo comment line be is designed to take up space - lots and lots of space.  Mondo comment line bf is designed to take up space - lots and lots of space.  Mondo comment line c0 is designed to take up space - lots and lots of space.  Mondo comment line c1 is designed to take up space - lots and lots of space.  Mondo comment line c2 is designed to take up space - lots and lots of space.  Mondo comment line c3 is designed to take up space - lots and lots of space.  Mondo comment line c4 is designed to take up space - lots and lots of space.  Mondo comment line c5 is designed to take up space - lots and lots of space.  Mondo comment line c6 is designed to take up space - lots and lots of space.  Mondo comment line c7 is designed to take up space - lots and lots of space.  Mondo comment line c8 is designed to take up space - lots and lots of space.  Mondo comment line c9 is designed to take up space - lots and lots of space.  Mondo comment line ca is designed to take up space - lots and lots of space.  Mondo comment line cb is designed to take up space - lots and lots of space.  Mondo comment line cc is designed to take up space - lots and lots of space.  Mondo comment line cd is designed to take up space - lots and lots of space.  Mondo comment line ce is designed to take up space - lots and lots of space.  Mondo comment line cf is designed to take up space - lots and lots of space.  Mondo comment line d0 is designed to take up space - lots and lots of space.  Mondo comment line d1 is designed to take up space - lots and lots of space.  Mondo comment line d2 is designed to take up space - lots and lots of space.  Mondo comment line d3 is designed to take up space - lots and lots of space.  Mondo comment line d4 is designed to take up space - lots and lots of space.  Mondo comment line d5 is designed to take up space - lots and lots of space.  Mondo comment line d6 is designed to take up space - lots and lots of space.  Mondo comment line d7 is designed to take up space - lots and lots of space.  Mondo comment line d8 is designed to take up space - lots and lots of space.  Mondo comment line d9 is designed to take up space - lots and lots of space.  Mondo comment line da is designed to take up space - lots and lots of space.  Mondo comment line db is designed to take up space - lots and lots of space.  Mondo comment line dc is designed to take up space - lots and lots of space.  Mondo comment line dd is designed to take up space - lots and lots of space.  Mondo comment line de is designed to take up space - lots and lots of space.  Mondo comment line df is designed to take up space - lots and lots of space.  Mondo comment line e0 is designed to take up space - lots and lots of space.  Mondo comment line e1 is designed to take up space - lots and lots of space.  Mondo comment line e2 is designed to take up space - lots and lots of space.  Mondo comment line e3 is designed to take up space - lots and lots of space.  Mondo comment line e4 is designed to take up space - lots and lots of space.  Mondo comment line e5 is designed to take up space - lots and lots of space.  Mondo comment line e6 is designed to take up space - lots and lots of space.  Mondo comment line e7 is designed to take up space - lots and lots of space.  Mondo comment line e8 is designed to take up space - lots and lots of space.  Mondo comment line e9 is designed to take up space - lots and lots of space.  Mondo comment line ea is designed to take up space - lots and lots of space.  Mondo comment line eb is designed to take up space - lots and lots of space.  Mondo comment line ec is designed to take up space - lots and lots of space.  Mondo comment line ed is designed to take up space - lots and lots of space.  Mondo comment line ee is designed to take up space - lots and lots of space.  Mondo comment line ef is designed to take up space - lots and lots of space.  Mondo comment line f0 is designed to take up space - lots and lots of space.  Mondo comment line f1 is designed to take up space - lots and lots of space.  Mondo comment line f2 is designed to take up space - lots and lots of space.  Mondo comment line f3 is designed to take up space - lots and lots of space.  Mondo comment line f4 is designed to take up space - lots and lots of space.  Mondo comment line f5 is designed to take up space - lots and lots of space.  Mondo comment line f6 is designed to take up space - lots and lots of space.  Mondo comment line f7 is designed to take up space - lots and lots of space.  Mondo comment line f8 is designed to take up space - lots and lots of space.  Mondo comment line f9 is designed to take up space - lots and lots of space.  Mondo comment line fa is designed to take up space - lots and lots of space.  Mondo comment line fb is designed to take up space - lots and lots of space.  Mondo comment line fc is designed to take up space - lots and lots of space.  Mondo comment line fd is designed to take up space - lots and lots of space.  Mondo comment line fe is designed to take up space - lots and lots of space.  Mondo comment line ff is designed to take up space - lots and lots of space."
 226 CommentZipFile() {
 227         mkdir -p META-INF
 228         echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF
 229         echo "Main-Class: PrintVersion" >> META-INF/MANIFEST.MF
 230         if [ "$1" != "" ]; then
 231             echo "JRE-Version: $1" >> META-INF/MANIFEST.MF
 232         fi
 233         cp $TESTCLASSES/PrintVersion.class .
 234 
 235         # The remaining code in CommentZipFile essentially replaces the
 236         #   following code, which added comments to the jar file.
 237         #   Unfortunately zipnote has been broken since 3.0 [ 2008 ] and
 238         #   there has been no new [ fixed ] version.  zipnote has probably
 239         #   always failed, or failed for a long time without causing the
 240         #   test to fail.  So no comments were added to the file.
 241         #   The comments are added using zip(1) during the creation of the
 242         #   zip file.
 243         #
 244         # NOTE:
 245         #   It seems the original intent of this test was to add a very long
 246         #   comment for one file.  But zip allows a max of 256 characters, so
 247         #   we settle for adding 256-character comments to lots of files.
 248         #
 249         # $JAR $2cMf PrintVersion PrintVersion.class AfairlyLong*
 250         # $JAR $2umf META-INF/MANIFEST.MF PrintVersion
 251         # /usr/bin/zipnote PrintVersion.zip > zipout
 252         # ... code to modify zipout adding comments
 253         # /usr/bin/zipnote -w PrintVersion.zip < zipin
 254         # mv PrintVersion.zip PrintVersion
 255         #
 256 
 257 
 258         for i in 0 1 2 3 4 5 6 7 8 9 ; do
 259                 for j in 0 1 2 3 4 5 6 7 8 9 ; do
 260                         touch AfairlyLongNameEatsUpDirectorySpaceBetter$i$j
 261                 done
 262         done
 263 
 264         zip -$2c PrintVersion.zip PrintVersion.class AfairlyLong* META-INF/MANIFEST.MF << FINI
 265 File Comment Line.
 266 File Comment Line.
 267 File Comment Line.
 268 File Comment Line.
 269 File Comment Line.
 270 File Comment Line.
 271 File Comment Line.
 272 File Comment Line.
 273 File Comment Line.
 274 File Comment Line.
 275 File Comment Line.
 276 File Comment Line.
 277 File Comment Line.
 278 File Comment Line.
 279 File Comment Line.
 280 File Comment Line.
 281 File Comment Line.
 282 File Comment Line.
 283 File Comment Line.
 284 File Comment Line.
 285 $MONDO
 286 File Comment Line.
 287 File Comment Line.
 288 File Comment Line.
 289 FINI
 290 
 291         rm -f AfairlyLong*
 292 
 293     mv PrintVersion.zip PrintVersion
 294 
 295 }
 296 
 297 #
 298 # Attempt to launch a vm using a version specifier and make sure the
 299 # resultant launch (probably a "mock vm") is appropriate.
 300 #
 301 LaunchVM() {
 302         if [ "$1" != "" ]; then
 303                 mess="`$JAVA \"$1\" -jar PrintVersion 2>&1`"
 304                 if [ $? -eq 0 ]; then
 305                         echo "Unexpected success of -Version:$1"
 306                         echo "$mess"
 307                         exit 1
 308                 fi
 309         else
 310                 mess="`$JAVA -jar PrintVersion 2>&1`"
 311                 if [ $? -ne 0 ]; then
 312                         prefix=`echo "$mess" | cut -d ' ' -f 1-3`
 313                         if [ "$prefix" != "Unable to locate" ]; then
 314                                 echo "$mess"
 315                                 exit 1
 316                         fi
 317                         echo "Unexpected error in attempting to locate $1"
 318                         exit 1
 319                 fi
 320 
 321         fi
 322 
 323         echo $mess | grep "$2" > /dev/null 2>&1
 324         if [ $? != 0 ]; then
 325             echo "Launched $mess, expected $1"
 326             exit 1
 327         fi
 328 }
 329 
 330 # Tests very long Main-Class attribute in the jar
 331 TestLongMainClass() {
 332     JVER=$1
 333     if [ "$JVER" = "mklink" ]; then
 334         JVER=XX
 335         JDKXX=jdk/j2re$JVER
 336         rm -rf jdk
 337         mkdir jdk
 338         ln -s $TESTJAVA $JDKXX
 339         JAVA_VERSION_PATH="`pwd`/jdk"
 340         export JAVA_VERSION_PATH
 341     fi
 342     $JAVAEXE -cp $TESTCLASSES ZipMeUp UglyBetty.jar 4097 
 343     message="`$JAVAEXE -version:$JVER -jar UglyBetty.jar 2>&1`"
 344     echo $message | grep "Error: main-class: attribute exceeds system limits" > /dev/null 2>&1
 345     if [ $? -ne 0 ]; then
 346         printf "Long manifest test did not get expected error"
 347         exit 1
 348     fi
 349     unset JAVA_VERSION_PATH
 350     rm -rf jdk
 351 }
 352 
 353 #
 354 # Main test sequence starts here
 355 #
 356 
 357 RELEASE=`$JAVA -version 2>&1 | head -n 1 | cut -d ' ' -f 3 | \
 358   sed -e "s/\"//g"`
 359 BASE_RELEASE=`echo $RELEASE | sed -e "s/-.*//g"`
 360 
 361 #
 362 # Make sure that the generic jar/manifest reading code works. Test both
 363 # compressed and "stored" jar files.
 364 #
 365 # The "Ugly" jar (long manifest line) tests are only run if the combination
 366 # of the file name length restrictions and the length of the cwd allow it.
 367 #
 368 CreateJar "" ""
 369 LaunchVM "" "${RELEASE}"
 370 CreateJar "" "0"
 371 LaunchVM "" "${RELEASE}"
 372 if [ `IsWindows` = "true" ]; then
 373     MAXIMUM_PATH=255;
 374 else
 375     MAXIMUM_PATH=1024;
 376 fi
 377 
 378 PATH_LENGTH=`printf "%s" "$UGLYCLASS" | wc -c`
 379 if [ ${PATH_LENGTH} -lt ${MAXIMUM_PATH} ]; then
 380         CreateUglyJar "" ""
 381         LaunchVM "" "${RELEASE}"
 382         CreateUglyJar "" "0"
 383         LaunchVM "" "${RELEASE}"
 384 else
 385     printf "Warning: Skipped UglyJar test, path length exceeded, %d" $MAXIMUM_PATH
 386     printf " allowed, the current path is %d\n" $PATH_LENGTH
 387 fi
 388 CreateAlignedJar "" ""
 389 LaunchVM "" "${RELEASE}"
 390 CreateFullJar "" ""
 391 LaunchVM "" "${RELEASE}"
 392 
 393 #
 394 # 4998210 shows that some very strange behaviors are semi-supported.
 395 # In this case, it's the ability to prepend any kind of stuff to the
 396 # jar file and require that the jar file still work.  Note that this
 397 # "interface" isn't publically supported and we may choose to break
 398 # it in the future, but this test guarantees that we won't break it
 399 # without informed consent. We take advantage the fact that the
 400 # "FullJar" we just tested is probably the best jar to begin with
 401 # for this test.
 402 #
 403 echo "This is just meaningless bytes to prepend to the jar" > meaningless
 404 mv PrintVersion meaningfull
 405 cat meaningless meaningfull > PrintVersion
 406 LaunchVM "" "${RELEASE}" 
 407 rm meaningless meaningfull
 408 
 409 #
 410 # Officially, one must use "the jar command to create a jar file.  However,
 411 # all the comments about jar commands **imply** that jar files and zip files
 412 # are equivalent.  (Note: this isn't true due to the "0xcafe" insertion.)
 413 # On systems which have a command line zip, test the ability to use zip
 414 # to construct a jar and then use it (6387069).
 415 #
 416 if [ -x /usr/bin/zip ]; then
 417         CreateZippyJar "" "-q"
 418         LaunchVM "" "${RELEASE}"
 419 fi
 420 
 421 #
 422 # jar files shouldn't have comments, but it is possible that somebody added
 423 # one by using zip -c, zip -z, zipnote or a similar utility.  On systems
 424 # that have "zipnote", verify this functionality.
 425 #
 426 # This serves a dual purpose of creating a very large "central directory
 427 # entry" which validates to code to read such entries.
 428 #
 429 if [ -x /usr/bin/zipnote ]; then
 430         CreateFullJar "" ""
 431         CommentZipFile "AfairlyLongNameEatsUpDirectorySpaceBetter20"
 432         LaunchVM "" "${RELEASE}"
 433 fi
 434 
 435 #
 436 # Now test specification of mJRE
 437 #
 438 #   In some cases this should result in failure of the command,
 439 #   in some cases, a warning messages, with the command succeeding.
 440 #
 441 
 442         # Commandline use of "-version:" should fail
 443         #   with a message containing "no longer supported"
 444         LaunchVM "-version:1.10+" "Error: Specifying an alternate JDK/JRE"
 445         LaunchVM "-version:prettymuchanything" "Error: Specifying an alternate JDK/JRE"
 446 
 447         # Commandline use of "-jre-restrict-search" should now fail
 448         LaunchVM "-jre-restrict-search" "\-jre\-no\-restrict\-search are also no longer valid"
 449         # Commandline use of "-jre-no-restrict-search" should now fail
 450         LaunchVM "-jre-no-restrict-search" "\-jre\-no\-restrict\-search are also no longer valid"
 451 
 452 
 453         # mJRE directives to use a specific version should be flagged
 454         #   with a warning, but the jar should be executed with the
 455         #   current jre
 456         CreateFullJar "junk request" ""
 457         LaunchVM "" "${RELEASE}"
 458         # Going to silently ignore JRE-Version setting in jar file manifest
 459         #LaunchVM "" "warning: The jarfile JRE-Version"
 460         
 461 
 462 exit 0
 463