Path: blob/master/test/jdk/tools/launcher/ClassPathWildCard.sh
41144 views
#!/bin/sh1# @test2# @bug 65103373# @run shell ClassPathWildCard.sh4# @summary A very basic/rudimentary test for classpath wildcards5# @author Kumar Srinivasan67#8# Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.9# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.10#11# This code is free software; you can redistribute it and/or modify it12# under the terms of the GNU General Public License version 2 only, as13# published by the Free Software Foundation.14#15# This code is distributed in the hope that it will be useful, but WITHOUT16# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or17# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License18# version 2 for more details (a copy is included in the LICENSE file that19# accompanied this code).20#21# You should have received a copy of the GNU General Public License version22# 2 along with this work; if not, write to the Free Software Foundation,23# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.24#25# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA26# or visit www.oracle.com if you need additional information or have any27# questions.28#2930# An elaborate wildcard testing is done by test/tools/javac/Paths/wcMineField.sh,31# this test is a small subset, primarily to ensure that java and javaw launcher32# behave consistently, while we are it , doesn't hurt to test other platforms33# as well.3435# For debugging36# set -x37# _JAVA_LAUNCHER_DEBUG=true ; export _JAVA_LAUNCHER_DEBUG3839# Verify directory context variables are set40if [ "${TESTJAVA}" = "" ]; then41echo "TESTJAVA not set. Test cannot execute. Failed."42exit 143fi4445if [ "${COMPILEJAVA}" = "" ]; then46COMPILEJAVA="${TESTJAVA}"47fi4849if [ "${TESTSRC}" = "" ]; then50echo "TESTSRC not set. Test cannot execute. Failed."51exit 152fi5354if [ "${TESTCLASSES}" = "" ]; then55echo "TESTCLASSES not set. Test cannot execute. Failed."56exit 157fi5859JAVA=$TESTJAVA/bin/java60JAVAC=$COMPILEJAVA/bin/javac61JAR=$COMPILEJAVA/bin/jar6263OUTEXT=".out"6465# We write out a test file, as javaw does not have any notion about66# stdout or stderr.6768EmitJavaFile() {69fullName=$170fileName=`basename $fullName .java`7172(73printf "import java.io.*;\n"74printf "public class %s {\n" $fileName75printf " public static void main(String[] args) {"76printf " String m = \"%s:\";\n" $fileName77printf " m = m.concat(\"java.class.path=\");\n"78printf " m = m.concat(System.getProperty(\"java.class.path\",\"NONE\"));\n"79printf " System.out.println(m);\n"80printf " try {\n"81printf " PrintStream ps = new PrintStream(\"%s\");\n" $fileName$OUTEXT82printf " ps.println(m);\n"83printf " ps.flush(); ps.close();\n"84printf " } catch (Exception e) {\n"85printf " System.out.println(e.getMessage());\n"86printf " System.exit(1);\n"87printf " }\n"88printf " }\n"89printf "}\n"90) > $fullName91}9293CreateClassFiles() {94Exp=$195[ -d Test${Exp} ] || mkdir Test${Exp}96EmitJavaFile Test${Exp}/Test${Exp}.java97$JAVAC ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d Test${Exp} Test${Exp}/Test${Exp}.java || exit 198}99100CreateJarFiles() {101Exp=$1102[ -d JarDir ] || mkdir JarDir103CreateClassFiles $Exp104$JAR ${TESTTOOLVMOPTS} -cvf JarDir/Test${Exp}.jar -C Test${Exp} . || exit 1105}106107CheckFail() {108if [ ! -f ${1}${OUTEXT} ]; then109printf "Error: %s fails\n" "$1"110exit 1111fi112}113114# Note: see CR:6328875 this is why we use the NOOP variable115# below on Windows116117ExecJava() {118variant=$1119NOOP=$2120121# Test JAR files first122rm -f TestA${OUTEXT}123$JAVA${variant} -classpath JarDir/"*"$NOOP TestA || exit 1124CheckFail TestA125126rm -f TestB${OUTEXT}127$JAVA${variant} -cp JarDir/"*"$NOOP TestB || exit 1128CheckFail TestB129130131# Throw some class files into the mix132cp TestC/*.class JarDir133cp TestD/*.class JarDir134135rm -f TestC${OUTEXT}136$JAVA${variant} --class-path JarDir${PATHSEP}JarDir/"*"$NOOP TestC || exit 1137CheckFail TestC138139rm -f TestD${OUTEXT}140$JAVA${variant} --class-path=JarDir${PATHSEP}JarDir/"*"$NOOP TestD || exit 1141CheckFail TestD142}143144CreateJarFiles A145CreateJarFiles B146CreateClassFiles C147CreateClassFiles D148149OS=`uname -s`150case $OS in151Windows*|CYGWIN*)152PATHSEP=";"153ExecJava "" "${PATHSEP}NOOPDIR"154ExecJava "w" "${PATHSEP}NOOPDIR"155break156;;157158*)159PATHSEP=":"160ExecJava "" ""161break162;;163esac164165exit 0166167168