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

Use just the latest Weld and fix CDI-BV module #4595

Merged
merged 1 commit into from
Oct 8, 2020
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
4 changes: 0 additions & 4 deletions examples/helloworld-cdi2-se/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@

<description>Jersey "Hello world" example with CDI 2 SE.</description>

<properties>
<weld.version>${weld3.version}</weld.version>
</properties>

<dependencies>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -81,7 +81,12 @@ public Object[] getArgs() {

@Override
public void setArgs(final Object[] args) {
this.args = args;
if (args.length == this.args.length) {
// Replace the original arguments with the new ones
System.arraycopy(args, 0, this.args, 0, args.length);
} else {
this.args = args;
}
}

@Override
Expand Down
11 changes: 7 additions & 4 deletions ext/cdi/jersey-cdi1x-validation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,19 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.ext.cdi</groupId>
<artifactId>jersey-cdi1x</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<scope>provided</scope>
<exclusions>
<!-- Remove ancient jakarta.el that causes problems with Hibernate -->
<exclusion>
<groupId>jakarta.el</groupId>
<artifactId>el-api</artifactId>
</exclusion>
<exclusion>
<groupId>jakarta.el</groupId>
<artifactId>jakarta.el-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ public CdiInterceptorWrapper(BeanManager beanManager) {

@AroundInvoke
public Object validateMethodInvocation(InvocationContext ctx) throws Exception {
final boolean isJaxRsMethod = extension.jaxRsResourceCache.apply(ctx.getMethod().getDeclaringClass());
final boolean isJaxRsMethod = extension.getJaxRsResourceCache().apply(ctx.getMethod().getDeclaringClass());
return isJaxRsMethod ? ctx.proceed() : interceptor.validateMethodInvocation(ctx);
}

@AroundConstruct
public void validateConstructorInvocation(InvocationContext ctx) throws Exception {
final boolean isJaxRsConstructor = extension.jaxRsResourceCache.apply(ctx.getConstructor().getDeclaringClass());
final boolean isJaxRsConstructor = extension.getJaxRsResourceCache().apply(ctx.getConstructor().getDeclaringClass());
if (!isJaxRsConstructor) {
interceptor.validateConstructorInvocation(ctx);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import jakarta.enterprise.util.AnnotationLiteral;
import jakarta.interceptor.Interceptor;

import org.glassfish.jersey.ext.cdi1x.internal.JerseyVetoed;
import org.glassfish.jersey.internal.util.collection.Cache;
import org.glassfish.jersey.server.model.Resource;

Expand All @@ -51,12 +52,13 @@
* @author Jakub Podlesak
*/
@Priority(value = Interceptor.Priority.PLATFORM_BEFORE + 199)
@JerseyVetoed
public class CdiInterceptorWrapperExtension implements Extension {

public static final AnnotationLiteral<Default> DEFAULT_ANNOTATION_LITERAL = new AnnotationLiteral<Default>() {};
public static final AnnotationLiteral<Any> ANY_ANNOTATION_LITERAL = new AnnotationLiteral<Any>() {};

final Cache<Class<?>, Boolean> jaxRsResourceCache = new Cache<>(clazz -> Resource.from(clazz) != null);
private Cache<Class<?>, Boolean> jaxRsResourceCache = new Cache<>(clazz -> Resource.from(clazz) != null);

private AnnotatedType<ValidationInterceptor> interceptorAnnotatedType;

Expand All @@ -82,7 +84,10 @@ private void beforeBeanDiscovery(@Observes BeforeBeanDiscovery beforeBeanDiscove
* @param afterTypeDiscovery CDI bootstrap event.
*/
private void afterTypeDiscovery(@Observes final AfterTypeDiscovery afterTypeDiscovery) {
afterTypeDiscovery.getInterceptors().removeIf(ValidationInterceptor.class::equals);
// Does throw java.lang.IndexOutOfBoundsException in Weld 4
// afterTypeDiscovery.getInterceptors().removeIf(ValidationInterceptor.class::equals);
// iterator.remove throws as well
afterTypeDiscovery.getInterceptors().remove(ValidationInterceptor.class);
}

/**
Expand Down Expand Up @@ -171,4 +176,12 @@ public void destroy(ValidationInterceptor instance,
}
});
}

/* package */ Cache<Class<?>, Boolean> getJaxRsResourceCache() {
/* CDI injection hack */
if (jaxRsResourceCache == null) {
jaxRsResourceCache = new Cache<>(clazz -> Resource.from(clazz) != null);
}
return jaxRsResourceCache;
}
}
1 change: 0 additions & 1 deletion inject/cdi2-se/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<version>${weld3.version}</version>
</dependency>

<dependency>
Expand Down
8 changes: 3 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2118,18 +2118,16 @@
<spring5.version>5.1.5.RELEASE</spring5.version>
<surefire.version>3.0.0-M3</surefire.version>

<weld.version>2.2.14.Final</weld.version> <!-- 2.4.1 doesn't work - bv tests -->
<weld.version>4.0.0.Beta1</weld.version> <!-- 2.4.1 doesn't work - bv tests -->
<!-- Jakartified, eligible for CQ -->
<validation.impl.version>7.0.0.Alpha1</validation.impl.version>
<weld3.version>4.0.0.Alpha2</weld3.version>
<weld4.version>4.0.0.Alpha2</weld4.version>
<validation.impl.version>7.0.0.Alpha6</validation.impl.version>
<!-- END of Jakartified, eligible for CQ -->
<xerces.version>2.11.0</xerces.version>

<!-- do not need CQs (below this line till the end of version properties)-->
<gf.impl.version>5.1.0</gf.impl.version>
<!-- Jakartified -->
<cdi.api.version>3.0.0-M4</cdi.api.version>
<cdi.api.version>3.0.0</cdi.api.version>
<ejb.version>4.0.0-RC2</ejb.version>
<grizzly2.version>3.0.0-M1</grizzly2.version>
<hk2.version>3.0.0-M2</hk2.version>
Expand Down
4 changes: 0 additions & 4 deletions tests/e2e-inject/cdi2-se/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@

<description>Jersey E2E Inject CDI SE tests</description>

<properties>
<weld.version>${weld3.version}</weld.version>
</properties>

<dependencies>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
Expand Down
1 change: 0 additions & 1 deletion tests/integration/JERSEY-2988/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet-core</artifactId>
<version>${weld3.version}</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,5 @@
</profiles>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>always</forkMode>
<enableAssertions>false</enableAssertions>
<!-- TODO remove after jakartification -->
<excludes>
<exclude>org/glassfish/jersey/tests/cdi/bv/CombinedTest.java</exclude>
<exclude>org/glassfish/jersey/tests/cdi/bv/RawCdiTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@

package org.glassfish.jersey.tests.cdi.bv;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.validation.ConstraintViolationException;
import jakarta.validation.ValidationException;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import org.glassfish.jersey.server.spi.ValidationInterceptor;
import org.glassfish.jersey.server.spi.ValidationInterceptorContext;

import org.jboss.weld.interceptor.util.proxy.TargetInstanceProxy;

/**
Expand Down Expand Up @@ -66,7 +65,7 @@ public void onValidate(ValidationInterceptorContext ctx) throws ValidationExcept

final Object resource = ctx.getResource();
if (resource instanceof TargetInstanceProxy) {
ctx.setResource(((TargetInstanceProxy) resource).getTargetInstance());
ctx.setResource(((TargetInstanceProxy) resource).weld_getTargetInstance());
}

try {
Expand All @@ -79,6 +78,7 @@ public void onValidate(ValidationInterceptorContext ctx) throws ValidationExcept
ValidationResultUtil.updateValidationResultProperty(resource, validationResultGetter,
constraintViolationException.getConstraintViolations());
pir.setValidationResult(validationResult);
ctx.getArgs()[0] = ""; // Let it not be null
} else {
// Then check for a field
final Field vr = ValidationResultUtil.getValidationResultField(resource);
Expand All @@ -88,6 +88,7 @@ public void onValidate(ValidationInterceptorContext ctx) throws ValidationExcept
} else {
if (isValidationResultInArgs(ctx.getArgs())) {
this.validationResult.setViolations(constraintViolationException.getConstraintViolations());
ctx.getArgs()[0] = ""; // Let it not be null
} else {
throw constraintViolationException;
}
Expand Down
17 changes: 0 additions & 17 deletions tests/integration/cdi-integration/cdi-log-check/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,5 @@
<maven.test.skip>false</maven.test.skip>
</properties>
</profile>
<profile>
<id>jakartification_exclude_tests</id> <!-- TODO remove after jakartification -->
<activation>
<jdk>[1.8,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
2 changes: 0 additions & 2 deletions tests/integration/cdi-integration/cdi-manually-bound/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<!-- <version>3.0.0-M2</version>-->
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext.cdi</groupId>
Expand All @@ -49,7 +48,6 @@
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<version>4.0.0.Alpha1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
17 changes: 0 additions & 17 deletions tests/integration/cdi-integration/cdi-test-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,5 @@
<maven.test.skip>false</maven.test.skip>
</properties>
</profile>
<profile>
<id>jakartification_exclude_tests</id> <!-- TODO remove after jakartification -->
<activation>
<jdk>[1.8,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>