This is an automated email from the ASF dual-hosted git repository.

radcortez pushed a commit to branch TOMEE-2408
in repository https://gitbox.apache.org/repos/asf/tomee.git


The following commit(s) were added to refs/heads/TOMEE-2408 by this push:
     new 2ffed70  TOMEE-2408 - Refactored the way to add MP libraries in the 
container scanner. Added an event to allow to decouple the code and register 
the required libraries when needed.
2ffed70 is described below

commit 2ffed7081e627b2d65dbf0d5c9c33b307567fc5c
Author: Roberto Cortez <radcor...@yahoo.com>
AuthorDate: Fri Feb 1 19:17:11 2019 +0000

    TOMEE-2408 - Refactored the way to add MP libraries in the container 
scanner. Added an event to allow to decouple the code and register the required 
libraries when needed.
---
 .../apache/openejb/config/DeploymentLoader.java    |  6 +++-
 .../config/event/AfterContainerUrlScanEvent.java   | 42 ++++++++++++++++++++++
 .../org/apache/tomee/catalina/TomcatLoader.java    |  2 --
 .../java/org/apache/tomee/installer/Installer.java |  2 --
 .../microprofile/TomEEMicroProfileListener.java    | 34 ++++++++++++++++++
 5 files changed, 81 insertions(+), 5 deletions(-)

diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
index 9b56bdb..9a09802 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
@@ -25,6 +25,8 @@ import org.apache.openejb.api.RemoteClient;
 import org.apache.openejb.cdi.CompositeBeans;
 import org.apache.openejb.classloader.ClassLoaderConfigurer;
 import org.apache.openejb.classloader.WebAppEnricher;
+import org.apache.openejb.config.event.AfterContainerUrlScanEvent;
+import org.apache.openejb.config.event.BeforeAppInfoBuilderEvent;
 import org.apache.openejb.config.event.BeforeDeploymentEvent;
 import org.apache.openejb.config.sys.Resources;
 import org.apache.openejb.core.EmptyResourcesClassLoader;
@@ -1106,7 +1108,7 @@ public class DeploymentLoader implements 
DeploymentFilterable {
                         try {
                             UrlSet urlSet = new 
UrlSet(ParentClassLoaderFinder.Helper.get());
                             urlSet = URLs.cullSystemJars(urlSet);
-                            final PatternFilter containerIncludes = new 
PatternFilter(SystemInstance.get().getProperty(OPENEJB_CONTAINER_INCLUDES, 
".*(geronimo|mp-jwt|mp-common|failsafe).*"));
+                            final PatternFilter containerIncludes = new 
PatternFilter(SystemInstance.get().getProperty(OPENEJB_CONTAINER_INCLUDES, ""));
                             final PatternFilter containerExcludes = new 
PatternFilter(SystemInstance.get().getProperty(OPENEJB_CONTAINER_EXCLUDES, ""));
                             urlSet = 
NewLoaderLogic.applyBuiltinExcludes(urlSet, containerIncludes, 
containerExcludes);
                             containerUrls = urlSet.getUrls();
@@ -1136,6 +1138,8 @@ public class DeploymentLoader implements 
DeploymentFilterable {
                 containerUrls = Collections.emptyList();
             }
         }
+
+        SystemInstance.get().fireEvent(new 
AfterContainerUrlScanEvent(containerUrls));
     }
 
     public static List<URL> filterWebappUrls(final URL[] webUrls, final Filter 
filter, final URL exclusions) {
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/config/event/AfterContainerUrlScanEvent.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/config/event/AfterContainerUrlScanEvent.java
new file mode 100644
index 0000000..2594e06
--- /dev/null
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/config/event/AfterContainerUrlScanEvent.java
@@ -0,0 +1,42 @@
+/*
+ * 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.openejb.config.event;
+
+import org.apache.openejb.observer.Event;
+
+import java.net.URL;
+import java.util.List;
+
+@Event
+public class AfterContainerUrlScanEvent {
+    private List<URL> containerUrls;
+
+    public AfterContainerUrlScanEvent(final List<URL> containerUrls) {
+        this.containerUrls = containerUrls;
+    }
+
+    public List<URL> getContainerUrls() {
+        return containerUrls;
+    }
+
+    @Override
+    public String toString() {
+        return "AfterContainerUrlScanEvent{" +
+               "containerUrls=" + containerUrls +
+               '}';
+    }
+}
diff --git 
a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatLoader.java
 
b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatLoader.java
index fe48a09..79dcbee 100644
--- 
a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatLoader.java
+++ 
b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatLoader.java
@@ -215,8 +215,6 @@ public class TomcatLoader implements Loader {
         // for compatibility purpose, no more used normally by our trunk
         SystemInstance.get().setComponent(WebDeploymentListeners.class, new 
WebDeploymentListeners());
 
-        optionalService(properties, 
"org.apache.tomee.microprofile.MicroProfileService");
-
         // tomee webapp enricher
         final TomEEClassLoaderEnricher classLoaderEnricher = new 
TomEEClassLoaderEnricher();
         SystemInstance.get().setComponent(WebAppEnricher.class, 
classLoaderEnricher);
diff --git 
a/tomee/tomee-common/src/main/java/org/apache/tomee/installer/Installer.java 
b/tomee/tomee-common/src/main/java/org/apache/tomee/installer/Installer.java
index cfa4742..bac2c9c 100644
--- a/tomee/tomee-common/src/main/java/org/apache/tomee/installer/Installer.java
+++ b/tomee/tomee-common/src/main/java/org/apache/tomee/installer/Installer.java
@@ -794,8 +794,6 @@ public class Installer implements InstallerInterface {
                 systemPropertiesWriter.write("#\n");
                 systemPropertiesWriter.write("# Which paths / libraries should 
be scanned?\n");
                 systemPropertiesWriter.write("openejb.scan.webapp.container = 
true\n");
-                
systemPropertiesWriter.write("openejb.scan.webapp.container.includes = 
.*(geronimo|mp-jwt|mp-common|failsafe).*\n");
-                
systemPropertiesWriter.write("openejb.scan.webapp.container.excludes = \n");
 
             } catch (final IOException e) {
                 // ignored, this file is far to be mandatory
diff --git 
a/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/TomEEMicroProfileListener.java
 
b/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/TomEEMicroProfileListener.java
index 353ac8e..1f349e5 100644
--- 
a/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/TomEEMicroProfileListener.java
+++ 
b/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/TomEEMicroProfileListener.java
@@ -22,15 +22,49 @@ import 
org.apache.geronimo.microprofile.metrics.common.jaxrs.MetricsEndpoints;
 import org.apache.geronimo.microprofile.metrics.jaxrs.CdiMetricsEndpoints;
 import org.apache.geronimo.microprofile.openapi.jaxrs.OpenAPIEndpoint;
 import org.apache.openejb.assembler.classic.WebAppInfo;
+import org.apache.openejb.config.event.AfterContainerUrlScanEvent;
 import org.apache.openejb.observer.Observes;
 import org.apache.openejb.observer.event.BeforeEvent;
 import org.apache.tomee.catalina.event.AfterApplicationCreated;
+import org.apache.tomee.installer.Paths;
 
 import javax.servlet.ServletContext;
 import javax.servlet.ServletRegistration;
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.Collection;
+import java.util.List;
 
 public class TomEEMicroProfileListener {
+    private static final String[] MICROPROFILE_LIBS_IMPLS_PREFIXES = new 
String[]{
+            "mp-common",
+            "geronimo-config",
+            "safeguard",
+            "mp-jwt",
+            "geronimo-health",
+            "geronimo-metrics",
+            "geronimo-opentracing",
+            "geronimo-openapi",
+            "cxf-rt-rs-mp-client",
+            };
+
+    @SuppressWarnings("Duplicates")
+    public void enrichContainerWithMicroProfile(@Observes final 
AfterContainerUrlScanEvent afterContainerUrlScanEvent) {
+        final List<URL> containerUrls = 
afterContainerUrlScanEvent.getContainerUrls();
+        final Paths paths = new Paths(new 
File(System.getProperty("openejb.home")));
+        for (final String prefix : MICROPROFILE_LIBS_IMPLS_PREFIXES) {
+            final File file = paths.findTomEELibJar(prefix);
+            if (file != null) {
+                try {
+                    containerUrls.add(file.toURI().toURL());
+                } catch (final MalformedURLException e) {
+                    // ignored
+                }
+            }
+        }
+    }
+
     public void processApplication(@Observes final 
BeforeEvent<AfterApplicationCreated> afterApplicationCreated) {
         final ServletContext context = 
afterApplicationCreated.getEvent().getContext();
         final WebAppInfo webApp = afterApplicationCreated.getEvent().getWeb();

Reply via email to