Skip to content

Commit

Permalink
Moved API classes to their own module. (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez committed May 1, 2020
1 parent ad0a475 commit 8581174
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 18 deletions.
100 changes: 100 additions & 0 deletions api/pom.xml
@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
~ Copyright 2017 Red Hat, Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.smallrye.config</groupId>
<artifactId>smallrye-config-parent</artifactId>
<version>1.7.1-SNAPSHOT</version>
</parent>

<artifactId>smallrye-config-api</artifactId>

<name>SmallRye: MicroProfile Config API</name>

<dependencies>
<dependency>
<groupId>org.eclipse.microprofile.config</groupId>
<artifactId>microprofile-config-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.smallrye.common</groupId>
<artifactId>smallrye-common-annotation</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<enableAssertions>true</enableAssertions>
<argLine>-Xmx512m</argLine>
<forkMode>once</forkMode>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>coverage</id>
<properties>
<argLine>@{jacocoArgLine}</argLine>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>@{jacocoArgLine} -Xmx512m</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Expand Up @@ -4,6 +4,8 @@
import java.util.Collections;
import java.util.Iterator;

import io.smallrye.common.annotation.Experimental;

/**
* The ConfigSourceInterceptor allows to intercept the resolution of a configuration name before the
* configuration value is resolved by the Config and before any conversion taking place. It can also intercept
Expand All @@ -26,6 +28,7 @@
* of {@code io.smallrye.config.Priorities#APPLICATION} is assumed. If multiple interceptors are registered with the
* same priority, then their execution order may be non deterministic.
*/
@Experimental("Interceptor API to intercept resolution of a configuration name")
public interface ConfigSourceInterceptor extends Serializable {
/**
* Intercept the resolution of a configuration name and either return the corresponding {@link ConfigValue} or a
Expand Down
Expand Up @@ -3,10 +3,13 @@
import java.io.Serializable;
import java.util.Iterator;

import io.smallrye.common.annotation.Experimental;

/**
* Exposes contextual information about the intercepted invocation of {@link ConfigSourceInterceptor}. This allows
* implementers to control the behavior of the invocation chain.
*/
@Experimental("Interceptor API to intercept resolution of a configuration name")
public interface ConfigSourceInterceptorContext extends Serializable {
/**
* Proceeds to the next interceptor in the chain.
Expand Down
Expand Up @@ -2,6 +2,8 @@

import java.util.OptionalInt;

import io.smallrye.common.annotation.Experimental;

/**
* This ConfigSourceInterceptorFactory allows to initialize a {@link ConfigSourceInterceptor}, with access to the
* current {@link ConfigSourceInterceptorContext}.
Expand All @@ -12,12 +14,13 @@
* initialized.
* <p>
*
* Instances of this interface will be {@link SmallRyeConfigBuilder#addDiscoveredInterceptors()} via the
* Instances of this interface will be discovered by {@code SmallRyeConfigBuilder#addDiscoveredInterceptors()} via the
* {@link java.util.ServiceLoader} mechanism and can be registered by providing a
* {@code META-INF/services/io.smallrye.config.ConfigSourceInterceptorFactory}
* {@linkplain ClassLoader#getResource(String) resource} which contains the fully qualified class name of the
* custom {@code ConfigSourceProvider} implementation.
*/
@Experimental("Interceptor API to intercept resolution of a configuration name")
public interface ConfigSourceInterceptorFactory {
/**
* The default priority value, {@link Priorities#APPLICATION}.
Expand Down
Expand Up @@ -2,6 +2,8 @@

import java.util.Objects;

import io.smallrye.common.annotation.Experimental;

/**
* The ConfigValue is a metadata object that holds additional information after the lookup of a configuration.
* <p>
Expand All @@ -14,6 +16,7 @@
* This is used together with {@link ConfigValueConfigSource} and {@link ConfigSourceInterceptor} to expose the
* Configuration lookup metadata.
*/
@Experimental("Extension to the original ConfigSource to allow retrieval of additional metadata on config lookup")
public class ConfigValue {
private final String name;
private final String value;
Expand Down
Expand Up @@ -5,6 +5,8 @@

import org.eclipse.microprofile.config.spi.ConfigSource;

import io.smallrye.common.annotation.Experimental;

/**
* Extends the original {@link ConfigSource} to expose methods that return a {@link ConfigValue}. The
* {@link ConfigValue} allows to retrieve additional metadata associated with the configuration resolution.
Expand All @@ -17,6 +19,7 @@
*
* Ideally, this should move the the MicroProfile Config API, once the concept is well-proven.
*/
@Experimental("Extension to the original ConfigSource to allow retrieval of additional metadata on config lookup")
public interface ConfigValueConfigSource extends ConfigSource {
/**
* Return the {@link ConfigValue} for the specified property in this configuration source.
Expand Down
Expand Up @@ -9,12 +9,15 @@
import java.util.Map;
import java.util.Set;

import io.smallrye.common.annotation.Experimental;

/**
* The ConfigValueMapView is view over a Map of String configs names and ConfigValue value.
* <p>
*
* Use this to wrap the ConfigValue map and expose it where a Map of String name and String value is required.
*/
@Experimental("Extension to the original ConfigSource to allow retrieval of additional metadata on config lookup")
public final class ConfigValueMapView extends AbstractMap<String, String> {
private final Map<String, ConfigValue> delegate;

Expand Down
@@ -1,9 +1,12 @@
package io.smallrye.config;

import io.smallrye.common.annotation.Experimental;

/**
* A collection of built-in priority constants for {@link ConfigSourceInterceptor} that are supposed to be
* ordered based on their {@code javax.annotation.Priority} class-level annotation.
*/
@Experimental("Interceptor API to intercept resolution of a configuration name")
public final class Priorities {
/**
* Range for early interceptors defined by Platform specifications.
Expand Down
Expand Up @@ -5,7 +5,6 @@
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.AbstractMap;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -99,20 +98,6 @@ public void values() {
assertThrows(UnsupportedOperationException.class, () -> values.remove("1234"));
}

@Test
public void configSourceMap() throws IOException {
final ConfigValuePropertiesConfigSource configSource = new ConfigValuePropertiesConfigSource(
ConfigValueMapViewTest.class.getResource("/config-values.properties"));
final Map<String, String> properties = configSource.getProperties();

assertEquals("abc", properties.get("my.prop"));
assertEquals("abc", properties.get("my.prop"));
assertThrows(UnsupportedOperationException.class, () -> properties.remove("x"));
assertThrows(UnsupportedOperationException.class, () -> properties.put("x", "x"));
assertThrows(UnsupportedOperationException.class, () -> properties.putAll(new HashMap<>()));
assertThrows(UnsupportedOperationException.class, properties::clear);
}

private ConfigValueMapView sampleMap() {
final Map<String, ConfigValue> configValueMap = new HashMap<>();
configValueMap.put("my.prop", ConfigValue.builder().withName("my.prop").withValue("1234").build());
Expand Down
4 changes: 4 additions & 0 deletions implementation/pom.xml
Expand Up @@ -45,6 +45,10 @@
<artifactId>jakarta.annotation-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.smallrye.config</groupId>
<artifactId>smallrye-config-api</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye.config</groupId>
<artifactId>smallrye-config-common</artifactId>
Expand Down
Expand Up @@ -314,7 +314,8 @@ private static class ConfigSources implements Serializable {
ConfigSources(final List<ConfigSource> sources, final ConfigSources configSources) {
sources.sort(CONFIG_SOURCE_COMPARATOR);

SmallRyeConfigSourceInterceptorContext current = new SmallRyeConfigSourceInterceptorContext(EMPTY, null);
SmallRyeConfigSourceInterceptorContext current = new SmallRyeConfigSourceInterceptorContext(
EMPTY, null);

for (int i = sources.size() - 1; i >= 0; i--) {
current = new SmallRyeConfigSourceInterceptorContext(configSourceInterceptor(sources.get(i)), current);
Expand Down
Expand Up @@ -21,7 +21,7 @@ public void size() {

@Test
public void isEmpty() {
assertTrue(new ConfigValueMapView(new HashMap<>()).isEmpty());
assertTrue(new ConfigValueMapStringView(new HashMap<>(), "test", 1).isEmpty());
}

@Test
Expand Down
@@ -1,5 +1,12 @@
package io.smallrye.config;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.microprofile.config.Config;
import org.junit.Assert;
import org.junit.Test;
Expand All @@ -13,6 +20,20 @@ public void interceptor() throws Exception {
Assert.assertEquals("20", config.getValue("my.prop.20", String.class));
}

@Test
public void configSourceMap() throws IOException {
final ConfigValuePropertiesConfigSource configSource = new ConfigValuePropertiesConfigSource(
ConfigValuePropertiesConfigSourceTest.class.getResource("/config-values.properties"));
final Map<String, String> properties = configSource.getProperties();

assertEquals("abc", properties.get("my.prop"));
assertEquals("abc", properties.get("my.prop"));
assertThrows(UnsupportedOperationException.class, () -> properties.remove("x"));
assertThrows(UnsupportedOperationException.class, () -> properties.put("x", "x"));
assertThrows(UnsupportedOperationException.class, () -> properties.putAll(new HashMap<>()));
assertThrows(UnsupportedOperationException.class, properties::clear);
}

private static Config buildConfig() throws Exception {
return new SmallRyeConfigBuilder()
.addDefaultSources()
Expand Down
11 changes: 11 additions & 0 deletions pom.xml
Expand Up @@ -65,6 +65,7 @@

<modules>
<module>common</module>
<module>api</module>
<module>implementation</module>
<module>sources/hocon</module>
<module>sources/file-system</module>
Expand Down Expand Up @@ -115,6 +116,11 @@
</dependency>

<!-- External SmallRye Dependencies -->
<dependency>
<groupId>io.smallrye.common</groupId>
<artifactId>smallrye-common-annotation</artifactId>
<version>${version.smallrye.common}</version>
</dependency>
<dependency>
<groupId>io.smallrye.common</groupId>
<artifactId>smallrye-common-expression</artifactId>
Expand All @@ -127,6 +133,11 @@
</dependency>

<!-- Dependencies provided by the project -->
<dependency>
<groupId>io.smallrye.config</groupId>
<artifactId>smallrye-config-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.smallrye.config</groupId>
<artifactId>smallrye-config-common</artifactId>
Expand Down

0 comments on commit 8581174

Please sign in to comment.