blob: 46a4866e4862ab1b4dc97652a82de09b816f5005 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001#!/bin/sh
2# @test
3# @bug 6510337
4# @run shell ClassPathWildCard.sh
5# @summary A very basic/rudimentary test for classpath wildcards
6# @author Kumar Srinivasan
7
8#
9# Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
10# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
11#
12# This code is free software; you can redistribute it and/or modify it
13# under the terms of the GNU General Public License version 2 only, as
14# published by the Free Software Foundation.
15#
16# This code is distributed in the hope that it will be useful, but WITHOUT
17# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19# version 2 for more details (a copy is included in the LICENSE file that
20# accompanied this code).
21#
22# You should have received a copy of the GNU General Public License version
23# 2 along with this work; if not, write to the Free Software Foundation,
24# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25#
26# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
27# CA 95054 USA or visit www.sun.com if you need additional information or
28# have any questions.
29#
30
31# An elaborate wildcard testing is done by test/tools/javac/Paths/wcMineField.sh,
32# this test is a small subset, primarily to ensure that java and javaw launcher
33# behave consistently, while we are it , doesn't hurt to test other platforms
34# as well.
35
36# For debugging
37# set -x
38# _JAVA_LAUNCHER_DEBUG=true ; export _JAVA_LAUNCHER_DEBUG
39
40# Verify directory context variables are set
41if [ "${TESTJAVA}" = "" ]; then
42 echo "TESTJAVA not set. Test cannot execute. Failed."
43 exit 1
44fi
45
46if [ "${TESTSRC}" = "" ]; then
47 echo "TESTSRC not set. Test cannot execute. Failed."
48 exit 1
49fi
50
51if [ "${TESTCLASSES}" = "" ]; then
52 echo "TESTCLASSES not set. Test cannot execute. Failed."
53 exit 1
54fi
55
56JAVA=$TESTJAVA/bin/java
57JAVAC=$TESTJAVA/bin/javac
58JAR=$TESTJAVA/bin/jar
59
60OUTEXT=".out"
61
62# We write out a test file, as javaw does not have any notion about
63# stdout or stderr.
64
65EmitJavaFile() {
66 fullName=$1
67 fileName=`basename $fullName .java`
68
69(
70 printf "import java.io.*;\n"
71 printf "public class %s {\n" $fileName
72 printf " public static void main(String[] args) {"
73 printf " String m = \"%s:\";\n" $fileName
74 printf " m = m.concat(\"java.class.path=\");\n"
75 printf " m = m.concat(System.getProperty(\"java.class.path\",\"NONE\"));\n"
76 printf " System.out.println(m);\n"
77 printf " try {\n"
78 printf " PrintStream ps = new PrintStream(\"%s\");\n" $fileName$OUTEXT
79 printf " ps.println(m);\n"
80 printf " ps.flush(); ps.close();\n"
81 printf " } catch (Exception e) {\n"
82 printf " System.out.println(e.getMessage());\n"
83 printf " System.exit(1);\n"
84 printf " }\n"
85 printf " }\n"
86 printf "}\n"
87) > $fullName
88}
89
90CreateClassFiles() {
91 Exp=$1
92 [ -d Test${Exp} ] || mkdir Test${Exp}
93 EmitJavaFile Test${Exp}/Test${Exp}.java
94 $JAVAC -d Test${Exp} Test${Exp}/Test${Exp}.java || exit 1
95}
96
97CreateJarFiles() {
98 Exp=$1
99 [ -d JarDir ] || mkdir JarDir
100 CreateClassFiles $Exp
101 $JAR -cvf JarDir/Test${Exp}.jar -C Test${Exp} . || exit 1
102}
103
104CheckFail() {
105 if [ ! -f ${1}${OUTEXT} ]; then
106 printf "Error: %s fails\n" "$1"
107 exit 1
108 fi
109}
110
111# Note: see CR:6328875 this is why we use the NOOP variable
112# below on Windows
113
114ExecJava() {
115 variant=$1
116 NOOP=$2
117
118 # Test JAR files first
119 rm -f TestA${OUTEXT}
120 $JAVA${variant} -classpath JarDir/"*"$NOOP TestA || exit 1
121 CheckFail TestA
122
123 rm -f TestB${OUTEXT}
124 $JAVA${variant} -classpath JarDir/"*"$NOOP TestB || exit 1
125 CheckFail TestB
126
127
128 # Throw some class files into the mix
129 cp TestC/*.class JarDir
130 cp TestD/*.class JarDir
131
132 rm -f TestC${OUTEXT}
133 $JAVA${variant} -classpath JarDir${PATHSEP}JarDir/"*"$NOOP TestC || exit 1
134 CheckFail TestC
135
136 rm -f TestD${OUTEXT}
137 $JAVA${variant} -classpath JarDir${PATHSEP}JarDir/"*"$NOOP TestD || exit 1
138 CheckFail TestD
139}
140
141CreateJarFiles A
142CreateJarFiles B
143CreateClassFiles C
144CreateClassFiles D
145
146OS=`uname -s`
147case $OS in
148 Windows*|Cygwin*)
149 PATHSEP=";"
150 ExecJava "" "${PATHSEP}NOOPDIR"
151 ExecJava "w" "${PATHSEP}NOOPDIR"
152 break
153 ;;
154
155 *)
156 PATHSEP=":"
157 ExecJava "" ""
158 break
159 ;;
160esac
161
162exit 0