You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by rm...@apache.org on 2016/11/09 11:52:32 UTC

[3/5] deltaspike git commit: adding @Source and @Filter to ensure we don't break existing applications

adding @Source and @Filter to ensure we don't break existing applications


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

Branch: refs/heads/master
Commit: 3f8252eb797ffba6e54917afdbd720937c0fe3b0
Parents: 0cb288d
Author: rmannibucau <rm...@apache.org>
Authored: Mon Nov 7 11:59:40 2016 +0100
Committer: rmannibucau <rm...@apache.org>
Committed: Mon Nov 7 11:59:40 2016 +0100

----------------------------------------------------------------------
 .../deltaspike/core/api/config/Filter.java      | 40 ++++++++++++++++++++
 .../deltaspike/core/api/config/Source.java      | 40 ++++++++++++++++++++
 .../impl/config/ConfigurationExtension.java     |  9 +++--
 .../core/api/config/injectable/CdiFilter.java   |  2 +
 .../core/api/config/injectable/CdiSource.java   |  2 +
 5 files changed, 90 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/3f8252eb/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/Filter.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/Filter.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/Filter.java
new file mode 100644
index 0000000..12ae2d9
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/Filter.java
@@ -0,0 +1,40 @@
+/*
+ * 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.api.config;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Marker to let DeltaSpike pick automatically the decorated instance
+ * as a ConfigFilter of current CDI module.
+ *
+ * The underlying Bean should be normal-scoped.
+ */
+@Target({ METHOD, TYPE })
+@Retention(RUNTIME)
+@Documented
+public @interface Filter
+{
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/3f8252eb/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/Source.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/Source.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/Source.java
new file mode 100644
index 0000000..5061fa8
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/Source.java
@@ -0,0 +1,40 @@
+/*
+ * 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.api.config;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Marker to let DeltaSpike pick automatically the decorated instance
+ * as a ConfigSource of current CDI module.
+ *
+ * The underlying Bean should be normal-scoped.
+ */
+@Target({ METHOD, TYPE })
+@Retention(RUNTIME)
+@Documented
+public @interface Source
+{
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/3f8252eb/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 63b1867..65e3f2a 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
@@ -45,7 +45,9 @@ import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.deltaspike.core.api.config.ConfigProperty;
 import org.apache.deltaspike.core.api.config.ConfigResolver;
+import org.apache.deltaspike.core.api.config.Filter;
 import org.apache.deltaspike.core.api.config.PropertyFileConfig;
+import org.apache.deltaspike.core.api.config.Source;
 import org.apache.deltaspike.core.api.exclude.Exclude;
 import org.apache.deltaspike.core.api.provider.BeanProvider;
 import org.apache.deltaspike.core.spi.activation.Deactivatable;
@@ -127,9 +129,7 @@ public class ConfigurationExtension implements Extension, Deactivatable
 
     public void findSources(@Observes ProcessBean<? extends ConfigSource> source)
     {
-        final Class<?> beanClass = source.getBean().getBeanClass();
-        if (beanClass != null && beanClass.getName().startsWith("org.apache.deltaspike.core.impl.config.")) // built-in
-        {
+        if (!source.getAnnotated().isAnnotationPresent(Source.class)) {
             return;
         }
         cdiSources.add(source.getBean());
@@ -137,6 +137,9 @@ public class ConfigurationExtension implements Extension, Deactivatable
 
     public void findFilters(@Observes ProcessBean<? extends ConfigFilter> filter)
     {
+        if (!filter.getAnnotated().isAnnotationPresent(Filter.class)) {
+            return;
+        }
         cdiFilters.add(filter.getBean());
     }
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/3f8252eb/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/injectable/CdiFilter.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/injectable/CdiFilter.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/injectable/CdiFilter.java
index 8ca6031..5f5023a 100644
--- a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/injectable/CdiFilter.java
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/injectable/CdiFilter.java
@@ -18,10 +18,12 @@
  */
 package org.apache.deltaspike.test.core.api.config.injectable;
 
+import org.apache.deltaspike.core.api.config.Filter;
 import org.apache.deltaspike.core.spi.config.ConfigFilter;
 
 import javax.enterprise.context.ApplicationScoped;
 
+@Filter
 @ApplicationScoped
 public class CdiFilter implements ConfigFilter
 {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/3f8252eb/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/injectable/CdiSource.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/injectable/CdiSource.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/injectable/CdiSource.java
index facd83f..951a9d1 100644
--- a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/injectable/CdiSource.java
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/injectable/CdiSource.java
@@ -18,12 +18,14 @@
  */
 package org.apache.deltaspike.test.core.api.config.injectable;
 
+import org.apache.deltaspike.core.api.config.Source;
 import org.apache.deltaspike.core.impl.config.MapConfigSource;
 
 import javax.enterprise.context.ApplicationScoped;
 import java.util.HashMap;
 import java.util.Map;
 
+@Source
 @ApplicationScoped
 public class CdiSource extends MapConfigSource
 {