bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1504027 - in /bval/branches/bval-11: bval-jsr303/src/main/java/org/apache/bval/cdi/ bval-tck11/src/main/java/org/apache/bval/arquillian/
Date Wed, 17 Jul 2013 07:25:12 GMT
Author: rmannibucau
Date: Wed Jul 17 07:25:11 2013
New Revision: 1504027

URL: http://svn.apache.org/r1504027
Log:
hacking an arquillian extension to add BValInterceptor

Added:
    bval/branches/bval-11/bval-tck11/src/main/java/org/apache/bval/arquillian/CdiMethodValidationProcessor.java
Modified:
    bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/cdi/BValExtension.java
    bval/branches/bval-11/bval-tck11/src/main/java/org/apache/bval/arquillian/BValArquillianExtension.java

Modified: bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/cdi/BValExtension.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/cdi/BValExtension.java?rev=1504027&r1=1504026&r2=1504027&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/cdi/BValExtension.java
(original)
+++ bval/branches/bval-11/bval-jsr303/src/main/java/org/apache/bval/cdi/BValExtension.java
Wed Jul 17 07:25:11 2013
@@ -49,7 +49,7 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 // mainly copied from deltaspike to not force users to use deltaspike
-// which would be a pain in servers
+// which would be a pain in app servers
 // TODO: get rid of beans.xml adding interceptor automatically
 public class BValExtension implements Extension {
     private static final Logger LOGGER = Logger.getLogger(BValExtension.class.getName());
@@ -85,6 +85,7 @@ public class BValExtension implements Ex
 
     public void addBvalBinding(final @Observes BeforeBeanDiscovery beforeBeanDiscovery, final
BeanManager beanManager) {
         beforeBeanDiscovery.addInterceptorBinding(BValBinding.class);
+        beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(BValInterceptor.class));
     }
 
     public <A> void processAnnotatedType(final @Observes ProcessAnnotatedType<A>
pat) {

Modified: bval/branches/bval-11/bval-tck11/src/main/java/org/apache/bval/arquillian/BValArquillianExtension.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-tck11/src/main/java/org/apache/bval/arquillian/BValArquillianExtension.java?rev=1504027&r1=1504026&r2=1504027&view=diff
==============================================================================
--- bval/branches/bval-11/bval-tck11/src/main/java/org/apache/bval/arquillian/BValArquillianExtension.java
(original)
+++ bval/branches/bval-11/bval-tck11/src/main/java/org/apache/bval/arquillian/BValArquillianExtension.java
Wed Jul 17 07:25:11 2013
@@ -18,11 +18,13 @@
  */
 package org.apache.bval.arquillian;
 
+import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor;
 import org.jboss.arquillian.core.spi.LoadableExtension;
 import org.jboss.arquillian.test.spi.TestEnricher;
 
 public class BValArquillianExtension implements LoadableExtension {
     public void register(final ExtensionBuilder builder) {
-        builder.service(TestEnricher.class, EJBEnricher.class);
+        builder.service(TestEnricher.class, EJBEnricher.class)
+            .service(ApplicationArchiveProcessor.class, CdiMethodValidationProcessor.class);
     }
 }

Added: bval/branches/bval-11/bval-tck11/src/main/java/org/apache/bval/arquillian/CdiMethodValidationProcessor.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-tck11/src/main/java/org/apache/bval/arquillian/CdiMethodValidationProcessor.java?rev=1504027&view=auto
==============================================================================
--- bval/branches/bval-11/bval-tck11/src/main/java/org/apache/bval/arquillian/CdiMethodValidationProcessor.java
(added)
+++ bval/branches/bval-11/bval-tck11/src/main/java/org/apache/bval/arquillian/CdiMethodValidationProcessor.java
Wed Jul 17 07:25:11 2013
@@ -0,0 +1,87 @@
+/*
+ * 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.bval.arquillian;
+
+import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor;
+import org.jboss.arquillian.test.spi.TestClass;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ArchivePath;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.Node;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.container.ManifestContainer;
+import org.jboss.shrinkwrap.api.container.WebContainer;
+import org.jboss.shrinkwrap.impl.base.MemoryMapArchiveImpl;
+import org.jboss.shrinkwrap.impl.base.NodeImpl;
+
+import java.lang.reflect.Field;
+import java.util.Map;
+
+public class CdiMethodValidationProcessor implements ApplicationArchiveProcessor {
+    private static final String BEANS_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+
+            "<beans xmlns=\"http://java.sun.com/xml/ns/javaee\"\n" +
+            "       xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
+            "       xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee\n" +
+            "      http://java.sun.com/xml/ns/javaee/beans_1_0.xsd\">\n" +
+            "  <interceptors>\n" +
+            "    <class>org.apache.bval.cdi.BValInterceptor</class>\n" +
+            "  </interceptors>\n" +
+            "</beans>";
+
+    public void process(final Archive<?> applicationArchive, final TestClass testClass)
{
+        final String path;
+        if (WebContainer.class.isInstance(applicationArchive)) {
+            path = "WEB-INF/beans.xml";
+        } else {
+            path = "META-INF-INF/beans.xml";
+        }
+
+        final Node beansXml = applicationArchive.get(path);
+        if (beansXml != null && beansXml.getAsset() == EmptyAsset.INSTANCE) {
+            final Map<ArchivePath, NodeImpl> content = getInternal(applicationArchive);
+            content.remove(ArchivePaths.create(path));
+            if (path.startsWith("META-INF")) {
+                ManifestContainer.class.cast(applicationArchive).addAsManifestResource(new
StringAsset(BEANS_XML), "beans.xml");
+            } else {
+                WebContainer.class.cast(applicationArchive).addAsWebInfResource(new StringAsset(BEANS_XML),
"beans.xml");
+            }
+        }
+    }
+
+    private Map getInternal(Archive<?> applicationArchive) {
+        return get(Map.class, get(MemoryMapArchiveImpl.class, applicationArchive, "archive"),
"content");
+    }
+
+    private static <T> T get(final Class<T> clazz, final Object instance, final
String field) {
+        Class<?> c = instance.getClass();
+        while (c != Object.class && c != null) {
+            final Field f;
+            try {
+                f = c.getDeclaredField(field);
+                f.setAccessible(true);
+                return clazz.cast(f.get(instance));
+            } catch (final Exception e) {
+                // no-op
+            }
+            c = c.getSuperclass();
+        }
+        return null;
+    }
+}



Mime
View raw message