From 5032abbc83fb6ec45de092a02a9022f350251460 Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Thu, 4 Apr 2024 12:26:34 +0100 Subject: [PATCH] Rename Loader to Config (#230) --- .../config/{Loader.java => Config.java} | 100 +++++------------- api/src/main/java/module-info.java | 4 +- .../tck/{LoaderTest.java => ConfigTest.java} | 16 +-- ...oaderTest.java => NegativeConfigTest.java} | 8 +- 4 files changed, 40 insertions(+), 88 deletions(-) rename api/src/main/java/jakarta/config/{Loader.java => Config.java} (60%) rename tck/src/main/java/jakarta/config/tck/{LoaderTest.java => ConfigTest.java} (86%) rename tck/src/main/java/jakarta/config/tck/{NegativeLoaderTest.java => NegativeConfigTest.java} (89%) diff --git a/api/src/main/java/jakarta/config/Loader.java b/api/src/main/java/jakarta/config/Config.java similarity index 60% rename from api/src/main/java/jakarta/config/Loader.java rename to api/src/main/java/jakarta/config/Config.java index c479b9b..5efd133 100644 --- a/api/src/main/java/jakarta/config/Loader.java +++ b/api/src/main/java/jakarta/config/Config.java @@ -32,9 +32,9 @@ * file found on the classpath that follows a format that is recognized by the class {@link java.util.Properties}.

* *

In the following example the {@code MyConfigurationRelatedObject} is the configuration interface to be - * resolved. An instance of the configuration interface is created by the {@link Loader}:

+ * resolved. An instance of the configuration interface is created by the {@link Config}:

* - *
 {@linkplain Loader Loader} loader = {@linkplain Loader Loader}.{@linkplain Loader#bootstrap() bootstrap()};
+ * 
 {@linkplain Config Loader} loader = {@linkplain Config Loader}.{@linkplain Config#bootstrap() bootstrap()};
  *MyConfigurationRelatedObject object = null;
  *try {
  *  object = loader
@@ -52,122 +52,72 @@
  *     
  • safe for concurrent use by multiple threads
  • *
  • must not return {@code null}.
  • * - * - * @see #bootstrap() - * - * @see #bootstrap(ClassLoader) - * - * @see #load(Class) - * - * @see #path(String) - * - * @see Terminology */ -public interface Loader { - +public interface Config { /** - * Loads a configuration-related object of the supplied {@code - * type} and returns it. - * - *

    Note: The rules governing how it is - * determined whether any given configuration-related object is - * "of the supplied {@code type}" are currently wholly - * undefined.

    - * - *

    Implementations of this method may or may not return a determinate - * value.

    + * Loads an object of the supplied {@code type} from the current {@link Config} configuration path. * * @param the type of object to load - * - * @param type the type of object to load; must not be {@code - * null} - * + * @param type the type of object to load; must not be {@code null} * @return the loaded object; never {@code null} - * * @exception NoSuchElementException if the requested object is not found. - * - * @exception ConfigException if the invocation was sound but the - * object could not be loaded for any reason not related to absence - * - * @exception IllegalArgumentException if the suplied {@code type} - * was invalid for any reason - * - * @exception NullPointerException if the supplied {@code type} - * was {@code null} + * @exception IllegalArgumentException if the supplied {@code type} was invalid for any reason + * @exception NullPointerException if the supplied {@code type} was {@code null} */ T load(Class type); /** - * Return a new instance of a {@link Loader} with the configuration path set. - *
    - * The configuration path identifies where the configuration relevant for the annotated configuration class is found - * in a given application's persistent configuration. + * Return a new instance of a {@link Config} with the configuration path set. * - *

    The configuration path uses the dot symbol as a separator.

    + *

    The configuration path uses the dot symbol {@code .} as a separator.

    * *
    - * For instance, if the persistent configuration contains + * For instance, if the configuration contains *
      my.configuration.user=tester
    - * the configuration path for the configuration portion {@code user=tester} would be {@code my.configuration}. + * the configuration path for the configuration name {@code user} is {@code my.configuration}. * - * @param path a configuration path. - * @return a new instance of the {@link Loader} class with a configured path. - * - * @see Configuration#path() Configuration#path + * @param path a configuration path + * @return a new instance of the {@link Config} class with a new configuration path */ - Loader path(String path); + Config path(String path); /** - * {@linkplain #bootstrap(ClassLoader) Bootstraps} a {@link Loader} instance for subsequent usage using + * {@linkplain #bootstrap(ClassLoader) Bootstraps} a {@link Config} instance for subsequent usage using * the {@linkplain Thread#getContextClassLoader() context classloader}. * - *

    This method never returns {@code null}.

    - * *

    This method is idempotent.

    * *

    This method is safe for concurrent use by multiple threads.

    * - *

    This method may or may not return a determinate value. - * See {@link #bootstrap(ClassLoader)} for details.

    - * *

    Except as possibly noted above, the observable behavior of this method is specified to be identical to that * of the {@link #bootstrap(ClassLoader)} method.

    * - * @return a {@link Loader}; never {@code null} + * @return a {@link Config}; never {@code null} * * @exception java.util.ServiceConfigurationError if bootstrapping failed because of a * {@link ServiceLoader#load(Class, ClassLoader)} or {@link ServiceLoader#findFirst()} problem. - * @exception ConfigException if bootstrapping failed because of a {@link Loader#load(Class)} problem. + * @exception ConfigException if bootstrapping failed because of a {@link Config#load(Class)} problem. * * @see #bootstrap(ClassLoader) */ - static Loader bootstrap() { + static Config bootstrap() { return bootstrap(Thread.currentThread().getContextClassLoader()); } /** - * Bootstraps a {@link Loader} instance for subsequent usage. + * Bootstraps a {@link Config} instance for subsequent usage. *
    - * A primordial {@link Loader} is located with observable effects equal to those resulting from + * A primordial {@link Config} is located with observable effects equal to those resulting from * executing the following code: * *
    *
    -     *  {@linkplain Loader} loader = {@linkplain ServiceLoader}.{@linkplain ServiceLoader#load(Class, ClassLoader) load(Loader.class, classLoader)}
    +     *  {@linkplain Config} loader = {@linkplain ServiceLoader}.{@linkplain ServiceLoader#load(Class, ClassLoader) load(Loader.class, classLoader)}
          *  .{@linkplain java.util.ServiceLoader#findFirst() findFirst()}
          *  .{@linkplain java.util.Optional#orElseThrow() orElseThrow}({@linkplain NoSuchElementException#NoSuchElementException() NoSuchElementException::new});
          * 
    *
    * - *

    This method may or may not return a determinate value - * depending on the implementation of the {@link Loader} loaded in step 2 above.

    - * - *

    Note: The implementation of this method may change without notice between any two versions - * of this specification. The requirements described above, however, will be honored in any minor version of this - * specification within a given major version.

    - * * @param classLoader the {@link ClassLoader} used * to {@linkplain ServiceLoader#load(Class, ClassLoader) locate service provider files}; * may be {@code null} to indicate the system classloader (or bootstrap class loader) in @@ -175,13 +125,13 @@ static Loader bootstrap() { * often is the return value of an invocation of * {@link Thread#getContextClassLoader() Thread.currentThread().getContextClassLoader()} * - * @return a {@link Loader}; never {@code null} + * @return a {@link Config}; never {@code null} * * @exception java.util.ServiceConfigurationError if bootstrapping failed because of a {@link ServiceLoader#load(Class, ClassLoader)} problem. - * @exception NoSuchElementException if a {@linkplain Loader} is not found. + * @exception NoSuchElementException if a {@linkplain Config} is not found. */ - static Loader bootstrap(ClassLoader classLoader) { - return ServiceLoader.load(Loader.class, classLoader) + static Config bootstrap(ClassLoader classLoader) { + return ServiceLoader.load(Config.class, classLoader) .findFirst() .orElseThrow(NoSuchElementException::new); } diff --git a/api/src/main/java/module-info.java b/api/src/main/java/module-info.java index a10e03b..a90f46f 100644 --- a/api/src/main/java/module-info.java +++ b/api/src/main/java/module-info.java @@ -17,10 +17,12 @@ * limitations under the License. */ +import jakarta.config.Config; + /** * Jakarta Config API. */ module jakarta.config.api { exports jakarta.config; - uses jakarta.config.Loader; + uses Config; } diff --git a/tck/src/main/java/jakarta/config/tck/LoaderTest.java b/tck/src/main/java/jakarta/config/tck/ConfigTest.java similarity index 86% rename from tck/src/main/java/jakarta/config/tck/LoaderTest.java rename to tck/src/main/java/jakarta/config/tck/ConfigTest.java index 91b405f..39814e9 100644 --- a/tck/src/main/java/jakarta/config/tck/LoaderTest.java +++ b/tck/src/main/java/jakarta/config/tck/ConfigTest.java @@ -19,7 +19,7 @@ package jakarta.config.tck; -import jakarta.config.Loader; +import jakarta.config.Config; import jakarta.config.tck.common.AnyConfiguration; import jakarta.config.tck.common.JakartaConfigValues; import jakarta.config.tck.common.My; @@ -30,10 +30,10 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; -public class LoaderTest { +public class ConfigTest { @Test public void testTopLevelConfig() { - TopLevelConfig configuration = Loader.bootstrap().load(TopLevelConfig.class); + TopLevelConfig configuration = Config.bootstrap().load(TopLevelConfig.class); assertThat(configuration.my().username(), equalTo(JakartaConfigValues.myUserName)); assertThat(configuration.my().password(), equalTo(JakartaConfigValues.myPassword)); assertThat(configuration.my().configuration().key(), equalTo(JakartaConfigValues.myConfigurationKey)); @@ -42,7 +42,7 @@ public void testTopLevelConfig() { @Test public void testSecondLevelMyInterface() { - My configuration = Loader.bootstrap().load(My.class); + My configuration = Config.bootstrap().load(My.class); assertThat(configuration.username(), equalTo(JakartaConfigValues.myUserName)); assertThat(configuration.password(), equalTo(JakartaConfigValues.myPassword)); assertThat(configuration.configuration().key(), equalTo(JakartaConfigValues.myConfigurationKey)); @@ -50,25 +50,25 @@ public void testSecondLevelMyInterface() { @Test public void testSecondLevelOtherInterface() { - Other configuration = Loader.bootstrap().load(Other.class); + Other configuration = Config.bootstrap().load(Other.class); assertThat(configuration.configuration().key(), equalTo(JakartaConfigValues.otherConfigurationKey)); } @Test public void testOverridePathSecondLevelOtherInterface() { - Other configuration = Loader.bootstrap().path("my").load(Other.class); + Other configuration = Config.bootstrap().path("my").load(Other.class); assertThat(configuration.configuration().key(), equalTo(JakartaConfigValues.myConfigurationKey)); } @Test public void testThirdLevelAnyConfigurationInterface() { - AnyConfiguration configuration = Loader.bootstrap().load(AnyConfiguration.class); + AnyConfiguration configuration = Config.bootstrap().load(AnyConfiguration.class); assertThat(configuration.key(), equalTo(JakartaConfigValues.myConfigurationKey)); } @Test public void testOverridePathThirdLevelAnyConfigurationInterface() { - AnyConfiguration configuration = Loader.bootstrap().path("other.configuration").load(AnyConfiguration.class); + AnyConfiguration configuration = Config.bootstrap().path("other.configuration").load(AnyConfiguration.class); assertThat(configuration.key(), equalTo(JakartaConfigValues.otherConfigurationKey)); } } diff --git a/tck/src/main/java/jakarta/config/tck/NegativeLoaderTest.java b/tck/src/main/java/jakarta/config/tck/NegativeConfigTest.java similarity index 89% rename from tck/src/main/java/jakarta/config/tck/NegativeLoaderTest.java rename to tck/src/main/java/jakarta/config/tck/NegativeConfigTest.java index b462317..fdcde8f 100644 --- a/tck/src/main/java/jakarta/config/tck/NegativeLoaderTest.java +++ b/tck/src/main/java/jakarta/config/tck/NegativeConfigTest.java @@ -20,18 +20,18 @@ package jakarta.config.tck; import jakarta.config.ConfigException; -import jakarta.config.Loader; +import jakarta.config.Config; import jakarta.config.tck.common.AnyConfiguration; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.NoSuchElementException; -public class NegativeLoaderTest { +public class NegativeConfigTest { @Test public void testFailWhenNotAnnotatedInterface() { try { - Loader.bootstrap().path("my.configuration").load(NotAnnotatedConfiguration.class); + Config.bootstrap().path("my.configuration").load(NotAnnotatedConfiguration.class); Assertions.fail("Expected ConfigException has not been thrown when the interface does not contain @Configuration"); } catch (ConfigException configException) { // pass @@ -41,7 +41,7 @@ public void testFailWhenNotAnnotatedInterface() { @Test public void testFailWhenUnknowPath() { try { - Loader.bootstrap().path("my.config").load(AnyConfiguration.class); + Config.bootstrap().path("my.config").load(AnyConfiguration.class); Assertions.fail("Expected NoSuchObjectException has not been thrown when the configuration object not found"); } catch (NoSuchElementException noSuchElementException) { // pass