deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject git commit: DELTASPIKE-611 support for @Exclude on abstract classes
Date Mon, 26 May 2014 14:29:56 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 801f28269 -> 900d57084


DELTASPIKE-611 support for @Exclude on abstract classes


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

Branch: refs/heads/master
Commit: 900d570843e4585fe50c7b4682f7b149aba25ffa
Parents: 801f282
Author: gpetracek <gpetracek@apache.org>
Authored: Mon May 26 16:14:13 2014 +0200
Committer: gpetracek <gpetracek@apache.org>
Committed: Mon May 26 16:27:56 2014 +0200

----------------------------------------------------------------------
 .../exclude/extension/ExcludeExtension.java     | 37 ++++++++-
 .../core/api/exclude/uc001/BaseEntity1.java     | 23 ++++++
 .../core/api/exclude/uc001/BaseEntity2.java     | 26 +++++++
 .../core/api/exclude/uc001/BaseEntity3.java     | 26 +++++++
 .../test/core/api/exclude/uc001/Entity1.java    | 23 ++++++
 .../test/core/api/exclude/uc001/Entity2.java    | 23 ++++++
 .../test/core/api/exclude/uc001/Entity3.java    | 23 ++++++
 .../api/exclude/uc001/EntityExcludeTest.java    | 80 ++++++++++++++++++++
 8 files changed, 258 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/900d5708/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java
index 22dd33c..d819f13 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java
@@ -41,6 +41,7 @@ import javax.enterprise.inject.spi.ProcessAnnotatedType;
 import javax.enterprise.util.Nonbinding;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -152,13 +153,13 @@ public class ExcludeExtension implements Extension, Deactivatable
         //also forces deterministic project-stage initialization
         ProjectStage projectStage = ProjectStageProducer.getInstance().getProjectStage();
 
-        if (!processAnnotatedType.getAnnotatedType().getJavaClass().isAnnotationPresent(Exclude.class))
+        Exclude exclude = extractExcludeAnnotation(processAnnotatedType.getAnnotatedType().getJavaClass());
+
+        if (exclude == null)
         {
             return;
         }
 
-        Exclude exclude = (Exclude) processAnnotatedType.getAnnotatedType().getJavaClass().getAnnotation(Exclude.class);
-
         if (!evalExcludeWithoutCondition(processAnnotatedType, exclude))
         {
             return; //veto called already
@@ -177,6 +178,36 @@ public class ExcludeExtension implements Extension, Deactivatable
         evalExcludeWithExpression(processAnnotatedType, exclude);
     }
 
+    //only support the physical usage and inheritance if @Exclude comes from an abstract
class
+    //TODO re-visit the impact of java.lang.annotation.Inherited (for @Exclude) for the available
use-cases
+    protected Exclude extractExcludeAnnotation(Class<?> currentClass)
+    {
+        Exclude result = currentClass.getAnnotation(Exclude.class);
+
+        if (result != null)
+        {
+            return result;
+        }
+
+        currentClass = currentClass.getSuperclass();
+
+        while (!Object.class.equals(currentClass) && currentClass != null)
+        {
+            if (Modifier.isAbstract(currentClass.getModifiers()))
+            {
+                result = currentClass.getAnnotation(Exclude.class);
+            }
+
+            if (result != null)
+            {
+                return result;
+            }
+
+            currentClass = currentClass.getSuperclass();
+        }
+        return null;
+    }
+
     protected void vetoCustomProjectStageBeans(ProcessAnnotatedType processAnnotatedType)
     {
         //currently there is a veto for all project-stage implementations,

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/900d5708/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/BaseEntity1.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/BaseEntity1.java
b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/BaseEntity1.java
new file mode 100644
index 0000000..e5695ce
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/BaseEntity1.java
@@ -0,0 +1,23 @@
+/*
+ * 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.test.core.api.exclude.uc001;
+
+public abstract class BaseEntity1
+{
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/900d5708/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/BaseEntity2.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/BaseEntity2.java
b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/BaseEntity2.java
new file mode 100644
index 0000000..5c744ac
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/BaseEntity2.java
@@ -0,0 +1,26 @@
+/*
+ * 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.test.core.api.exclude.uc001;
+
+import org.apache.deltaspike.core.api.exclude.Exclude;
+
+@Exclude
+public abstract class BaseEntity2
+{
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/900d5708/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/BaseEntity3.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/BaseEntity3.java
b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/BaseEntity3.java
new file mode 100644
index 0000000..4110e2a
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/BaseEntity3.java
@@ -0,0 +1,26 @@
+/*
+ * 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.test.core.api.exclude.uc001;
+
+import org.apache.deltaspike.core.api.exclude.Exclude;
+
+@Exclude
+public class BaseEntity3
+{
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/900d5708/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/Entity1.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/Entity1.java
b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/Entity1.java
new file mode 100644
index 0000000..55d3c64
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/Entity1.java
@@ -0,0 +1,23 @@
+/*
+ * 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.test.core.api.exclude.uc001;
+
+public class Entity1 extends BaseEntity1
+{
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/900d5708/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/Entity2.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/Entity2.java
b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/Entity2.java
new file mode 100644
index 0000000..1d2bdaa
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/Entity2.java
@@ -0,0 +1,23 @@
+/*
+ * 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.test.core.api.exclude.uc001;
+
+public class Entity2 extends BaseEntity2
+{
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/900d5708/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/Entity3.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/Entity3.java
b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/Entity3.java
new file mode 100644
index 0000000..dad05fc
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/Entity3.java
@@ -0,0 +1,23 @@
+/*
+ * 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.test.core.api.exclude.uc001;
+
+public class Entity3 extends BaseEntity3
+{
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/900d5708/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/EntityExcludeTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/EntityExcludeTest.java
b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/EntityExcludeTest.java
new file mode 100644
index 0000000..9d54501
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/exclude/uc001/EntityExcludeTest.java
@@ -0,0 +1,80 @@
+/*
+* 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.test.core.api.exclude.uc001;
+
+import org.apache.deltaspike.core.api.provider.BeanProvider;
+import org.apache.deltaspike.core.util.ProjectStageProducer;
+import org.apache.deltaspike.test.util.ArchiveUtils;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(Arquillian.class)
+public class EntityExcludeTest
+{
+    @Deployment
+    public static WebArchive deploy()
+    {
+        String simpleName = EntityExcludeTest.class.getSimpleName();
+        String archiveName = simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1);
+
+        System.setProperty("org.apache.deltaspike.ProjectStage", "Development");
+        ProjectStageProducer.setProjectStage(null);
+
+        JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, archiveName + ".jar")
+                .addPackage(EntityExcludeTest.class.getPackage())
+                .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
+
+        return ShrinkWrap.create(WebArchive.class, archiveName + ".war")
+                .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive())
+                .addAsLibraries(testJar)
+                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
+    }
+
+    @Test
+    public void entityWithoutExclusion()
+    {
+        Entity1 entity1 = BeanProvider.getContextualReference(Entity1.class, true);
+        Assert.assertNotNull(entity1);
+    }
+
+    @Test
+    public void excludedEntity()
+    {
+        Entity2 entity2 = BeanProvider.getContextualReference(Entity2.class, true);
+        Assert.assertNull(entity2);
+    }
+
+    //TODO discuss it - if we don't need it, we can use @Inherited
+    @Test
+    public void excludedBaseClassWithoutInheritance()
+    {
+        BaseEntity3 baseEntity3 = BeanProvider.getContextualReference(BaseEntity3.class,
true);
+        Assert.assertTrue(baseEntity3 instanceof Entity3);
+
+        Entity3 entity3 = BeanProvider.getContextualReference(Entity3.class, true);
+        Assert.assertNotNull(entity3);
+    }
+}


Mime
View raw message