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