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 Sep 18, 2024
1 parent 557db14 commit 6fa6229
Show file tree
Hide file tree
Showing 131 changed files with 11,790 additions and 512 deletions.
51 changes: 38 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,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 @@ -952,6 +953,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 @@ -1253,15 +1261,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 @@ -1276,24 +1300,25 @@
<artifactId>cssparser</artifactId>
<version>0.9.30</version>
</dependency>

<!-- Bean validation -->
<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
70 changes: 70 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 @@ -279,6 +280,75 @@
<oldValue>{"rating", "summary", "description", "licenses", "website", "authors", "features", "extensionFeatures", "scm", "issueManagement", "category", "allowedNamespaces", "recommended", "properties"}</oldValue>
<newValue>{"rating", "summary", "description", "licenses", "website", "authors", "supportPlans", "features", "extensionFeatures", "scm", "issueManagement", "category", "allowedNamespaces", "recommended", "properties"}</newValue>
</item>
</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>
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

import ${package}.HelloWorld;

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

/**
* Make the HelloWorld API available to scripting.
Expand Down
Loading

0 comments on commit 6fa6229

Please sign in to comment.