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 29set -e 30 31exception=0 32 33if [ -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`" 40fi 41 42JAVAC="$COMPILEJAVA/bin/javac" 43JAR="$COMPILEJAVA/bin/jar" 44JAVA="$TESTJAVA/bin/java ${TESTVMOPTS}" 45 46TESTDIR="$TESTCLASSES/classes" 47PLUGINDIR="$TESTCLASSES/classes" 48mkdir -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 53mkdir -p $TESTCLASSES/tmpdir/simp 54cp -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. 58mkdir -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 62OS=`uname -s` 63case "$OS" in 64 Windows_* | CYGWIN* ) 65CPSEP=";" 66 ;; 67 * ) 68CPSEP=":" 69 ;; 70esac 71 72# expect to find SimpReader via jar on classpath. 73# Will be treated as a regular jar. 74echo "Test classpath jar .. " 75$JAVA -cp ${TESTDIR}${CPSEP}${PLUGINDIR}/simp.jar simptest.TestSIMPPlugin 76if [ $? -ne 0 ]; then 77 exception=1 78 echo "Classpath test failed: exception thrown!" 79fi 80echo "Test classpath jar with security manager .." 81$JAVA -Djava.security.manager -cp .${CPSEP}${TESTDIR}${CPSEP}${PLUGINDIR}/simp.jar simptest.TestSIMPPlugin 82if [ $? -ne 0 ]; then 83 exception=1 84 echo "Classpath + SecurityManager test failed: exception thrown!" 85fi 86 87# expect to find SimpReader on module path 88echo "Test modular jar .. " 89$JAVA --module-path $PLUGINDIR -cp $TESTDIR simptest.TestSIMPPlugin 90 91if [ $? -ne 0 ]; then 92 exception=1 93 echo "modular jar test failed: exception thrown!" 94fi 95 96echo "Test modular jar with security manager .." 97$JAVA -Djava.security.manager --module-path $PLUGINDIR -cp $TESTDIR simptest.TestSIMPPlugin 98if [ $? -ne 0 ]; then 99 exception=1 100 echo "modular jar with security manager test failed: exception thrown!" 101fi 102 103if [ $exception -ne 0 ]; then 104 echo "TEST FAILED" 105 exit 1 106fi 107exit 0 108