Skip to content

Commit 89de7de

Browse files
jansupolsenivam
authored andcommitted
Use Skipping Analyzer always
Signed-off-by: jansupol <[email protected]>
1 parent 425bc88 commit 89de7de

File tree

12 files changed

+328
-20
lines changed

12 files changed

+328
-20
lines changed

core-common/src/main/java/org/glassfish/jersey/internal/util/collection/Views.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2019 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2024 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -24,13 +24,12 @@
2424
import java.util.List;
2525
import java.util.ListIterator;
2626
import java.util.Map;
27+
import java.util.Objects;
2728
import java.util.Set;
2829
import java.util.function.Function;
2930
import java.util.function.Predicate;
3031
import java.util.stream.Collectors;
3132

32-
import static org.glassfish.jersey.internal.guava.Preconditions.checkNotNull;
33-
3433
/**
3534
* Collections utils, which provide transforming views for {@link List} and {@link Map}.
3635
*
@@ -197,8 +196,8 @@ public int size() {
197196
* @return union view of given sets.
198197
*/
199198
public static <E> Set<E> setUnionView(final Set<? extends E> set1, final Set<? extends E> set2) {
200-
checkNotNull(set1, "set1");
201-
checkNotNull(set2, "set2");
199+
Objects.requireNonNull(set1, "set1");
200+
Objects.requireNonNull(set2, "set2");
202201

203202
return new AbstractSet<E>() {
204203
@Override
@@ -220,18 +219,19 @@ private Set<E> getUnion(Set<? extends E> set1, Set<? extends E> set2) {
220219
}
221220

222221
/**
223-
* Create a view of a difference of provided sets.
222+
* Create a view of a difference of provided sets, i.e. the diff filters out from the first set the items included
223+
* in the second set.
224224
* <p>
225225
* View is updated whenever any of the provided set changes.
226226
*
227227
* @param set1 first set.
228228
* @param set2 second set.
229229
* @param <E> set item type.
230-
* @return union view of given sets.
230+
* @return view that is a difference of given sets.
231231
*/
232232
public static <E> Set<E> setDiffView(final Set<? extends E> set1, final Set<? extends E> set2) {
233-
checkNotNull(set1, "set1");
234-
checkNotNull(set2, "set2");
233+
Objects.requireNonNull(set1, "set1");
234+
Objects.requireNonNull(set2, "set2");
235235

236236
return new AbstractSet<E>() {
237237
@Override

ext/cdi/jersey-cdi1x/src/main/java/org/glassfish/jersey/ext/cdi1x/internal/CdiComponentProvider.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2022 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2024 Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2018, 2022 Payara Foundation and/or its affiliates. All rights reserved.
44
*
55
* This program and the accompanying materials are made available under the
@@ -59,8 +59,6 @@
5959
import javax.enterprise.inject.spi.AnnotatedParameter;
6060
import javax.enterprise.inject.spi.AnnotatedType;
6161
import javax.enterprise.inject.spi.Bean;
62-
import javax.enterprise.inject.spi.BeanManager;
63-
import javax.enterprise.inject.spi.BeforeBeanDiscovery;
6462
import javax.enterprise.inject.spi.BeforeShutdown;
6563
import javax.enterprise.inject.spi.Extension;
6664
import javax.enterprise.inject.spi.InjectionPoint;
@@ -144,6 +142,8 @@ public Boolean apply(final Class<?> clazz) {
144142
private volatile Map<Class<?>, Set<Method>> methodsToSkip = new HashMap<>();
145143
private volatile Map<Class<?>, Set<Field>> fieldsToSkip = new HashMap<>();
146144

145+
private boolean initialized = false;
146+
147147
public CdiComponentProvider() {
148148
customHk2TypesProvider = CdiUtil.lookupService(Hk2CustomBoundTypesProvider.class);
149149
injectionManagerStore = CdiUtil.createHk2InjectionManagerStore();
@@ -155,7 +155,7 @@ public void initialize(final InjectionManager injectionManager) {
155155
this.injectionManager = injectionManager;
156156
this.beanManager = CdiUtil.getBeanManager();
157157

158-
if (beanManager != null) {
158+
if (beanManager != null && !injectionManager.getClass().getSimpleName().equals("NonInjectionManager")) {
159159
// Try to get CdiComponentProvider created by CDI.
160160
final CdiComponentProvider extension = beanManager.getExtension(CdiComponentProvider.class);
161161

@@ -168,18 +168,19 @@ public void initialize(final InjectionManager injectionManager) {
168168
bindHk2ClassAnalyzer();
169169

170170
LOGGER.config(LocalizationMessages.CDI_PROVIDER_INITIALIZED());
171+
initialized = true;
171172
}
172173
}
173174
}
174175

175176
@Override
176177
public boolean bind(final Class<?> clazz, final Set<Class<?>> providerContracts) {
177-
return bind(clazz, providerContracts, ContractProvider.NO_PRIORITY);
178+
return initialized && bind(clazz, providerContracts, ContractProvider.NO_PRIORITY);
178179
}
179180

180181
@Override
181182
public boolean bind(Class<?> component, ContractProvider contractProvider) {
182-
return contractProvider != null
183+
return initialized && contractProvider != null
183184
? bind(component, contractProvider.getContracts(), contractProvider.getPriority(component))
184185
: bind(component, Collections.EMPTY_SET);
185186
}
@@ -629,11 +630,8 @@ private void bindHk2ClassAnalyzer() {
629630
ClassAnalyzer defaultClassAnalyzer =
630631
injectionManager.getInstance(ClassAnalyzer.class, ClassAnalyzer.DEFAULT_IMPLEMENTATION_NAME);
631632

632-
int skippedElements = methodsToSkip.size() + fieldsToSkip.size();
633-
634-
ClassAnalyzer customizedClassAnalyzer = skippedElements > 0
635-
? new InjecteeSkippingAnalyzer(defaultClassAnalyzer, methodsToSkip, fieldsToSkip, beanManager)
636-
: defaultClassAnalyzer;
633+
ClassAnalyzer customizedClassAnalyzer =
634+
new InjecteeSkippingAnalyzer(defaultClassAnalyzer, methodsToSkip, fieldsToSkip, beanManager);
637635

638636
Binder binder = new AbstractBinder() {
639637
@Override
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
5+
6+
This program and the accompanying materials are made available under the
7+
terms of the Eclipse Public License v. 2.0, which is available at
8+
http://www.eclipse.org/legal/epl-2.0.
9+
10+
This Source Code may also be made available under the following Secondary
11+
Licenses when the conditions for such availability set forth in the
12+
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
13+
version 2 with the GNU Classpath Exception, which is available at
14+
https://www.gnu.org/software/classpath/license.html.
15+
16+
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
17+
18+
-->
19+
20+
<project xmlns="http://maven.apache.org/POM/4.0.0"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23+
<parent>
24+
<artifactId>cdi-integration-project</artifactId>
25+
<groupId>org.glassfish.jersey.tests.integration.cdi</groupId>
26+
<version>2.46-SNAPSHOT</version>
27+
</parent>
28+
<modelVersion>4.0.0</modelVersion>
29+
30+
<artifactId>cdi-skipping-analyzer</artifactId>
31+
32+
<dependencies>
33+
<dependency>
34+
<groupId>jakarta.ws.rs</groupId>
35+
<artifactId>jakarta.ws.rs-api</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>jakarta.annotation</groupId>
39+
<artifactId>jakarta.annotation-api</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>jakarta.enterprise</groupId>
43+
<artifactId>jakarta.enterprise.cdi-api</artifactId>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.glassfish.jersey.ext.cdi</groupId>
47+
<artifactId>jersey-cdi1x</artifactId>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.jboss.weld.se</groupId>
51+
<artifactId>weld-se-core</artifactId>
52+
<scope>test</scope>
53+
</dependency>
54+
<dependency>
55+
<groupId>org.glassfish.jersey.test-framework</groupId>
56+
<artifactId>jersey-test-framework-util</artifactId>
57+
<scope>test</scope>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
61+
<artifactId>jersey-test-framework-provider-bundle</artifactId>
62+
<type>pom</type>
63+
<scope>test</scope>
64+
</dependency>
65+
<dependency>
66+
<groupId>org.glassfish.jersey.incubator</groupId>
67+
<artifactId>jersey-injectless-client</artifactId>
68+
<version>${jersey.version}</version>
69+
</dependency>
70+
</dependencies>
71+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
17+
package org.glassfish.jersey.tests.cdi.skippinganalyzer;
18+
19+
public interface CdiService<T> {
20+
void doService(T t);
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
17+
package org.glassfish.jersey.tests.cdi.skippinganalyzer;
18+
19+
import javax.enterprise.context.ApplicationScoped;
20+
import javax.enterprise.event.Observes;
21+
import javax.enterprise.inject.spi.AfterBeanDiscovery;
22+
import javax.enterprise.inject.spi.Extension;
23+
import java.io.IOException;
24+
25+
public class CdiServiceExtension implements Extension {
26+
public void observe(@Observes AfterBeanDiscovery event) throws IOException, ClassNotFoundException {
27+
event.addBean()
28+
.addType(CdiService.class)
29+
.beanClass(CdiService.class)
30+
.scope(ApplicationScoped.class)
31+
.createWith(context -> new CdiServiceImpl());
32+
}
33+
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
17+
package org.glassfish.jersey.tests.cdi.skippinganalyzer;
18+
19+
import javax.enterprise.inject.spi.BeanManager;
20+
import javax.inject.Inject;
21+
22+
public class CdiServiceImpl implements CdiService<StringBuilder> {
23+
24+
@Inject
25+
BeanManager beanManager;
26+
27+
@Override
28+
public void doService(StringBuilder sb) {
29+
sb.append(getClass().getSimpleName());
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
17+
package org.glassfish.jersey.tests.cdi.skippinganalyzer;
18+
19+
import javax.enterprise.context.ApplicationScoped;
20+
21+
@ApplicationScoped
22+
public class WeldDiscoveredBean {
23+
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
5+
6+
This program and the accompanying materials are made available under the
7+
terms of the Eclipse Public License v. 2.0, which is available at
8+
http://www.eclipse.org/legal/epl-2.0.
9+
10+
This Source Code may also be made available under the following Secondary
11+
Licenses when the conditions for such availability set forth in the
12+
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
13+
version 2 with the GNU Classpath Exception, which is available at
14+
https://www.gnu.org/software/classpath/license.html.
15+
16+
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
17+
18+
-->
19+
20+
21+
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22+
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
23+
bean-discovery-mode="annotated" version="2.0">
24+
</beans>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.glassfish.jersey.tests.cdi.skippinganalyzer.CdiServiceExtension
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
5+
6+
This program and the accompanying materials are made available under the
7+
terms of the Eclipse Public License v. 2.0, which is available at
8+
http://www.eclipse.org/legal/epl-2.0.
9+
10+
This Source Code may also be made available under the following Secondary
11+
Licenses when the conditions for such availability set forth in the
12+
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
13+
version 2 with the GNU Classpath Exception, which is available at
14+
https://www.gnu.org/software/classpath/license.html.
15+
16+
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
17+
18+
-->
19+
20+
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
23+
version="3.0">
24+
</web-app>

0 commit comments

Comments
 (0)