Mercurial > hg > openjdk > jdk9 > jdk
changeset 17194:fb80de0ea690
8180375: Rename <baseName>Provider to <packagename>.spi.<simpleName>Provider
Reviewed-by: mchung
line wrap: on
line diff
--- a/src/java.base/share/classes/java/util/ResourceBundle.java Thu Jun 01 18:48:56 2017 +0000 +++ b/src/java.base/share/classes/java/util/ResourceBundle.java Thu Jun 01 14:52:53 2017 -0700 @@ -216,16 +216,17 @@ * the caller module, those resource bundles need to be loaded from service * providers of {@link ResourceBundleProvider}. The caller module must declare * "{@code uses}" and the service interface name is the concatenation of the - * base name of the bundles and the string "{@code Provider}". The + * package name of the base name, string "{@code .spi.}", the simple class + * name of the base name, and the string "{@code Provider}". The * <em>bundle provider modules</em> containing resource bundles must * declare "{@code provides}" with the service interface name and * its implementation class name. For example, if the base name is * "{@code com.example.app.MyResources}", the caller module must declare - * "{@code uses com.example.app.MyResourcesProvider;}" and a module containing resource - * bundles must declare "{@code provides com.example.app.MyResourcesProvider + * "{@code uses com.example.app.spi.MyResourcesProvider;}" and a module containing resource + * bundles must declare "{@code provides com.example.app.spi.MyResourcesProvider * with com.example.app.internal.MyResourcesProviderImpl;}" * where {@code com.example.app.internal.MyResourcesProviderImpl} is an - * implementation class of {@code com.example.app.MyResourcesProvider}.</li> + * implementation class of {@code com.example.app.spi.MyResourcesProvider}.</li> * <li>If you want to use non-standard formats in named modules, such as XML, * {@link ResourceBundleProvider} needs to be used.</li> * <li>The {@code getBundle} method with a {@code ClassLoader} may not be able to @@ -243,9 +244,10 @@ * * The {@code getBundle} factory methods load service providers of * {@link ResourceBundleProvider}, if available, using {@link ServiceLoader}. - * The service type is designated by {@code basename+"Provider"}. For + * The service type is designated by + * {@code <package name> + ".spi." + <simple name> + "Provider"}. For * example, if the base name is "{@code com.example.app.MyResources}", the service - * type is {@code com.example.app.MyResourcesProvider}. + * type is {@code com.example.app.spi.MyResourcesProvider}. * <p> * In named modules, the loaded service providers for the given base name are * used to load resource bundles. If no service provider is available, or if @@ -923,7 +925,12 @@ * <p> Resource bundles in named modules may be encapsulated. When * the resource bundle is loaded from a provider, the caller module * must have an appropriate <i>uses</i> clause in its <i>module descriptor</i> - * to declare that the module uses implementations of {@code "baseName"Provider}. + * to declare that the module uses implementations of + * {@code <package name> + ".spi." + <simple name> + "Provider"}. + * Otherwise, it will load the resource bundles that are local in the + * given module or that are visible to the class loader of the given module + * (refer to the <a href="#bundleprovider">Resource Bundles in Named Modules</a> + * section for details). * When the resource bundle is loaded from the specified module, it is * subject to the encapsulation rules specified by * {@link Module#getResourceAsStream Module.getResourceAsStream}. @@ -958,20 +965,17 @@ * <p> Resource bundles in named modules may be encapsulated. When * the resource bundle is loaded from a provider, the caller module * must have an appropriate <i>uses</i> clause in its <i>module descriptor</i> - * to declare that the module uses implementations of {@code "baseName"Provider}. + * to declare that the module uses implementations of + * {@code <package name> + ".spi." + <simple name> + "Provider"}. + * Otherwise, it will load the resource bundles that are local in the + * given module or that are visible to the class loader of the given module + * (refer to the <a href="#bundleprovider">Resource Bundles in Named Modules</a> + * section for details). * When the resource bundle is loaded from the specified module, it is * subject to the encapsulation rules specified by * {@link Module#getResourceAsStream Module.getResourceAsStream}. * * <p> - * If the given {@code module} is a named module, this method will - * load the service providers for {@link java.util.spi.ResourceBundleProvider} - * and also resource bundles that are local in the given module or that - * are visible to the class loader of the given module (refer to the - * <a href="#bundleprovider">Resource Bundles in Named Modules</a> section - * for details). - * - * <p> * If the given {@code module} is an unnamed module, then this method is * equivalent to calling {@link #getBundle(String, Locale, ClassLoader) * getBundle(baseName, targetLocale, module.getClassLoader()} to load @@ -1070,8 +1074,10 @@ * Resource bundles in a named module are private to that module. If * the caller is in a named module, this method will find resource bundles * from the service providers of {@link java.util.spi.ResourceBundleProvider} - * and also find resource bundles that are in the caller's module or - * that are visible to the given class loader. + * if any. Otherwise, it will load the resource bundles that are visible to + * the given {@code loader} (refer to the + * <a href="#bundleprovider">Resource Bundles in Named Modules</a> section + * for details). * If the caller is in a named module and the given {@code loader} is * different than the caller's class loader, or if the caller is not in * a named module, this method will not find resource bundles from named @@ -1883,8 +1889,15 @@ private static Class<ResourceBundleProvider> getResourceBundleProviderType(String baseName, ClassLoader loader) { - // Look up <baseName> + "Provider" - String providerName = baseName + "Provider"; + // Look up <packagename> + ".spi." + <name>"Provider" + int i = baseName.lastIndexOf('.'); + if (i <= 0) { + return null; + } + + String name = baseName.substring(i+1, baseName.length()) + "Provider"; + String providerName = baseName.substring(0, i) + ".spi." + name; + // Use the class loader of the getBundle caller so that the caller's // visibility of the provider type is checked. return AccessController.doPrivileged(
--- a/src/java.base/share/classes/java/util/spi/ResourceBundleProvider.java Thu Jun 01 18:48:56 2017 +0000 +++ b/src/java.base/share/classes/java/util/spi/ResourceBundleProvider.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -35,11 +35,11 @@ * during a call to the * {@link ResourceBundle#getBundle(String, Locale, ClassLoader) * ResourceBundle.getBundle} method. The provider service type is determined by - * {@code basename+"Provider"}. + * {@code <package name> + ".spi." + <simple name> + "Provider"}. * * <p> * For example, if the base name is "com.example.app.MyResources", - * {@code com.example.app.MyResourcesProvider} will be the provider service type: + * {@code com.example.app.spi.MyResourcesProvider} will be the provider service type: * <pre>{@code * public interface MyResourcesProvider extends ResourceBundleProvider { * }
--- a/test/java/util/ResourceBundle/modules/appbasic/src/asiabundles/jdk/test/resources/asia/MyResourcesAsia.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/appbasic/src/asiabundles/jdk/test/resources/asia/MyResourcesAsia.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -28,7 +28,7 @@ import java.util.Set; import java.util.spi.AbstractResourceBundleProvider; -import jdk.test.resources.MyResourcesProvider; +import jdk.test.resources.spi.MyResourcesProvider; public class MyResourcesAsia extends AbstractResourceBundleProvider implements MyResourcesProvider
--- a/test/java/util/ResourceBundle/modules/appbasic/src/asiabundles/module-info.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/appbasic/src/asiabundles/module-info.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -24,6 +24,6 @@ module asiabundles { requires test; - provides jdk.test.resources.MyResourcesProvider + provides jdk.test.resources.spi.MyResourcesProvider with jdk.test.resources.asia.MyResourcesAsia; }
--- a/test/java/util/ResourceBundle/modules/appbasic/src/eubundles/jdk/test/resources/eu/MyResourcesEU.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/appbasic/src/eubundles/jdk/test/resources/eu/MyResourcesEU.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -28,7 +28,7 @@ import java.util.Set; import java.util.spi.AbstractResourceBundleProvider; -import jdk.test.resources.MyResourcesProvider; +import jdk.test.resources.spi.MyResourcesProvider; public class MyResourcesEU extends AbstractResourceBundleProvider implements MyResourcesProvider
--- a/test/java/util/ResourceBundle/modules/appbasic/src/eubundles/module-info.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/appbasic/src/eubundles/module-info.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -24,6 +24,6 @@ module eubundles { requires test; - provides jdk.test.resources.MyResourcesProvider + provides jdk.test.resources.spi.MyResourcesProvider with jdk.test.resources.eu.MyResourcesEU; }
--- a/test/java/util/ResourceBundle/modules/appbasic/src/test/jdk/test/resources/MyResourcesProvider.java Thu Jun 01 18:48:56 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +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. - */ - -package jdk.test.resources; - -import java.util.spi.ResourceBundleProvider; - -public interface MyResourcesProvider extends ResourceBundleProvider { -}
--- a/test/java/util/ResourceBundle/modules/appbasic/src/test/jdk/test/resources/MyResourcesProviderImpl.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/appbasic/src/test/jdk/test/resources/MyResourcesProviderImpl.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -26,6 +26,7 @@ import java.util.Locale; import java.util.ResourceBundle; import java.util.spi.AbstractResourceBundleProvider; +import jdk.test.resources.spi.MyResourcesProvider; public class MyResourcesProviderImpl extends AbstractResourceBundleProvider implements MyResourcesProvider
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/util/ResourceBundle/modules/appbasic/src/test/jdk/test/resources/spi/MyResourcesProvider.java Thu Jun 01 14:52:53 2017 -0700 @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2015, 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. + */ + +package jdk.test.resources.spi; + +import java.util.spi.ResourceBundleProvider; + +public interface MyResourcesProvider extends ResourceBundleProvider { +}
--- a/test/java/util/ResourceBundle/modules/appbasic/src/test/module-info.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/appbasic/src/test/module-info.java Thu Jun 01 14:52:53 2017 -0700 @@ -22,7 +22,7 @@ */ module test { - exports jdk.test.resources to eubundles, asiabundles; - uses jdk.test.resources.MyResourcesProvider; - provides jdk.test.resources.MyResourcesProvider with jdk.test.resources.MyResourcesProviderImpl; + exports jdk.test.resources.spi to eubundles, asiabundles; + uses jdk.test.resources.spi.MyResourcesProvider; + provides jdk.test.resources.spi.MyResourcesProvider with jdk.test.resources.MyResourcesProviderImpl; }
--- a/test/java/util/ResourceBundle/modules/appbasic2/src/asiabundles/jdk/test/resources/asia/MyResourcesAsia.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/appbasic2/src/asiabundles/jdk/test/resources/asia/MyResourcesAsia.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -24,7 +24,7 @@ package jdk.test.resources.asia; import java.util.Locale; -import jdk.test.resources.MyResourcesProvider; +import jdk.test.resources.spi.MyResourcesProvider; public class MyResourcesAsia extends MyResourcesProvider { public MyResourcesAsia() {
--- a/test/java/util/ResourceBundle/modules/appbasic2/src/asiabundles/module-info.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/appbasic2/src/asiabundles/module-info.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -24,6 +24,6 @@ module asiabundles { requires test; - provides jdk.test.resources.MyResourcesProvider + provides jdk.test.resources.spi.MyResourcesProvider with jdk.test.resources.asia.MyResourcesAsia; }
--- a/test/java/util/ResourceBundle/modules/appbasic2/src/eubundles/jdk/test/resources/eu/MyResourcesEU.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/appbasic2/src/eubundles/jdk/test/resources/eu/MyResourcesEU.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -24,7 +24,7 @@ package jdk.test.resources.eu; import java.util.Locale; -import jdk.test.resources.MyResourcesProvider; +import jdk.test.resources.spi.MyResourcesProvider; public class MyResourcesEU extends MyResourcesProvider { public MyResourcesEU() {
--- a/test/java/util/ResourceBundle/modules/appbasic2/src/eubundles/module-info.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/appbasic2/src/eubundles/module-info.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -24,6 +24,6 @@ module eubundles { requires test; - provides jdk.test.resources.MyResourcesProvider + provides jdk.test.resources.spi.MyResourcesProvider with jdk.test.resources.eu.MyResourcesEU; }
--- a/test/java/util/ResourceBundle/modules/appbasic2/src/test/jdk/test/resources/MyResourcesProvider.java Thu Jun 01 18:48:56 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +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. - */ - -package jdk.test.resources; - - -import java.util.Locale; -import java.util.ResourceBundle; -import java.util.spi.AbstractResourceBundleProvider; - -public abstract class MyResourcesProvider extends AbstractResourceBundleProvider { - protected MyResourcesProvider(String... formats) { - super(formats); - } - - @Override - public ResourceBundle getBundle(String baseName, Locale locale) { - if (isSupportedInModule(locale)) { - return super.getBundle(baseName, locale); - } - return null; - } - - protected abstract boolean isSupportedInModule(Locale locale); -}
--- a/test/java/util/ResourceBundle/modules/appbasic2/src/test/jdk/test/resources/MyResourcesProviderImpl.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/appbasic2/src/test/jdk/test/resources/MyResourcesProviderImpl.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -24,6 +24,7 @@ package jdk.test.resources; import java.util.Locale; +import jdk.test.resources.spi.MyResourcesProvider; public class MyResourcesProviderImpl extends MyResourcesProvider { public MyResourcesProviderImpl() {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/util/ResourceBundle/modules/appbasic2/src/test/jdk/test/resources/spi/MyResourcesProvider.java Thu Jun 01 14:52:53 2017 -0700 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2015, 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. + */ + +package jdk.test.resources.spi; + + +import java.util.Locale; +import java.util.ResourceBundle; +import java.util.spi.AbstractResourceBundleProvider; + +public abstract class MyResourcesProvider extends AbstractResourceBundleProvider { + protected MyResourcesProvider(String... formats) { + super(formats); + } + + @Override + public ResourceBundle getBundle(String baseName, Locale locale) { + if (isSupportedInModule(locale)) { + return super.getBundle(baseName, locale); + } + return null; + } + + protected abstract boolean isSupportedInModule(Locale locale); +}
--- a/test/java/util/ResourceBundle/modules/appbasic2/src/test/module-info.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/appbasic2/src/test/module-info.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -22,7 +22,7 @@ */ module test { - exports jdk.test.resources to eubundles, asiabundles; - uses jdk.test.resources.MyResourcesProvider; - provides jdk.test.resources.MyResourcesProvider with jdk.test.resources.MyResourcesProviderImpl; + exports jdk.test.resources.spi to eubundles, asiabundles; + uses jdk.test.resources.spi.MyResourcesProvider; + provides jdk.test.resources.spi.MyResourcesProvider with jdk.test.resources.MyResourcesProviderImpl; }
--- a/test/java/util/ResourceBundle/modules/basic/src/asiabundles/jdk/test/resources/asia/MyResourcesAsia.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/basic/src/asiabundles/jdk/test/resources/asia/MyResourcesAsia.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -24,7 +24,7 @@ package jdk.test.resources.asia; import java.util.Locale; -import jdk.test.resources.MyResourcesProvider; +import jdk.test.resources.spi.MyResourcesProvider; /** *
--- a/test/java/util/ResourceBundle/modules/basic/src/asiabundles/module-info.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/basic/src/asiabundles/module-info.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -24,6 +24,6 @@ module asiabundles { requires mainbundles; - provides jdk.test.resources.MyResourcesProvider + provides jdk.test.resources.spi.MyResourcesProvider with jdk.test.resources.asia.MyResourcesAsia; }
--- a/test/java/util/ResourceBundle/modules/basic/src/eubundles/jdk/test/resources/eu/MyResourcesEU.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/basic/src/eubundles/jdk/test/resources/eu/MyResourcesEU.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -24,7 +24,7 @@ package jdk.test.resources.eu; import java.util.Locale; -import jdk.test.resources.MyResourcesProvider; +import jdk.test.resources.spi.MyResourcesProvider; /** *
--- a/test/java/util/ResourceBundle/modules/basic/src/eubundles/module-info.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/basic/src/eubundles/module-info.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -24,6 +24,6 @@ module eubundles { requires mainbundles; - provides jdk.test.resources.MyResourcesProvider + provides jdk.test.resources.spi.MyResourcesProvider with jdk.test.resources.eu.MyResourcesEU; }
--- a/test/java/util/ResourceBundle/modules/basic/src/mainbundles/jdk/test/resources/MyResourcesMain.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/basic/src/mainbundles/jdk/test/resources/MyResourcesMain.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -24,6 +24,7 @@ package jdk.test.resources; import java.util.Locale; +import jdk.test.resources.spi.MyResourcesProvider; public class MyResourcesMain extends MyResourcesProvider { public MyResourcesMain() {
--- a/test/java/util/ResourceBundle/modules/basic/src/mainbundles/jdk/test/resources/MyResourcesProvider.java Thu Jun 01 18:48:56 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +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. - */ - -package jdk.test.resources; - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.ResourceBundle; -import java.util.ResourceBundle.Control; -import java.util.Set; -import java.util.spi.AbstractResourceBundleProvider; - - -public class MyResourcesProvider extends AbstractResourceBundleProvider { - private final String region; - private final Set<Locale> supportedLocales; - private final List<String> formats; - - protected MyResourcesProvider() { - region = ""; - supportedLocales = null; - formats = Collections.emptyList(); - } - - protected MyResourcesProvider(String format, String region, Locale... locales) { - super(format); - this.region = region; - this.supportedLocales = new HashSet<>(Arrays.asList(locales)); - this.formats = Collections.singletonList(format); - } - - @Override - public ResourceBundle getBundle(String baseName, Locale locale) { - if (isSupportedInModule(locale)) { - return super.getBundle(baseName, locale); - } - return null; - } - - @Override - protected String toBundleName(String baseName, Locale locale) { - String name = addRegion(baseName); - return Control.getControl(Control.FORMAT_DEFAULT).toBundleName(name, locale); - } - - private String addRegion(String baseName) { - if (region.isEmpty()) { - return baseName; - } - int index = baseName.lastIndexOf('.'); - return baseName.substring(0, index + 1) + region + baseName.substring(index); - } - - protected boolean isSupportedInModule(Locale locale) { - return supportedLocales.contains(locale); - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/util/ResourceBundle/modules/basic/src/mainbundles/jdk/test/resources/spi/MyResourcesProvider.java Thu Jun 01 14:52:53 2017 -0700 @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2015, 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. + */ + +package jdk.test.resources.spi; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.ResourceBundle; +import java.util.ResourceBundle.Control; +import java.util.Set; +import java.util.spi.AbstractResourceBundleProvider; + + +public class MyResourcesProvider extends AbstractResourceBundleProvider { + private final String region; + private final Set<Locale> supportedLocales; + private final List<String> formats; + + protected MyResourcesProvider() { + region = ""; + supportedLocales = null; + formats = Collections.emptyList(); + } + + protected MyResourcesProvider(String format, String region, Locale... locales) { + super(format); + this.region = region; + this.supportedLocales = new HashSet<>(Arrays.asList(locales)); + this.formats = Collections.singletonList(format); + } + + @Override + public ResourceBundle getBundle(String baseName, Locale locale) { + if (isSupportedInModule(locale)) { + return super.getBundle(baseName, locale); + } + return null; + } + + @Override + protected String toBundleName(String baseName, Locale locale) { + String name = addRegion(baseName); + return Control.getControl(Control.FORMAT_DEFAULT).toBundleName(name, locale); + } + + private String addRegion(String baseName) { + if (region.isEmpty()) { + return baseName; + } + int index = baseName.lastIndexOf('.'); + return baseName.substring(0, index + 1) + region + baseName.substring(index); + } + + protected boolean isSupportedInModule(Locale locale) { + return supportedLocales.contains(locale); + } +}
--- a/test/java/util/ResourceBundle/modules/basic/src/mainbundles/module-info.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/basic/src/mainbundles/module-info.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -22,7 +22,7 @@ */ module mainbundles { - exports jdk.test.resources to test, eubundles, asiabundles; - provides jdk.test.resources.MyResourcesProvider + exports jdk.test.resources.spi to test, eubundles, asiabundles; + provides jdk.test.resources.spi.MyResourcesProvider with jdk.test.resources.MyResourcesMain; }
--- a/test/java/util/ResourceBundle/modules/basic/src/test/module-info.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/basic/src/test/module-info.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -23,5 +23,5 @@ module test { requires mainbundles; - uses jdk.test.resources.MyResourcesProvider; + uses jdk.test.resources.spi.MyResourcesProvider; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/util/ResourceBundle/modules/layer/run.sh Thu Jun 01 14:52:53 2017 -0700 @@ -0,0 +1,52 @@ +# +# 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 +# @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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/util/ResourceBundle/modules/layer/src/Main.java Thu Jun 01 14:52:53 2017 -0700 @@ -0,0 +1,66 @@ +/* + * 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. + */ + +import java.lang.module.Configuration; +import java.lang.module.ModuleFinder; +import java.lang.reflect.Method; +import java.nio.file.Paths; +import java.util.List; +import java.util.Locale; +import java.util.ResourceBundle; + +public class Main { + public static void main(String... args) throws Exception { + ModuleFinder afterFinder = ModuleFinder.of(Paths.get("mods")); + + Configuration cf = ModuleLayer.boot().configuration() + .resolveAndBind(ModuleFinder.of(), afterFinder, + List.of("m1", "m2")); + + System.out.println("Configuration: " + cf); + + ModuleLayer l = ModuleLayer.defineModulesWithManyLoaders(cf, + List.of(ModuleLayer.boot()), + ClassLoader.getPlatformClassLoader()) + .layer(); + + Module m1 = l.findModule("m1").get(); + ResourceBundle bundle = + ResourceBundle.getBundle("p.resources.MyResource", + Locale.US, m1); + ResourceBundle jabundle = + ResourceBundle.getBundle("p.resources.MyResource", + Locale.JAPANESE, m1); + + String enResult = bundle.getString("key"); + String jaResult = jabundle.getString("key"); + if (!"hi".equals(enResult) || !"ja".equals(jaResult)) { + throw new RuntimeException("Unexpected resources loaded: en: " + + enResult + ", ja: " + jaResult); + } + + Class<?> c = Class.forName(m1, "p.Main"); + Method m = c.getDeclaredMethod("run"); + m.invoke(null); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/util/ResourceBundle/modules/layer/src/m1/module-info.java Thu Jun 01 14:52:53 2017 -0700 @@ -0,0 +1,29 @@ +/* + * 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. + */ + +module m1 { + exports p; + exports p.resources.spi; + uses p.resources.spi.MyResourceProvider; + provides p.resources.spi.MyResourceProvider with p.internal.BundleProvider; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/util/ResourceBundle/modules/layer/src/m1/p/Main.java Thu Jun 01 14:52:53 2017 -0700 @@ -0,0 +1,53 @@ +/* + * 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. + */ + +package p; + +import java.util.Locale; +import java.util.ResourceBundle; +import java.io.InputStream; + +public class Main { + public static void main(String... args) { + run(); + } + + public static void run() { + ClassLoader loader = + Main.class.getModule().getLayer().findLoader("m1"); + ClassLoader loader2 = + Main.class.getModule().getLayer().findLoader("m2"); + + ResourceBundle bundle = + ResourceBundle.getBundle("p.resources.MyResource", Locale.US); + ResourceBundle bundle1 = + ResourceBundle.getBundle("p.resources.MyResource", Locale.JAPANESE); + + String enResult = bundle.getString("key"); + String jaResult = bundle1.getString("key"); + if (!"hi".equals(enResult) || !"ja".equals(jaResult)) { + throw new RuntimeException("Unexpected resources loaded: en: " + + enResult + ", ja: " + jaResult); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/util/ResourceBundle/modules/layer/src/m1/p/internal/BundleProvider.java Thu Jun 01 14:52:53 2017 -0700 @@ -0,0 +1,50 @@ +/* + * 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. + */ + +package p.internal; + +import p.resources.spi.MyResourceProvider; + +import java.io.IOException; +import java.io.InputStream; +import java.io.UncheckedIOException; +import java.util.Locale; +import java.util.PropertyResourceBundle; +import java.util.ResourceBundle; +import java.util.spi.AbstractResourceBundleProvider; + +public class BundleProvider extends AbstractResourceBundleProvider + implements MyResourceProvider { + public BundleProvider() { + super(); + } + @Override + public ResourceBundle getBundle(String baseName, Locale locale) { + if (locale.equals(Locale.ENGLISH) || locale.equals(Locale.ROOT)) { + return super.getBundle(baseName, locale); + } + + return null; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/util/ResourceBundle/modules/layer/src/m1/p/resources/MyResource.properties Thu Jun 01 14:52:53 2017 -0700 @@ -0,0 +1,24 @@ +# +# 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. +# + +key=hi
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/util/ResourceBundle/modules/layer/src/m1/p/resources/spi/MyResourceProvider.java Thu Jun 01 14:52:53 2017 -0700 @@ -0,0 +1,30 @@ +/* + * 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. + */ + +package p.resources.spi; + +import java.util.spi.ResourceBundleProvider; + + +public interface MyResourceProvider extends ResourceBundleProvider { +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/util/ResourceBundle/modules/layer/src/m2/module-info.java Thu Jun 01 14:52:53 2017 -0700 @@ -0,0 +1,27 @@ +/* + * 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. + */ + +module m2 { + requires m1; + provides p.resources.spi.MyResourceProvider with p.internal.BundleProvider; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/util/ResourceBundle/modules/layer/src/m2/p/internal/BundleProvider.java Thu Jun 01 14:52:53 2017 -0700 @@ -0,0 +1,47 @@ +/* + * 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. + */ + +package p.internal; + +import p.resources.spi.MyResourceProvider; + + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.util.Locale; +import java.util.ResourceBundle; +import java.util.spi.AbstractResourceBundleProvider; + +public class BundleProvider extends AbstractResourceBundleProvider + implements MyResourceProvider { + public BundleProvider() { + super(); + } + @Override + public ResourceBundle getBundle(String baseName, Locale locale) { + if (locale.equals(Locale.JAPANESE)) { + return super.getBundle(baseName, locale); + } + return null; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/util/ResourceBundle/modules/layer/src/m2/p/resources/MyResource_ja.properties Thu Jun 01 14:52:53 2017 -0700 @@ -0,0 +1,24 @@ +# +# 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. +# + +key=ja
--- a/test/java/util/ResourceBundle/modules/simple/src/bundles/jdk/test/resources/MyResourcesProvider.java Thu Jun 01 18:48:56 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +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. - */ - -package jdk.test.resources; - -import java.util.Locale; -import java.util.spi.AbstractResourceBundleProvider; - -public class MyResourcesProvider extends AbstractResourceBundleProvider { - public MyResourcesProvider() { - super("java.class", "java.properties"); - System.err.println("MyResourcesProvider called " + this); - } - - @Override - protected String toBundleName(String baseName, Locale locale) { - StringBuilder sb = new StringBuilder(baseName); - String lang = locale.getLanguage(); - if (!lang.isEmpty()) { - sb.append('_').append(lang); - String country = locale.getCountry(); - if (!country.isEmpty()) { - sb.append('_').append(country); - } - } - return sb.toString(); - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/util/ResourceBundle/modules/simple/src/bundles/jdk/test/resources/spi/MyResourcesProvider.java Thu Jun 01 14:52:53 2017 -0700 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015, 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. + */ + +package jdk.test.resources.spi; + +import java.util.Locale; +import java.util.spi.AbstractResourceBundleProvider; + +public class MyResourcesProvider extends AbstractResourceBundleProvider { + public MyResourcesProvider() { + super("java.class", "java.properties"); + System.err.println("MyResourcesProvider called " + this); + } + + @Override + protected String toBundleName(String baseName, Locale locale) { + StringBuilder sb = new StringBuilder(baseName); + String lang = locale.getLanguage(); + if (!lang.isEmpty()) { + sb.append('_').append(lang); + String country = locale.getCountry(); + if (!country.isEmpty()) { + sb.append('_').append(country); + } + } + return sb.toString(); + } +}
--- a/test/java/util/ResourceBundle/modules/simple/src/bundles/module-info.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/simple/src/bundles/module-info.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -22,6 +22,6 @@ */ module bundles { - exports jdk.test.resources to test; - provides jdk.test.resources.MyResourcesProvider with jdk.test.resources.MyResourcesProvider; + exports jdk.test.resources.spi to test; + provides jdk.test.resources.spi.MyResourcesProvider with jdk.test.resources.spi.MyResourcesProvider; }
--- a/test/java/util/ResourceBundle/modules/simple/src/test/module-info.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/simple/src/test/module-info.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -24,5 +24,5 @@ module test { requires bundles; - uses jdk.test.resources.MyResourcesProvider; + uses jdk.test.resources.spi.MyResourcesProvider; }
--- a/test/java/util/ResourceBundle/modules/visibility/src/exported.named.bundles/jdk/test/resources/exported/classes/MyResourcesProvider.java Thu Jun 01 18:48:56 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +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. - */ - -package jdk.test.resources.exported.classes; - -import java.util.Locale; -import java.util.spi.AbstractResourceBundleProvider; - -public class MyResourcesProvider extends AbstractResourceBundleProvider { - public MyResourcesProvider() { - super("java.class", "java.properties"); - System.err.println("MyResourcesProvider called " + this); - } - - @Override - protected String toBundleName(String baseName, Locale locale) { - StringBuilder sb = new StringBuilder(baseName); - String lang = locale.getLanguage(); - if (!lang.isEmpty()) { - sb.append('_').append(lang); - String country = locale.getCountry(); - if (!country.isEmpty()) { - sb.append('_').append(country); - } - } - return sb.toString(); - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/util/ResourceBundle/modules/visibility/src/exported.named.bundles/jdk/test/resources/exported/classes/spi/MyResourcesProvider.java Thu Jun 01 14:52:53 2017 -0700 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015, 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. + */ + +package jdk.test.resources.exported.classes.spi; + +import java.util.Locale; +import java.util.spi.AbstractResourceBundleProvider; + +public class MyResourcesProvider extends AbstractResourceBundleProvider { + public MyResourcesProvider() { + super("java.class", "java.properties"); + System.err.println("MyResourcesProvider called " + this); + } + + @Override + protected String toBundleName(String baseName, Locale locale) { + StringBuilder sb = new StringBuilder(baseName); + String lang = locale.getLanguage(); + if (!lang.isEmpty()) { + sb.append('_').append(lang); + String country = locale.getCountry(); + if (!country.isEmpty()) { + sb.append('_').append(country); + } + } + return sb.toString(); + } +}
--- a/test/java/util/ResourceBundle/modules/visibility/src/exported.named.bundles/module-info.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/visibility/src/exported.named.bundles/module-info.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -25,6 +25,6 @@ // unqualified exports to verify that resource bundles are not picked // up by other named modules exports jdk.test.resources.exported.classes; - provides jdk.test.resources.exported.classes.MyResourcesProvider - with jdk.test.resources.exported.classes.MyResourcesProvider; + provides jdk.test.resources.exported.classes.spi.MyResourcesProvider + with jdk.test.resources.exported.classes.spi.MyResourcesProvider; }
--- a/test/java/util/ResourceBundle/modules/visibility/src/named.bundles/jdk/test/resources/classes/MyResourcesProvider.java Thu Jun 01 18:48:56 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +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. - */ - -package jdk.test.resources.classes; - -import java.util.Locale; -import java.util.ResourceBundle; -import java.util.spi.AbstractResourceBundleProvider; - -public class MyResourcesProvider extends AbstractResourceBundleProvider { - public MyResourcesProvider() { - super("java.class"); - } - - @Override - protected String toBundleName(String baseName, Locale locale) { - StringBuilder sb = new StringBuilder(baseName); - String lang = locale.getLanguage(); - if (!lang.isEmpty()) { - sb.append('_').append(lang); - String country = locale.getCountry(); - if (!country.isEmpty()) { - sb.append('_').append(country); - } - } - return sb.toString(); - } - - @Override - public ResourceBundle getBundle(String baseName, Locale locale) { - ResourceBundle rb = super.getBundle(baseName, locale); - String tag = locale.toLanguageTag(); - if (tag.equals("und")) { - tag = "ROOT"; // to a human friendly name - } - System.out.printf(" MyResourcesProvider.getBundle(%s, %s)%n -> %s%n", - baseName, tag, rb); - return rb; - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/util/ResourceBundle/modules/visibility/src/named.bundles/jdk/test/resources/classes/spi/MyResourcesProvider.java Thu Jun 01 14:52:53 2017 -0700 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2015, 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. + */ + +package jdk.test.resources.classes.spi; + +import java.util.Locale; +import java.util.ResourceBundle; +import java.util.spi.AbstractResourceBundleProvider; + +public class MyResourcesProvider extends AbstractResourceBundleProvider { + public MyResourcesProvider() { + super("java.class"); + } + + @Override + protected String toBundleName(String baseName, Locale locale) { + StringBuilder sb = new StringBuilder(baseName); + String lang = locale.getLanguage(); + if (!lang.isEmpty()) { + sb.append('_').append(lang); + String country = locale.getCountry(); + if (!country.isEmpty()) { + sb.append('_').append(country); + } + } + return sb.toString(); + } + + @Override + public ResourceBundle getBundle(String baseName, Locale locale) { + ResourceBundle rb = super.getBundle(baseName, locale); + String tag = locale.toLanguageTag(); + if (tag.equals("und")) { + tag = "ROOT"; // to a human friendly name + } + System.out.printf(" MyResourcesProvider.getBundle(%s, %s)%n -> %s%n", + baseName, tag, rb); + return rb; + } +}
--- a/test/java/util/ResourceBundle/modules/visibility/src/named.bundles/jdk/test/resources/props/MyResourcesProvider.java Thu Jun 01 18:48:56 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +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. - */ - -package jdk.test.resources.props; - -import java.util.Locale; -import java.util.ResourceBundle; -import java.util.spi.AbstractResourceBundleProvider; - -public class MyResourcesProvider extends AbstractResourceBundleProvider { - public MyResourcesProvider() { - super("java.properties"); - } - - @Override - protected String toBundleName(String baseName, Locale locale) { - StringBuilder sb = new StringBuilder(baseName); - String lang = locale.getLanguage(); - if (!lang.isEmpty()) { - sb.append('_').append(lang); - String country = locale.getCountry(); - if (!country.isEmpty()) { - sb.append('_').append(country); - } - } - return sb.toString(); - } - - @Override - public ResourceBundle getBundle(String baseName, Locale locale) { - ResourceBundle rb = super.getBundle(baseName, locale); - String tag = locale.toLanguageTag(); - if (tag.equals("und")) { - tag = "ROOT"; // to a human friendly name - } - System.out.printf(" MyResourcesProvider.getBundle(%s, %s)%n -> %s%n", - baseName, tag, rb); - return rb; - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/util/ResourceBundle/modules/visibility/src/named.bundles/jdk/test/resources/props/spi/MyResourcesProvider.java Thu Jun 01 14:52:53 2017 -0700 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2015, 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. + */ + +package jdk.test.resources.props.spi; + +import java.util.Locale; +import java.util.ResourceBundle; +import java.util.spi.AbstractResourceBundleProvider; + +public class MyResourcesProvider extends AbstractResourceBundleProvider { + public MyResourcesProvider() { + super("java.properties"); + } + + @Override + protected String toBundleName(String baseName, Locale locale) { + StringBuilder sb = new StringBuilder(baseName); + String lang = locale.getLanguage(); + if (!lang.isEmpty()) { + sb.append('_').append(lang); + String country = locale.getCountry(); + if (!country.isEmpty()) { + sb.append('_').append(country); + } + } + return sb.toString(); + } + + @Override + public ResourceBundle getBundle(String baseName, Locale locale) { + ResourceBundle rb = super.getBundle(baseName, locale); + String tag = locale.toLanguageTag(); + if (tag.equals("und")) { + tag = "ROOT"; // to a human friendly name + } + System.out.printf(" MyResourcesProvider.getBundle(%s, %s)%n -> %s%n", + baseName, tag, rb); + return rb; + } +}
--- a/test/java/util/ResourceBundle/modules/visibility/src/named.bundles/module-info.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/visibility/src/named.bundles/module-info.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -22,10 +22,10 @@ */ module named.bundles { - exports jdk.test.resources.classes to test; // exports only to test - exports jdk.test.resources.props to test; // exports only to test - provides jdk.test.resources.classes.MyResourcesProvider - with jdk.test.resources.classes.MyResourcesProvider; - provides jdk.test.resources.props.MyResourcesProvider - with jdk.test.resources.props.MyResourcesProvider; + exports jdk.test.resources.classes.spi to test; // exports only to test + exports jdk.test.resources.props.spi to test; // exports only to test + provides jdk.test.resources.classes.spi.MyResourcesProvider + with jdk.test.resources.classes.spi.MyResourcesProvider; + provides jdk.test.resources.props.spi.MyResourcesProvider + with jdk.test.resources.props.spi.MyResourcesProvider; }
--- a/test/java/util/ResourceBundle/modules/visibility/src/test/module-info.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/visibility/src/test/module-info.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -22,8 +22,8 @@ */ module test { - // jdk.test.resources.classes.MyResourcesProvider is in named.bundles. + // jdk.test.resources.classes.spi.MyResourcesProvider is in named.bundles. requires named.bundles; - uses jdk.test.resources.classes.MyResourcesProvider; - uses jdk.test.resources.props.MyResourcesProvider; + uses jdk.test.resources.classes.spi.MyResourcesProvider; + uses jdk.test.resources.props.spi.MyResourcesProvider; }
--- a/test/java/util/ResourceBundle/modules/xmlformat/src/bundles/jdk/test/resources/MyResourcesProvider.java Thu Jun 01 18:48:56 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +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. - */ - -package jdk.test.resources; - -import java.io.BufferedInputStream; -import java.io.InputStream; -import java.io.IOException; -import java.util.Enumeration; -import java.util.Locale; -import java.util.Properties; -import java.util.ResourceBundle; -import java.util.spi.ResourceBundleProvider; - -public class MyResourcesProvider implements ResourceBundleProvider { - @Override - public ResourceBundle getBundle(String baseName, Locale locale) { - String xmlName = toXMLName(baseName, locale); - try (InputStream is = this.getClass().getModule().getResourceAsStream(xmlName)) { - return new XMLResourceBundle(new BufferedInputStream(is)); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - private String toXMLName(String baseName, Locale locale) { - StringBuilder sb = new StringBuilder(baseName.replace('.', '/')); - String lang = locale.getLanguage(); - if (!lang.isEmpty()) { - sb.append('_').append(lang); - String country = locale.getCountry(); - if (!country.isEmpty()) { - sb.append('_').append(country); - } - } - return sb.append(".xml").toString(); - } - - private static class XMLResourceBundle extends ResourceBundle { - private Properties props; - - XMLResourceBundle(InputStream stream) throws IOException { - props = new Properties(); - props.loadFromXML(stream); - } - - @Override - protected Object handleGetObject(String key) { - if (key == null) { - throw new NullPointerException(); - } - return props.get(key); - } - - @Override - public Enumeration<String> getKeys() { - // Not implemented - return null; - } - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/util/ResourceBundle/modules/xmlformat/src/bundles/jdk/test/resources/spi/MyResourcesProvider.java Thu Jun 01 14:52:53 2017 -0700 @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2015, 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. + */ + +package jdk.test.resources.spi; + +import java.io.BufferedInputStream; +import java.io.InputStream; +import java.io.IOException; +import java.util.Enumeration; +import java.util.Locale; +import java.util.Properties; +import java.util.ResourceBundle; +import java.util.spi.ResourceBundleProvider; + +public class MyResourcesProvider implements ResourceBundleProvider { + @Override + public ResourceBundle getBundle(String baseName, Locale locale) { + String xmlName = toXMLName(baseName, locale); + try (InputStream is = this.getClass().getModule().getResourceAsStream(xmlName)) { + return new XMLResourceBundle(new BufferedInputStream(is)); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private String toXMLName(String baseName, Locale locale) { + StringBuilder sb = new StringBuilder(baseName.replace('.', '/')); + String lang = locale.getLanguage(); + if (!lang.isEmpty()) { + sb.append('_').append(lang); + String country = locale.getCountry(); + if (!country.isEmpty()) { + sb.append('_').append(country); + } + } + return sb.append(".xml").toString(); + } + + private static class XMLResourceBundle extends ResourceBundle { + private Properties props; + + XMLResourceBundle(InputStream stream) throws IOException { + props = new Properties(); + props.loadFromXML(stream); + } + + @Override + protected Object handleGetObject(String key) { + if (key == null) { + throw new NullPointerException(); + } + return props.get(key); + } + + @Override + public Enumeration<String> getKeys() { + // Not implemented + return null; + } + } +}
--- a/test/java/util/ResourceBundle/modules/xmlformat/src/bundles/module-info.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/xmlformat/src/bundles/module-info.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -22,6 +22,6 @@ */ module bundles { - exports jdk.test.resources to test; - provides jdk.test.resources.MyResourcesProvider with jdk.test.resources.MyResourcesProvider; + exports jdk.test.resources.spi to test; + provides jdk.test.resources.spi.MyResourcesProvider with jdk.test.resources.spi.MyResourcesProvider; }
--- a/test/java/util/ResourceBundle/modules/xmlformat/src/test/module-info.java Thu Jun 01 18:48:56 2017 +0000 +++ b/test/java/util/ResourceBundle/modules/xmlformat/src/test/module-info.java Thu Jun 01 14:52:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -24,5 +24,5 @@ module test { requires bundles; - uses jdk.test.resources.MyResourcesProvider; + uses jdk.test.resources.spi.MyResourcesProvider; }