26 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 27 # or visit www.oracle.com if you need additional information or have any 28 # 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 41 if [ "${TESTJAVA}" = "" ]; then 42 echo "TESTJAVA not set. Test cannot execute. Failed." 43 exit 1 44 fi 45 46 if [ "${TESTSRC}" = "" ]; then 47 echo "TESTSRC not set. Test cannot execute. Failed." 48 exit 1 49 fi 50 51 if [ "${TESTCLASSES}" = "" ]; then 52 echo "TESTCLASSES not set. Test cannot execute. Failed." 53 exit 1 54 fi 55 56 JAVA=$TESTJAVA/bin/java 57 JAVAC=$TESTJAVA/bin/javac 58 JAR=$TESTJAVA/bin/jar 59 60 OUTEXT=".out" 61 62 # We write out a test file, as javaw does not have any notion about 63 # stdout or stderr. 64 65 EmitJavaFile() { 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 90 CreateClassFiles() { 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 97 CreateJarFiles() { 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 104 CheckFail() { 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 114 ExecJava() { 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 | 26 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 27 # or visit www.oracle.com if you need additional information or have any 28 # 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 41 if [ "${TESTJAVA}" = "" ]; then 42 echo "TESTJAVA not set. Test cannot execute. Failed." 43 exit 1 44 fi 45 46 if [ "${COMPILEJAVA}" = "" ]; then 47 COMPILEJAVA="${TESTJAVA}" 48 fi 49 50 if [ "${TESTSRC}" = "" ]; then 51 echo "TESTSRC not set. Test cannot execute. Failed." 52 exit 1 53 fi 54 55 if [ "${TESTCLASSES}" = "" ]; then 56 echo "TESTCLASSES not set. Test cannot execute. Failed." 57 exit 1 58 fi 59 60 JAVA=$TESTJAVA/bin/java 61 JAVAC=$COMPILEJAVA/bin/javac 62 JAR=$COMPILEJAVA/bin/jar 63 64 OUTEXT=".out" 65 66 # We write out a test file, as javaw does not have any notion about 67 # stdout or stderr. 68 69 EmitJavaFile() { 70 fullName=$1 71 fileName=`basename $fullName .java` 72 73 ( 74 printf "import java.io.*;\n" 75 printf "public class %s {\n" $fileName 76 printf " public static void main(String[] args) {" 77 printf " String m = \"%s:\";\n" $fileName 78 printf " m = m.concat(\"java.class.path=\");\n" 79 printf " m = m.concat(System.getProperty(\"java.class.path\",\"NONE\"));\n" 80 printf " System.out.println(m);\n" 81 printf " try {\n" 82 printf " PrintStream ps = new PrintStream(\"%s\");\n" $fileName$OUTEXT 83 printf " ps.println(m);\n" 84 printf " ps.flush(); ps.close();\n" 85 printf " } catch (Exception e) {\n" 86 printf " System.out.println(e.getMessage());\n" 87 printf " System.exit(1);\n" 88 printf " }\n" 89 printf " }\n" 90 printf "}\n" 91 ) > $fullName 92 } 93 94 CreateClassFiles() { 95 Exp=$1 96 [ -d Test${Exp} ] || mkdir Test${Exp} 97 EmitJavaFile Test${Exp}/Test${Exp}.java 98 $JAVAC ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d Test${Exp} Test${Exp}/Test${Exp}.java || exit 1 99 } 100 101 CreateJarFiles() { 102 Exp=$1 103 [ -d JarDir ] || mkdir JarDir 104 CreateClassFiles $Exp 105 $JAR ${TESTTOOLVMOPTS} -cvf JarDir/Test${Exp}.jar -C Test${Exp} . || exit 1 106 } 107 108 CheckFail() { 109 if [ ! -f ${1}${OUTEXT} ]; then 110 printf "Error: %s fails\n" "$1" 111 exit 1 112 fi 113 } 114 115 # Note: see CR:6328875 this is why we use the NOOP variable 116 # below on Windows 117 118 ExecJava() { 119 variant=$1 120 NOOP=$2 121 122 # Test JAR files first 123 rm -f TestA${OUTEXT} 124 $JAVA${variant} -classpath JarDir/"*"$NOOP TestA || exit 1 125 CheckFail TestA |