[webbeans-commits] Webbeans SVN: r2626 - in test-harness/trunk: impl/src/main/java/org/jboss/testharness/impl/packaging/ear and 6 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Sat Apr 25 13:31:47 EDT 2009


Author: dan.j.allen
Date: 2009-04-25 13:31:47 -0400 (Sat, 25 Apr 2009)
New Revision: 2626

Added:
   test-harness/trunk/impl/src/main/java/org/jboss/testharness/impl/packaging/ear/PersistenceXml.java
   test-harness/trunk/tests/src/test/java/org/jboss/testharness/impl/packaging/ear/persistence.xml
   test-harness/trunk/tests/src/test/resources/org/jboss/testharness/impl/packaging/ear/persistence.xml
   test-harness/trunk/tests/src/test/resources/org/jboss/testharness/test/impl/packaging/descriptors/
   test-harness/trunk/tests/src/test/resources/org/jboss/testharness/test/impl/packaging/descriptors/ear/
   test-harness/trunk/tests/src/test/resources/org/jboss/testharness/test/impl/packaging/descriptors/ear/dummy-ds.xml
   test-harness/trunk/tests/src/test/resources/org/jboss/testharness/test/impl/packaging/descriptors/ear/import.sql
Modified:
   test-harness/trunk/impl/src/main/java/org/jboss/testharness/impl/packaging/ArtifactGenerator.java
   test-harness/trunk/impl/src/main/java/org/jboss/testharness/impl/packaging/Resource.java
   test-harness/trunk/impl/src/main/java/org/jboss/testharness/impl/packaging/ear/EarArtifactDescriptor.java
   test-harness/trunk/impl/src/main/java/org/jboss/testharness/impl/packaging/ear/EjbJarArtifactDescriptor.java
   test-harness/trunk/tests/src/test/java/org/jboss/testharness/test/impl/packaging/descriptors/ear/EarArtifactTest.java
Log:
add support for persistence.xml in EAR packaging (with tests)
allow use of @Resource directly on @Artifact class
add support for packaging resource inside of EJB-JAR or WAR in EAR packaging (with tests)
report number of artifacts to be dumped


Modified: test-harness/trunk/impl/src/main/java/org/jboss/testharness/impl/packaging/ArtifactGenerator.java
===================================================================
--- test-harness/trunk/impl/src/main/java/org/jboss/testharness/impl/packaging/ArtifactGenerator.java	2009-04-25 17:25:09 UTC (rev 2625)
+++ test-harness/trunk/impl/src/main/java/org/jboss/testharness/impl/packaging/ArtifactGenerator.java	2009-04-25 17:31:47 UTC (rev 2626)
@@ -19,6 +19,7 @@
 import org.jboss.testharness.api.ResourceDescriptor;
 import org.jboss.testharness.impl.packaging.ear.EarArtifactDescriptor;
 import org.jboss.testharness.impl.packaging.ear.EjbJarXml;
+import org.jboss.testharness.impl.packaging.ear.PersistenceXml;
 import org.jboss.testharness.impl.packaging.jsr299.BeansXml;
 import org.jboss.testharness.impl.packaging.jsr299.JSR299ArtifactDescriptor;
 import org.jboss.testharness.impl.packaging.jsr299.TCKArtifactDescriptor;
@@ -37,6 +38,7 @@
       private final boolean addDeclaringPackage;
       private final String beansXml;
       private final String ejbJarXml;
+      private final String persistenceXml;
       private final PackagingType packagingType;
       private final Collection<ResourceDescriptor> resources;
       private final Collection<Class<?>> classes;
@@ -82,13 +84,21 @@
          
          if (declaringClass.isAnnotationPresent(EjbJarXml.class))
          {
-            this.ejbJarXml = asAbsolutePath(declaringClass.getAnnotation(EjbJarXml.class).value());	
+            this.ejbJarXml = asAbsolutePath(declaringClass.getAnnotation(EjbJarXml.class).value());
          }
          else
          {
             this.ejbJarXml = null;
          }
-        	 
+
+         if (declaringClass.isAnnotationPresent(PersistenceXml.class))
+         {
+            this.persistenceXml = asAbsolutePath(declaringClass.getAnnotation(PersistenceXml.class).value());
+         }
+         else
+         {
+            this.persistenceXml = null;
+         }
          
          if (declaringClass.isAnnotationPresent(IntegrationTest.class))
          {
@@ -100,14 +110,16 @@
             this.unit = true;
             this.runLocally = false;
          }
-         
-         if (declaringClass.isAnnotationPresent(Resources.class))
+
+         this.resources = new ArrayList<ResourceDescriptor>();
+         if (declaringClass.isAnnotationPresent(Resource.class))
          {
-            this.resources = asResourceDescriptors(declaringClass.getAnnotation(Resources.class).value());
+            this.resources.add(asResourceDescriptor(declaringClass.getAnnotation(Resource.class)));
          }
-         else
+
+         if (declaringClass.isAnnotationPresent(Resources.class))
          {
-            this.resources = Collections.emptyList();
+            this.resources.addAll(asResourceDescriptors(declaringClass.getAnnotation(Resources.class).value()));
          }
          
          if (declaringClass.isAnnotationPresent(Classes.class))
@@ -163,7 +175,7 @@
       
       public TCKArtifactDescriptor createArtifact()
       {
-         final TCKArtifactDescriptor artifact = newArtifact(packagingType, declaringClass, beansXml, ejbJarXml, standalone, addDeclaringPackage);
+         final TCKArtifactDescriptor artifact = newArtifact(packagingType, declaringClass, beansXml, ejbJarXml, persistenceXml, standalone, addDeclaringPackage);
          artifact.setUnit(unit);
          artifact.setRunLocally(runLocally);
          artifact.setExpectedDeploymentException(expectedDeploymentException);
@@ -184,10 +196,15 @@
          List<ResourceDescriptor> resourceDescriptorImpls = new ArrayList<ResourceDescriptor>();
          for (Resource resource : resources)
          {
-            resourceDescriptorImpls.add(new ResourceDescriptorImpl(resource.destination(), asAbsolutePath(resource.source())));
+            resourceDescriptorImpls.add(asResourceDescriptor(resource));
          }
          return resourceDescriptorImpls;
       }
+
+      private ResourceDescriptor asResourceDescriptor(Resource resource)
+      {
+         return new ResourceDescriptorImpl(resource.destination(), asAbsolutePath(resource.source()));
+      }
       
       private String asAbsolutePath(String path)
       {
@@ -201,7 +218,7 @@
          }
       }
       
-      private static TCKArtifactDescriptor newArtifact(PackagingType packagingType, Class<?> declaringClass, String beansXml, String ejbJarXml, boolean standalone, boolean addDeclaringPackage)
+      private static TCKArtifactDescriptor newArtifact(PackagingType packagingType, Class<?> declaringClass, String beansXml, String ejbJarXml, String persistenceXml, boolean standalone, boolean addDeclaringPackage)
       {
          TCKArtifactDescriptor artifact;
          if (!standalone && packagingType.equals(WAR))
@@ -214,7 +231,7 @@
          } 
          else if (!standalone && packagingType.equals(EAR))
          {
-            artifact = new EarArtifactDescriptor(declaringClass, beansXml, ejbJarXml).initialize();
+            artifact = new EarArtifactDescriptor(declaringClass, beansXml, ejbJarXml, persistenceXml).initialize();
          }
          else
          {
@@ -276,7 +293,7 @@
       {
          throw new IllegalStateException("Cannot use debug directory " + configuration.getOutputDirectory() + ", it already exists");
       }
-      log.info("Writing artifacts to " + configuration.getOutputDirectory());
+      log.info("Writing " + artifacts.size() + " artifact(s) to " + configuration.getOutputDirectory());
       for (ArtifactDescriptor artifact : artifacts)
       {
          try

Modified: test-harness/trunk/impl/src/main/java/org/jboss/testharness/impl/packaging/Resource.java
===================================================================
--- test-harness/trunk/impl/src/main/java/org/jboss/testharness/impl/packaging/Resource.java	2009-04-25 17:25:09 UTC (rev 2625)
+++ test-harness/trunk/impl/src/main/java/org/jboss/testharness/impl/packaging/Resource.java	2009-04-25 17:31:47 UTC (rev 2626)
@@ -10,7 +10,9 @@
 import org.jboss.testharness.impl.packaging.jsr299.BeansXml;
 
 /**
- * Specify an additional resource to be added to the artifact.
+ * Specify an additional resource to be added to the artifact. You can
+ * specify muliple resources by nesting multiple @Resource annotations
+ * within a @Resources annotation.
  * 
  * @see Resources
  * @see BeansXml

Modified: test-harness/trunk/impl/src/main/java/org/jboss/testharness/impl/packaging/ear/EarArtifactDescriptor.java
===================================================================
--- test-harness/trunk/impl/src/main/java/org/jboss/testharness/impl/packaging/ear/EarArtifactDescriptor.java	2009-04-25 17:25:09 UTC (rev 2625)
+++ test-harness/trunk/impl/src/main/java/org/jboss/testharness/impl/packaging/ear/EarArtifactDescriptor.java	2009-04-25 17:31:47 UTC (rev 2626)
@@ -18,16 +18,18 @@
 {
    
    private static final Logger log = Logger.getLogger(EarArtifactDescriptor.class);
-   
+   private static final String WAR_RESOURCE_PREFIX = "war:/";
+   private static final String EJB_JAR_RESOURCE_PREFIX = "ejb-jar:/";
+
    public static final String APPLICATION_XML_DESTINATION = "META-INF/application.xml";
    
    private final EjbJarArtifactDescriptor ejbJar;
    private final WarArtifactDescriptor war;
    
-   public EarArtifactDescriptor(Class<?> declaringClass, String beansXmlSourceFileName, String ejbJarXml)
+   public EarArtifactDescriptor(Class<?> declaringClass, String beansXmlSourceFileName, String ejbJarXml, String persistenceXml)
    {
       super(declaringClass, null);
-      this.ejbJar = new EjbJarArtifactDescriptor(declaringClass, beansXmlSourceFileName, ejbJarXml).initialize();
+      this.ejbJar = new EjbJarArtifactDescriptor(declaringClass, beansXmlSourceFileName, ejbJarXml, persistenceXml).initialize();
       this.war = new WarArtifactDescriptor(declaringClass, null)
       {
          
@@ -129,11 +131,16 @@
    {
       for (ResourceDescriptor resource : new HashSet<ResourceDescriptor>(getResources()))
       {
-         if (resource.getName().startsWith("war"))
+         if (resource.getName().startsWith(WAR_RESOURCE_PREFIX))
          {
             getResources().remove(resource);
-            war.getResources().add(new ResourceDescriptorImpl(resource.getName().substring(3), resource.getSource()));
+            war.getResources().add(new ResourceDescriptorImpl(resource.getName().substring(WAR_RESOURCE_PREFIX.length()), resource.getSource()));
          }
+         else if (resource.getName().startsWith(EJB_JAR_RESOURCE_PREFIX))
+         {
+            getResources().remove(resource);
+            ejbJar.getResources().add(new ResourceDescriptorImpl(resource.getName().substring(EJB_JAR_RESOURCE_PREFIX.length()), resource.getSource()));
+         }
       }
       getResources().add(new ResourceDescriptorImpl(war.getDefaultName(), war.getJar()));
       getResources().add(new ResourceDescriptorImpl(ejbJar.getDefaultName(), ejbJar.getJar()));

Modified: test-harness/trunk/impl/src/main/java/org/jboss/testharness/impl/packaging/ear/EjbJarArtifactDescriptor.java
===================================================================
--- test-harness/trunk/impl/src/main/java/org/jboss/testharness/impl/packaging/ear/EjbJarArtifactDescriptor.java	2009-04-25 17:25:09 UTC (rev 2625)
+++ test-harness/trunk/impl/src/main/java/org/jboss/testharness/impl/packaging/ear/EjbJarArtifactDescriptor.java	2009-04-25 17:31:47 UTC (rev 2626)
@@ -12,13 +12,19 @@
    public static final String EJB_JAR_XML_DESTINATION = "META-INF/ejb-jar.xml";
    public static final String STANDARD_EJB_JAR_XML_FILE_NAME = "org/jboss/testharness/impl/packaging/ear/ejb-jar.xml";
    public static final String CUSTOM_EJB_JAR_XML_FILE_NAME = "org/jboss/testharness/impl/packaging/ear/custom-ejb-jar.xml";
+
+   public static final String PERSISTENCE_XML_DESTINATION = "META-INF/persistence.xml";
+   public static final String STANDARD_PERSISTENCE_XML_FILE_NAME = "org/jboss/testharness/impl/packaging/ear/persistence.xml";
+   public static final String CUSTOM_PERSISTENCE_XML_FILE_NAME = "org/jboss/testharness/impl/packaging/ear/custom-persistence.xml";
    
    private final String ejbJarXml;
+   private final String persistenceXml;
    
-   public EjbJarArtifactDescriptor(Class<?> declaringClass, String beansXmlSourceFileName, String ejbJarXml)
+   public EjbJarArtifactDescriptor(Class<?> declaringClass, String beansXmlSourceFileName, String ejbJarXml, String persistenceXml)
    {
       super(declaringClass, beansXmlSourceFileName);
       this.ejbJarXml = ejbJarXml;
+      this.persistenceXml = persistenceXml;
    }
    
    @Override
@@ -31,13 +37,27 @@
       }
       else
       {
-         URL ejbJarXml = loadResource(CUSTOM_EJB_JAR_XML_FILE_NAME);
-         if (ejbJarXml == null)
+         URL ejbJarXmlLocation = loadResource(CUSTOM_EJB_JAR_XML_FILE_NAME);
+         if (ejbJarXmlLocation == null)
          {
-            ejbJarXml = loadResource(STANDARD_EJB_JAR_XML_FILE_NAME);
+            ejbJarXmlLocation = loadResource(STANDARD_EJB_JAR_XML_FILE_NAME);
          }
-         getResources().add(new ResourceDescriptorImpl(EJB_JAR_XML_DESTINATION, ejbJarXml));
+         getResources().add(new ResourceDescriptorImpl(EJB_JAR_XML_DESTINATION, ejbJarXmlLocation));
       }
+
+      if (persistenceXml != null)
+      {
+         getResources().add(new ResourceDescriptorImpl(PERSISTENCE_XML_DESTINATION, persistenceXml));
+      }
+      else
+      {
+         URL persistenceXmlLocation = loadResource(CUSTOM_PERSISTENCE_XML_FILE_NAME);
+         if (persistenceXmlLocation == null)
+         {
+            persistenceXmlLocation = loadResource(STANDARD_PERSISTENCE_XML_FILE_NAME);
+         }
+         getResources().add(new ResourceDescriptorImpl(PERSISTENCE_XML_DESTINATION, persistenceXmlLocation));
+      }
       
       return this;
    }

Added: test-harness/trunk/impl/src/main/java/org/jboss/testharness/impl/packaging/ear/PersistenceXml.java
===================================================================
--- test-harness/trunk/impl/src/main/java/org/jboss/testharness/impl/packaging/ear/PersistenceXml.java	                        (rev 0)
+++ test-harness/trunk/impl/src/main/java/org/jboss/testharness/impl/packaging/ear/PersistenceXml.java	2009-04-25 17:31:47 UTC (rev 2626)
@@ -0,0 +1,32 @@
+package org.jboss.testharness.impl.packaging.ear;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import org.jboss.testharness.impl.packaging.Resource;
+
+/**
+ * Override the default META-INF/persistence.xml
+ * 
+ * @see Resource
+ * 
+ * @author Dan Allen
+ *
+ */
+ at Documented
+ at Retention(RUNTIME)
+ at Target(TYPE)
+public @interface PersistenceXml
+{
+   
+   /**
+    * Location of the overriding file, relative to the current location or the
+    * root this classpath if beginning with a '/'.
+    */
+   String value();
+   
+}

Added: test-harness/trunk/tests/src/test/java/org/jboss/testharness/impl/packaging/ear/persistence.xml
===================================================================
--- test-harness/trunk/tests/src/test/java/org/jboss/testharness/impl/packaging/ear/persistence.xml	                        (rev 0)
+++ test-harness/trunk/tests/src/test/java/org/jboss/testharness/impl/packaging/ear/persistence.xml	2009-04-25 17:31:47 UTC (rev 2626)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" 
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" 
+   version="1.0">
+</persistence>

Modified: test-harness/trunk/tests/src/test/java/org/jboss/testharness/test/impl/packaging/descriptors/ear/EarArtifactTest.java
===================================================================
--- test-harness/trunk/tests/src/test/java/org/jboss/testharness/test/impl/packaging/descriptors/ear/EarArtifactTest.java	2009-04-25 17:25:09 UTC (rev 2625)
+++ test-harness/trunk/tests/src/test/java/org/jboss/testharness/test/impl/packaging/descriptors/ear/EarArtifactTest.java	2009-04-25 17:31:47 UTC (rev 2626)
@@ -10,6 +10,7 @@
 import java.util.jar.JarInputStream;
 
 import org.jboss.testharness.AbstractTest;
+import org.jboss.testharness.impl.packaging.ResourceDescriptorImpl;
 import org.jboss.testharness.impl.packaging.ear.EarArtifactDescriptor;
 import org.jboss.testharness.test.impl.packaging.AbstractArtifactTest;
 import org.testng.annotations.Test;
@@ -19,7 +20,7 @@
    @Test
    public void testDefaultEar() throws Exception
    {
-      EarArtifactDescriptor ear = new EarArtifactDescriptor(DummyTest.class, null, null).initialize();
+      EarArtifactDescriptor ear = new EarArtifactDescriptor(DummyTest.class, null, null, null).initialize();
       ear.getClasses().add(Cow.class);
       File root = ear.getExplodedJar();
       assert root.isDirectory();
@@ -80,6 +81,10 @@
       File ejbJarXml = new File(ejbJarRoot, "META-INF/ejb-jar.xml");
       assert ejbJarXml.isFile();
       assert ejbJarXml.length() > 0;
+
+      File persistenceXml = new File(ejbJarRoot, "META-INF/persistence.xml");
+      assert persistenceXml.isFile();
+      assert persistenceXml.length() > 0;
       
       File webbeansXml = new File(ejbJarRoot, "META-INF/beans.xml");
       assert webbeansXml.isFile();
@@ -117,8 +122,10 @@
    @Test
    public void testJarProduction() throws Exception
    {
-      EarArtifactDescriptor ear = new EarArtifactDescriptor(DummyTest.class, null, null).initialize();
+      EarArtifactDescriptor ear = new EarArtifactDescriptor(DummyTest.class, null, null, null).initialize();
       ear.getClasses().add(Cow.class);
+      ear.getResources().add(new ResourceDescriptorImpl("dummy-ds.xml", asAbsolutePath(DummyTest.class, "dummy-ds.xml")));
+      ear.getResources().add(new ResourceDescriptorImpl("ejb-jar:/import.sql", asAbsolutePath(DummyTest.class, "import.sql")));
       JarInputStream is = new JarInputStream(ear.getJarAsStream());
       JarEntry entry;
       List<String> fileNames = new ArrayList<String>();
@@ -130,6 +137,7 @@
       assert fileNames.contains("META-INF/application.xml");
       assert fileNames.contains("META-INF/jboss-test-harness.properties");
       assert fileNames.contains("lib/jboss-test-harness.jar");
+      assert fileNames.contains("dummy-ds.xml");
       assert fileNames.contains(DummyTest.class.getName() + ".jar");
       assert fileNames.contains(DummyTest.class.getName() + ".war");
       
@@ -146,9 +154,23 @@
       }
       is.close();
       assert fileNames.contains("META-INF/ejb-jar.xml");
+      assert fileNames.contains("META-INF/persistence.xml");
       assert fileNames.contains("META-INF/beans.xml");
       assert fileNames.contains("org/jboss/testharness/test/impl/packaging/descriptors/ear/Cow.class");
+      assert fileNames.contains("import.sql");
    }
 
+   private String asAbsolutePath(Class clazz, String path)
+   {
+      if (path.startsWith("/"))
+      {
+         return path.substring(1);
+      }
+      else
+      {
+         return clazz.getPackage().getName().replace(".", "/") + "/" + path;
+      }
+   }
+
 }
 

Added: test-harness/trunk/tests/src/test/resources/org/jboss/testharness/impl/packaging/ear/persistence.xml
===================================================================
--- test-harness/trunk/tests/src/test/resources/org/jboss/testharness/impl/packaging/ear/persistence.xml	                        (rev 0)
+++ test-harness/trunk/tests/src/test/resources/org/jboss/testharness/impl/packaging/ear/persistence.xml	2009-04-25 17:31:47 UTC (rev 2626)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" 
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" 
+   version="1.0">
+</persistence>

Added: test-harness/trunk/tests/src/test/resources/org/jboss/testharness/test/impl/packaging/descriptors/ear/dummy-ds.xml
===================================================================
--- test-harness/trunk/tests/src/test/resources/org/jboss/testharness/test/impl/packaging/descriptors/ear/dummy-ds.xml	                        (rev 0)
+++ test-harness/trunk/tests/src/test/resources/org/jboss/testharness/test/impl/packaging/descriptors/ear/dummy-ds.xml	2009-04-25 17:31:47 UTC (rev 2626)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE datasources PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
+    "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">
+<datasources>
+</datasources>

Added: test-harness/trunk/tests/src/test/resources/org/jboss/testharness/test/impl/packaging/descriptors/ear/import.sql
===================================================================




More information about the weld-commits mailing list