jdk/test/tools/launcher/ClassPathWildCard.sh
author henryjen
Fri, 27 Jan 2017 13:10:27 -0800
changeset 43330 6aa5f2938b75
parent 15254 3997a6f357cb
permissions -rw-r--r--
8172309: classpath wildcards code does not support --class-path Reviewed-by: ksrini
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
#
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 5506
diff changeset
     9
# Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
2
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
#
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4663
diff changeset
    26
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4663
diff changeset
    27
# or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4663
diff changeset
    28
# questions.
2
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
15254
3997a6f357cb 8005978: shell tests need to use the $COMPILEJDK for javac, jar and other tools
alanb
parents: 9035
diff changeset
    46
if [ "${COMPILEJAVA}" = "" ]; then
3997a6f357cb 8005978: shell tests need to use the $COMPILEJDK for javac, jar and other tools
alanb
parents: 9035
diff changeset
    47
  COMPILEJAVA="${TESTJAVA}"
3997a6f357cb 8005978: shell tests need to use the $COMPILEJDK for javac, jar and other tools
alanb
parents: 9035
diff changeset
    48
fi
3997a6f357cb 8005978: shell tests need to use the $COMPILEJDK for javac, jar and other tools
alanb
parents: 9035
diff changeset
    49
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
if [ "${TESTSRC}" = "" ]; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
  echo "TESTSRC not set.  Test cannot execute.  Failed."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
  exit 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
if [ "${TESTCLASSES}" = "" ]; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
  echo "TESTCLASSES not set.  Test cannot execute.  Failed."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
  exit 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
JAVA=$TESTJAVA/bin/java
15254
3997a6f357cb 8005978: shell tests need to use the $COMPILEJDK for javac, jar and other tools
alanb
parents: 9035
diff changeset
    61
JAVAC=$COMPILEJAVA/bin/javac
3997a6f357cb 8005978: shell tests need to use the $COMPILEJDK for javac, jar and other tools
alanb
parents: 9035
diff changeset
    62
JAR=$COMPILEJAVA/bin/jar
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
OUTEXT=".out"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
# We write out a test file, as javaw does not have any notion about
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
# stdout or stderr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
EmitJavaFile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    fullName=$1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    fileName=`basename $fullName .java`
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    printf "import java.io.*;\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    printf "public class %s {\n" $fileName
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    printf "   public static void main(String[] args) {"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    printf "       String m = \"%s:\";\n" $fileName
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    printf "       m = m.concat(\"java.class.path=\");\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    printf "       m = m.concat(System.getProperty(\"java.class.path\",\"NONE\"));\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    printf "       System.out.println(m);\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    printf "       try {\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    printf "          PrintStream ps = new PrintStream(\"%s\");\n" $fileName$OUTEXT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    printf "          ps.println(m);\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    printf "          ps.flush(); ps.close();\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    printf "       } catch (Exception e) {\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    printf "           System.out.println(e.getMessage());\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    printf "           System.exit(1);\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    printf "       }\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    printf "   }\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    printf "}\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
) > $fullName
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
CreateClassFiles() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
  Exp=$1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
  [ -d Test${Exp} ] || mkdir Test${Exp} 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
  EmitJavaFile Test${Exp}/Test${Exp}.java
15254
3997a6f357cb 8005978: shell tests need to use the $COMPILEJDK for javac, jar and other tools
alanb
parents: 9035
diff changeset
    98
  $JAVAC ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d Test${Exp} Test${Exp}/Test${Exp}.java || exit 1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
CreateJarFiles() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
  Exp=$1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
  [ -d JarDir ] || mkdir JarDir
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
  CreateClassFiles $Exp
15254
3997a6f357cb 8005978: shell tests need to use the $COMPILEJDK for javac, jar and other tools
alanb
parents: 9035
diff changeset
   105
  $JAR ${TESTTOOLVMOPTS} -cvf JarDir/Test${Exp}.jar -C Test${Exp} . || exit 1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
CheckFail() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
  if [ ! -f ${1}${OUTEXT} ]; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     printf "Error: %s fails\n" "$1"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     exit 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
  fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
# Note: see CR:6328875 this is why we use the NOOP variable 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
# below on Windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
ExecJava() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
  variant=$1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
  NOOP=$2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
  # Test JAR files first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
  rm -f TestA${OUTEXT}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
  $JAVA${variant} -classpath JarDir/"*"$NOOP TestA || exit 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
  CheckFail TestA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
  rm -f TestB${OUTEXT}
43330
6aa5f2938b75 8172309: classpath wildcards code does not support --class-path
henryjen
parents: 15254
diff changeset
   128
  $JAVA${variant} -cp JarDir/"*"$NOOP TestB || exit 1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
  CheckFail TestB
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
  # Throw some class files into the mix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
  cp TestC/*.class JarDir
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
  cp TestD/*.class JarDir
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
  rm -f TestC${OUTEXT}
43330
6aa5f2938b75 8172309: classpath wildcards code does not support --class-path
henryjen
parents: 15254
diff changeset
   137
  $JAVA${variant} --class-path JarDir${PATHSEP}JarDir/"*"$NOOP TestC || exit 1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
  CheckFail TestC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
  rm -f TestD${OUTEXT}
43330
6aa5f2938b75 8172309: classpath wildcards code does not support --class-path
henryjen
parents: 15254
diff changeset
   141
  $JAVA${variant} --class-path=JarDir${PATHSEP}JarDir/"*"$NOOP TestD || exit 1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
  CheckFail TestD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
CreateJarFiles A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
CreateJarFiles B
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
CreateClassFiles C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
CreateClassFiles D
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
OS=`uname -s`
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
case $OS in 
4663
dfea6ffdb0dc 6911104: Tests do not work with CYGWIN: tools, sun/tools, and com/sun/tools
ohair
parents: 2
diff changeset
   152
    Windows*|CYGWIN*)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        PATHSEP=";"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        ExecJava "" "${PATHSEP}NOOPDIR"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        ExecJava "w" "${PATHSEP}NOOPDIR"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        break
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    ;;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    *)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        PATHSEP=":"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        ExecJava "" ""
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
	break
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    ;;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
esac
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
exit 0