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

Make sure InjecteeSkippingAnalyzer is always installed #3972

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
41 changes: 40 additions & 1 deletion extension/eclipse-jersey/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand All @@ -14,6 +16,10 @@

<name>Piranha - Extension - Eclipse Jersey</name>

<properties>
<jersey.version>3.1.8</jersey.version>
</properties>

<dependencies>
<!-- compile -->
<dependency>
Expand All @@ -22,13 +28,38 @@
<version>${project.version}</version>
<scope>compile</scope>
</dependency>

<!-- provided -->
<dependency>
<groupId>cloud.piranha.extension</groupId>
<artifactId>piranha-extension-scinitializer</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>cloud.piranha.extension</groupId>
<artifactId>piranha-extension-scinitializer</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>cdi-tck-api</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
<version>2.0.1.MR</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<scope>provided</scope>
</dependency>

<!-- runtime -->
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
Expand All @@ -54,6 +85,14 @@
<version>${jersey.version}</version>
<scope>runtime</scope>
</dependency>

<!--
<dependency>
<groupId>org.glassfish.jersey.ext.cdi</groupId>
<artifactId>jersey-cdi1x-servlet</artifactId>
<version>${jersey.version}</version>
<scope>runtime</scope>
</dependency>-->
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,63 @@
*/
package cloud.piranha.extension.jersey;

import jakarta.enterprise.event.Observes;
import jakarta.enterprise.inject.spi.BeanManager;
import jakarta.enterprise.inject.spi.BeforeBeanDiscovery;
import jakarta.enterprise.inject.spi.Extension;

import java.lang.System.Logger;

import cloud.piranha.core.api.WebApplication;
import cloud.piranha.core.api.WebApplicationExtension;
import java.lang.System.Logger;

import static java.lang.System.Logger.Level.TRACE;

/**
* The extension that delivers Eclipse Jersey to Piranha.
*
* @author Manfred Riem ([email protected])
*/
public class JerseyExtension implements WebApplicationExtension {
public class JerseyExtension implements WebApplicationExtension, Extension {

/**
* Stores the logger.
*/
private static final Logger LOGGER = System.getLogger(JerseyExtension.class.getName());

/**
* Configure the extension.
*
*
* @param webApplication the web application.
*/
@Override
public void configure(WebApplication webApplication) {
LOGGER.log(TRACE, "Configuring Jersey extension");
}

/**
*
* @param beforeBean
* @param beanManager
*/
public void register(@Observes BeforeBeanDiscovery beforeBean, BeanManager beanManager) {
// Force a class analyzer to be added that makes sure a REST resource is not attempted
// to be injected by both CDI and HK2.
//
// See https://github.com/eclipse-ee4j/jersey/issues/5745 on why this is needed
addAnnotatedTypes(beforeBean, beanManager, JerseyTargetBean.class, JerseySourceBean.class);
}

/**
*
* @param beforeBean
* @param beanManager
* @param types
*/
public static void addAnnotatedTypes(BeforeBeanDiscovery beforeBean, BeanManager beanManager, Class<?>... types) {
for (Class<?> type : types) {
beforeBean.addAnnotatedType(beanManager.createAnnotatedType(type), "JerseyExtension " + type.getName());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2002-2024 Manorrock.com. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.jersey;

import jakarta.enterprise.context.Dependent;

@Dependent
public class JerseySourceBean {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2002-2024 Manorrock.com. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.extension.jersey;

import jakarta.enterprise.context.Dependent;
import jakarta.inject.Inject;

@Dependent
public class JerseyTargetBean {

/**
*dd
*/
@Inject
JerseySourceBean bean;

}
7 changes: 4 additions & 3 deletions extension/eclipse-jersey/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@
* This module delivers the Eclipse Jersey integration extension.
*
* <p>
* This extension integrates Eclipse Jersey into Piranha. See
* This extension integrates Eclipse Jersey into Piranha. See
* https://github.com/eclipse-ee4j/jersey for more information about its
* project.
* </p>
*
*
* @author Manfred Riem ([email protected])
*/
module cloud.piranha.extension.jersey {

requires cloud.piranha.core.api;
requires static cloud.piranha.extension.scinitializer;
requires jakarta.cdi;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cloud.piranha.extension.jersey.JerseyExtension
Loading