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 8137317 8139238 26 # @summary Visibility tests for ResourceBundle.getBundle with and without 27 # an unnamed module argument. 28 29 30 set -e 31 STATUS=0 32 33 runJava() 34 { 35 echo "Executing java $@" 36 $JAVA $@ || STATUS=1 37 echo 38 } 39 40 if [ -z "$TESTJAVA" ]; then 41 if [ $# -lt 1 ]; then exit 1; fi 42 TESTJAVA="$1"; shift 43 COMPILEJAVA="${TESTJAVA}" 44 TESTSRC="`pwd`" 45 TESTCLASSES="`pwd`" 46 fi 47 48 JAVAC="$COMPILEJAVA/bin/javac" 49 JAVA="$TESTJAVA/bin/java" 50 51 rm -rf mods classes 52 53 MODS=`cd $TESTSRC/src; find . -name module-info.java -exec dirname {} \; | sed 's:\./::'` 54 55 for M in $MODS 56 do 57 mkdir -p mods/$M 58 CLASSES="`find $TESTSRC/src/$M -name '*.java'`" 59 if [ "x$CLASSES" != x ]; then 60 $JAVAC -g -d mods -modulesourcepath $TESTSRC/src $CLASSES 61 fi 62 PROPS="`(cd $TESTSRC/src/$M; find . -name '*.properties')`" 63 if [ "x$PROPS" != x ]; then 64 for P in $PROPS 65 do 66 D=`dirname $P` 67 mkdir -p mods/$M/$D 68 cp $TESTSRC/src/$M/$P mods/$M/$D/ 69 done 70 fi 71 done 72 73 # Package jdk.test is in named module "test". 74 # Package jdk.embargo is in named module "embargo". 75 76 # jdk.{test,embargo}.TestWithUnnamedModuleArg call: 77 # ResourceBundle.getBundle(basename, classloader.getUnnamedModule()) 78 # where classloader is the TCCL or system class loader. 79 # jdk.{test,embargo}.TestWithNoModuleArg call: 80 # ResourceBundle.getBundle(basename) 81 82 # jdk.test.resources[.exported].classes.* are class-based resource bundles. 83 # jdk.test.resources[.exported].props.* are properties file-based resource bundles. 84 85 # Packages jdk.test.resources.{classes,props} in named module "named.bundles" 86 # are exported only to named module "test". 87 # Packages jdk.test.resources.exported.{classes,props} in named module 88 # "exported.named.bundle" are exported to unnamed modules. 89 90 ######################################## 91 # Test cases with jdk.test.resources.* # 92 ######################################## 93 94 # Tests using jdk.test.TestWithNoModuleArg and jdk.embargo.TestWithNoModuleArg 95 # neither of which specifies an unnamed module with ResourceBundle.getBundle(). 96 97 # jdk.test.resources.{classes,props}.* are available only to named module "test" 98 # by ResourceBundleProvider. 99 runJava -mp mods -m test/jdk.test.TestWithNoModuleArg \ 100 jdk.test.resources.classes.MyResources true 101 runJava -mp mods -m test/jdk.test.TestWithNoModuleArg \ 102 jdk.test.resources.props.MyResources true 103 runJava -mp mods -m embargo/jdk.embargo.TestWithNoModuleArg \ 104 jdk.test.resources.classes.MyResources false 105 runJava -mp mods -m embargo/jdk.embargo.TestWithNoModuleArg \ 106 jdk.test.resources.props.MyResources false 107 108 # Add mods/named.bundles to the class path. 109 runJava -cp mods/named.bundles -mp mods -m test/jdk.test.TestWithNoModuleArg \ 110 jdk.test.resources.classes.MyResources true 111 runJava -cp mods/named.bundles -mp mods -m test/jdk.test.TestWithNoModuleArg \ 112 jdk.test.resources.props.MyResources true 113 runJava -cp mods/named.bundles -mp mods -m embargo/jdk.embargo.TestWithNoModuleArg \ 114 jdk.test.resources.classes.MyResources false 115 runJava -cp mods/named.bundles -mp mods -m embargo/jdk.embargo.TestWithNoModuleArg \ 116 jdk.test.resources.props.MyResources false 117 118 # Tests using jdk.test.TestWithUnnamedModuleArg and jdk.embargo.TestWithUnnamedModuleArg 119 # both of which specify an unnamed module with ResourceBundle.getBundle. 120 121 # jdk.test.resources.classes is exported to named module "test". 122 # IllegalAccessException is thrown in ResourceBundle.Control.newBundle(). 123 runJava -mp mods -m test/jdk.test.TestWithUnnamedModuleArg \ 124 jdk.test.resources.classes.MyResources false 125 126 # jdk.test.resources.props is exported to named module "test". 127 # loader.getResource() doesn't find jdk.test.resources.props.MyResources. 128 runJava -mp mods -m test/jdk.test.TestWithUnnamedModuleArg \ 129 jdk.test.resources.props.MyResources false 130 131 # IllegalAccessException is thrown in ResourceBundle.Control.newBundle(). 132 runJava -mp mods -m embargo/jdk.embargo.TestWithUnnamedModuleArg \ 133 jdk.test.resources.classes.MyResources false 134 # jdk.test.resources.props is exported to named module "test". 135 # loader.getResource() doesn't find jdk.test.resources.props.MyResources. 136 runJava -mp mods -m embargo/jdk.embargo.TestWithUnnamedModuleArg \ 137 jdk.test.resources.props.MyResources false 138 139 # Add mods/named.bundles to the class path 140 141 # IllegalAccessException is thrown in ResourceBundle.Control.newBundle(). 142 runJava -cp mods/named.bundles -mp mods -m test/jdk.test.TestWithUnnamedModuleArg \ 143 jdk.test.resources.classes.MyResources false 144 # loader.getResource() finds jdk.test.resources.exported.props.MyResources. 145 runJava -cp mods/named.bundles -mp mods -m test/jdk.test.TestWithUnnamedModuleArg \ 146 jdk.test.resources.props.MyResources true 147 148 # jdk.test.resources.exported.classes.MyResources is treated 149 # as if the class is in an unnamed module. 150 runJava -cp mods/named.bundles -mp mods -m embargo/jdk.embargo.TestWithUnnamedModuleArg \ 151 jdk.test.resources.classes.MyResources true 152 # loader.getResource() finds jdk.test.resources.exported.props.MyResources. 153 runJava -cp mods/named.bundles -mp mods -m embargo/jdk.embargo.TestWithUnnamedModuleArg \ 154 jdk.test.resources.props.MyResources true 155 156 ################################################# 157 # Test cases with jdk.test.resources.exported.* # 158 ################################################# 159 # Tests using jdk.test.TestWithNoModuleArg and jdk.embargo.TestWithNoModuleArg 160 # neither of which specifies an unnamed module with ResourceBundle.getBundle. 161 162 # None of jdk.test.resources.exported.** is available to the named modules. 163 runJava -mp mods -m test/jdk.test.TestWithNoModuleArg \ 164 jdk.test.resources.exported.classes.MyResources false 165 runJava -mp mods -m test/jdk.test.TestWithNoModuleArg \ 166 jdk.test.resources.exported.props.MyResources false 167 runJava -mp mods -m embargo/jdk.embargo.TestWithNoModuleArg \ 168 jdk.test.resources.exported.classes.MyResources false 169 runJava -mp mods -m embargo/jdk.embargo.TestWithNoModuleArg \ 170 jdk.test.resources.exported.props.MyResources false 171 172 # Add mods/exported.named.bundles to the class path. 173 runJava -cp mods/exported.named.bundles -mp mods -m test/jdk.test.TestWithNoModuleArg \ 174 jdk.test.resources.exported.classes.MyResources false 175 runJava -cp mods/exported.named.bundles -mp mods -m test/jdk.test.TestWithNoModuleArg \ 176 jdk.test.resources.exported.props.MyResources false 177 runJava -cp mods/exported.named.bundles -mp mods -m embargo/jdk.embargo.TestWithNoModuleArg \ 178 jdk.test.resources.exported.classes.MyResources false 179 runJava -cp mods/exported.named.bundles -mp mods -m embargo/jdk.embargo.TestWithNoModuleArg \ 180 jdk.test.resources.exported.props.MyResources false 181 182 # Tests using jdk.test.TestWithUnnamedModuleArg and jdk.embargo.TestWithUnnamedModuleArg 183 # which specify an unnamed module with ResourceBundle.getBundle. 184 185 # loader.loadClass() doesn't find jdk.test.resources.exported.classes.MyResources 186 # and throws a ClassNotFoundException. 187 runJava -mp mods -m test/jdk.test.TestWithUnnamedModuleArg \ 188 jdk.test.resources.exported.classes.MyResources false 189 # The properties files in jdk.test.resources.exported.props are not found with loader.getResource(). 190 runJava -mp mods -m test/jdk.test.TestWithUnnamedModuleArg \ 191 jdk.test.resources.exported.props.MyResources false 192 193 194 # loader.loadClass() doesn't find jdk.test.resources.exported.classes.MyResources 195 # and throws a ClassNotFoundException. 196 runJava -mp mods -m embargo/jdk.embargo.TestWithUnnamedModuleArg \ 197 jdk.test.resources.exported.classes.MyResources false 198 # The properties files in jdk.test.resources.exported.props are not found 199 # with loader.getResource(). 200 runJava -mp mods -m embargo/jdk.embargo.TestWithUnnamedModuleArg \ 201 jdk.test.resources.exported.props.MyResources false 202 203 # Add mods/exported.named.bundles to the class path. 204 205 # jdk.test.resources.exported.classes.MyResources.getModule().isNamed() returns false. 206 runJava -cp mods/exported.named.bundles -mp mods -m test/jdk.test.TestWithUnnamedModuleArg \ 207 jdk.test.resources.exported.classes.MyResources true 208 # loader.getResource() finds jdk.test.resources.exported.props.MyResources. 209 runJava -cp mods/exported.named.bundles -mp mods -m test/jdk.test.TestWithUnnamedModuleArg \ 210 jdk.test.resources.exported.props.MyResources true 211 212 # jdk.test.resources.exported.classes.MyResources.getModule().isNamed() returns false. 213 runJava -cp mods/exported.named.bundles -mp mods -m embargo/jdk.embargo.TestWithUnnamedModuleArg \ 214 jdk.test.resources.exported.classes.MyResources true 215 # loader.getResource() finds jdk.test.resources.exported.props.MyResources. 216 runJava -cp mods/exported.named.bundles -mp mods -m embargo/jdk.embargo.TestWithUnnamedModuleArg \ 217 jdk.test.resources.exported.props.MyResources true 218 219 ####################################### 220 # Test cases with jdk.pkg.resources.* # 221 ####################################### 222 # Prepare resource bundles in an unnamed module 223 PKG=$TESTSRC/src/pkg 224 mkdir -p classes/jdk/pkg/resources/props 225 $JAVAC -g -d classes $PKG/jdk/pkg/test/Main.java $PKG/jdk/pkg/resources/classes/MyResources.java 226 cp $PKG/jdk/pkg/resources/props/MyResources.properties classes/jdk/pkg/resources/props 227 228 # jdk.pkg.resources.* are in an unnamed module. 229 # jdk.pkg.test.Main calls ResourceBundle.getBundle with an unnamed module. 230 runJava -cp classes jdk.pkg.test.Main jdk.pkg.resources.classes.MyResources true 231 runJava -cp classes jdk.pkg.test.Main jdk.pkg.resources.props.MyResources true 232 233 exit $STATUS