Skip to content

Commit

Permalink
Moved CDI related code to its own module. (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez authored Dec 14, 2020
1 parent 3f21c8f commit e575006
Show file tree
Hide file tree
Showing 24 changed files with 196 additions and 42 deletions.
110 changes: 110 additions & 0 deletions cdi/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
~ Copyright 2020 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>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>smallrye-config</artifactId>

<name>SmallRye: MicroProfile Config CDI Implementation</name>

<dependencies>
<dependency>
<groupId>io.smallrye.config</groupId>
<artifactId>smallrye-config-core</artifactId>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-processor</artifactId>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-testkit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-junit5</artifactId>
<exclusions>
<exclusion>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<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>
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ public String getConfigPropertyName() {
return configPropertyName;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import io.smallrye.config.KeyValuesConfigSource;

@ExtendWith(WeldJunit5Extension.class)
class InjectedConfigSerializationTest extends InjectionTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ public abstract class InjectionTest {
protected static void beforeClass() throws Exception {
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
final URLClassLoader urlClassLoader = new URLClassLoader(new URL[] {
new URL("memory", null, 0, "/",
new InMemoryStreamHandler(
"io.smallrye.config.inject.InjectionTestConfigFactory"))
new URL("memory", null, 0, "/", new InMemoryStreamHandler(InjectionTestConfigFactory.class.getName()))
}, contextClassLoader);
Thread.currentThread().setContextClassLoader(urlClassLoader);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.smallrye.config.inject;

import static io.smallrye.config.KeyValuesConfigSource.config;
import static io.smallrye.config.inject.KeyValuesConfigSource.config;

import java.util.HashMap;
import java.util.HashSet;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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.
*/
package io.smallrye.config.inject;

import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

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

public class KeyValuesConfigSource implements ConfigSource, Serializable {

private final Map<String, String> properties = new HashMap<>();

private KeyValuesConfigSource(Map<String, String> properties) {
this.properties.putAll(properties);
}

@Override
public Map<String, String> getProperties() {
return Collections.unmodifiableMap(properties);
}

@Override
public Set<String> getPropertyNames() {
return Collections.unmodifiableSet(properties.keySet());
}

@Override
public String getValue(String propertyName) {
return properties.get(propertyName);
}

@Override
public String getName() {
return "KeyValuesConfigSource";
}

public static ConfigSource config(Map<String, String> properties) {
return new KeyValuesConfigSource(properties);
}

public static ConfigSource config(String... keyValues) {
if (keyValues.length % 2 != 0) {
throw new IllegalArgumentException("keyValues array must be a multiple of 2");
}

Map<String, String> props = new HashMap<>();
for (int i = 0; i < keyValues.length; i += 2) {
props.put(keyValues[i], keyValues[i + 1]);
}
return new KeyValuesConfigSource(props);
}
}
34 changes: 2 additions & 32 deletions implementation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,15 @@
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>smallrye-config</artifactId>
<artifactId>smallrye-config-core</artifactId>

<name>SmallRye: MicroProfile Config Implementation</name>
<name>SmallRye: MicroProfile Config Core Implementation</name>

<dependencies>
<dependency>
<groupId>org.eclipse.microprofile.config</groupId>
<artifactId>microprofile-config-api</artifactId>
</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>
Expand Down Expand Up @@ -83,31 +78,6 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-testkit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-junit5</artifactId>
<exclusions>
<exclusion>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.smallrye.testing</groupId>
<artifactId>smallrye-testing-utilities</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.eclipse.microprofile.config.spi.Converter;

import io.smallrye.common.constraint.Assert;
import io.smallrye.config.inject.InjectionMessages;

/**
* Information about a configuration interface.
Expand Down Expand Up @@ -695,7 +694,7 @@ static Class<?> rawTypeOf(final Type type) {
return Object.class;
}
} else {
throw InjectionMessages.msg.noRawType(type);
throw ConfigMessages.msg.noRawType(type);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.smallrye.config;

import java.io.InvalidObjectException;
import java.lang.reflect.Type;
import java.util.NoSuchElementException;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -127,4 +128,7 @@ interface ConfigMessages {

@Message(id = 37, value = "The Converter API cannot convert a null value")
NullPointerException converterNullValue();

@Message(id = 38, value = "Type has no raw type class: %s")
IllegalArgumentException noRawType(Type type);
}
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<sonar.projectName>SmallRye Config</sonar.projectName>
<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/../coverage/target/site/jacoco-aggregate/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
</properties>

<licenses>
<license>
<name>Apache License, Version 2.0</name>
Expand All @@ -67,6 +67,7 @@
<modules>
<module>common</module>
<module>implementation</module>
<module>cdi</module>
<module>sources/hocon</module>
<module>sources/file-system</module>
<module>sources/yaml</module>
Expand Down Expand Up @@ -126,6 +127,11 @@
<artifactId>smallrye-config-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.smallrye.config</groupId>
<artifactId>smallrye-config-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.smallrye.config</groupId>
<artifactId>smallrye-config</artifactId>
Expand Down

0 comments on commit e575006

Please sign in to comment.