Skip to content

Commit 71eb854

Browse files
Remove Undertow dependency from ArC
1 parent f3d7845 commit 71eb854

File tree

12 files changed

+109
-57
lines changed

12 files changed

+109
-57
lines changed

core/deployment/src/main/java/org/jboss/shamrock/deployment/Capabilities.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@
2222

2323
/**
2424
* The list of capabilities.
25-
*
2625
*/
2726
public final class Capabilities extends SimpleBuildItem {
2827

2928
public static final String CDI_ARC = "org.jboss.shamrock.cdi";
3029
public static final String TRANSACTIONS = "org.jboss.shamrock.transactions";
31-
public static final String UNDERTOW = "org.jboss.shamrock.undertow";
3230

3331
private final Set<String> capabilities;
3432

@@ -43,5 +41,5 @@ public Capabilities(Set<String> capabilities) {
4341
public Set<String> getCapabilities() {
4442
return capabilities;
4543
}
46-
44+
4745
}

extensions/arc/deployment/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@
4242
<groupId>org.jboss.protean.arc</groupId>
4343
<artifactId>arc-processor</artifactId>
4444
</dependency>
45-
<dependency>
46-
<groupId>org.jboss.shamrock</groupId>
47-
<artifactId>shamrock-undertow-deployment</artifactId>
48-
</dependency>
4945

5046
<dependency>
5147
<groupId>org.jboss.shamrock</groupId>

extensions/arc/deployment/src/main/java/org/jboss/shamrock/arc/deployment/ArcAnnotationProcessor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
import org.jboss.shamrock.deployment.builditem.substrate.ReflectiveClassBuildItem;
6363
import org.jboss.shamrock.deployment.builditem.substrate.ReflectiveFieldBuildItem;
6464
import org.jboss.shamrock.deployment.builditem.substrate.ReflectiveMethodBuildItem;
65-
import org.jboss.shamrock.undertow.ServletExtensionBuildItem;
6665

6766
public class ArcAnnotationProcessor {
6867

@@ -104,7 +103,7 @@ public class ArcAnnotationProcessor {
104103
@BuildStep(providesCapabilities = Capabilities.CDI_ARC, applicationArchiveMarkers = { "META-INF/beans.xml",
105104
"META-INF/services/javax.enterprise.inject.spi.Extension" })
106105
@Record(STATIC_INIT)
107-
public BeanContainerBuildItem build(ArcDeploymentTemplate arcTemplate, BuildProducer<ServletExtensionBuildItem> extensions,
106+
public BeanContainerBuildItem build(ArcDeploymentTemplate arcTemplate,
108107
BuildProducer<InjectionProviderBuildItem> injectionProvider, List<BeanContainerListenerBuildItem> beanContainerListenerBuildItems,
109108
ApplicationArchivesBuildItem applicationArchivesBuildItem, List<GeneratedBeanBuildItem> generatedBeans,
110109
List<AnnotationsTransformerBuildItem> annotationTransformers, ShutdownContextBuildItem shutdown, BuildProducer<FeatureBuildItem> feature)
@@ -196,7 +195,6 @@ public void writeResource(Resource resource) throws IOException {
196195
BeanContainer bc = arcTemplate.initBeanContainer(container,
197196
beanContainerListenerBuildItems.stream().map(BeanContainerListenerBuildItem::getBeanContainerListener).collect(Collectors.toList()));
198197
injectionProvider.produce(new InjectionProviderBuildItem(arcTemplate.setupInjection(container)));
199-
extensions.produce(new ServletExtensionBuildItem(arcTemplate.setupRequestScope(container)));
200198

201199
return new BeanContainerBuildItem(bc);
202200
}

extensions/arc/deployment/src/main/java/org/jboss/shamrock/arc/deployment/BeanDefiningAnnotationsBuildStep.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,11 @@
44
import org.jboss.shamrock.annotations.BuildProducer;
55
import org.jboss.shamrock.annotations.BuildStep;
66
import org.jboss.shamrock.deployment.Capabilities;
7-
import org.jboss.shamrock.undertow.UndertowBuildStep;
87

98
public class BeanDefiningAnnotationsBuildStep {
109

1110
@BuildStep
1211
void beanDefiningAnnotations(Capabilities capabilities, BuildProducer<BeanDefiningAnnotationBuildItem> annotations) {
13-
if (capabilities.isCapabilityPresent(Capabilities.UNDERTOW)) {
14-
// Arc integration depends on undertow so we want to avoid cyclic dependencies
15-
annotations.produce(new BeanDefiningAnnotationBuildItem(UndertowBuildStep.WEB_FILTER));
16-
annotations.produce(new BeanDefiningAnnotationBuildItem(UndertowBuildStep.WEB_SERVLET));
17-
annotations.produce(new BeanDefiningAnnotationBuildItem(UndertowBuildStep.WEB_LISTENER));
18-
}
19-
2012
// TODO: we should only add this when running the tests
2113
annotations.produce(new BeanDefiningAnnotationBuildItem(DotName.createSimple("org.junit.runner.RunWith")));
2214
}

extensions/arc/runtime/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@
4444
<groupId>org.jboss.shamrock</groupId>
4545
<artifactId>shamrock-core-runtime</artifactId>
4646
</dependency>
47-
<dependency>
48-
<groupId>io.undertow</groupId>
49-
<artifactId>undertow-servlet</artifactId>
50-
</dependency>
5147
</dependencies>
5248

5349
<build>

extensions/arc/runtime/src/main/java/org/jboss/shamrock/arc/runtime/ArcDeploymentTemplate.java

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import java.util.List;
2121
import java.util.function.Supplier;
2222

23-
import javax.servlet.ServletContext;
24-
2523
import org.jboss.protean.arc.Arc;
2624
import org.jboss.protean.arc.ArcContainer;
2725
import org.jboss.protean.arc.InstanceHandle;
@@ -31,11 +29,6 @@
3129
import org.jboss.shamrock.runtime.ShutdownContext;
3230
import org.jboss.shamrock.runtime.Template;
3331

34-
import io.undertow.server.HttpServerExchange;
35-
import io.undertow.servlet.ServletExtension;
36-
import io.undertow.servlet.api.DeploymentInfo;
37-
import io.undertow.servlet.api.ThreadSetupHandler;
38-
3932
/**
4033
* @author Martin Kouba
4134
*/
@@ -69,36 +62,22 @@ public T get() {
6962
}
7063
};
7164
}
72-
};
73-
for(BeanContainerListener i : beanConfigurators) {
74-
i.created(beanContainer);
75-
}
76-
return beanContainer;
77-
}
7865

79-
public ServletExtension setupRequestScope(ArcContainer arcContainer) {
80-
return new ServletExtension() {
8166
@Override
82-
public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) {
83-
deploymentInfo.addThreadSetupAction(new ThreadSetupHandler() {
84-
@Override
85-
public <T, C> Action<T, C> create(Action<T, C> action) {
86-
return new Action<T, C>() {
87-
@Override
88-
public T call(HttpServerExchange exchange, C context) throws Exception {
89-
ManagedContext requestContext = arcContainer.requestContext();
90-
requestContext.activate();
91-
try {
92-
return action.call(exchange, context);
93-
} finally {
94-
requestContext.terminate();
95-
}
96-
}
97-
};
98-
}
99-
});
67+
public <T, U, R> R withinRequestContext(RequestAction<T, U, R> action, T t, U u) throws Exception {
68+
ManagedContext ctx = container.requestContext();
69+
ctx.activate();
70+
try {
71+
return action.run(t, u);
72+
} finally {
73+
ctx.terminate();
74+
}
10075
}
10176
};
77+
for (BeanContainerListener i : beanConfigurators) {
78+
i.created(beanContainer);
79+
}
80+
return beanContainer;
10281
}
10382

10483
public InjectionFactory setupInjection(ArcContainer container) {

extensions/arc/runtime/src/main/java/org/jboss/shamrock/arc/runtime/BeanContainer.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,28 @@ public interface BeanContainer {
2323
default <T> T instance(Class<T> type, Annotation... qualifiers) {
2424
return instanceFactory(type, qualifiers).get();
2525
}
26+
2627
<T> Factory<T> instanceFactory(Class<T> type, Annotation... qualifiers);
2728

29+
/**
30+
* Runs the given action within the scope of the CDI request context
31+
*
32+
* @param action The action to run
33+
* @param t The first context parameter, this is passed to the action
34+
* @param u The second context parameter, this is passed to the action
35+
* @return the value returned by the action
36+
* @throws Exception
37+
*/
38+
<T, U, R> R withinRequestContext(RequestAction<T, U, R> action, T t, U u) throws Exception;
2839

2940
interface Factory<T> {
3041

3142
T get();
3243
}
3344

45+
interface RequestAction<T, U, R> {
46+
47+
R run(T t, U u) throws Exception;
48+
}
49+
3450
}

extensions/undertow/deployment/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
<groupId>org.jboss.shamrock</groupId>
3838
<artifactId>shamrock-core-deployment</artifactId>
3939
</dependency>
40+
<dependency>
41+
<groupId>org.jboss.shamrock</groupId>
42+
<artifactId>shamrock-arc-deployment</artifactId>
43+
</dependency>
4044
<dependency>
4145
<groupId>org.jboss.shamrock</groupId>
4246
<artifactId>shamrock-undertow-runtime</artifactId>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2019 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.jboss.shamrock.undertow;
18+
19+
import org.jboss.shamrock.annotations.BuildProducer;
20+
import org.jboss.shamrock.annotations.BuildStep;
21+
import org.jboss.shamrock.annotations.ExecutionTime;
22+
import org.jboss.shamrock.annotations.Record;
23+
import org.jboss.shamrock.arc.deployment.BeanContainerBuildItem;
24+
import org.jboss.shamrock.arc.deployment.BeanDefiningAnnotationBuildItem;
25+
import org.jboss.shamrock.undertow.runtime.UndertowDeploymentTemplate;
26+
27+
public class UndertowArcIntegrationBuildStep {
28+
29+
@BuildStep
30+
@Record(ExecutionTime.STATIC_INIT)
31+
ServletExtensionBuildItem integrateRequestContext(BeanContainerBuildItem beanContainerBuildItem, UndertowDeploymentTemplate template) {
32+
return new ServletExtensionBuildItem(template.setupRequestScope(beanContainerBuildItem.getValue()));
33+
}
34+
35+
@BuildStep
36+
void beanDefiningAnnotations(BuildProducer<BeanDefiningAnnotationBuildItem> annotations) {
37+
annotations.produce(new BeanDefiningAnnotationBuildItem(UndertowBuildStep.WEB_FILTER));
38+
annotations.produce(new BeanDefiningAnnotationBuildItem(UndertowBuildStep.WEB_SERVLET));
39+
annotations.produce(new BeanDefiningAnnotationBuildItem(UndertowBuildStep.WEB_LISTENER));
40+
}
41+
}

extensions/undertow/deployment/src/main/java/org/jboss/shamrock/undertow/UndertowBuildStep.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,14 @@ SubstrateConfigBuildItem config() {
155155

156156
.build();
157157
}
158-
158+
159159
@BuildStep
160160
HotDeploymentConfigFileBuildItem configFile() {
161161
return new HotDeploymentConfigFileBuildItem(WEB_XML);
162162
}
163163

164164
@Record(STATIC_INIT)
165-
@BuildStep(providesCapabilities = Capabilities.UNDERTOW)
165+
@BuildStep
166166
public ServletDeploymentBuildItem build(ApplicationArchivesBuildItem applicationArchivesBuildItem,
167167
List<ServletBuildItem> servlets,
168168
List<FilterBuildItem> filters,

0 commit comments

Comments
 (0)