8210408: Refactor java.util.ResourceBundle:i18n shell tests to plain java tests
Reviewed-by: naoto
This commit is contained in:
parent
6c75023f1d
commit
2b38340ad7
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2007, 2018, 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
|
||||
@ -21,6 +21,17 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6299235 8210408
|
||||
* @summary test Bug 6299235 to make sure the third-party provided sun resources
|
||||
* could be picked up.
|
||||
* @modules java.desktop
|
||||
* @library patches
|
||||
* @build java.desktop/sun.awt.resources.awt_ru_RU
|
||||
* @run main Bug6299235Test
|
||||
*/
|
||||
|
||||
import java.awt.Toolkit;
|
||||
import java.util.Locale;
|
||||
|
||||
@ -35,7 +46,7 @@ import java.util.Locale;
|
||||
*/
|
||||
|
||||
public class Bug6299235Test {
|
||||
static final Locale ru_RU = new Locale("ru", "RU");
|
||||
private static final Locale ru_RU = new Locale("ru", "RU");
|
||||
|
||||
public static void main(String args[]) {
|
||||
Locale locale = Locale.getDefault();
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 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.
|
||||
*/
|
||||
|
||||
package sun.awt.resources;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
/**
|
||||
* A faked sun.awt.resources.awt_ru_RU resource file.
|
||||
*/
|
||||
public class awt_ru_RU extends ListResourceBundle {
|
||||
@Override
|
||||
public Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "foo", "bar" }
|
||||
};
|
||||
}
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Copyright (c) 2007, 2013, 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.
|
||||
#
|
||||
#!/bin/sh
|
||||
#
|
||||
# @test
|
||||
# @bug 6299235
|
||||
# @summary test Bug 6299235 to make sure the third-party provided sun resources could be picked up.
|
||||
# @modules java.desktop
|
||||
# @build Bug6299235Test
|
||||
# @run shell Bug6299235Test.sh
|
||||
|
||||
# set platform-dependent variables
|
||||
OS=`uname -s`
|
||||
case "$OS" in
|
||||
SunOS | Linux | Darwin | AIX )
|
||||
PATHSEP=":"
|
||||
FILESEP="/"
|
||||
;;
|
||||
Windows* | CYGWIN* )
|
||||
PATHSEP=";"
|
||||
FILESEP="\\"
|
||||
;;
|
||||
* )
|
||||
echo "${OS} is unrecognized system!"
|
||||
exit 1;
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -z "${TESTSRC}" ]; then
|
||||
echo "TESTSRC undefined: defaulting to ."
|
||||
TESTSRC=.
|
||||
fi
|
||||
|
||||
if [ -z "${TESTJAVA}" ]; then
|
||||
echo "TESTJAVA undefined: can't continue."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "TESTJAVA=${TESTJAVA}"
|
||||
echo "TESTSRC=${TESTSRC}"
|
||||
echo "TESTCLASSES=${TESTCLASSES}"
|
||||
|
||||
PATCHDIR=${TESTCLASSES}/patches
|
||||
rm -rf $PATCHDIR
|
||||
mkdir -p $PATCHDIR/java.desktop
|
||||
|
||||
cd ${PATCHDIR}/java.desktop
|
||||
${TESTJAVA}/bin/jar xf ${TESTSRC}/awtres.jar
|
||||
|
||||
echo
|
||||
${TESTJAVA}/bin/java ${TESTVMOPTS} --patch-module java.desktop=${PATCHDIR}/java.desktop \
|
||||
-cp ${TESTCLASSES} Bug6299235Test
|
||||
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "Test fails: exception thrown!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
Binary file not shown.
187
test/jdk/java/util/ResourceBundle/modules/ModuleTestUtil.java
Normal file
187
test/jdk/java/util/ResourceBundle/modules/ModuleTestUtil.java
Normal file
@ -0,0 +1,187 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 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.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import jdk.test.lib.JDKToolLauncher;
|
||||
import jdk.test.lib.compiler.CompilerUtils;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
|
||||
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
|
||||
|
||||
public class ModuleTestUtil {
|
||||
|
||||
private ModuleTestUtil() {
|
||||
// Private constructor to prevent class instantiation
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile all the java sources and copy the resource files in the module.
|
||||
*
|
||||
* @param src path to the source directory
|
||||
* @param dest path to the destination directory
|
||||
* @param mn module name
|
||||
* @param resFormat resource format
|
||||
*/
|
||||
public static void prepareModule(Path src, Path dest, String mn,
|
||||
String resFormat) {
|
||||
compileModule(src, dest, mn);
|
||||
copyResFiles(src, dest, mn, resFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile all the java sources in the module.
|
||||
*
|
||||
* @param src path to the source directory
|
||||
* @param dest path to the destination directory
|
||||
* @param mn module name
|
||||
*/
|
||||
public static void compileModule(Path src, Path dest, String mn) {
|
||||
try {
|
||||
boolean compiled = CompilerUtils.compile(src.resolve(mn), dest,
|
||||
"--module-source-path", src.toString());
|
||||
if (!compiled) {
|
||||
throw new RuntimeException("Compile module " + mn + " failed.");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Compile module " + mn + " failed.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile all the java sources in the unnamed package.
|
||||
*
|
||||
* @param src path to the source directory
|
||||
* @param dest path to the destination directory
|
||||
* @param pn package name
|
||||
*/
|
||||
public static void compilePkg(Path src, Path dest, String pn) {
|
||||
try {
|
||||
boolean compiled = CompilerUtils.compile(src.resolve(pn),
|
||||
dest.resolve(pn));
|
||||
if (!compiled) {
|
||||
throw new RuntimeException("Compile package " + pn + " failed.");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Compile package " + pn + " failed.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy all the resource files.
|
||||
*
|
||||
* @param src path to the source directory
|
||||
* @param dest path to the destination directory
|
||||
* @param mn module name
|
||||
* @param resFormat resource format
|
||||
*/
|
||||
public static void copyResFiles(Path src, Path dest, String mn,
|
||||
String resFormat) {
|
||||
try (Stream<Path> stream = Files.walk(src.resolve(mn))
|
||||
.filter(path -> path.toString().endsWith(resFormat))) {
|
||||
stream.forEach(f -> {
|
||||
String resName = f.toString();
|
||||
String relativePath = resName.substring(src.toString().length());
|
||||
Path destFile = Paths.get(dest.toString() + relativePath);
|
||||
try {
|
||||
Path destParentDir = destFile.getParent();
|
||||
if (Files.notExists(destParentDir)) {
|
||||
Files.createDirectories(destParentDir);
|
||||
}
|
||||
Files.copy(f, destFile, REPLACE_EXISTING);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Copy " + f.toString() + " to "
|
||||
+ destFile.toString() + " failed.");
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Copy resource files failed.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the module test.
|
||||
*
|
||||
* @param mp module path
|
||||
* @param mn module name
|
||||
* @param localeList locale list
|
||||
*/
|
||||
public static void runModule(String mp, String mn, List<String> localeList)
|
||||
throws Throwable {
|
||||
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("java");
|
||||
launcher.addToolArg("-p")
|
||||
.addToolArg(mp)
|
||||
.addToolArg("-m")
|
||||
.addToolArg(mn);
|
||||
localeList.forEach(launcher::addToolArg);
|
||||
|
||||
int exitCode = ProcessTools.executeCommand(launcher.getCommand())
|
||||
.getExitValue();
|
||||
if (exitCode != 0) {
|
||||
throw new RuntimeException("Execution of the test failed. "
|
||||
+ "Unexpected exit code: " + exitCode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the module test with a jar file specified by the classpath.
|
||||
*
|
||||
* @param cp classpath
|
||||
* @param mp module path
|
||||
* @param mn module name
|
||||
* @param localeList locale list
|
||||
* @param expected expected execution status
|
||||
*/
|
||||
public static void runModuleWithCp(String cp, String mp, String mn,
|
||||
List<String> localeList, boolean expected) throws Throwable {
|
||||
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("java");
|
||||
launcher.addToolArg("-cp")
|
||||
.addToolArg(cp)
|
||||
.addToolArg("-p")
|
||||
.addToolArg(mp)
|
||||
.addToolArg("-m")
|
||||
.addToolArg(mn);
|
||||
localeList.forEach(launcher::addToolArg);
|
||||
|
||||
int exitCode = ProcessTools.executeCommand(launcher.getCommand())
|
||||
.getExitValue();
|
||||
if (expected) {
|
||||
if (exitCode != 0) {
|
||||
throw new RuntimeException("Execution of the test loads bundles "
|
||||
+ "from the jar file specified by the class-path failed. "
|
||||
+ "Unexpected exit code: " + exitCode);
|
||||
}
|
||||
} else {
|
||||
if (exitCode == 0) {
|
||||
throw new RuntimeException("Execution of the test not loads bundles "
|
||||
+ "from the jar file specified by the class-path failed. "
|
||||
+ "Unexpected exit code: " + exitCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2015, 2016, 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 8044767
|
||||
# @summary Basic test for ResourceBundle with modules; named module "test"
|
||||
# contains resource bundles for root and en, and separate named modules
|
||||
# "eubundles" and "asiabundles" contain other resource bundles.
|
||||
|
||||
set -e
|
||||
|
||||
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"
|
||||
|
||||
|
||||
for I in eu asia
|
||||
do
|
||||
B=${I}bundles
|
||||
mkdir -p mods/$B
|
||||
CLASSES="`find $TESTSRC/src/$B -name '*.java'`"
|
||||
if [ "x$CLASSES" != x ]; then
|
||||
$JAVAC -g -d mods --module-source-path $TESTSRC/src -cp mods/test $CLASSES
|
||||
fi
|
||||
PROPS="`(cd $TESTSRC/src/$B; find . -name '*.properties')`"
|
||||
if [ "x$PROPS" != x ]; then
|
||||
for P in $PROPS
|
||||
do
|
||||
D=`dirname $P`
|
||||
mkdir -p mods/$B/$D
|
||||
cp $TESTSRC/src/$B/$P mods/$B/$D/
|
||||
done
|
||||
fi
|
||||
done
|
||||
|
||||
mkdir -p mods/test
|
||||
$JAVAC -g -d mods --module-source-path $TESTSRC/src `find $TESTSRC/src/test -name "*.java"`
|
||||
|
||||
$JAVA -p mods -m test/jdk.test.Main de fr ja zh-tw en de
|
||||
|
||||
exit $?
|
@ -1,68 +0,0 @@
|
||||
#
|
||||
# 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 8044767
|
||||
# @summary Basic test for ResourceBundle with modules; named module "test"
|
||||
# contains resource bundles for root and en, and separate named modules
|
||||
# "eubundles" and "asiabundles" contain other resource bundles.
|
||||
|
||||
set -e
|
||||
|
||||
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"
|
||||
|
||||
|
||||
for I in eu asia
|
||||
do
|
||||
B=${I}bundles
|
||||
mkdir -p mods/$B
|
||||
CLASSES="`find $TESTSRC/src/$B -name '*.java'`"
|
||||
if [ "x$CLASSES" != x ]; then
|
||||
$JAVAC -g -d mods --module-source-path $TESTSRC/src -cp mods/test $CLASSES
|
||||
fi
|
||||
PROPS="`(cd $TESTSRC/src/$B; find . -name '*.properties')`"
|
||||
if [ "x$PROPS" != x ]; then
|
||||
for P in $PROPS
|
||||
do
|
||||
D=`dirname $P`
|
||||
mkdir -p mods/$B/$D
|
||||
cp $TESTSRC/src/$B/$P mods/$B/$D/
|
||||
done
|
||||
fi
|
||||
done
|
||||
|
||||
mkdir -p mods/test
|
||||
$JAVAC -g -d mods --module-source-path $TESTSRC/src `find $TESTSRC/src/test -name "*.java"`
|
||||
|
||||
$JAVA -p mods -m test/jdk.test.Main de fr ja zh-tw en de
|
||||
|
||||
exit $?
|
206
test/jdk/java/util/ResourceBundle/modules/basic/BasicTest.java
Normal file
206
test/jdk/java/util/ResourceBundle/modules/basic/BasicTest.java
Normal file
@ -0,0 +1,206 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2018, 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 8044767 8139067 8210408
|
||||
* @summary Basic tests for ResourceBundle with modules:
|
||||
* 1) Named module "test" contains resource bundles for root and en,
|
||||
* and separate named modules "eubundles" and "asiabundles" contain
|
||||
* other resource bundles.
|
||||
* 2) ResourceBundle.getBundle caller is in named module "test",
|
||||
* resource bundles are grouped in main (module "mainbundles"),
|
||||
* EU (module "eubundles"), and Asia (module "asiabundles").
|
||||
* 3) ResourceBundle.getBundle caller is in named module "test" and all
|
||||
* resource bundles are in single named module "bundles".
|
||||
* 4) ResourceBundle.getBundle caller is in named module "test" and all
|
||||
* resource bundles in xml format are in single named module "bundles".
|
||||
* 5) Resource bundles in a local named module with no ResourceBundleProviders.
|
||||
* @library /test/lib
|
||||
* ..
|
||||
* @build jdk.test.lib.JDKToolLauncher
|
||||
* jdk.test.lib.Utils
|
||||
* jdk.test.lib.compiler.CompilerUtils
|
||||
* jdk.test.lib.process.ProcessTools
|
||||
* ModuleTestUtil
|
||||
* @run testng BasicTest
|
||||
*/
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
import jdk.test.lib.JDKToolLauncher;
|
||||
import jdk.test.lib.Utils;
|
||||
import jdk.test.lib.compiler.CompilerUtils;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static jdk.test.lib.Asserts.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
@Test
|
||||
public class BasicTest {
|
||||
private static final String SRC_DIR_APPBASIC = "srcAppbasic";
|
||||
private static final String SRC_DIR_APPBASIC2 = "srcAppbasic2";
|
||||
private static final String SRC_DIR_BASIC = "srcBasic";
|
||||
private static final String SRC_DIR_SIMPLE = "srcSimple";
|
||||
private static final String SRC_DIR_XML = "srcXml";
|
||||
private static final String SRC_DIR_MODLOCAL = "srcModlocal";
|
||||
|
||||
private static final String MODS_DIR_APPBASIC = "modsAppbasic";
|
||||
private static final String MODS_DIR_APPBASIC2 = "modsAppbasic2";
|
||||
private static final String MODS_DIR_BASIC = "modsBasic";
|
||||
private static final String MODS_DIR_SIMPLE = "modsSimple";
|
||||
private static final String MODS_DIR_XML = "modsXml";
|
||||
private static final String MODS_DIR_MODLOCAL = "modsModlocal";
|
||||
|
||||
private static final String EXTRA_JAR_BASIC = "extra_basic.jar";
|
||||
private static final String EXTRA_JAR_MODLOCAL = "extra_modlocal.jar";
|
||||
|
||||
private static final List<String> LOCALE_LIST = List.of("de", "fr", "ja",
|
||||
"zh-tw", "en", "de");
|
||||
private static final List<String> LOCALE_LIST_BASIC = List.of("de", "fr",
|
||||
"ja", "ja-jp", "zh-tw", "en", "de", "ja-jp");
|
||||
|
||||
private static final List<String> MODULE_LIST = List.of("asiabundles",
|
||||
"eubundles", "test");
|
||||
private static final List<String> MODULE_LIST_BASIC = List.of("mainbundles",
|
||||
"asiabundles", "eubundles", "test");
|
||||
private static final List<String> MODULE_LIST_SIMPLE = List.of("bundles", "test");
|
||||
|
||||
private static final String MAIN = "test/jdk.test.Main";
|
||||
|
||||
@DataProvider(name = "basicTestData")
|
||||
Object[][] basicTestData() {
|
||||
return new Object[][] {
|
||||
// Named module "test" contains resource bundles for root and en,
|
||||
// and separate named modules "eubundles" and "asiabundles"
|
||||
// contain other resource bundles.
|
||||
{SRC_DIR_APPBASIC, MODS_DIR_APPBASIC, MODULE_LIST, LOCALE_LIST,
|
||||
".properties"},
|
||||
{SRC_DIR_APPBASIC2, MODS_DIR_APPBASIC2, MODULE_LIST, LOCALE_LIST,
|
||||
".properties"},
|
||||
|
||||
// Resource bundles are grouped in main (module "mainbundles"),
|
||||
// EU (module "eubundles"), and Asia (module "asiabundles").
|
||||
{SRC_DIR_BASIC, MODS_DIR_BASIC, MODULE_LIST_BASIC, LOCALE_LIST_BASIC,
|
||||
".properties"},
|
||||
|
||||
// All resource bundles are in single named module "bundles".
|
||||
{SRC_DIR_SIMPLE, MODS_DIR_SIMPLE, MODULE_LIST_SIMPLE, LOCALE_LIST,
|
||||
".properties"},
|
||||
|
||||
// All resource bundles in xml format are in single named
|
||||
// module "bundles".
|
||||
{SRC_DIR_XML, MODS_DIR_XML, MODULE_LIST_SIMPLE, LOCALE_LIST, ".xml"},
|
||||
|
||||
// Resource bundles local in named module "test".
|
||||
{SRC_DIR_MODLOCAL, MODS_DIR_MODLOCAL, List.of("test"), LOCALE_LIST,
|
||||
".properties"},
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "basicTestData")
|
||||
public void runBasicTest(String src, String mod, List<String> moduleList,
|
||||
List<String> localeList, String resFormat) throws Throwable {
|
||||
Path srcPath = Paths.get(Utils.TEST_SRC, src);
|
||||
Path modPath = Paths.get(Utils.TEST_CLASSES, mod);
|
||||
moduleList.forEach(mn -> ModuleTestUtil.prepareModule(srcPath, modPath,
|
||||
mn, resFormat));
|
||||
ModuleTestUtil.runModule(modPath.toString(), MAIN, localeList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void RunBasicTestWithCp() throws Throwable {
|
||||
Path jarPath = Paths.get(Utils.TEST_CLASSES, EXTRA_JAR_BASIC);
|
||||
Path srcPath = Paths.get(Utils.TEST_SRC, SRC_DIR_BASIC);
|
||||
Path modPath = Paths.get(Utils.TEST_CLASSES, MODS_DIR_BASIC);
|
||||
Path classPath = Paths.get(Utils.TEST_CLASSES).resolve("classes")
|
||||
.resolve("basic");
|
||||
|
||||
jarBasic(srcPath, classPath, jarPath);
|
||||
// jdk.test.Main should NOT load bundles from the jar file specified
|
||||
// by the class-path.
|
||||
ModuleTestUtil.runModuleWithCp(jarPath.toString(), modPath.toString(),
|
||||
MAIN, List.of("es", "vi"), false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runModLocalTestWithCp() throws Throwable {
|
||||
Path jarPath = Paths.get(Utils.TEST_CLASSES, EXTRA_JAR_MODLOCAL);
|
||||
Path srcPath = Paths.get(Utils.TEST_SRC, SRC_DIR_MODLOCAL);
|
||||
Path modPath = Paths.get(Utils.TEST_CLASSES, MODS_DIR_MODLOCAL);
|
||||
|
||||
jarModLocal(srcPath, jarPath);
|
||||
// jdk.test.Main should load bundles from the jar file specified by
|
||||
// the class-path.
|
||||
ModuleTestUtil.runModuleWithCp(jarPath.toString(), modPath.toString(),
|
||||
MAIN, List.of("vi"), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create extra_basic.jar to be added to the class path. It contains .class
|
||||
* and .properties resource bundles.
|
||||
*/
|
||||
private static void jarBasic(Path srcPath, Path classPath, Path jarPath)
|
||||
throws Throwable {
|
||||
boolean compiled = CompilerUtils.compile(srcPath.resolve("extra"),
|
||||
classPath);
|
||||
assertTrue(compiled, "Compile Java files for extra_basic.jar failed.");
|
||||
|
||||
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jar");
|
||||
launcher.addToolArg("-cf")
|
||||
.addToolArg(jarPath.toString())
|
||||
.addToolArg("-C")
|
||||
.addToolArg(classPath.toString())
|
||||
.addToolArg("jdk/test/resources/eu")
|
||||
.addToolArg("-C")
|
||||
.addToolArg(srcPath.resolve("extra").toString())
|
||||
.addToolArg("jdk/test/resources/asia");
|
||||
|
||||
int exitCode = ProcessTools.executeCommand(launcher.getCommand())
|
||||
.getExitValue();
|
||||
assertEquals(exitCode, 0, "Create extra_basic.jar failed. "
|
||||
+ "Unexpected exit code: " + exitCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create extra_modlocal.jar to be added to the class path. Expected
|
||||
* properties files are picked up from the class path.
|
||||
*/
|
||||
private static void jarModLocal(Path srcPath, Path jarPath) throws Throwable {
|
||||
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jar");
|
||||
launcher.addToolArg("-cf")
|
||||
.addToolArg(jarPath.toString())
|
||||
.addToolArg("-C")
|
||||
.addToolArg(srcPath.resolve("extra").toString())
|
||||
.addToolArg("jdk/test/resources");
|
||||
|
||||
int exitCode = ProcessTools.executeCommand(launcher.getCommand())
|
||||
.getExitValue();
|
||||
assertEquals(exitCode, 0, "Create extra_modlocal.jar failed. "
|
||||
+ "Unexpected exit code: " + exitCode);
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
#
|
||||
# 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 8044767 8139067
|
||||
# @summary Basic test case for ResourceBundle with modules;
|
||||
# ResourceBundle.getBundle caller is in module named "test",
|
||||
# resource bundles are grouped in main (module "mainbundles"),
|
||||
# EU (module "eubundles"), and Asia (module "asiabundles").
|
||||
# Also adds a jar file containing resource bundles to the class path.
|
||||
|
||||
set -e
|
||||
|
||||
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"
|
||||
JAR="$COMPILEJAVA/bin/jar"
|
||||
JAVA="$TESTJAVA/bin/java"
|
||||
|
||||
rm -rf mods
|
||||
|
||||
CP=
|
||||
for I in main eu asia
|
||||
do
|
||||
B=${I}bundles
|
||||
mkdir -p mods/$B
|
||||
CLASSES="`find $TESTSRC/src/$B -name '*.java'`"
|
||||
if [ "x$CLASSES" != x ]; then
|
||||
$JAVAC -g -d mods --module-source-path $TESTSRC/src $CP $CLASSES
|
||||
fi
|
||||
PROPS="`(cd $TESTSRC/src/$B; find . -name '*.properties')`"
|
||||
if [ "x$PROPS" != x ]; then
|
||||
for P in $PROPS
|
||||
do
|
||||
D=`dirname $P`
|
||||
mkdir -p mods/$B/$D
|
||||
cp $TESTSRC/src/$B/$P mods/$B/$D/
|
||||
done
|
||||
fi
|
||||
CP="-cp mods/mainbundles"
|
||||
done
|
||||
|
||||
mkdir -p mods/test
|
||||
$JAVAC -g -cp mods/mainbundles -d mods --module-source-path $TESTSRC/src \
|
||||
`find $TESTSRC/src/test -name "*.java"`
|
||||
|
||||
# Create a jar to be added to the class path. Expected only properties files are
|
||||
# picked up from the class path.
|
||||
rm -f extra.jar
|
||||
mkdir -p classes
|
||||
$JAVAC -d classes $TESTSRC/src/extra/jdk/test/resources/eu/*.java
|
||||
$JAR -cf extra.jar -C classes jdk/test/resources/eu \
|
||||
-C $TESTSRC/src/extra jdk/test/resources/asia
|
||||
|
||||
STATUS=0
|
||||
|
||||
echo "jdk.test.Main should load bundles using ResourceBundleProviders."
|
||||
$JAVA -p mods -m test/jdk.test.Main de fr ja ja-jp zh-tw en de ja-jp || STATUS=1
|
||||
|
||||
echo "jdk.test.Main should NOT load bundles from the jar file specified by the class-path."
|
||||
$JAVA -cp extra.jar -p mods -m test/jdk.test.Main es vi && STATUS=1
|
||||
|
||||
exit $STATUS
|
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 2018, 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 8180375 8185251 8210408
|
||||
* @summary Tests resource bundles are correctly loaded from modules through
|
||||
* "<packageName>.spi.<simpleName>Provider" types.
|
||||
* @library /test/lib
|
||||
* ..
|
||||
* @build jdk.test.lib.JDKToolLauncher
|
||||
* jdk.test.lib.Utils
|
||||
* jdk.test.lib.compiler.CompilerUtils
|
||||
* jdk.test.lib.process.ProcessTools
|
||||
* ModuleTestUtil
|
||||
* @run main LayerTest
|
||||
*/
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
import jdk.test.lib.JDKToolLauncher;
|
||||
import jdk.test.lib.Utils;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
|
||||
public class LayerTest {
|
||||
private static final Path SRC_DIR = Paths.get(Utils.TEST_SRC, "src");
|
||||
private static final Path MODS_DIR = Paths.get(Utils.TEST_CLASSES, "mods");
|
||||
private static final List<String> MODULE_LIST = List.of("m1", "m2");
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
MODULE_LIST.forEach(mn -> ModuleTestUtil.prepareModule(SRC_DIR,
|
||||
MODS_DIR, mn, ".properties"));
|
||||
compileCmd();
|
||||
runCmd();
|
||||
}
|
||||
|
||||
private static void compileCmd() throws Throwable {
|
||||
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("javac");
|
||||
launcher.addToolArg("-d")
|
||||
.addToolArg(Utils.TEST_CLASSES)
|
||||
.addToolArg(SRC_DIR.resolve("Main.java").toString());
|
||||
|
||||
int exitCode = ProcessTools.executeCommand(launcher.getCommand())
|
||||
.getExitValue();
|
||||
if (exitCode != 0) {
|
||||
throw new RuntimeException("Compile of the test failed. "
|
||||
+ "Unexpected exit code: " + exitCode);
|
||||
}
|
||||
}
|
||||
|
||||
private static void runCmd() throws Throwable {
|
||||
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("java");
|
||||
launcher.addToolArg("-cp")
|
||||
.addToolArg(Utils.TEST_CLASSES)
|
||||
.addToolArg("Main")
|
||||
.addToolArg(Utils.TEST_CLASSES);
|
||||
|
||||
int exitCode = ProcessTools.executeCommand(launcher.getCommand())
|
||||
.getExitValue();
|
||||
if (exitCode != 0) {
|
||||
throw new RuntimeException("Execution of the test failed. "
|
||||
+ "Unexpected exit code: " + exitCode);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2017, 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 8180375 8185251
|
||||
# @summary Tests resource bundles are correctly loaded from
|
||||
# modules through "<packageName>.spi.<simpleName>Provider" types.
|
||||
|
||||
set -e
|
||||
|
||||
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
|
||||
$JAVAC --module-source-path $TESTSRC/src -d mods --module m1,m2
|
||||
|
||||
mkdir -p mods/m1/p/resources mods/m2/p/resources
|
||||
cp $TESTSRC/src/m1/p/resources/*.properties mods/m1/p/resources
|
||||
cp $TESTSRC/src/m2/p/resources/*.properties mods/m2/p/resources
|
||||
|
||||
mkdir classes
|
||||
$JAVAC -d classes $TESTSRC/src/Main.java
|
||||
|
||||
$JAVA -cp classes Main
|
@ -31,7 +31,7 @@ import java.util.ResourceBundle;
|
||||
|
||||
public class Main {
|
||||
public static void main(String... args) throws Exception {
|
||||
ModuleFinder afterFinder = ModuleFinder.of(Paths.get("mods"));
|
||||
ModuleFinder afterFinder = ModuleFinder.of(Paths.get(args[0], "mods"));
|
||||
|
||||
Configuration cf = ModuleLayer.boot().configuration()
|
||||
.resolveAndBind(ModuleFinder.of(), afterFinder,
|
||||
|
@ -1,78 +0,0 @@
|
||||
#
|
||||
# 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 8044767 8139067
|
||||
# @summary Test case for having resource bundles in a local named module
|
||||
# with no ResourceBundleProviders.
|
||||
|
||||
|
||||
set -e
|
||||
|
||||
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"
|
||||
JAR="$COMPILEJAVA/bin/jar"
|
||||
JAVA="$TESTJAVA/bin/java"
|
||||
|
||||
rm -rf mods
|
||||
mkdir -p mods/test
|
||||
|
||||
#
|
||||
# Copy .properties files
|
||||
#
|
||||
PROPS="`(cd $TESTSRC/src; find . -name '*.properties')`"
|
||||
if [ "x$PROPS" != x ]; then
|
||||
for P in $PROPS
|
||||
do
|
||||
D=`dirname $P`
|
||||
mkdir -p mods/$D
|
||||
cp $TESTSRC/src/$P mods/$D/
|
||||
done
|
||||
fi
|
||||
|
||||
$JAVAC -g -d mods --module-source-path $TESTSRC/src \
|
||||
-cp mods/bundles `find $TESTSRC/src/test -name "*.java"`
|
||||
|
||||
# Create a jar to be added to the class path. Expected properties files are
|
||||
# picked up from the class path.
|
||||
rm -f extra.jar
|
||||
mkdir -p classes
|
||||
$JAR -cf extra.jar -C $TESTSRC/src/extra jdk/test/resources
|
||||
|
||||
STATUS=0
|
||||
|
||||
echo 'jdk.test.Main should load bundles local to named module "test".'
|
||||
$JAVA -p mods -m test/jdk.test.Main de fr ja zh-tw en de || STATUS=1
|
||||
|
||||
echo "jdk.test.Main should load bundles from the jar file specified by the class-path."
|
||||
$JAVA -cp extra.jar -p mods -m test/jdk.test.Main vi || STATUS=1
|
||||
|
||||
|
||||
exit $STATUS
|
@ -1,70 +0,0 @@
|
||||
#
|
||||
# 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 8044767
|
||||
# @summary Simple test case for ResourceBundle with named modules;
|
||||
# ResourceBundle.getBundle caller is in named module "test" and
|
||||
# all resource bundles are in single named module "bundles" with
|
||||
# service providers.
|
||||
|
||||
|
||||
set -e
|
||||
|
||||
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
|
||||
|
||||
mkdir -p mods/test
|
||||
|
||||
B=bundles
|
||||
mkdir -p mods/$B
|
||||
CLASSES="`find $TESTSRC/src/$B -name '*.java'`"
|
||||
if [ "x$CLASSES" != x ]; then
|
||||
$JAVAC -g -d mods --module-source-path $TESTSRC/src $CLASSES
|
||||
fi
|
||||
PROPS="`(cd $TESTSRC/src/$B; find . -name '*.properties')`"
|
||||
if [ "x$PROPS" != x ]; then
|
||||
for P in $PROPS
|
||||
do
|
||||
D=`dirname $P`
|
||||
mkdir -p mods/$B/$D
|
||||
cp $TESTSRC/src/$B/$P mods/$B/$D/
|
||||
done
|
||||
fi
|
||||
|
||||
$JAVAC -g -d mods --module-source-path $TESTSRC/src \
|
||||
-cp mods/bundles `find $TESTSRC/src/test -name "*.java"`
|
||||
|
||||
$JAVA -p mods -m test/jdk.test.Main de fr ja zh-tw en de
|
||||
|
||||
exit $?
|
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 2018, 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 8210408
|
||||
* @summary Test unnamed module to find resource bundles exported from a named
|
||||
* module.
|
||||
* @library /test/lib
|
||||
* ..
|
||||
* @build jdk.test.lib.JDKToolLauncher
|
||||
* jdk.test.lib.Utils
|
||||
* jdk.test.lib.compiler.CompilerUtils
|
||||
* jdk.test.lib.process.ProcessTools
|
||||
* ModuleTestUtil
|
||||
* @run main UnNamedTest
|
||||
*/
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
import jdk.test.lib.JDKToolLauncher;
|
||||
import jdk.test.lib.Utils;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
|
||||
public class UnNamedTest {
|
||||
private static final Path SRC_DIR = Paths.get(Utils.TEST_SRC, "src");
|
||||
private static final Path MODS_DIR = Paths.get(Utils.TEST_CLASSES, "mods");
|
||||
|
||||
private static final List<String> LOCALE_LIST = List.of("de", "fr", "ja",
|
||||
"zh-tw", "en", "de");
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
ModuleTestUtil.prepareModule(SRC_DIR, MODS_DIR, "bundles", ".properties");
|
||||
compileCmd();
|
||||
runCmd();
|
||||
}
|
||||
|
||||
private static void compileCmd() throws Throwable {
|
||||
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("javac");
|
||||
launcher.addToolArg("-d")
|
||||
.addToolArg(Utils.TEST_CLASSES)
|
||||
.addToolArg(Paths.get(Utils.TEST_SRC, "Main.java").toString());
|
||||
|
||||
int exitCode = ProcessTools.executeCommand(launcher.getCommand())
|
||||
.getExitValue();
|
||||
if (exitCode != 0) {
|
||||
throw new RuntimeException("Compile of the test failed. "
|
||||
+ "Unexpected exit code: " + exitCode);
|
||||
}
|
||||
}
|
||||
|
||||
private static void runCmd() throws Throwable {
|
||||
// access resource bundles that are exported private unconditionally.
|
||||
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("java");
|
||||
launcher.addToolArg("-cp")
|
||||
.addToolArg(Utils.TEST_CLASSES)
|
||||
.addToolArg("--module-path")
|
||||
.addToolArg(MODS_DIR.toString())
|
||||
.addToolArg("--add-modules")
|
||||
.addToolArg("bundles")
|
||||
.addToolArg("Main");
|
||||
LOCALE_LIST.forEach(launcher::addToolArg);
|
||||
|
||||
int exitCode = ProcessTools.executeCommand(launcher.getCommand())
|
||||
.getExitValue();
|
||||
if (exitCode != 0) {
|
||||
throw new RuntimeException("Execution of the test1 failed. "
|
||||
+ "Unexpected exit code: " + exitCode);
|
||||
}
|
||||
|
||||
// --add-exports can't open resources
|
||||
launcher = JDKToolLauncher.createUsingTestJDK("java");
|
||||
launcher.addToolArg("-cp")
|
||||
.addToolArg(Utils.TEST_CLASSES)
|
||||
.addToolArg("--module-path")
|
||||
.addToolArg(MODS_DIR.toString())
|
||||
.addToolArg("--add-modules")
|
||||
.addToolArg("bundles")
|
||||
.addToolArg("--add-opens")
|
||||
.addToolArg("bundles/jdk.test.internal.resources=ALL-UNNAMED")
|
||||
.addToolArg("Main");
|
||||
LOCALE_LIST.forEach(launcher::addToolArg);
|
||||
|
||||
exitCode = ProcessTools.executeCommand(launcher.getCommand())
|
||||
.getExitValue();
|
||||
if (exitCode != 0) {
|
||||
throw new RuntimeException("Execution of the test2 failed. "
|
||||
+ "Unexpected exit code: " + exitCode);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2016, 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
|
||||
# @summary Test unnamed module to find resource bundles exported
|
||||
# from a named module
|
||||
|
||||
|
||||
set -e
|
||||
|
||||
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
|
||||
|
||||
mkdir -p mods/test
|
||||
|
||||
B=bundles
|
||||
mkdir -p mods/$B
|
||||
CLASSES="`find $TESTSRC/src/$B -name '*.java'`"
|
||||
if [ "x$CLASSES" != x ]; then
|
||||
$JAVAC -g -d mods --module-source-path $TESTSRC/src $CLASSES
|
||||
fi
|
||||
PROPS="`(cd $TESTSRC/src/$B; find . -name '*.properties')`"
|
||||
if [ "x$PROPS" != x ]; then
|
||||
for P in $PROPS
|
||||
do
|
||||
D=`dirname $P`
|
||||
mkdir -p mods/$B/$D
|
||||
cp $TESTSRC/src/$B/$P mods/$B/$D/
|
||||
done
|
||||
fi
|
||||
|
||||
mkdir classes
|
||||
$JAVAC -d classes $TESTSRC/Main.java
|
||||
|
||||
# access resource bundles that are exported private unconditionally
|
||||
$JAVA -cp classes --module-path mods --add-modules bundles \
|
||||
Main de fr ja zh-tw en de
|
||||
|
||||
# --add-exports can't open resources
|
||||
$JAVA -cp classes --module-path mods --add-modules bundles \
|
||||
--add-opens bundles/jdk.test.internal.resources=ALL-UNNAMED \
|
||||
Main de fr ja zh-tw en de
|
||||
|
||||
exit $?
|
@ -0,0 +1,336 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2018, 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 8210408
|
||||
* @summary Visibility tests for ResourceBundle.getBundle with and without
|
||||
* an unnamed module argument.
|
||||
* @library /test/lib
|
||||
* ..
|
||||
* @build jdk.test.lib.JDKToolLauncher
|
||||
* jdk.test.lib.Utils
|
||||
* jdk.test.lib.compiler.CompilerUtils
|
||||
* jdk.test.lib.process.ProcessTools
|
||||
* ModuleTestUtil
|
||||
* @run testng VisibilityTest
|
||||
*/
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
import jdk.test.lib.JDKToolLauncher;
|
||||
import jdk.test.lib.Utils;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
@Test
|
||||
public class VisibilityTest {
|
||||
private static final Path SRC_DIR = Paths.get(Utils.TEST_SRC, "src");
|
||||
private static final Path MODS_DIR = Paths.get(Utils.TEST_CLASSES, "mods");
|
||||
private static final Path CLASSES_DIR = Paths.get(Utils.TEST_CLASSES, "classes");
|
||||
private static final Path NAMED_BUNDLES_DIR = MODS_DIR.resolve("named.bundles");
|
||||
private static final Path EXPORTED_NAMED_BUNDLES_DIR = MODS_DIR.resolve("exported.named.bundles");
|
||||
|
||||
private static final List<String> MODULE_LIST = List.of("embargo",
|
||||
"exported.named.bundles", "named.bundles", "test");
|
||||
|
||||
@BeforeTest
|
||||
public void prepareTestEnv() throws Throwable {
|
||||
MODULE_LIST.forEach(mn -> ModuleTestUtil.prepareModule(SRC_DIR,
|
||||
MODS_DIR, mn, ".properties"));
|
||||
|
||||
// Prepare resource bundles in an unnamed module
|
||||
ModuleTestUtil.compilePkg(SRC_DIR, CLASSES_DIR, "pkg");
|
||||
ModuleTestUtil.copyResFiles(SRC_DIR, CLASSES_DIR, "pkg", ".properties");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
@DataProvider(name = "RunWithTestResData")
|
||||
Object[][] RunWithTestResData() {
|
||||
return new Object[][] {
|
||||
// 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.
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithNoModuleArg",
|
||||
"jdk.test.resources.classes.MyResources", "true")},
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithNoModuleArg",
|
||||
"jdk.test.resources.props.MyResources", "true")},
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithNoModuleArg",
|
||||
"jdk.test.resources.classes.MyResources", "false")},
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithNoModuleArg",
|
||||
"jdk.test.resources.props.MyResources", "false")},
|
||||
|
||||
// Add mods/named.bundles to the class path.
|
||||
{List.of("-cp", NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithNoModuleArg",
|
||||
"jdk.test.resources.classes.MyResources", "true")},
|
||||
{List.of("-cp", NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithNoModuleArg",
|
||||
"jdk.test.resources.props.MyResources", "true")},
|
||||
{List.of("-cp", NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithNoModuleArg",
|
||||
"jdk.test.resources.classes.MyResources", "true")},
|
||||
{List.of("-cp", NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-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().
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-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.
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.props.MyResources", "false")},
|
||||
|
||||
// IllegalAccessException is thrown in ResourceBundle.Control.newBundle().
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-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.
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-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().
|
||||
{List.of("-cp", NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.classes.MyResources", "false")},
|
||||
|
||||
// loader.getResource() finds jdk.test.resources.exported.props.MyResources.
|
||||
{List.of("-cp", NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-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.
|
||||
{List.of("-cp", NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.classes.MyResources", "true")},
|
||||
|
||||
// loader.getResource() finds jdk.test.resources.exported.props.MyResources.
|
||||
{List.of("-cp", NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.props.MyResources", "true")},
|
||||
};
|
||||
}
|
||||
|
||||
@DataProvider(name = "RunWithExportedResData")
|
||||
Object[][] RunWithExportedResData() {
|
||||
return new Object[][] {
|
||||
// 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.
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithNoModuleArg",
|
||||
"jdk.test.resources.exported.classes.MyResources", "false")},
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithNoModuleArg",
|
||||
"jdk.test.resources.exported.props.MyResources", "false")},
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithNoModuleArg",
|
||||
"jdk.test.resources.exported.classes.MyResources", "false")},
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithNoModuleArg",
|
||||
"jdk.test.resources.exported.props.MyResources", "false")},
|
||||
|
||||
// Add mods/exported.named.bundles to the class path.
|
||||
{List.of("-cp", EXPORTED_NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithNoModuleArg",
|
||||
"jdk.test.resources.exported.classes.MyResources", "true")},
|
||||
{List.of("-cp", EXPORTED_NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithNoModuleArg",
|
||||
"jdk.test.resources.exported.props.MyResources", "true")},
|
||||
{List.of("-cp", EXPORTED_NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithNoModuleArg",
|
||||
"jdk.test.resources.exported.classes.MyResources", "true")},
|
||||
{List.of("-cp", EXPORTED_NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-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.
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-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().
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-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.
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-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().
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-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.
|
||||
{List.of("-cp", EXPORTED_NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.exported.classes.MyResources", "true")},
|
||||
|
||||
// loader.getResource() finds jdk.test.resources.exported.props.MyResources.
|
||||
{List.of("-cp", EXPORTED_NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.exported.props.MyResources", "true")},
|
||||
|
||||
// jdk.test.resources.exported.classes.MyResources.getModule().isNamed()
|
||||
// returns false.
|
||||
{List.of("-cp", EXPORTED_NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.exported.classes.MyResources", "true")},
|
||||
|
||||
// loader.getResource() finds jdk.test.resources.exported.props.MyResources.
|
||||
{List.of("-cp", EXPORTED_NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.exported.props.MyResources", "true")},
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@DataProvider(name = "RunWithPkgResData")
|
||||
Object[][] RunWithPkgResData() {
|
||||
return new Object[][] {
|
||||
// jdk.pkg.resources.* are in an unnamed module.
|
||||
// jdk.pkg.test.Main calls ResourceBundle.getBundle with an unnamed module.
|
||||
{ List.of("-cp", CLASSES_DIR.resolve("pkg").toString(), "jdk.pkg.test.Main",
|
||||
"jdk.pkg.resources.classes.MyResources", "true")},
|
||||
{ List.of("-cp", CLASSES_DIR.resolve("pkg").toString(), "jdk.pkg.test.Main",
|
||||
"jdk.pkg.resources.props.MyResources", "true")},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases with jdk.test.resources.*
|
||||
*/
|
||||
@Test(dataProvider = "RunWithTestResData")
|
||||
public void RunWithTestRes(List<String> argsList) throws Throwable {
|
||||
int exitCode = runCmd(argsList);
|
||||
assertEquals(exitCode, 0, "Execution of the tests with "
|
||||
+ "jdk.test.resources.* failed. "
|
||||
+ "Unexpected exit code: " + exitCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases with jdk.test.resources.exported.*
|
||||
*/
|
||||
@Test(dataProvider = "RunWithExportedResData")
|
||||
public void RunWithExportedRes(List<String> argsList) throws Throwable {
|
||||
int exitCode = runCmd(argsList);
|
||||
assertEquals(exitCode, 0, "Execution of the tests with "
|
||||
+ "jdk.test.resources.exported.* failed. "
|
||||
+ "Unexpected exit code: " + exitCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases with jdk.pkg.resources.*
|
||||
*/
|
||||
@Test(dataProvider = "RunWithPkgResData")
|
||||
public void RunWithPkgRes(List<String> argsList) throws Throwable {
|
||||
int exitCode = runCmd(argsList);
|
||||
assertEquals(exitCode, 0, "Execution of the tests with "
|
||||
+ "jdk.pkg.resources.* failed. "
|
||||
+ "Unexpected exit code: " + exitCode);
|
||||
}
|
||||
|
||||
private int runCmd(List<String> argsList) throws Throwable {
|
||||
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("java");
|
||||
argsList.forEach(launcher::addToolArg);
|
||||
|
||||
return ProcessTools.executeCommand(launcher.getCommand()).getExitValue();
|
||||
}
|
||||
}
|
@ -1,233 +0,0 @@
|
||||
#
|
||||
# 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
|
@ -1,68 +0,0 @@
|
||||
#
|
||||
# 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
|
||||
# @summary Simple test case for ResourceBundle with modules;
|
||||
# ResourceBundle.getBundle caller is in module named "test" and
|
||||
# all resource bundles are in single module named "bundles".
|
||||
|
||||
|
||||
set -e
|
||||
|
||||
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
|
||||
|
||||
mkdir -p mods/test
|
||||
|
||||
B=bundles
|
||||
mkdir -p mods/$B
|
||||
CLASSES="`find $TESTSRC/src/$B -name '*.java'`"
|
||||
if [ "x$CLASSES" != x ]; then
|
||||
$JAVAC -g -d mods --module-source-path $TESTSRC/src $CLASSES
|
||||
fi
|
||||
PROPS="`(cd $TESTSRC/src/$B; find . -name '*.xml')`"
|
||||
if [ "x$PROPS" != x ]; then
|
||||
for P in $PROPS
|
||||
do
|
||||
D=`dirname $P`
|
||||
mkdir -p mods/$B/$D
|
||||
cp $TESTSRC/src/$B/$P mods/$B/$D/
|
||||
done
|
||||
fi
|
||||
|
||||
$JAVAC -g -d mods --module-source-path $TESTSRC/src \
|
||||
-cp mods/bundles `find $TESTSRC/src/test -name "*.java"`
|
||||
|
||||
$JAVA -p mods -m test/jdk.test.Main de fr ja zh-tw en de
|
||||
|
||||
exit $?
|
Loading…
x
Reference in New Issue
Block a user