METAMODEL-1149: Packaging of META-INF files for DataContext factories

Project: http://git-wip-us.apache.org/repos/asf/metamodel-membrane/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/metamodel-membrane/commit/16e50070
Tree: http://git-wip-us.apache.org/repos/asf/metamodel-membrane/tree/16e50070
Diff: http://git-wip-us.apache.org/repos/asf/metamodel-membrane/diff/16e50070

Branch: refs/heads/master
Commit: 16e500703eb326a3d04eb93d2c8df3972ac5a72b
Parents: a91b35e
Author: Kasper Sørensen <i.am.kasper.soren...@gmail.com>
Authored: Sat Aug 5 19:49:17 2017 -0700
Committer: Kasper Sørensen <i.am.kasper.soren...@gmail.com>
Committed: Sat Aug 5 19:49:17 2017 -0700

----------------------------------------------------------------------
 .../app/CachedDataSourceRegistryWrapper.java    |  9 ++--
 .../membrane/app/MembraneStartupLogger.java     | 48 ++++++++++++++++++++
 undertow/pom.xml                                |  4 ++
 3 files changed, 57 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/metamodel-membrane/blob/16e50070/core/src/main/java/org/apache/metamodel/membrane/app/CachedDataSourceRegistryWrapper.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/metamodel/membrane/app/CachedDataSourceRegistryWrapper.java
 
b/core/src/main/java/org/apache/metamodel/membrane/app/CachedDataSourceRegistryWrapper.java
index 04a0872..77fbb77 100644
--- 
a/core/src/main/java/org/apache/metamodel/membrane/app/CachedDataSourceRegistryWrapper.java
+++ 
b/core/src/main/java/org/apache/metamodel/membrane/app/CachedDataSourceRegistryWrapper.java
@@ -19,7 +19,6 @@
 package org.apache.metamodel.membrane.app;
 
 import java.util.List;
-import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.metamodel.DataContext;
@@ -34,6 +33,7 @@ import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
 import com.google.common.cache.RemovalListener;
 import com.google.common.cache.RemovalNotification;
+import com.google.common.util.concurrent.UncheckedExecutionException;
 
 /**
  * A wrapper that adds a cache around a {@link DataSourceRegistry} in order to
@@ -54,7 +54,8 @@ public class CachedDataSourceRegistryWrapper implements 
DataSourceRegistry {
         this(delegate, DEFAULT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
     }
 
-    public CachedDataSourceRegistryWrapper(final DataSourceRegistry delegate, 
final long cacheTimeout, final TimeUnit cacheTimeoutUnit) {
+    public CachedDataSourceRegistryWrapper(final DataSourceRegistry delegate, 
final long cacheTimeout,
+            final TimeUnit cacheTimeoutUnit) {
         this.delegate = delegate;
         this.loadingCache = 
CacheBuilder.newBuilder().expireAfterAccess(cacheTimeout, 
cacheTimeoutUnit).removalListener(
                 createRemovalListener()).build(createCacheLoader());
@@ -95,8 +96,8 @@ public class CachedDataSourceRegistryWrapper implements 
DataSourceRegistry {
     @Override
     public DataContext openDataContext(final String dataSourceName) throws 
NoSuchDataSourceException {
         try {
-            return loadingCache.get(dataSourceName);
-        } catch (ExecutionException e) {
+            return loadingCache.getUnchecked(dataSourceName);
+        } catch (UncheckedExecutionException e) {
             final Throwable cause = e.getCause();
             if (cause instanceof RuntimeException) {
                 throw (RuntimeException) cause;

http://git-wip-us.apache.org/repos/asf/metamodel-membrane/blob/16e50070/core/src/main/java/org/apache/metamodel/membrane/app/MembraneStartupLogger.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/metamodel/membrane/app/MembraneStartupLogger.java
 
b/core/src/main/java/org/apache/metamodel/membrane/app/MembraneStartupLogger.java
new file mode 100644
index 0000000..fd30f8f
--- /dev/null
+++ 
b/core/src/main/java/org/apache/metamodel/membrane/app/MembraneStartupLogger.java
@@ -0,0 +1,48 @@
+/**
+ * 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.metamodel.membrane.app;
+
+import java.util.Collection;
+
+import javax.annotation.PostConstruct;
+
+import org.apache.metamodel.factory.DataContextFactory;
+import org.apache.metamodel.factory.DataContextFactoryRegistry;
+import org.apache.metamodel.factory.DataContextFactoryRegistryImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+@Component
+public class MembraneStartupLogger {
+
+    private static final Logger logger = 
LoggerFactory.getLogger(MembraneStartupLogger.class);
+
+    @PostConstruct
+    public void onStartup() {
+        final DataContextFactoryRegistry dataContextRegistry = 
DataContextFactoryRegistryImpl.getDefaultInstance();
+        final Collection<DataContextFactory> factories = 
dataContextRegistry.getFactories();
+
+        logger.info("Apache MetaModel loaded with {} DataContext factories:", 
factories.size());
+
+        for (DataContextFactory factory : factories) {
+            logger.info("- {}", factory.getClass().getName());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/metamodel-membrane/blob/16e50070/undertow/pom.xml
----------------------------------------------------------------------
diff --git a/undertow/pom.xml b/undertow/pom.xml
index d1b989a..e284c9d 100644
--- a/undertow/pom.xml
+++ b/undertow/pom.xml
@@ -57,6 +57,10 @@ under the License.
                                                                        
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                                                        
<resource>META-INF/spring.schemas</resource>
                                                                </transformer>
+                                                               <transformer
+                                                                       
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
+                                                                       
<resource>META-INF/services/org.apache.metamodel.factory.DataContextFactory</resource>
+                                                               </transformer>
                                                        </transformers>
                                                </configuration>
                                        </execution>

Reply via email to