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

MicroProfile Config 3.0 Support #23807

Merged
merged 17 commits into from
Jun 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 38 additions & 1 deletion appserver/featuresets/glassfish/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2022 Contributors to Eclipse Foundation.
Copyright (c) 2015, 2022 Oracle and/or its affiliates. All rights reserved.

This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -844,5 +844,42 @@
</exclusion>
</exclusions>
</dependency>

<!-- MicroProfile Glassfish Connectors -->
<dependency>
<groupId>org.glassfish.main.microprofile</groupId>
<artifactId>microprofile-connectors</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- MicroProfile Config -->
<dependency>
<groupId>org.eclipse.microprofile.config</groupId>
<artifactId>microprofile-config-api</artifactId>
<version>${microprofile.config-api.version}</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.glassfish.main.microprofile</groupId>
<artifactId>microprofile-config</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
130 changes: 130 additions & 0 deletions appserver/microprofile/config/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2022 Contributors to Eclipse Foundation.

This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
http://www.eclipse.org/legal/epl-2.0.

This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.

SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0

-->

<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>org.glassfish.main.microprofile</groupId>
<artifactId>microprofile-parent</artifactId>
<version>7.0.0-SNAPSHOT</version>
</parent>

<artifactId>microprofile-config</artifactId>
<packaging>glassfish-jar</packaging>

<name>GlassFish MicroProfile Config</name>

<dependencies>
<!-- APIs -->
<dependency>
<groupId>io.helidon.microprofile.config</groupId>
<artifactId>helidon-microprofile-config</artifactId>
<version>${helidon-config.version}</version>
</dependency>

<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
</dependency>

<!-- Internal Dependencies -->
<dependency>
<groupId>org.glassfish.main.common</groupId>
<artifactId>glassfish-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.main.common</groupId>
<artifactId>internal-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.main.web</groupId>
<artifactId>weld-integration</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<supportedProjectTypes>
<supportedProjectType>glassfish-jar</supportedProjectType>
</supportedProjectTypes>
<instructions>
<!-- A list of packages that are exposed to classes outside the bundle -->
<Export-Package>
org.glassfish.microprofile.config,
io.helidon.config.mp,
</Export-Package>
<!-- A list of dependencies to include in the bundle (as they're not native OSGI bundles) -->
<Embed-Dependency>
<!--
The helidon MP config dependency tree, illustrating what we actually output to the GF bundle
-->
groupId=io.helidon.microprofile.config;inline=true,
groupId=io.helidon.config;artifactId=helidon-config-mp;inline=true,
groupId=io.helidon.common;artifactId=helidon-common;inline=true,
groupId=io.helidon.common;artifactId=helidon-common-service-loader;inline=true,
groupId=io.helidon.config;artifactId=helidon-config-yaml-mp;inline=true,
groupId=io.helidon.config;artifactId=helidon-config;inline=true,
<!--
groupId=io.helidon.common;artifactId=helidon-common-reactive;inline=true,
groupId=io.helidon.common;artifactId=helidon-common-mapper;inline=true, -->
groupId=io.helidon.common;artifactId=helidon-common-media-type;inline=true,
groupId=io.helidon.config;artifactId=helidon-config-yaml;inline=true,
artifactId=snakeyaml;inline=true,
<!--
groupId=io.helidon.config;artifactId=helidon-config-encryption;inline=true,
groupId=io.helidon.common;artifactId=helidon-common-key-util;inline=true,
groupId=io.helidon.common;artifactId=helidon-common-configurable;inline=true,
groupId=io.helidon.common;artifactId=helidon-common-context;inline=true,
groupId=io.helidon.common;artifactId=helidon-common-crypto;inline=true,
groupId=io.helidon.config;artifactId=helidon-config-object-mapping;inline=true, -->
</Embed-Dependency>
<!--
Include transitive dependencies (note that this only include compile scoped dependencies,
other scoped dependencies still need explicit inclusion)
-->
<Embed-Transitive>true</Embed-Transitive>
<Multi-Release>true</Multi-Release>
<Include-Resource>
{maven-resources},
META-INF/hk2-locator/=target/classes/META-INF/hk2-locator/,
</Include-Resource>
</instructions>
</configuration>
<executions>
<execution>
<id>osgi-bundle</id>
<phase>package</phase>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2022 Contributors to Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.microprofile.config;

import jakarta.annotation.Priority;
import org.eclipse.microprofile.config.spi.Converter;

/**
* A patched class converter to use the current context classloader, rather than the bundle classloader.
* This will allow access to webapp classes
*/
@Priority(2)
@SuppressWarnings("rawtypes")
public class ApplicationClassConverter implements Converter<Class> {

@Override
public Class<?> convert(String stringValue) throws IllegalArgumentException, NullPointerException {
try {
return Class.forName(stringValue, true, Thread.currentThread().getContextClassLoader());
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Failed to convert property " + stringValue + " to class", e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2022 Contributors to Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.microprofile.config;

import org.eclipse.microprofile.config.ConfigProvider;
import org.glassfish.api.deployment.ApplicationContainer;
import org.glassfish.api.deployment.ApplicationContext;
import org.glassfish.api.deployment.DeploymentContext;

import java.net.JarURLConnection;

public class ConfigApplicationContainer implements ApplicationContainer<Object> {

private static final String JAR_URL_PROTOCOL = "jar";

private final DeploymentContext deploymentContext;

public ConfigApplicationContainer(DeploymentContext deploymentContext) {
this.deploymentContext = deploymentContext;
}

@Override
public Object getDescriptor() {
return null;
}

@Override
public boolean start(ApplicationContext startupContext) throws Exception {

// Set the JAR caching behaviour for config init
// (to prevent using cached microprofile-config file contents)
final var shouldCacheJarContents = JarURLConnection.getDefaultUseCaches(JAR_URL_PROTOCOL);
JarURLConnection.setDefaultUseCaches(JAR_URL_PROTOCOL, false);

ConfigProvider.getConfig(startupContext.getClassLoader());

// Reset the JAR caching behaviour
JarURLConnection.setDefaultUseCaches(JAR_URL_PROTOCOL, shouldCacheJarContents);

return true;
}

@Override
public boolean stop(ApplicationContext stopContext) {
return true;
}

@Override
public boolean suspend() {
return false;
}

@Override
public boolean resume() throws Exception {
return false;
}

@Override
public ClassLoader getClassLoader() {
return deploymentContext.getFinalClassLoader();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2022 Contributors to Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.microprofile.config;

import org.glassfish.api.container.Container;
import org.glassfish.api.deployment.Deployer;
import org.jvnet.hk2.annotations.Service;

@Service(name = "org.glassfish.microprofile.config.ConfigContainer")
public class ConfigContainer implements Container {

@Override
public Class<? extends Deployer> getDeployer() {
return ConfigDeployer.class;
}

@Override
public String getName() {
return "MicroProfile Config";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2022 Contributors to Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.microprofile.config;

import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
import org.glassfish.api.container.Container;
import org.glassfish.api.deployment.ApplicationContainer;
import org.glassfish.api.deployment.Deployer;
import org.glassfish.api.deployment.DeploymentContext;
import org.glassfish.api.deployment.MetaData;
import org.jvnet.hk2.annotations.Service;

import java.util.ServiceLoader;

@Service
public class ConfigDeployer implements Deployer {

@Override
public MetaData getMetaData() {
return null;
}

@Override
public boolean prepare(DeploymentContext deploymentContext) {
return true;
}

@Override
public ApplicationContainer load(Container container, DeploymentContext deploymentContext) {

// Initialise Config providers
final var resolver = ServiceLoader.load(ConfigProviderResolver.class).iterator().next();
ConfigProviderResolver.setInstance(resolver);

return new ConfigApplicationContainer(deploymentContext);
}

@Override
public void unload(ApplicationContainer applicationContainer, DeploymentContext deploymentContext) {}

@Override
public void clean(DeploymentContext deploymentContext) {}

@Override
public Object loadMetaData(Class aClass, DeploymentContext deploymentContext) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.helidon.microprofile.config.ConfigCdiExtension
Loading