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