Skip to content

Commit

Permalink
XCOMMONS-2777: Add support for jakarta.inject annotations
Browse files Browse the repository at this point in the history
XCOMMONS-2797: Allow accessing a javax.inject.Provider as a jakarta.inject.Provider and the opposite
XCOMMONS-2963: Upgrade to Servlet 5.0
XCOMMONS-2962: Provide a javax/jakarta bridge for Servlet APIs
XCOMMONS-2994: Upgrade to Websocket 2.1.1
XCOMMONS-2108: Upgrade to Bean Validation 3.0.2
XCOMMONS-2109: Upgrade to Hibernate Validator 8.0.1
XCOMMONS-2475: Use Expressly instead of Apache EL
  • Loading branch information
tmortagne committed Jan 10, 2025
1 parent bff04ec commit 9879228
Show file tree
Hide file tree
Showing 148 changed files with 13,536 additions and 505 deletions.
82 changes: 43 additions & 39 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,12 @@
<antlr4.version>4.13.2</antlr4.version>

<!-- Servlet specifications -->
<servlet.version>3.1.0</servlet.version>
<javax.servlet.version>3.1.0</javax.servlet.version>
<jakarta.servlet.version>5.0.0</jakarta.servlet.version>

<!-- EL implementation -->
<!-- Use the same version as the one that comes with the custom XWiki Jetty application server -->
<apache-el.version>9.0.90</apache-el.version>
<!-- WebSocket specifications -->
<javax.websocket.version>1.1</javax.websocket.version>
<jakarta.websocket.version>2.1.1</jakarta.websocket.version>

<webdrivermanager.version>5.9.2</webdrivermanager.version>

Expand Down Expand Up @@ -757,13 +758,6 @@
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jsonSchema</artifactId>
<version>${jackson.version}</version>
<exclusions>
<!-- We use jakarta.validation:jakarta.validation-api -->
<exclusion>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
Expand Down Expand Up @@ -958,6 +952,13 @@
<version>3.30.2-GA</version>
</dependency>

<!-- Injection -->
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
<version>2.0.1</version>
</dependency>

<!-- Triggered by several Maven related projects (Doxia, Maven, Aether) as transitive dependency. We need
these explicit versions to help Maven decide which version to use. -->
<dependency>
Expand Down Expand Up @@ -1259,15 +1260,31 @@
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet.version}</version>
<version>${javax.servlet.version}</version>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>${jakarta.servlet.version}</version>
<!-- It should always be provided as the API jar is provided by the Servlet Container in which XWiki is
deployed -->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.websocket</groupId>
<artifactId>javax.websocket-api</artifactId>
<version>1.1</version>
<version>${javax.websocket.version}</version>
</dependency>
<dependency>
<groupId>jakarta.websocket</groupId>
<artifactId>jakarta.websocket-api</artifactId>
<version>${jakarta.websocket.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.websocket</groupId>
<artifactId>jakarta.websocket-client-api</artifactId>
<version>${jakarta.websocket.version}</version>
<scope>provided</scope>
</dependency>
<!-- Needed for Legacy modules. The version needs to be in sync with the one used by the AspectJ plugin -->
Expand All @@ -1282,24 +1299,30 @@
<artifactId>cssparser</artifactId>
<version>0.9.30</version>
</dependency>

<!-- Bean validation -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>2.0.2</version>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.2.5.Final</version>
<version>8.0.1.Final</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.mortbay.jasper</groupId>
<artifactId>apache-el</artifactId>
<version>${apache-el.version}</version>
<!-- The EL implementation is supposed to come with the application server, but we need one for tests -->
<scope>test</scope>
<groupId>org.glassfish.expressly</groupId>
<artifactId>expressly</artifactId>
<version>5.0.0</version>
<!-- The implementation of Expression Language is supposed to come with the application server -->
<scope>provided</scope>
</dependency>

<!-- Mail -->
Expand Down Expand Up @@ -2049,25 +2072,6 @@
</rules>
</configuration>
</execution>
<!-- Check that we use the right version of the Validation API -->
<execution>
<id>enforce-jakarta.validation-api</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<skip>${xwiki.enforcer.enforce-jakarta.validation-api.skip}</skip>
<rules>
<bannedDependencies>
<searchTransitive>true</searchTransitive>
<message>Use jakarta.validation:jakarta.validation-api instead</message>
<excludes>
<exclude>javax.validation:validation-api</exclude>
</excludes>
</bannedDependencies>
</rules>
</configuration>
</execution>
<!-- Check that we use the right version of the Hibernate Validator -->
<execution>
<id>enforce-hibernate-validator</id>
Expand Down
63 changes: 63 additions & 0 deletions xwiki-commons-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<module>xwiki-commons-websocket</module>
<module>xwiki-commons-xml</module>
<module>xwiki-commons-xstream</module>
<module>xwiki-commons-jakartabridge</module>
</modules>
<build>
<pluginManagement>
Expand Down Expand Up @@ -238,6 +239,68 @@
</item>
</differences>
</revapi.differences>

<!-- Jakarta -->
<revapi.differences>
<justification>revapi false positives</justification>
<criticality>allowed</criticality>
<differences>
<item>
<ignore>true</ignore>
<code>java.class.nonFinalClassInheritsFromNewClass</code>
<old>class org.xwiki.component.embed.GenericProvider&lt;T&gt;</old>
<new>class org.xwiki.component.embed.GenericProvider&lt;T&gt;</new>
<superClass>org.xwiki.component.internal.AbstractGenericProvider&lt;T&gt;</superClass>
</item>
<item>
<ignore>true</ignore>
<code>java.class.nonFinalClassInheritsFromNewClass</code>
<old>class org.xwiki.component.embed.GenericProvider&lt;T&gt;</old>
<new>class org.xwiki.component.embed.GenericProvider&lt;T&gt;</new>
<superClass>org.xwiki.component.internal.JavaXGenericProvider&lt;T&gt;</superClass>
</item>
</differences>
</revapi.differences>
<revapi.differences>
<justification>Moved to WebSocket 2.1.1</justification>
<criticality>highlight</criticality>
<differences>
<item>
<ignore>true</ignore>
<code>java.class.noLongerImplementsInterface</code>
<old>class org.xwiki.websocket.AbstractPartialMessageHandler&lt;T&gt;</old>
<new>class org.xwiki.websocket.AbstractPartialMessageHandler&lt;T&gt;</new>
<interface>javax.websocket.MessageHandler.Partial&lt;T&gt;</interface>
</item>
<item>
<ignore>true</ignore>
<code>java.class.noLongerImplementsInterface</code>
<old>class org.xwiki.websocket.AbstractPartialMessageHandler&lt;T&gt;</old>
<new>class org.xwiki.websocket.AbstractPartialMessageHandler&lt;T&gt;</new>
<interface>javax.websocket.MessageHandler</interface>
</item>
<item>
<ignore>true</ignore>
<code>java.class.noLongerImplementsInterface</code>
<old>class org.xwiki.websocket.AbstractPartialStringMessageHandler</old>
<new>class org.xwiki.websocket.AbstractPartialStringMessageHandler</new>
<interface>javax.websocket.MessageHandler.Partial&lt;java.lang.String&gt;</interface>
</item>
<item>
<ignore>true</ignore>
<code>java.class.noLongerImplementsInterface</code>
<old>class org.xwiki.websocket.AbstractPartialStringMessageHandler</old>
<new>class org.xwiki.websocket.AbstractPartialStringMessageHandler</new>
<interface>javax.websocket.MessageHandler</interface>
</item>
<item>
<ignore>true</ignore>
<regex>true</regex>
<code>java.method.parameterTypeChanged</code>
<old>parameter .* org.xwiki.websocket.WebSocketContext::.*</old>
</item>
</differences>
</revapi.differences>
</analysisConfiguration>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- We add this dependency here so that users of the Component API just need to depend on this artifact and
don't have to explicitly add a dependency on javax.inject:java.inject. -->
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
</dependency>
<!-- Keep supporting both the Jakarta and Javax injection APIs -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>

<!-- Testing dependencies -->
<dependency>
<groupId>org.xwiki.commons</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import javax.inject.Provider;
import jakarta.inject.Provider;

import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.xwiki.component.util.DefaultParameterizedType;
Expand All @@ -42,6 +43,9 @@
*/
public class DefaultComponentDependency<T> extends DefaultComponentRole<T> implements ComponentDependency<T>
{
private static final Set<Class<?>> SPECIAL_ROLES =
Set.of(List.class, Collection.class, Map.class, javax.inject.Provider.class, Provider.class);

/**
* @see #getName()
*/
Expand Down Expand Up @@ -115,7 +119,8 @@ public boolean equals(Object object)
{
boolean result;

// See http://www.technofundo.com/tech/java/equalhash.html for the detail of this algorithm.
// See http://www.technofundo.com/tech/java/equalhash.html for the detail of
// this algorithm.
if (this == object) {
result = true;
} else {
Expand Down Expand Up @@ -192,7 +197,7 @@ public Class<T> getRole()
{
Class mapping = getMappingType();

if (mapping == List.class || mapping == Collection.class || mapping == Map.class || mapping == Provider.class) {
if (SPECIAL_ROLES.contains(mapping)) {
return ReflectionUtils.getTypeClass(ReflectionUtils.getLastTypeGenericArgument(getRoleType()));
} else {
return mapping;
Expand All @@ -204,7 +209,7 @@ public void setRole(Class<T> role)
{
Class mapping = getMappingType();

if (mapping == List.class || mapping == Collection.class || mapping == Map.class || mapping == Provider.class) {
if (SPECIAL_ROLES.contains(mapping)) {
Type ownerType;
Class<?> rawType;
if (getRoleType() instanceof ParameterizedType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import java.lang.reflect.Type;

import javax.inject.Inject;
import jakarta.inject.Inject;

import org.xwiki.component.descriptor.ComponentDescriptor;
import org.xwiki.component.manager.ComponentManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.inject.Inject;
import javax.inject.Singleton;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;

import org.xwiki.component.annotation.Component;
import org.xwiki.component.manager.ComponentLookupException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.inject.Provider;
import jakarta.inject.Singleton;

import org.apache.commons.lang3.StringUtils;
import org.xwiki.component.annotation.Component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @version $Id$
* @since 3.3M1
*/
public class DefaultComponentRoleTest
class DefaultComponentRoleTest
{
private interface Role
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*
* @version $Id$
*/
public class DefaultNamespaceValidatorTest
class DefaultNamespaceValidatorTest
{
private DefaultNamespaceValidator validator = new DefaultNamespaceValidator();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*
* @version $Id$
*/
public class NamespaceTest
class NamespaceTest
{
@Test
void equalsAndHashCode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*
* @version $Id$
*/
public class NamespaceUtilsTest
class NamespaceUtilsTest
{
@Test
void getPrefix()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @version $Id$
*/
public class DefaultParameterizedTypeTest
class DefaultParameterizedTypeTest
{
@Test
void toStringTest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
* @version $Id$
*/
public class ReflectionMethodUtilsTest
class ReflectionMethodUtilsTest
{
@Test
void testGetMethodParameterAnnotations() throws SecurityException, NoSuchMethodException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
*
* @version $Id$
*/
public class ReflectionUtilsTest
class ReflectionUtilsTest
{
private static interface TestInterfaceSimple
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import ${package}.HelloWorld;
import org.xwiki.component.annotation.Component;

import javax.inject.Singleton;
import jakarta.inject.Singleton;

/**
* Implementation of a {@code HelloWorld} component.
Expand Down
Loading

0 comments on commit 9879228

Please sign in to comment.