deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject deltaspike git commit: DELTASPIKE-897 check for invalid ClassDeactivator configurations
Date Tue, 28 Jul 2015 17:17:07 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 346371b9f -> b4a68137b


DELTASPIKE-897 check for invalid ClassDeactivator configurations


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/b4a68137
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/b4a68137
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/b4a68137

Branch: refs/heads/master
Commit: b4a68137bbac040e61bdddf5c2914f44e06fe845
Parents: 346371b
Author: gpetracek <gpetracek@apache.org>
Authored: Tue Jul 28 19:10:55 2015 +0200
Committer: gpetracek <gpetracek@apache.org>
Committed: Tue Jul 28 19:11:47 2015 +0200

----------------------------------------------------------------------
 .../core/api/config/base/CoreBaseConfig.java    | 22 ++++++++++++++++++++
 .../core/util/ClassDeactivationUtils.java       | 20 ++++++++++++++++++
 2 files changed, 42 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b4a68137/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/base/CoreBaseConfig.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/base/CoreBaseConfig.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/base/CoreBaseConfig.java
index 113ca21..e36048a 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/base/CoreBaseConfig.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/base/CoreBaseConfig.java
@@ -42,6 +42,28 @@ public interface CoreBaseConfig extends DeltaSpikeBaseConfig
                         .getValue();
     }
 
+    interface Validation
+    {
+        ViolationMode VIOLATION_MODE =
+                ConfigResolver.resolve("deltaspike.validation.violation-mode")
+                        .as(ViolationMode.class, new ConfigResolver.Converter<ViolationMode>()
+                        {
+                            @Override
+                            public ViolationMode convert(String value)
+                            {
+                                return ViolationMode.valueOf(value);
+                            }
+                        })
+                        .withCurrentProjectStage(true)
+                        .withDefault(ViolationMode.FAIL)
+                        .getValue();
+
+        enum ViolationMode
+        {
+            IGNORE, WARN, FAIL
+        }
+    }
+
     interface MBeanIntegration
     {
         Boolean AUTO_UNREGISTER =

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b4a68137/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassDeactivationUtils.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassDeactivationUtils.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassDeactivationUtils.java
index a69f730..6fcd715 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassDeactivationUtils.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassDeactivationUtils.java
@@ -19,6 +19,7 @@
 package org.apache.deltaspike.core.util;
 
 import org.apache.deltaspike.core.api.config.ConfigResolver;
+import org.apache.deltaspike.core.api.config.base.CoreBaseConfig;
 import org.apache.deltaspike.core.spi.activation.ClassDeactivator;
 import org.apache.deltaspike.core.spi.activation.Deactivatable;
 
@@ -149,6 +150,25 @@ public abstract class ClassDeactivationUtils
     //synchronized isn't needed - #initDeactivatableCacheFor is already synchronized
     private static List<ClassDeactivator> initConfiguredClassDeactivators(ClassLoader
classLoader)
     {
+        if (!ServiceUtils.loadServiceImplementations(ClassDeactivator.class).isEmpty())
+        {
+            CoreBaseConfig.Validation.ViolationMode violationMode = CoreBaseConfig.Validation.VIOLATION_MODE;
+
+            String message = "It isn't supported to configure " + ClassDeactivator.class.getName()
+
+                    " via the std. service-loader config. " +
+                    "Please remove all META-INF/services/" + ClassDeactivator.class.getName()
+ " files. " +
+                    "Please configure it via the DeltaSpike-Config (e.g. META-INF/apache-deltaspike.properties).";
+
+            if (violationMode == CoreBaseConfig.Validation.ViolationMode.FAIL)
+            {
+                throw new IllegalStateException(message);
+            }
+            else if (violationMode == CoreBaseConfig.Validation.ViolationMode.WARN)
+            {
+                LOG.warning(message);
+            }
+        }
+
         List<String> classDeactivatorClassNames = ConfigResolver.getAllPropertyValues(ClassDeactivator.class.getName());
 
         List<ClassDeactivator> classDeactivators = new ArrayList<ClassDeactivator>();


Mime
View raw message