Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Hocon/Json Configuration Source for MP #4218

Merged
merged 15 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@
<artifactId>helidon-config-yaml-mp</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-hocon-mp</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-git</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions config/config-mp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
<groupId>org.eclipse.microprofile.config</groupId>
<artifactId>microprofile-config-api</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-hocon-mp</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-yaml-mp</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021 Oracle and/or its affiliates.
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -65,6 +65,7 @@
import io.helidon.config.ConfigException;
import io.helidon.config.ConfigMappers;
import io.helidon.config.ConfigValue;
import io.helidon.config.hocon.mp.HoconMpConfigSource;
import io.helidon.config.mp.spi.MpConfigFilter;
import io.helidon.config.yaml.mp.YamlMpConfigSource;

Expand Down Expand Up @@ -252,6 +253,10 @@ private void processMetaSources(List<io.helidon.config.Config> configs) {
case "yaml":
delegates = yamlSource(config);
break;
case "hocon":
case "json":
delegates = hoconSource(config);
break;
default:
throw new ConfigException("Meta configuration source type \"" + type + "\" is not supported. Use on of: "
+ "system-properties, environment-variables, properties, yaml");
Expand Down Expand Up @@ -295,6 +300,14 @@ private List<ConfigSource> yamlSource(io.helidon.config.Config config) {
YamlMpConfigSource::create);
}

private List<ConfigSource> hoconSource(io.helidon.config.Config config) {
return sourceFromMeta(config,
HoconMpConfigSource::create,
HoconMpConfigSource::classPath,
HoconMpConfigSource::classPath,
HoconMpConfigSource::create);
}

private List<ConfigSource> sourceFromMeta(io.helidon.config.Config config,
Function<Path, ConfigSource> fromPath,
Function<String, List<ConfigSource>> fromClasspath,
Expand Down
5 changes: 3 additions & 2 deletions config/config-mp/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021 Oracle and/or its affiliates.
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,6 +25,7 @@
requires transitive microprofile.config.api;
requires java.annotation;
requires io.helidon.common.serviceloader;
requires io.helidon.config.hocon.mp;

exports io.helidon.config.mp;
exports io.helidon.config.mp.spi;
Expand All @@ -36,4 +37,4 @@
uses io.helidon.config.spi.ConfigParser;

provides org.eclipse.microprofile.config.spi.ConfigProviderResolver with io.helidon.config.mp.MpConfigProviderResolver;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates.
* Copyright (c) 2021, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -72,6 +72,32 @@ void testMetaYaml() {
assertThat(config.getValue("value", String.class), is("classpath"));
}

@Test
void testMetaHocon() {
System.setProperty(MpMetaConfig.META_CONFIG_SYSTEM_PROPERTY, "custom-mp-meta-config-hocon.yaml");
config = ConfigProvider.getConfig();

assertThat(config.getValue("string", String.class), is("String"));
assertThat(config.getValue("number", String.class), is("175"));
assertThat(config.getValue("array.0", String.class), is("One"));
assertThat(config.getValue("array.1", String.class), is("Two"));
assertThat(config.getValue("array.2", String.class), is("Three"));
assertThat(config.getValue("boolean", String.class), is("true"));
}

@Test
void testMetaJson() {
System.setProperty(MpMetaConfig.META_CONFIG_SYSTEM_PROPERTY, "custom-mp-meta-config-json.yaml");
config = ConfigProvider.getConfig();

assertThat(config.getValue("string", String.class), is("String"));
assertThat(config.getValue("number", String.class), is("175"));
assertThat(config.getValue("array.0", String.class), is("One"));
assertThat(config.getValue("array.1", String.class), is("Two"));
assertThat(config.getValue("array.2", String.class), is("Three"));
assertThat(config.getValue("boolean", String.class), is("true"));
}

@Test
void testMetaProperties() {
System.setProperty(MpMetaConfig.META_CONFIG_SYSTEM_PROPERTY, "custom-mp-meta-config.properties");
Expand Down
24 changes: 24 additions & 0 deletions config/config-mp/src/test/resources/custom-application.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Copyright (c) 2022 Oracle and/or its affiliates.
#
# 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.
#
tomas-langer marked this conversation as resolved.
Show resolved Hide resolved

string = String
number = 175
array = [
One
Two
Three
]
boolean = true
10 changes: 10 additions & 0 deletions config/config-mp/src/test/resources/custom-application.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"string": "String",
"number": 175,
"array": [
"One",
"Two",
tomas-langer marked this conversation as resolved.
Show resolved Hide resolved
"Three"
],
"boolean": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# Copyright (c) 2022 Oracle and/or its affiliates.
#
# 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.
#

add-discovered-sources: false
add-discovered-converters: false

sources:
- type: "hocon"
classpath: "custom-application.conf"
optional: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# Copyright (c) 2022 Oracle and/or its affiliates.
#
# 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.
#

add-discovered-sources: false
add-discovered-converters: false

sources:
- type: "json"
classpath: "custom-application.json"
optional: false
31 changes: 31 additions & 0 deletions config/hocon-mp/etc/spotbugs/exclude.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2022 Oracle and/or its affiliates.

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.

-->

<FindBugsFilter
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://github.com/spotbugs/filter/3.0.0"
xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubusercontent.com/spotbugs/spotbugs/3.1.0/spotbugs/etc/findbugsfilter.xsd">

<Match>
<Class name="io.helidon.config.hocon.mp.HoconMpConfigIncluder"/>
klustria marked this conversation as resolved.
Show resolved Hide resolved
<Method name="include"/>
<Bug pattern=" URLCONNECTION_SSRF_FD"/>
</Match>

</FindBugsFilter>
64 changes: 64 additions & 0 deletions config/hocon-mp/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2022 Oracle and/or its affiliates.

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.helidon.config</groupId>
<artifactId>helidon-config-project</artifactId>
<version>2.5.1-SNAPSHOT</version>
</parent>
<artifactId>helidon-config-hocon-mp</artifactId>
<name>Helidon Config HOCON MP</name>

<description>
HOCON support for Helidon MP.
</description>

<properties>
<spotbugs.exclude>etc/spotbugs/exclude.xml</spotbugs.exclude>
</properties>

<dependencies>
<dependency>
klustria marked this conversation as resolved.
Show resolved Hide resolved
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-hocon</artifactId>
</dependency>
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.config</groupId>
<artifactId>microprofile-config-api</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Loading