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 Oct 23, 2024
1 parent 0e24927 commit 663432b
Show file tree
Hide file tree
Showing 131 changed files with 11,816 additions and 539 deletions.
82 changes: 43 additions & 39 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,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 -->
<apachache-el.version>9.0.90</apachache-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 @@ -761,13 +762,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 @@ -962,6 +956,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 @@ -1263,15 +1264,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 @@ -1286,24 +1303,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>${apachache-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 @@ -2053,25 +2076,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
86 changes: 85 additions & 1 deletion 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 @@ -223,7 +224,90 @@
</differences>
</revapi.differences>
-->

<!-- Jakarta -->
<revapi.differences>
<justification>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>Move to Jakarta WebSocket 2.1.1</justification>
<criticality>highlight</criticality>
<differences>
<item>
<ignore>true</ignore>
<regex>true</regex>
<code>java.class.noLongerImplementsInterface</code>
<interface>javax.websocket..*</interface>
</item>
<item>
<ignore>true</ignore>
<code>java.method.parameterTypeChanged</code>
<old>parameter &lt;T&gt; T org.xwiki.websocket.WebSocketContext::call(===javax.websocket.Session===, java.util.concurrent.Callable&lt;T&gt;) throws java.lang.Exception</old>
<new>parameter &lt;T&gt; T org.xwiki.websocket.WebSocketContext::call(===jakarta.websocket.Session===, java.util.concurrent.Callable&lt;T&gt;) throws java.lang.Exception</new>
<parameterIndex>0</parameterIndex>
</item>
<item>
<ignore>true</ignore>
<code>java.method.parameterTypeChanged</code>
<old>parameter void org.xwiki.websocket.WebSocketContext::initialize(===javax.websocket.server.ServerEndpointConfig===, javax.websocket.server.HandshakeRequest, javax.websocket.HandshakeResponse)</old>
<new>parameter void org.xwiki.websocket.WebSocketContext::initialize(===jakarta.websocket.server.ServerEndpointConfig===, jakarta.websocket.server.HandshakeRequest, jakarta.websocket.HandshakeResponse)</new>
<parameterIndex>0</parameterIndex>
</item>
<item>
<ignore>true</ignore>
<code>java.method.parameterTypeChanged</code>
<old>parameter void org.xwiki.websocket.WebSocketContext::initialize(javax.websocket.server.ServerEndpointConfig, ===javax.websocket.server.HandshakeRequest===, javax.websocket.HandshakeResponse)</old>
<new>parameter void org.xwiki.websocket.WebSocketContext::initialize(jakarta.websocket.server.ServerEndpointConfig, ===jakarta.websocket.server.HandshakeRequest===, jakarta.websocket.HandshakeResponse)</new>
<parameterIndex>1</parameterIndex>
</item>
<item>
<ignore>true</ignore>
<code>java.method.parameterTypeChanged</code>
<old>parameter void org.xwiki.websocket.WebSocketContext::initialize(javax.websocket.server.ServerEndpointConfig, javax.websocket.server.HandshakeRequest, ===javax.websocket.HandshakeResponse===)</old>
<new>parameter void org.xwiki.websocket.WebSocketContext::initialize(jakarta.websocket.server.ServerEndpointConfig, jakarta.websocket.server.HandshakeRequest, ===jakarta.websocket.HandshakeResponse===)</new>
<parameterIndex>2</parameterIndex>
</item>
<item>
<ignore>true</ignore>
<code>java.method.parameterTypeChanged</code>
<old>parameter void org.xwiki.websocket.WebSocketContext::run(===javax.websocket.Session===, java.lang.Runnable)</old>
<new>parameter void org.xwiki.websocket.WebSocketContext::run(===jakarta.websocket.Session===, java.lang.Runnable)</new>
<parameterIndex>0</parameterIndex>
</item>
<item>
<ignore>true</ignore>
<code>java.annotation.added</code>
<old>method java.lang.Boolean org.xwiki.extension.index.IndexedExtension::isCompatible(java.lang.String)</old>
<new>method java.lang.Boolean org.xwiki.extension.index.IndexedExtension::isCompatible(java.lang.String)</new>
<annotation>@javax.annotation.Nullable</annotation>
<justification>A null value was already documented as a valid value to be returned, not a breakage</justification>
</item>
<item>
<ignore>true</ignore>
<code>java.annotation.added</code>
<old>method java.lang.Boolean org.xwiki.extension.wrap.WrappingIndexedExtension&lt;T extends org.xwiki.extension.index.IndexedExtension&gt;::isCompatible(java.lang.String)</old>
<new>method java.lang.Boolean org.xwiki.extension.wrap.WrappingIndexedExtension&lt;T extends org.xwiki.extension.Extension&gt;::isCompatible(java.lang.String)</new>
<annotation>@javax.annotation.Nullable</annotation>
<justification>A null value was already documented as a valid value to be returned, not a breakage</justification>
</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,13 +26,14 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;

import javax.inject.Provider;
import java.util.Set;

import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.xwiki.component.util.DefaultParameterizedType;
import org.xwiki.component.util.ReflectionUtils;

import jakarta.inject.Provider;

/**
* Default implementation of {@link ComponentDependency}.
*
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,12 +21,12 @@

import java.lang.reflect.Type;

import javax.inject.Inject;

import org.xwiki.component.descriptor.ComponentDescriptor;
import org.xwiki.component.manager.ComponentManager;
import org.xwiki.component.manager.ComponentRepositoryException;

import jakarta.inject.Inject;

/**
* Generic implementation that creates Component Manager instances based on the generic notion of a key. This is used
* for example by the Wiki Component Manager or the User Component Manager which respectively have a key returning the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

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

import org.xwiki.component.annotation.Component;
import org.xwiki.component.manager.ComponentLookupException;
import org.xwiki.component.manager.ComponentManager;
import org.xwiki.component.namespace.NamespaceUtils;

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

/**
* Default implementation of {@link ComponentManagerManager}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
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 org.apache.commons.lang3.StringUtils;
import org.xwiki.component.annotation.Component;
import org.xwiki.component.manager.ComponentManager;
import org.xwiki.component.namespace.NamespaceNotAllowedException;
import org.xwiki.component.namespace.NamespaceValidator;

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

/**
* Default implementation of {@link NamespaceValidator}.
*
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
Loading

0 comments on commit 663432b

Please sign in to comment.