1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
|
#
# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
# @test
# @bug 8137317 8139238
# @summary Visibility tests for ResourceBundle.getBundle with and without
# an unnamed module argument.
set -e
STATUS=0
runJava()
{
echo "Executing java $@"
$JAVA $@ || STATUS=1
echo
}
if [ -z "$TESTJAVA" ]; then
if [ $# -lt 1 ]; then exit 1; fi
TESTJAVA="$1"; shift
COMPILEJAVA="${TESTJAVA}"
TESTSRC="`pwd`"
TESTCLASSES="`pwd`"
fi
JAVAC="$COMPILEJAVA/bin/javac"
JAVA="$TESTJAVA/bin/java"
rm -rf mods classes
MODS=`cd $TESTSRC/src; find . -name module-info.java -exec dirname {} \; | sed 's:\./::'`
for M in $MODS
do
mkdir -p mods/$M
CLASSES="`find $TESTSRC/src/$M -name '*.java'`"
if [ "x$CLASSES" != x ]; then
$JAVAC -g -d mods --module-source-path $TESTSRC/src $CLASSES
fi
PROPS="`(cd $TESTSRC/src/$M; find . -name '*.properties')`"
if [ "x$PROPS" != x ]; then
for P in $PROPS
do
D=`dirname $P`
mkdir -p mods/$M/$D
cp $TESTSRC/src/$M/$P mods/$M/$D/
done
fi
done
# Package jdk.test is in named module "test".
# Package jdk.embargo is in named module "embargo".
# jdk.{test,embargo}.TestWithUnnamedModuleArg call:
# ResourceBundle.getBundle(basename, classloader.getUnnamedModule())
# where classloader is the TCCL or system class loader.
# jdk.{test,embargo}.TestWithNoModuleArg call:
# ResourceBundle.getBundle(basename)
# jdk.test.resources[.exported].classes.* are class-based resource bundles.
# jdk.test.resources[.exported].props.* are properties file-based resource bundles.
# Packages jdk.test.resources.{classes,props} in named module "named.bundles"
# are exported only to named module "test".
# Packages jdk.test.resources.exported.{classes,props} in named module
# "exported.named.bundle" are exported to unnamed modules.
########################################
# Test cases with jdk.test.resources.* #
########################################
# Tests using jdk.test.TestWithNoModuleArg and jdk.embargo.TestWithNoModuleArg
# neither of which specifies an unnamed module with ResourceBundle.getBundle().
# jdk.test.resources.{classes,props}.* are available only to named module "test"
# by ResourceBundleProvider.
runJava -p mods -m test/jdk.test.TestWithNoModuleArg \
jdk.test.resources.classes.MyResources true
runJava -p mods -m test/jdk.test.TestWithNoModuleArg \
jdk.test.resources.props.MyResources true
runJava -p mods -m embargo/jdk.embargo.TestWithNoModuleArg \
jdk.test.resources.classes.MyResources false
runJava -p mods -m embargo/jdk.embargo.TestWithNoModuleArg \
jdk.test.resources.props.MyResources false
# Add mods/named.bundles to the class path.
runJava -cp mods/named.bundles -p mods -m test/jdk.test.TestWithNoModuleArg \
jdk.test.resources.classes.MyResources true
runJava -cp mods/named.bundles -p mods -m test/jdk.test.TestWithNoModuleArg \
jdk.test.resources.props.MyResources true
runJava -cp mods/named.bundles -p mods -m embargo/jdk.embargo.TestWithNoModuleArg \
jdk.test.resources.classes.MyResources true
runJava -cp mods/named.bundles -p mods -m embargo/jdk.embargo.TestWithNoModuleArg \
jdk.test.resources.props.MyResources true
# Tests using jdk.test.TestWithUnnamedModuleArg and jdk.embargo.TestWithUnnamedModuleArg
# both of which specify an unnamed module with ResourceBundle.getBundle.
# jdk.test.resources.classes is exported to named module "test".
# IllegalAccessException is thrown in ResourceBundle.Control.newBundle().
runJava -p mods -m test/jdk.test.TestWithUnnamedModuleArg \
jdk.test.resources.classes.MyResources false
# jdk.test.resources.props is exported to named module "test".
# loader.getResource() doesn't find jdk.test.resources.props.MyResources.
runJava -p mods -m test/jdk.test.TestWithUnnamedModuleArg \
jdk.test.resources.props.MyResources false
# IllegalAccessException is thrown in ResourceBundle.Control.newBundle().
runJava -p mods -m embargo/jdk.embargo.TestWithUnnamedModuleArg \
jdk.test.resources.classes.MyResources false
# jdk.test.resources.props is exported to named module "test".
# loader.getResource() doesn't find jdk.test.resources.props.MyResources.
runJava -p mods -m embargo/jdk.embargo.TestWithUnnamedModuleArg \
jdk.test.resources.props.MyResources false
# Add mods/named.bundles to the class path
# IllegalAccessException is thrown in ResourceBundle.Control.newBundle().
runJava -cp mods/named.bundles -p mods -m test/jdk.test.TestWithUnnamedModuleArg \
jdk.test.resources.classes.MyResources false
# loader.getResource() finds jdk.test.resources.exported.props.MyResources.
runJava -cp mods/named.bundles -p mods -m test/jdk.test.TestWithUnnamedModuleArg \
jdk.test.resources.props.MyResources true
# jdk.test.resources.exported.classes.MyResources is treated
# as if the class is in an unnamed module.
runJava -cp mods/named.bundles -p mods -m embargo/jdk.embargo.TestWithUnnamedModuleArg \
jdk.test.resources.classes.MyResources true
# loader.getResource() finds jdk.test.resources.exported.props.MyResources.
runJava -cp mods/named.bundles -p mods -m embargo/jdk.embargo.TestWithUnnamedModuleArg \
jdk.test.resources.props.MyResources true
#################################################
# Test cases with jdk.test.resources.exported.* #
#################################################
# Tests using jdk.test.TestWithNoModuleArg and jdk.embargo.TestWithNoModuleArg
# neither of which specifies an unnamed module with ResourceBundle.getBundle.
# None of jdk.test.resources.exported.** is available to the named modules.
runJava -p mods -m test/jdk.test.TestWithNoModuleArg \
jdk.test.resources.exported.classes.MyResources false
runJava -p mods -m test/jdk.test.TestWithNoModuleArg \
jdk.test.resources.exported.props.MyResources false
runJava -p mods -m embargo/jdk.embargo.TestWithNoModuleArg \
jdk.test.resources.exported.classes.MyResources false
runJava -p mods -m embargo/jdk.embargo.TestWithNoModuleArg \
jdk.test.resources.exported.props.MyResources false
# Add mods/exported.named.bundles to the class path.
runJava -cp mods/exported.named.bundles -p mods -m test/jdk.test.TestWithNoModuleArg \
jdk.test.resources.exported.classes.MyResources true
runJava -cp mods/exported.named.bundles -p mods -m test/jdk.test.TestWithNoModuleArg \
jdk.test.resources.exported.props.MyResources true
runJava -cp mods/exported.named.bundles -p mods -m embargo/jdk.embargo.TestWithNoModuleArg \
jdk.test.resources.exported.classes.MyResources true
runJava -cp mods/exported.named.bundles -p mods -m embargo/jdk.embargo.TestWithNoModuleArg \
jdk.test.resources.exported.props.MyResources true
# Tests using jdk.test.TestWithUnnamedModuleArg and jdk.embargo.TestWithUnnamedModuleArg
# which specify an unnamed module with ResourceBundle.getBundle.
# loader.loadClass() doesn't find jdk.test.resources.exported.classes.MyResources
# and throws a ClassNotFoundException.
runJava -p mods -m test/jdk.test.TestWithUnnamedModuleArg \
jdk.test.resources.exported.classes.MyResources false
# The properties files in jdk.test.resources.exported.props are not found with loader.getResource().
runJava -p mods -m test/jdk.test.TestWithUnnamedModuleArg \
jdk.test.resources.exported.props.MyResources false
# loader.loadClass() doesn't find jdk.test.resources.exported.classes.MyResources
# and throws a ClassNotFoundException.
runJava -p mods -m embargo/jdk.embargo.TestWithUnnamedModuleArg \
jdk.test.resources.exported.classes.MyResources false
# The properties files in jdk.test.resources.exported.props are not found
# with loader.getResource().
runJava -p mods -m embargo/jdk.embargo.TestWithUnnamedModuleArg \
jdk.test.resources.exported.props.MyResources false
# Add mods/exported.named.bundles to the class path.
# jdk.test.resources.exported.classes.MyResources.getModule().isNamed() returns false.
runJava -cp mods/exported.named.bundles -p mods -m test/jdk.test.TestWithUnnamedModuleArg \
jdk.test.resources.exported.classes.MyResources true
# loader.getResource() finds jdk.test.resources.exported.props.MyResources.
runJava -cp mods/exported.named.bundles -p mods -m test/jdk.test.TestWithUnnamedModuleArg \
jdk.test.resources.exported.props.MyResources true
# jdk.test.resources.exported.classes.MyResources.getModule().isNamed() returns false.
runJava -cp mods/exported.named.bundles -p mods -m embargo/jdk.embargo.TestWithUnnamedModuleArg \
jdk.test.resources.exported.classes.MyResources true
# loader.getResource() finds jdk.test.resources.exported.props.MyResources.
runJava -cp mods/exported.named.bundles -p mods -m embargo/jdk.embargo.TestWithUnnamedModuleArg \
jdk.test.resources.exported.props.MyResources true
#######################################
# Test cases with jdk.pkg.resources.* #
#######################################
# Prepare resource bundles in an unnamed module
PKG=$TESTSRC/src/pkg
mkdir -p classes/jdk/pkg/resources/props
$JAVAC -g -d classes $PKG/jdk/pkg/test/Main.java $PKG/jdk/pkg/resources/classes/MyResources.java
cp $PKG/jdk/pkg/resources/props/MyResources.properties classes/jdk/pkg/resources/props
# jdk.pkg.resources.* are in an unnamed module.
# jdk.pkg.test.Main calls ResourceBundle.getBundle with an unnamed module.
runJava -cp classes jdk.pkg.test.Main jdk.pkg.resources.classes.MyResources true
runJava -cp classes jdk.pkg.test.Main jdk.pkg.resources.props.MyResources true
exit $STATUS
|