# @test MultipleJRE.sh
# @bug 4811102 4953711 4955505 4956301 4991229 4998210 5018605 6387069 6733959
# @build PrintVersion
# @build UglyPrintVersion
# @build ZipMeUp
# @run shell MultipleJRE.sh
# @summary Verify Multiple JRE version support
# @author Joseph E. Kowalski
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
# Verify directory context variables are set
if [ "${TESTJAVA}" = "" ]
then
echo "TESTJAVA not set. Test cannot execute. Failed."
exit 1
fi
if [ "${TESTSRC}" = "" ]
then
echo "TESTSRC not set. Test cannot execute. Failed."
exit 1
fi
if [ "${TESTCLASSES}" = "" ]
then
echo "TESTCLASSES not set. Test cannot execute. Failed."
exit 1
fi
JAVA="$TESTJAVA/bin/java -classpath $TESTCLASSES"
#
# Tests whether we are on windows (true) or not.
#
printf "true"
;;
* )
printf "false"
;;
esac
}
#
# Shell routine to test for the proper rejection of syntactically incorrect
# version specifications.
#
if [ $? -eq 0 ]; then
echo "Invalid version syntax $1 accepted"
exit 1
fi
echo "Unexpected error message for invalid syntax $1"
exit 1
fi
}
#
# Just as the name says. We sprinkle these in the appropriate location
# in the test file system and they just say who they are pretending to be.
#
}
#
# Constructs the jar file needed by these tests.
#
if [ "$1" != "" ]; then
fi
}
#
# Constructs a jar file using zip.
#
if [ "$1" != "" ]; then
fi
}
#
# Constructs a jar file with a Main-Class attribute of greater than
# 80 characters to validate the continuation line processing.
#
# Make this just long enough to require two continuation lines. Longer
# paths take too much away from the restricted Windows maximum path length.
# Note: see the variable UGLYCLASS and its check for path length.
#
# Make sure that 5018605 remains fixed by including additional sections
# in the Manifest which contain the same names as those allowed in the
# main section.
#
PACKAGE=reallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallylongpackagename
if [ "$1" != "" ]; then
fi
}
#
# Constructs a jar file with a fair number of "zip directory" entries and
# the MANIFEST.MF entry at or near the end of that directory to validate
# the ability to transverse that directory.
#
if [ "$1" != "" ]; then
fi
for i in 0 1 2 3 4 5 6 7 8 9 ; do
for j in 0 1 2 3 4 5 6 7 8 9 ; do
done
done
rm -f AfairlyLong*
}
#
# Creates a jar file with the attributes which caused the failure
# described in 4991229.
#
# Generate a bunch of CENTAB entries, each of which is 64 bytes long
# which practically guarentees we will hit the appropriate power of
# two buffer (initially 1K). Note that due to the perversity of
# shorter name to compensate.
#
if [ "$1" != "" ]; then
fi
for i in 0 1 2 3 4 5 6 7 8 9 ; do
for j in 0 1 2 3 4 5 6 7 8 9 ; do
touch 64BytesPerEntry-$i$j
done
done
$JAR $2cMf PrintVersion 57* 64* PrintVersion.class
rm -f 57* 64*
}
#
#
# 1) Make sure zip file comments (both per file and per archive) are
# properly processed and ignored.
#
# 2) A long file comment creates a mondo "Central Directory" entry in
# the zip file. Such a "mondo" entry could also be due to a very
# long file name (path) or a long "Ext" entry, but adding the long
# comment is the easiest way.
#
file=
tail="is designed to take up space - lots and lots of space."
for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do
for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do
done
done
fi
else
fi
fi
fi
fi
done < zipout
/usr/bin/zipnote -w PrintVersion.zip < zipin
}
#
# Attempt to launch a vm using a version specifier and make sure the
# resultant launch (probably a "mock vm") is appropriate.
#
if [ "$1" != "" ]; then
else
fi
if [ $? -ne 0 ]; then
echo "$mess"
exit 1
fi
echo "Unexpected error in attempting to locate $1"
exit 1
fi
if [ $? != 0 ]; then
echo "Launched $mess, expected $2"
exit 1
fi
}
# Tests very long Main-Class attribute in the jar
JVER=$1
export JAVA_VERSION_PATH
fi
if [ $? -ne 0 ]; then
printf "Long manifest test did not get expected error"
exit 1
fi
unset JAVA_VERSION_PATH
}
#
# Main test sequence starts here
#
#
# compressed and "stored" jar files.
#
# The "Ugly" jar (long manifest line) tests are only run if the combination
# of the file name length restrictions and the length of the cwd allow it.
#
CreateJar "" ""
LaunchVM "" "${RELEASE}"
CreateJar "" "0"
LaunchVM "" "${RELEASE}"
if [ `IsWindows` = "true" ]; then
MAXIMUM_PATH=255;
else
MAXIMUM_PATH=1024;
fi
CreateUglyJar "" ""
LaunchVM "" "${RELEASE}"
CreateUglyJar "" "0"
LaunchVM "" "${RELEASE}"
else
fi
CreateAlignedJar "" ""
LaunchVM "" "${RELEASE}"
CreateFullJar "" ""
LaunchVM "" "${RELEASE}"
#
# 4998210 shows that some very strange behaviors are semi-supported.
# In this case, it's the ability to prepend any kind of stuff to the
# jar file and require that the jar file still work. Note that this
# "interface" isn't publically supported and we may choose to break
# it in the future, but this test guarantees that we won't break it
# without informed consent. We take advantage the fact that the
# "FullJar" we just tested is probably the best jar to begin with
# for this test.
#
echo "This is just meaningless bytes to prepend to the jar" > meaningless
LaunchVM "" "${RELEASE}"
#
# Officially, one must use "the jar command to create a jar file. However,
# all the comments about jar commands **imply** that jar files and zip files
# are equivalent. (Note: this isn't true due to the "0xcafe" insertion.)
# On systems which have a command line zip, test the ability to use zip
# to construct a jar and then use it (6387069).
#
CreateZippyJar "" "-q"
LaunchVM "" "${RELEASE}"
fi
#
# jar files shouldn't have comments, but it is possible that somebody added
# one by using zip -c, zip -z, zipnote or a similar utility. On systems
# that have "zipnote", verify this functionality.
#
# This serves a dual purpose of creating a very large "central directory
# entry" which validates to code to read such entries.
#
CreateFullJar "" ""
CommentZipFile "AfairlyLongNameEatsUpDirectorySpaceBetter20"
LaunchVM "" "${RELEASE}"
fi
#
# Throw some syntactically challenged (illegal) version specifiers at
# the interface. Failure (of the launcher) is success for the test.
#
# On windows we see if there is another jre installed, usually
# there is, then we test using that, otherwise links are created
# to get through to SelectVersion.
if [ `IsWindows` = "false" ]; then
TestLongMainClass "mklink"
else
if [ $? -eq 0 ]; then
TestLongMainClass "1.0+"
else
printf "Warning: TestLongMainClass skipped as there is no"
printf "viable MJRE installed.\n"
fi
fi
#
# Because scribbling in the registry can be rather destructive, only a
# subset of the tests are run on Windows.
#
if [ `IsWindows` = "true" ]; then
exit 0;
fi
#
# Additional version specifiers containing spaces. (Sigh, unable to
# figure out the glomming on Windows)
#
#
# Create a mock installation of a number of shell scripts named as though
# they were installed JREs. Then test to see if the launcher can cause
# the right shell scripts to be invoked.
#
# Note, that as a side effect, this test verifies that JAVA_VERSION_PATH
# works.
#
export JAVA_VERSION_PATH
CreateMockVM 1.10
#
# Test extracting the version information from the jar file:
#
# Requested Expected
CreateJar "1.10+" ""
LaunchVM "" "1.20.0"
CreateJar "1.11.3_03+&1.11*" ""
LaunchVM "" "1.11.4"
CreateJar "1.12.3_03+&1.12.3*" ""
LaunchVM "" "1.12.3_03"
CreateJar "1.13.3_03+&1.13.3*" ""
#
# Test obtaining the version information from the command line (and that
# it overrides the manifest).
#
CreateJar "${BASERELEASE}*" ""
LaunchVM "1.10+" "1.20.0"
LaunchVM "1.11.3_03+&1.11*" "1.11.4"
LaunchVM "1.12.3_03+&1.12.3*" "1.12.3_03"
exit 0