Enrich classloader to add MicroProfile Config implementation Beans.
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/2421c524 Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/2421c524 Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/2421c524 Branch: refs/heads/master Commit: 2421c524f0928d476701729eb575624f73f7b91e Parents: 856f728 Author: Roberto Cortez <radcor...@yahoo.com> Authored: Fri Mar 2 01:20:01 2018 +0000 Committer: Roberto Cortez <radcor...@yahoo.com> Committed: Fri Mar 2 01:20:01 2018 +0000 ---------------------------------------------------------------------- .../src/main/resources/default.exclusions | 4 +- .../org/apache/tomee/catalina/TomcatLoader.java | 2 + .../MicroProfileClassLoaderEnricher.java | 53 ++++++++++++++++++++ .../tomee/microprofile/MicroProfileService.java | 46 +++++++++++++++++ 4 files changed, 104 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/2421c524/container/openejb-core/src/main/resources/default.exclusions ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/resources/default.exclusions b/container/openejb-core/src/main/resources/default.exclusions index f0e543b..d46396b 100644 --- a/container/openejb-core/src/main/resources/default.exclusions +++ b/container/openejb-core/src/main/resources/default.exclusions @@ -79,7 +79,9 @@ jfxrt.jar jnr- johnzon- fusemq-leveldb- -geronimo- +geronimo-connector +geronimo-javamail +geronimo-transaction google- gragent.jar groovy- http://git-wip-us.apache.org/repos/asf/tomee/blob/2421c524/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatLoader.java ---------------------------------------------------------------------- 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 8b066e5..22d9337 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 @@ -234,6 +234,8 @@ public class TomcatLoader implements Loader { } } + optionalService(properties, "org.apache.tomee.microprofile.MicroProfileService"); + // optional services if (optionalService(properties, "org.apache.tomee.webservices.TomeeJaxRsService")) { // in embedded mode we use regex, in tomcat we use tomcat servlet mapping http://git-wip-us.apache.org/repos/asf/tomee/blob/2421c524/tomee/tomee-microprofile/src/main/java/org/apache/tomee/microprofile/MicroProfileClassLoaderEnricher.java ---------------------------------------------------------------------- diff --git a/tomee/tomee-microprofile/src/main/java/org/apache/tomee/microprofile/MicroProfileClassLoaderEnricher.java b/tomee/tomee-microprofile/src/main/java/org/apache/tomee/microprofile/MicroProfileClassLoaderEnricher.java new file mode 100644 index 0000000..7100f87 --- /dev/null +++ b/tomee/tomee-microprofile/src/main/java/org/apache/tomee/microprofile/MicroProfileClassLoaderEnricher.java @@ -0,0 +1,53 @@ +/* + * 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.tomee.microprofile; + +import org.apache.openejb.classloader.WebAppEnricher; +import org.apache.tomee.installer.Paths; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Collection; +import java.util.HashSet; + +public class MicroProfileClassLoaderEnricher implements WebAppEnricher { + private static final String[] MICROPROFILE_LIBS_IMPLS_PREFIXES = new String[]{ + "geronimo-config-impl" + }; + + @SuppressWarnings("Duplicates") + @Override + public URL[] enrichment(final ClassLoader webappClassLaoder) { + final Collection<URL> urls = new HashSet<>(); + + // from prefix + final Paths paths = new Paths(new File(System.getProperty("openejb.home"))); // parameter is useless + for (final String prefix : MICROPROFILE_LIBS_IMPLS_PREFIXES) { + final File file = paths.findTomEELibJar(prefix); + if (file != null) { + try { + urls.add(file.toURI().toURL()); + } catch (final MalformedURLException e) { + // ignored + } + } + } + + return urls.toArray(new URL[urls.size()]); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/2421c524/tomee/tomee-microprofile/src/main/java/org/apache/tomee/microprofile/MicroProfileService.java ---------------------------------------------------------------------- diff --git a/tomee/tomee-microprofile/src/main/java/org/apache/tomee/microprofile/MicroProfileService.java b/tomee/tomee-microprofile/src/main/java/org/apache/tomee/microprofile/MicroProfileService.java new file mode 100644 index 0000000..94a4bc4 --- /dev/null +++ b/tomee/tomee-microprofile/src/main/java/org/apache/tomee/microprofile/MicroProfileService.java @@ -0,0 +1,46 @@ +/* + * 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.tomee.microprofile; + +import org.apache.openejb.component.ClassLoaderEnricher; +import org.apache.openejb.loader.SystemInstance; +import org.apache.openejb.spi.Service; + +import java.net.URL; +import java.util.Properties; + +/** + * This is used as an optional service in org.apache.tomee.catalina.TomcatLoader + */ +@SuppressWarnings("unused") +public class MicroProfileService implements Service { + @Override + public void init(final Properties props) throws Exception { + enrichClassLoaderWithMicroProfile(); + } + + private void enrichClassLoaderWithMicroProfile() { + final ClassLoaderEnricher enricher = SystemInstance.get().getComponent(ClassLoaderEnricher.class); + if (null != enricher) { + final MicroProfileClassLoaderEnricher classLoaderEnricher = new MicroProfileClassLoaderEnricher(); + for (final URL url : classLoaderEnricher.enrichment(null)) { + enricher.addUrl(url); + } + } + SystemInstance.get().removeObserver(this); + } +}