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
34if [ "${TESTJAVA}" = "" ]
35then
36  echo "TESTJAVA not set.  Test cannot execute.  Failed."
37  exit 1
38fi
39
40if [ "${COMPILEJAVA}" = "" ]; then
41  COMPILEJAVA="${TESTJAVA}"
42fi
43
44if [ "${TESTSRC}" = "" ]
45then
46  echo "TESTSRC not set.  Test cannot execute.  Failed."
47  exit 1
48fi
49
50if [ "${TESTCLASSES}" = "" ]
51then
52  echo "TESTCLASSES not set.  Test cannot execute.  Failed."
53  exit 1
54fi
55
56JAVAEXE="$TESTJAVA/bin/java ${TESTVMOPTS}"
57JAVA="$TESTJAVA/bin/java ${TESTVMOPTS} -classpath $TESTCLASSES"
58JAR="$COMPILEJAVA/bin/jar ${TESTTOOLVMOPTS}"
59OS=`uname -s`;
60
61#
62# Tests whether we are on windows (true) or not.
63#
64IsWindows() {
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#
79TestSyntax() {
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# Just as the name says.  We sprinkle these in the appropriate location
94# in the test file system and they just say who they are pretending to be.
95#
96CreateMockVM() {
97	mkdir -p jdk/j2re$1/bin
98	echo "#!/bin/sh"    > jdk/j2re$1/bin/java
99	echo "echo \"$1\"" >> jdk/j2re$1/bin/java
100	chmod +x jdk/j2re$1/bin/java
101}
102
103#
104# Constructs the jar file needed by these tests.
105#
106CreateJar() {
107	mkdir -p META-INF
108	echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF
109	echo "Main-Class: PrintVersion" >> META-INF/MANIFEST.MF
110	if [ "$1" != "" ]; then
111		echo "JRE-Version: $1" >> META-INF/MANIFEST.MF
112	fi
113	cp $TESTCLASSES/PrintVersion.class .
114	$JAR $2cmf META-INF/MANIFEST.MF PrintVersion PrintVersion.class
115}
116
117#
118# Constructs a jar file using zip.
119#
120CreateZippyJar() {
121	mkdir -p META-INF
122	echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF
123	echo "Main-Class: PrintVersion" >> META-INF/MANIFEST.MF
124	if [ "$1" != "" ]; then
125		echo "JRE-Version: $1" >> META-INF/MANIFEST.MF
126	fi
127	cp $TESTCLASSES/PrintVersion.class .
128	/usr/bin/zip $2 PrintVersion META-INF/MANIFEST.MF PrintVersion.class
129}
130
131#
132# Constructs a jar file with a Main-Class attribute of greater than
133# 80 characters to validate the continuation line processing.
134#
135# Make this just long enough to require two continuation lines.  Longer
136# paths take too much away from the restricted Windows maximum path length.
137# Note: see the variable UGLYCLASS and its check for path length.
138#
139# Make sure that 5018605 remains fixed by including additional sections
140# in the Manifest which contain the same names as those allowed in the
141# main section.
142#
143PACKAGE=reallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallylongpackagename
144UGLYCLASS=$TESTCLASSES/$PACKAGE/UglyPrintVersion.class
145CreateUglyJar() {
146	mkdir -p META-INF
147	echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF
148	echo "Main-Class: $PACKAGE.UglyPrintVersion" >> META-INF/MANIFEST.MF
149	if [ "$1" != "" ]; then
150		echo "JRE-Version: $1" >> META-INF/MANIFEST.MF
151	fi
152	echo "" >> META-INF/MANIFEST.MF
153	echo "Name: NotToBeFound.class" >> META-INF/MANIFEST.MF
154	echo "Main-Class: NotToBeFound" >> META-INF/MANIFEST.MF
155	mkdir -p $PACKAGE
156	cp $UGLYCLASS $PACKAGE
157	$JAR $2cmf META-INF/MANIFEST.MF PrintVersion \
158	    $PACKAGE/UglyPrintVersion.class
159}
160
161#
162# Constructs a jar file with a fair number of "zip directory" entries and
163# the MANIFEST.MF entry at or near the end of that directory to validate
164# the ability to transverse that directory.
165#
166CreateFullJar() {
167	mkdir -p META-INF
168	echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF
169	echo "Main-Class: PrintVersion" >> META-INF/MANIFEST.MF
170	if [ "$1" != "" ]; then
171	    echo "JRE-Version: $1" >> META-INF/MANIFEST.MF
172	fi
173	cp $TESTCLASSES/PrintVersion.class .
174	for i in 0 1 2 3 4 5 6 7 8 9 ; do
175		for j in 0 1 2 3 4 5 6 7 8 9 ; do
176			touch AfairlyLongNameEatsUpDirectorySpaceBetter$i$j
177		done
178	done
179	$JAR $2cMf PrintVersion PrintVersion.class AfairlyLong*
180	$JAR $2umf META-INF/MANIFEST.MF PrintVersion
181	rm -f AfairlyLong*
182}
183
184#
185# Creates a jar file with the attributes which caused the failure
186# described in 4991229.
187#
188# Generate a bunch of CENTAB entries, each of which is 64 bytes long
189# which practically guarentees we will hit the appropriate power of
190# two buffer (initially 1K).  Note that due to the perversity of
191# zip/jar files, the first entry gets extra stuff so it needs a
192# shorter name to compensate.
193#
194CreateAlignedJar() {
195	mkdir -p META-INF
196	echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF
197	echo "Main-Class: PrintVersion" >> META-INF/MANIFEST.MF
198	if [ "$1" != "" ]; then
199	    echo "JRE-Version: $1" >> META-INF/MANIFEST.MF
200	fi
201	cp $TESTCLASSES/PrintVersion.class .
202	touch 57BytesSpecial
203	for i in 0 1 2 3 4 5 6 7 8 9 ; do
204		for j in 0 1 2 3 4 5 6 7 8 9 ; do
205			touch 64BytesPerEntry-$i$j
206		done
207	done
208	$JAR $2cMf PrintVersion 57* 64* PrintVersion.class
209	$JAR $2umf META-INF/MANIFEST.MF PrintVersion
210	rm -f 57* 64*
211}
212
213#
214# Adds comments to a jar/zip file.  This serves two purposes:
215#
216#   1)	Make sure zip file comments (both per file and per archive) are
217#	properly processed and ignored.
218#
219#   2)	A long file comment creates a mondo "Central Directory" entry in
220#	the zip file. Such a "mondo" entry could also be due to a very
221#	long file name (path) or a long "Ext" entry, but adding the long
222#	comment is the easiest way.
223#
224MONDO=" 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."
225CommentZipFile() {
226	mkdir -p META-INF
227	echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF
228	echo "Main-Class: PrintVersion" >> META-INF/MANIFEST.MF
229	if [ "$1" != "" ]; then
230	    echo "JRE-Version: $1" >> META-INF/MANIFEST.MF
231	fi
232	cp $TESTCLASSES/PrintVersion.class .
233
234	# The remaining code in CommentZipFile essentially replaces the
235	#   following code, which added comments to the jar file.
236	#   Unfortunately zipnote has been broken since 3.0 [ 2008 ] and
237	#   there has been no new [ fixed ] version.  zipnote has probably
238	#   always failed, or failed for a long time without causing the
239	#   test to fail.  So no comments were added to the file.
240	#   The comments are added using zip(1) during the creation of the
241	#   zip file.
242	#
243	# NOTE:
244	#   It seems the original intent of this test was to add a very long
245	#   comment for one file.  But zip allows a max of 256 characters, so
246	#   we settle for adding 256-character comments to lots of files.
247	#
248	# $JAR $2cMf PrintVersion PrintVersion.class AfairlyLong*
249	# $JAR $2umf META-INF/MANIFEST.MF PrintVersion
250	# /usr/bin/zipnote PrintVersion.zip > zipout
251	# ... code to modify zipout adding comments
252	# /usr/bin/zipnote -w PrintVersion.zip < zipin
253	# mv PrintVersion.zip PrintVersion
254	#
255
256
257	for i in 0 1 2 3 4 5 6 7 8 9 ; do
258		for j in 0 1 2 3 4 5 6 7 8 9 ; do
259			touch AfairlyLongNameEatsUpDirectorySpaceBetter$i$j
260		done
261	done
262
263        zip -$2c PrintVersion.zip PrintVersion.class AfairlyLong* META-INF/MANIFEST.MF << FINI
264File Comment Line.
265File Comment Line.
266File Comment Line.
267File Comment Line.
268File Comment Line.
269File Comment Line.
270File Comment Line.
271File Comment Line.
272File Comment Line.
273File Comment Line.
274File Comment Line.
275File Comment Line.
276File Comment Line.
277File Comment Line.
278File Comment Line.
279File Comment Line.
280File Comment Line.
281File Comment Line.
282File Comment Line.
283File Comment Line.
284$MONDO
285File Comment Line.
286File Comment Line.
287File Comment Line.
288FINI
289
290	rm -f AfairlyLong*
291
292    mv PrintVersion.zip PrintVersion
293
294}
295
296#
297# Attempt to launch a vm using a version specifier and make sure the
298# resultant launch (probably a "mock vm") is appropriate.
299#
300LaunchVM() {
301	if [ "$1" != "" ]; then
302		mess="`$JAVA \"$1\" -jar PrintVersion 2>&1`"
303		if [ $? -eq 0 ]; then
304			echo "Unexpected success of -Version:$1"
305			echo "$mess"
306			exit 1
307		fi
308	else
309		mess="`$JAVA -jar PrintVersion 2>&1`"
310		if [ $? -ne 0 ]; then
311			prefix=`echo "$mess" | cut -d ' ' -f 1-3`
312			if [ "$prefix" != "Unable to locate" ]; then
313				echo "$mess"
314				exit 1
315			fi
316			echo "Unexpected error in attempting to locate $1"
317			exit 1
318		fi
319
320	fi
321
322	echo $mess | grep "$2" > /dev/null 2>&1
323	if [ $? != 0 ]; then
324	    echo "Launched $mess, expected $1"
325	    exit 1
326	fi
327}
328
329# Tests very long Main-Class attribute in the jar
330TestLongMainClass() {
331    JVER=$1
332    if [ "$JVER" = "mklink" ]; then
333        JVER=XX
334        JDKXX=jdk/j2re$JVER
335        rm -rf jdk
336        mkdir jdk
337        ln -s $TESTJAVA $JDKXX
338        JAVA_VERSION_PATH="`pwd`/jdk"
339        export JAVA_VERSION_PATH
340    fi
341    $JAVAEXE -cp $TESTCLASSES ZipMeUp UglyBetty.jar 4097 
342    message="`$JAVAEXE -version:$JVER -jar UglyBetty.jar 2>&1`"
343    echo $message | grep "Error: main-class: attribute exceeds system limits" > /dev/null 2>&1
344    if [ $? -ne 0 ]; then
345        printf "Long manifest test did not get expected error"
346        exit 1
347    fi
348    unset JAVA_VERSION_PATH
349    rm -rf jdk
350}
351
352#
353# Main test sequence starts here
354#
355
356RELEASE=`$JAVA -version 2>&1 | head -n 1 | cut -d ' ' -f 3 | \
357  sed -e "s/\"//g"`
358BASE_RELEASE=`echo $RELEASE | sed -e "s/-.*//g"`
359
360#
361# Make sure that the generic jar/manifest reading code works. Test both
362# compressed and "stored" jar files.
363#
364# The "Ugly" jar (long manifest line) tests are only run if the combination
365# of the file name length restrictions and the length of the cwd allow it.
366#
367CreateJar "" ""
368LaunchVM "" "${RELEASE}"
369CreateJar "" "0"
370LaunchVM "" "${RELEASE}"
371if [ `IsWindows` = "true" ]; then
372    MAXIMUM_PATH=255;
373else
374    MAXIMUM_PATH=1024;
375fi
376
377PATH_LENGTH=`printf "%s" "$UGLYCLASS" | wc -c`
378if [ ${PATH_LENGTH} -lt ${MAXIMUM_PATH} ]; then
379	CreateUglyJar "" ""
380	LaunchVM "" "${RELEASE}"
381	CreateUglyJar "" "0"
382	LaunchVM "" "${RELEASE}"
383else
384    printf "Warning: Skipped UglyJar test, path length exceeded, %d" $MAXIMUM_PATH
385    printf " allowed, the current path is %d\n" $PATH_LENGTH
386fi
387CreateAlignedJar "" ""
388LaunchVM "" "${RELEASE}"
389CreateFullJar "" ""
390LaunchVM "" "${RELEASE}"
391
392#
393# 4998210 shows that some very strange behaviors are semi-supported.
394# In this case, it's the ability to prepend any kind of stuff to the
395# jar file and require that the jar file still work.  Note that this
396# "interface" isn't publically supported and we may choose to break
397# it in the future, but this test guarantees that we won't break it
398# without informed consent. We take advantage the fact that the
399# "FullJar" we just tested is probably the best jar to begin with
400# for this test.
401#
402echo "This is just meaningless bytes to prepend to the jar" > meaningless
403mv PrintVersion meaningfull
404cat meaningless meaningfull > PrintVersion
405LaunchVM "" "${RELEASE}" 
406rm meaningless meaningfull
407
408#
409# Officially, one must use "the jar command to create a jar file.  However,
410# all the comments about jar commands **imply** that jar files and zip files
411# are equivalent.  (Note: this isn't true due to the "0xcafe" insertion.)
412# On systems which have a command line zip, test the ability to use zip
413# to construct a jar and then use it (6387069).
414#
415if [ -x /usr/bin/zip ]; then
416	CreateZippyJar "" "-q"
417	LaunchVM "" "${RELEASE}"
418fi
419
420#
421# jar files shouldn't have comments, but it is possible that somebody added
422# one by using zip -c, zip -z, zipnote or a similar utility.  On systems
423# that have "zipnote", verify this functionality.
424#
425# This serves a dual purpose of creating a very large "central directory
426# entry" which validates to code to read such entries.
427#
428if [ -x /usr/bin/zipnote ]; then
429	CreateFullJar "" ""
430	CommentZipFile "AfairlyLongNameEatsUpDirectorySpaceBetter20"
431	LaunchVM "" "${RELEASE}"
432fi
433
434exit 0
435