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-1017 ConfigValidator (first draft)
Date Mon, 02 Nov 2015 00:07:13 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master a6849f047 -> bfb85f3c2


DELTASPIKE-1017 ConfigValidator (first draft)


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

Branch: refs/heads/master
Commit: bfb85f3c2a0b673e92143a48b740d04ce8313c36
Parents: a6849f0
Author: gpetracek <gpetracek@apache.org>
Authored: Mon Nov 2 01:01:59 2015 +0100
Committer: gpetracek <gpetracek@apache.org>
Committed: Mon Nov 2 01:02:24 2015 +0100

----------------------------------------------------------------------
 .../core/spi/config/ConfigValidator.java        | 30 ++++++++++++++++++++
 .../impl/config/ConfigurationExtension.java     | 22 ++++++++++++++
 2 files changed, 52 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/bfb85f3c/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/spi/config/ConfigValidator.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/spi/config/ConfigValidator.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/spi/config/ConfigValidator.java
new file mode 100644
index 0000000..dc9b62a
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/spi/config/ConfigValidator.java
@@ -0,0 +1,30 @@
+/*
+ * 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.deltaspike.core.spi.config;
+
+import java.util.Set;
+
+public interface ConfigValidator
+{
+    /**
+     * @return a set of violation-messages if an invalid state is found
+     * those messages will be used to add one deployment-problem per message
+     */
+    Set<String> processValidation();
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/bfb85f3c/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java
index 48e0f17..09ac956 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java
@@ -37,8 +37,10 @@ import org.apache.deltaspike.core.api.config.PropertyFileConfig;
 import org.apache.deltaspike.core.api.exclude.Exclude;
 import org.apache.deltaspike.core.spi.activation.Deactivatable;
 import org.apache.deltaspike.core.spi.config.ConfigSource;
+import org.apache.deltaspike.core.spi.config.ConfigValidator;
 import org.apache.deltaspike.core.util.ClassDeactivationUtils;
 import org.apache.deltaspike.core.util.ClassUtils;
+import org.apache.deltaspike.core.util.ServiceUtils;
 
 /**
  * This extension handles {@link org.apache.deltaspike.core.api.config.PropertyFileConfig}s
@@ -136,6 +138,8 @@ public class ConfigurationExtension implements Extension, Deactivatable
 
         // finally add all
         ConfigResolver.addConfigSources(configSources);
+
+        processConfigurationValidation(adv);
     }
 
     /**
@@ -207,4 +211,22 @@ public class ConfigurationExtension implements Extension, Deactivatable
                 propertyFileConfigClass.getName() + " points to an invalid file: '" + fileName
+ "'", e);
         }
     }
+
+    protected void processConfigurationValidation(AfterDeploymentValidation adv)
+    {
+        for (ConfigValidator configValidator : ServiceUtils.loadServiceImplementations(ConfigValidator.class))
+        {
+            Set<String> violations = configValidator.processValidation();
+
+            if (violations == null)
+            {
+                continue;
+            }
+
+            for (String violation : violations)
+            {
+                adv.addDeploymentProblem(new IllegalStateException(violation));
+            }
+        }
+    }
 }


Mime
View raw message