Skip to content

Commit

Permalink
Merge pull request #228 from FroMage/mp-cp-1.1
Browse files Browse the repository at this point in the history
MP-CP 1.1
  • Loading branch information
FroMage authored Nov 2, 2020
2 parents b572fb6 + 5f39e38 commit 9043149
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.smallrye.context.application.context.propagation;

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Map;

import org.eclipse.microprofile.context.ThreadContext;
Expand All @@ -8,6 +10,28 @@

public class ApplicationContextProvider implements ThreadContextProvider {

static final ClassLoader SYSTEM_CL;

static {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
SYSTEM_CL = AccessController
.doPrivileged((PrivilegedAction<ClassLoader>) ApplicationContextProvider::calculateSystemClassLoader);
} else {
SYSTEM_CL = calculateSystemClassLoader();
}
}

private static ClassLoader calculateSystemClassLoader() {
ClassLoader cl = ClassLoader.getSystemClassLoader();
if (cl == null) {
// non-null ref that delegates to the system
cl = new ClassLoader(null) {
};
}
return cl;
}

@Override
public ThreadContextSnapshot currentContext(Map<String, String> props) {
ClassLoader capturedTCCL = Thread.currentThread().getContextClassLoader();
Expand All @@ -24,7 +48,7 @@ public ThreadContextSnapshot currentContext(Map<String, String> props) {

@Override
public ThreadContextSnapshot clearedContext(Map<String, String> props) {
ClassLoader capturedTCCL = null;
ClassLoader capturedTCCL = SYSTEM_CL;
return () -> {
ClassLoader movedTCCL = Thread.currentThread().getContextClassLoader();
if (capturedTCCL != movedTCCL)
Expand Down
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@
</scm>

<properties>
<version.microprofile.context-propagation>1.0.2</version.microprofile.context-propagation>
<version.microprofile.context-propagation>1.1</version.microprofile.context-propagation>
<version.microprofile.config>1.4</version.microprofile.config>
<version.smallrye.config>1.7.0</version.smallrye.config>
<version.smallrye.config>1.9.2</version.smallrye.config>
<version.jboss.threads>3.1.1.Final</version.jboss.threads>
<version.jta>1.3</version.jta>
<version.narayana>5.10.4.Final</version.narayana>
<version.rxjava2>2.2.19</version.rxjava2>
<version.rxjava1>1.3.8</version.rxjava1>

<!-- Testing versions -->
<version.smallrye.common>1.4.1</version.smallrye.common>
<version.jnpserver>5.0.5.Final</version.jnpserver>
<version.resteasy>4.5.3.Final</version.resteasy>
<version.hibernate>5.4.15.Final</version.hibernate>
Expand Down
7 changes: 7 additions & 0 deletions tck/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>smallrye-context-propagation-application</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
Expand Down
6 changes: 6 additions & 0 deletions tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.smallrye.common</groupId>
<artifactId>smallrye-common-function</artifactId>
<version>${version.smallrye.common}</version>
</dependency>

<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Map;
import java.util.function.BiConsumer;

import javax.annotation.Priority;
import javax.enterprise.util.AnnotationLiteral;

import org.eclipse.microprofile.config.ConfigProvider;
Expand All @@ -38,6 +39,7 @@
import org.junit.Assert;
import org.junit.Test;

import io.smallrye.common.function.Functions;
import io.smallrye.config.SmallRyeConfig;
import io.smallrye.config.SmallRyeConfigProviderResolver;
import io.smallrye.context.SmallRyeContextManagerProvider;
Expand Down Expand Up @@ -118,7 +120,10 @@ public void test() throws InstantiationException, IllegalAccessException, ClassN
.addPackages(true, ConfigProvider.class.getPackage().getName())
.addPackages(true, SmallRyeConfig.class.getPackage().getName())
.addPackages(true, Logger.class.getPackage().getName())
.addPackages(true, Functions.class.getPackage().getName())
.addPackage(AnnotationLiteral.class.getPackage().getName())
.addPackage(Priority.class.getPackage().getName())
.addPackage(io.smallrye.common.constraint.Assert.class.getPackage().getName())
// dont use addPackages for Smallrye-Context because it
// would include test packages
.addPackage(SmallRyeContextManagerProvider.class.getPackage().getName())
Expand Down

0 comments on commit 9043149

Please sign in to comment.