openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject [openwebbeans-meecrowave] branch master updated: MEECROWAVE-206 ensure meecrowave-core is not scanned since it does need and relies on an extension anyway for its discovery
Date Sat, 17 Aug 2019 17:12:20 GMT
This is an automated email from the ASF dual-hosted git repository.

rmannibucau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwebbeans-meecrowave.git


The following commit(s) were added to refs/heads/master by this push:
     new 3848825  MEECROWAVE-206 ensure meecrowave-core is not scanned since it does need
and relies on an extension anyway for its discovery
3848825 is described below

commit 38488253532e17aed98e4c9cf069ccf16ab3234b
Author: Romain Manni-Bucau <rmannibucau@apache.org>
AuthorDate: Sat Aug 17 19:12:09 2019 +0200

    MEECROWAVE-206 ensure meecrowave-core is not scanned since it does need and relies on
an extension anyway for its discovery
---
 .../org/apache/meecrowave/MeecrowaveExplosion.java | 25 --------------
 .../openwebbeans/MeecrowaveExtension.java          | 39 ++++++++++++++++++----
 .../meecrowave/openwebbeans/OWBAutoSetup.java      |  9 -----
 .../src/main/resources/META-INF/beans.xml          | 10 ++++--
 .../meecrowave/{ => test}/api/ListeningTest.java   | 19 ++++++-----
 5 files changed, 50 insertions(+), 52 deletions(-)

diff --git a/meecrowave-core/src/main/java/org/apache/meecrowave/MeecrowaveExplosion.java
b/meecrowave-core/src/main/java/org/apache/meecrowave/MeecrowaveExplosion.java
deleted file mode 100644
index 0ae9210..0000000
--- a/meecrowave-core/src/main/java/org/apache/meecrowave/MeecrowaveExplosion.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.meecrowave;
-
-public class MeecrowaveExplosion extends RuntimeException {
-    public MeecrowaveExplosion(final String msg, final Exception e) {
-        super(msg, e);
-    }
-}
diff --git a/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/MeecrowaveExtension.java
b/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/MeecrowaveExtension.java
index a944bd5..d47fff4 100644
--- a/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/MeecrowaveExtension.java
+++ b/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/MeecrowaveExtension.java
@@ -41,22 +41,47 @@ public class MeecrowaveExtension implements Extension {
 
     void addBeansFromJava(@Observes final BeforeBeanDiscovery bbd, final BeanManager bm)
{
         if (Cxfs.IS_PRESENT) {
-            // stream not really needed but here for the pattern in case we need other beans
-            Stream.of(MeecrowaveBus.class)
+            bbd.addInterceptorBinding(JAXRSFieldInjectionInterceptor.Binding.class);
+
+            Stream.of(MeecrowaveBus.class, JAXRSFieldInjectionInterceptor.class)
                   .forEach(type -> bbd.addAnnotatedType(bm.createAnnotatedType(type)));
         }
     }
 
-    void enableContextFieldInjectionWorks(@Observes final ProcessAnnotatedType<?> pat,
final BeanManager bm) {
+    void onPat(@Observes final ProcessAnnotatedType<?> pat, final BeanManager bm) {
         final AnnotatedType<?> at = pat.getAnnotatedType();
-        if (Cxfs.IS_PRESENT
-                && at.isAnnotationPresent(Path.class)
-                && !at.isAnnotationPresent(JAXRSFieldInjectionInterceptor.Binding.class)
-                && at.getAnnotations().stream().anyMatch(a -> bm.isNormalScope(a.annotationType())))
{
+        if (isJaxRsEndpoint(bm, at)) {
             pat.setAnnotatedType(new JAXRSFIeldInjectionAT(this, at));
+        } else if (isVetoedMeecrowaveCore(at.getJavaClass().getName())) {
+            pat.veto();
         }
     }
 
+    private boolean isJaxRsEndpoint(final BeanManager bm, final AnnotatedType<?> at)
{
+        return Cxfs.IS_PRESENT
+                && at.isAnnotationPresent(Path.class)
+                && !at.isAnnotationPresent(JAXRSFieldInjectionInterceptor.Binding.class)
+                && at.getAnnotations().stream().anyMatch(a -> bm.isNormalScope(a.annotationType()));
+    }
+
+    // for fatjars
+    private boolean isVetoedMeecrowaveCore(final String name) {
+        return !"org.apache.meecrowave.cxf.MeecrowaveBus".equals(name)
+                && !"org.apache.meecrowave.cxf.JAXRSFieldInjectionInterceptor".equals(name)
+                && (name.startsWith("org.apache.meecrowave.api.")
+                    || name.startsWith("org.apache.meecrowave.cdi.")
+                    || name.startsWith("org.apache.meecrowave.cxf.")
+                    || name.startsWith("org.apache.meecrowave.io.")
+                    || name.startsWith("org.apache.meecrowave.lang.")
+                    || name.startsWith("org.apache.meecrowave.logging.")
+                    || name.startsWith("org.apache.meecrowave.openwebbeans.")
+                    || name.startsWith("org.apache.meecrowave.runner.")
+                    || name.startsWith("org.apache.meecrowave.service.")
+                    || name.startsWith("org.apache.meecrowave.tomcat.")
+                    || name.startsWith("org.apache.meecrowave.watching.")
+                    || name.equals("org.apache.meecrowave.Meecrowave"));
+    }
+
     private static class JAXRSFIeldInjectionAT<T> extends AnnotatedTypeWrapper<T>
{
 
         private final Set<Annotation> annotations;
diff --git a/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBAutoSetup.java
b/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBAutoSetup.java
index f862b39..6fa4a9c 100644
--- a/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBAutoSetup.java
+++ b/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBAutoSetup.java
@@ -19,13 +19,10 @@
 package org.apache.meecrowave.openwebbeans;
 
 import org.apache.meecrowave.Meecrowave;
-import org.apache.meecrowave.cxf.Cxfs;
-import org.apache.meecrowave.cxf.JAXRSFieldInjectionInterceptor;
 import org.apache.webbeans.annotation.DefaultLiteral;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.configurator.BeanConfiguratorImpl;
 import org.apache.webbeans.container.BeanManagerImpl;
-import org.apache.webbeans.intercept.InterceptorsManager;
 import org.apache.webbeans.servlet.WebBeansConfigurationListener;
 
 import javax.enterprise.context.ApplicationScoped;
@@ -89,7 +86,6 @@ public class OWBAutoSetup implements ServletContainerInitializer {
 
         private void customizeContext(final WebBeansContext instance) {
             final BeanManagerImpl beanManager = instance.getBeanManagerImpl();
-            final InterceptorsManager interceptorsManager = instance.getInterceptorsManager();
 
             beanManager.addInternalBean(newBean(instance, configurator ->
                     configurator.beanClass(Meecrowave.Builder.class)
@@ -103,11 +99,6 @@ public class OWBAutoSetup implements ServletContainerInitializer {
                             .qualifiers(DefaultLiteral.INSTANCE)
                             .types(Meecrowave.class, AutoCloseable.class, Object.class)
                             .createWith(cc -> meecrowave)));
-
-            if (Cxfs.IS_PRESENT) {
-                interceptorsManager.addInterceptorBindingType(JAXRSFieldInjectionInterceptor.Binding.class);
-                beanManager.addAdditionalAnnotatedType(this, beanManager.createAnnotatedType(JAXRSFieldInjectionInterceptor.class));
-            }
         }
 
         private <T> Bean<?> newBean(final WebBeansContext instance, final Consumer<BeanConfigurator<T>>
configurer) {
diff --git a/meecrowave-core/src/main/resources/META-INF/beans.xml b/meecrowave-core/src/main/resources/META-INF/beans.xml
index 22807d9..3bb9076 100644
--- a/meecrowave-core/src/main/resources/META-INF/beans.xml
+++ b/meecrowave-core/src/main/resources/META-INF/beans.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <!--
     Licensed to the Apache Software Foundation (ASF) under one
     or more contributor license agreements.  See the NOTICE file
@@ -16,6 +17,9 @@
     specific language governing permissions and limitations
     under the License.
 -->
-<beans>
-    <trim/>
-</beans>
+<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+        http://xmlns.jcp.org/xml/ns/javaee
+        http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
+       version="2.0" bean-discovery-mode="none"/>
diff --git a/meecrowave-core/src/test/java/org/apache/meecrowave/api/ListeningTest.java b/meecrowave-core/src/test/java/org/apache/meecrowave/test/api/ListeningTest.java
similarity index 93%
rename from meecrowave-core/src/test/java/org/apache/meecrowave/api/ListeningTest.java
rename to meecrowave-core/src/test/java/org/apache/meecrowave/test/api/ListeningTest.java
index 7aa57e6..613eaeb 100644
--- a/meecrowave-core/src/test/java/org/apache/meecrowave/api/ListeningTest.java
+++ b/meecrowave-core/src/test/java/org/apache/meecrowave/test/api/ListeningTest.java
@@ -16,11 +16,12 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.meecrowave.api;
+package org.apache.meecrowave.test.api;
 
-import org.apache.catalina.LifecycleException;
-import org.apache.meecrowave.Meecrowave;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.event.Observes;
@@ -31,14 +32,16 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.client.Client;
 import javax.ws.rs.client.ClientBuilder;
 import javax.ws.rs.core.MediaType;
-import java.util.ArrayList;
-import java.util.List;
 
-import static org.junit.Assert.assertEquals;
+import org.apache.meecrowave.Meecrowave;
+import org.apache.meecrowave.api.ListeningBase;
+import org.apache.meecrowave.api.StartListening;
+import org.apache.meecrowave.api.StopListening;
+import org.junit.Test;
 
 public class ListeningTest {
     @Test
-    public void events() throws LifecycleException {
+    public void events() {
         final Listener listener;
         final String base;
         int count = 0;


Mime
View raw message