1 # 2 # Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 # 5 # This code is free software; you can redistribute it and/or modify it 6 # under the terms of the GNU General Public License version 2 only, as 7 # published by the Free Software Foundation. 8 # 9 # This code is distributed in the hope that it will be useful, but WITHOUT 10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 # version 2 for more details (a copy is included in the LICENSE file that 13 # accompanied this code). 14 # 15 # You should have received a copy of the GNU General Public License version 16 # 2 along with this work; if not, write to the Free Software Foundation, 17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 # 19 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 # or visit www.oracle.com if you need additional information or have any 21 # questions. 22 # 23 24 # @test 25 # @bug 8081729 8140314 26 # @summary Test external plugin as classpath jar and as a modular jar. 27 # Test both cases with and without a security manager. 28 29 set -e 30 31 exception=0 32 33 if [ -z "$TESTJAVA" ]; then 34 if [ $# -lt 1 ]; then echo "No Java path specified. Exiting."; fi 35 if [ $# -lt 1 ]; then exit 1; fi 36 TESTJAVA="$1"; shift 37 COMPILEJAVA="${TESTJAVA}" 38 TESTSRC="`pwd`" 39 TESTCLASSES="`pwd`" 40 fi 41 42 JAVAC="$COMPILEJAVA/bin/javac" 43 JAR="$COMPILEJAVA/bin/jar" 44 JAVA="$TESTJAVA/bin/java ${TESTVMOPTS}" 45 46 TESTDIR="$TESTCLASSES/classes" 47 PLUGINDIR="$TESTCLASSES/classes" 48 mkdir -p $TESTDIR 49 $JAVAC -d $TESTDIR `find $TESTSRC/src/simptest -name "*.java"` 50 51 # compile the plugin java sources and services file into a temp location. 52 53 mkdir -p $TESTCLASSES/tmpdir/simp 54 cp -r $TESTSRC/src/simp/META-INF $TESTCLASSES/tmpdir 55 $JAVAC -d $TESTCLASSES/tmpdir `find $TESTSRC/src/simp -name "*.java"` 56 57 # create modular jar file (inc. module-info.java) from the class files. 58 mkdir -p $PLUGINDIR 59 $JAR cf $PLUGINDIR/simp.jar -C $TESTCLASSES/tmpdir META-INF/services \ 60 -C $TESTCLASSES/tmpdir module-info.class -C $TESTCLASSES/tmpdir simp 61 62 OS=`uname -s` 63 case "$OS" in 64 Windows_* | CYGWIN* ) 65 CPSEP=";" 66 ;; 67 * ) 68 CPSEP=":" 69 ;; 70 esac 71 72 # expect to find SimpReader via jar on classpath. 73 # Will be treated as a regular jar. 74 echo "Test classpath jar .. " 75 $JAVA -cp ${TESTDIR}${CPSEP}${PLUGINDIR}/simp.jar simptest.TestSIMPPlugin 76 if [ $? -ne 0 ]; then 77 exception=1 78 echo "Classpath test failed: exception thrown!" 79 fi 80 echo "Test classpath jar with security manager .." 81 $JAVA -Djava.security.manager -cp .${CPSEP}${TESTDIR}${CPSEP}${PLUGINDIR}/simp.jar simptest.TestSIMPPlugin 82 if [ $? -ne 0 ]; then 83 exception=1 84 echo "Classpath + SecurityManager test failed: exception thrown!" 85 fi 86 87 # expect to find SimpReader on module path 88 echo "Test modular jar .. " 89 $JAVA -mp $PLUGINDIR -cp $TESTDIR simptest.TestSIMPPlugin 90 91 if [ $? -ne 0 ]; then 92 exception=1 93 echo "modular jar test failed: exception thrown!" 94 fi 95 96 echo "Test modular jar with security manager .." 97 $JAVA -Djava.security.manager -mp $PLUGINDIR -cp $TESTDIR simptest.TestSIMPPlugin 98 if [ $? -ne 0 ]; then 99 exception=1 100 echo "modular jar with security manager test failed: exception thrown!" 101 fi 102 103 if [ $exception -ne 0 ]; then 104 echo "TEST FAILED" 105 exit 1 106 fi 107 exit 0