jdk/test/sun/rmi/rmic/manifestClassPath/Util.sh
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
# Copyright 2007 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
# This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
# under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
# published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
# This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
# version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
# accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
# You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
# 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
# CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
# have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
# Utilities for shell tests
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
: ${TESTSRC=.} ${TESTCLASSES=.}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 java="${TESTJAVA+${TESTJAVA}/bin/}java"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
javac="${TESTJAVA+${TESTJAVA}/bin/}javac"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
  jar="${TESTJAVA+${TESTJAVA}/bin/}jar"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 rmic="${TESTJAVA+${TESTJAVA}/bin/}rmic"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
case `uname -s` in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
  Windows*|CYGWIN*)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    WindowsOnly() { "$@"; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    UnixOnly() { :; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    PS=";" ;;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
  *)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    UnixOnly() { "$@"; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    WindowsOnly() { :; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    PS=":";;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
esac
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
failed=""
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
Fail() { echo "FAIL: $1"; failed="${failed}."; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
Die() { printf "%s\n" "$*"; exit 1; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
Sys() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    printf "%s\n" "$*"; "$@"; rc="$?";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    test "$rc" -eq 0 || Die "Command \"$*\" failed with exitValue $rc";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
CheckFiles() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    for f in "$@"; do test -r "$f" || Die "File $f not found"; done
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
Report() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    test "$#" != 2 && Die "Usage: Report success|failure rc"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    if   test "$1" = "success" -a "$2" = 0; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
	echo "PASS: succeeded as expected"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    elif test "$1" = "failure" -a "$2" != 0; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
	echo "PASS: failed as expected"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    elif test "$1" = "success" -a "$2" != 0; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
	Fail "test failed unexpectedly"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    elif test "$1" = "failure" -a "$2" = 0; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
	Fail "test succeeded unexpectedly"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
	Die "Usage: Report success|failure rc"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
MkManifestWithClassPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    (echo "Manifest-Version: 1.0"; echo "Class-Path: $*") > MANIFEST.MF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
HorizontalRule() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    echo "-----------------------------------------------------------------"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
Test() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    HorizontalRule
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    expectedResult="$1"; shift
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    printf "%s\n" "$*"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    "$@"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    Report "$expectedResult" "$?"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
Failure() { Test failure "$@"; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
Success() { Test success "$@"; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
Bottom() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    test "$#" = 1 -a "$1" = "Line" || Die "Usage: Bottom Line"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    if test -n "$failed"; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
	count=`printf "%s" "$failed" | wc -c | tr -d ' '`
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
	echo "FAIL: $count tests failed"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
	exit 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
	echo "PASS: all tests gave expected results"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
	exit 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
BadJarFile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    for jarfilename in "$@"; do pwd > "$jarfilename"; done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
#----------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
# Usage: BCP=`DefaultBootClassPath`
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
# Returns default bootclasspath, discarding non-existent entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
#----------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
DefaultBootClassPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    echo 'public class B {public static void main(String[] a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    System.out.println(System.getProperty("sun.boot.class.path"));}}' > B.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    "$javac" B.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    _BCP_=""
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    for elt in `"$java" B | tr "${PS}" " "`; do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
	test -r "$elt" -a -n "$elt" && _BCP_="${_BCP_:+${_BCP_}${PS}}${elt}"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    rm -f B.java B.class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    printf "%s" "$_BCP_"	# Don't use echo -- unsafe on Windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
#----------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
# Foil message localization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
#----------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
DiagnosticsInEnglishPlease() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    LANG="C" LC_ALL="C" LC_MESSAGES="C"; export LANG LC_ALL LC_MESSAGES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
}