[jboss-svn-commits] JBL Code SVN: r10823 - in labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin: src and 16 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Apr 8 10:31:01 EDT 2007


Author: pgier
Date: 2007-04-08 10:31:01 -0400 (Sun, 08 Apr 2007)
New Revision: 10823

Added:
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/plugins/deploy/CompInfoVerifier.java
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/plugins/deploy/CompInfoVerifyMojo.java
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/java/
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/java/org/
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/java/org/jboss/
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/java/org/jboss/test/
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/java/org/jboss/test/maven/
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/java/org/jboss/test/maven/plugins/
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/java/org/jboss/test/maven/plugins/deploy/
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/java/org/jboss/test/maven/plugins/deploy/CompInfoVerifierTestCase.java
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/resources/
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/resources/org/
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/resources/org/jboss/
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/resources/org/jboss/test/
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/resources/org/jboss/test/maven/
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/resources/org/jboss/test/maven/plugins/
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/resources/org/jboss/test/maven/plugins/deploy/
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/resources/org/jboss/test/maven/plugins/deploy/component-info-test-bad.xml_test
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/resources/org/jboss/test/maven/plugins/deploy/component-info-test-good.xml_test
Modified:
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/pom.xml
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/plugins/deploy/JBossDeployMojo.java
Log:
JBBUILD-74; Added unit tests for component-info.xml verification.
Added new mojo to do verification from command line.

Modified: labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/pom.xml
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/pom.xml	2007-04-08 07:50:49 UTC (rev 10822)
+++ labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/pom.xml	2007-04-08 14:31:01 UTC (rev 10823)
@@ -1,4 +1,6 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" 
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <parent>
     <groupId>jboss</groupId>
     <artifactId>jboss-parent</artifactId>

Added: labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/plugins/deploy/CompInfoVerifier.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/plugins/deploy/CompInfoVerifier.java	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/plugins/deploy/CompInfoVerifier.java	2007-04-08 14:31:01 UTC (rev 10823)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ * 
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.maven.plugins.deploy;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+/**
+ * 
+ * Class to verify that a component-info.xml class is valid.
+ * 
+ * @author <a href="pgier at redhat.com">Paul Gier</a>
+ * 
+ */
+public class CompInfoVerifier
+{
+
+   /**
+    * Verify a component-info.xml file using the xsd.
+    * 
+    * @param compInfoFilePath Path to the component-info.xml to be verified.
+    */
+   public void verifyCompInfo(String compInfoFilePath) throws SAXException, java.io.FileNotFoundException
+   {
+      verifyCompInfo(new FileInputStream(compInfoFilePath));
+   }
+
+   /**
+    * Verify a component-info.xml file using the xsd.
+    * 
+    * @param compInfoFilePath Path to the component-info.xml to be verified.
+    */
+   public void verifyCompInfo(InputStream compInfo) throws SAXException
+   {
+      try
+      {
+         // Parse an XML document into a DOM tree.
+         DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+         Document document = parser.parse(compInfo);
+
+         // Create a SchemaFactory capable of understanding WXS schemas.
+         SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+
+         // Load a WXS schema, represented by a Schema instance.
+         Source schemaFile = new StreamSource(this.getClass().getResourceAsStream("component-info.xsd"));
+         Schema schema = factory.newSchema(schemaFile);
+
+         // Create a Validator object, which can be used to validate
+         // an instance document.
+         Validator validator = schema.newValidator();
+
+         // Validate the DOM tree.
+         validator.validate(new DOMSource(document));
+      }
+      catch (ParserConfigurationException e)
+      {
+         e.printStackTrace();
+      }
+      catch (IOException e)
+      {
+         e.printStackTrace();
+      }
+
+   }
+
+}

Added: labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/plugins/deploy/CompInfoVerifyMojo.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/plugins/deploy/CompInfoVerifyMojo.java	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/plugins/deploy/CompInfoVerifyMojo.java	2007-04-08 14:31:01 UTC (rev 10823)
@@ -0,0 +1,40 @@
+package org.jboss.maven.plugins.deploy;
+
+import java.io.FileNotFoundException;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.xml.sax.SAXException;
+
+/**
+ * Maven plugin for deploying to jboss repository.  By default
+ * it will bind to the deploy phase.
+ * 
+ * @goal comp-info-verify
+ * 
+ */
+public class CompInfoVerifyMojo extends AbstractMojo
+{
+
+   /**
+    * Main execution path of the plugin.  Generates component-info.xml, and copies jar files to repository location.
+    * TODO: Should be able to call this mojo from command line to verify any component-info.xml.
+    */
+   public void execute() throws MojoExecutionException
+   {
+      this.getLog().debug("Executing JBoss deploy plugin");
+      String pathToCompInfo = System.getProperty("comp-info");
+      if (pathToCompInfo == null)
+      {
+         pathToCompInfo = "component-info.xml";
+      }
+      CompInfoVerifier verifier = new CompInfoVerifier();
+      try {
+         verifier.verifyCompInfo("component-info.xml");
+      } catch (FileNotFoundException fnfe) {
+         fnfe.printStackTrace();
+      } catch (SAXException saxe) {
+         saxe.printStackTrace();
+      }
+   }
+}

Modified: labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/plugins/deploy/JBossDeployMojo.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/plugins/deploy/JBossDeployMojo.java	2007-04-08 07:50:49 UTC (rev 10822)
+++ labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/plugins/deploy/JBossDeployMojo.java	2007-04-08 14:31:01 UTC (rev 10823)
@@ -1,6 +1,8 @@
 package org.jboss.maven.plugins.deploy;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
@@ -17,6 +19,7 @@
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
+import org.xml.sax.SAXException;
 
 /**
  * Maven plugin for deploying to jboss repository.  By default
@@ -262,13 +265,13 @@
       }
 
       // Write the component info file
+      File compInfoFile = new File(deployToDir + fileSep + "component-info.xml");
       try
       {
          if (!deployToDir.exists())
          {
             deployToDir.mkdirs();
          }
-         File compInfoFile = new File(deployToDir + fileSep + "component-info.xml");
          FileWriter fw = new FileWriter(compInfoFile);
          this.getLog().info("Deploying file: " + compInfoFile.getCanonicalPath());
          fw.write(compInfoTemplate.toString());
@@ -276,8 +279,18 @@
       }
       catch (IOException ioe)
       {
-         ioe.printStackTrace();
+         this.getLog().error(ioe);
       }
+  
+      CompInfoVerifier verifier = new CompInfoVerifier();
+      try {
+         verifier.verifyCompInfo(new FileInputStream(compInfoFile));
+      }
+      catch (SAXException e) {
+         this.getLog().warn(e);
+      } catch (FileNotFoundException fnfe) {
+         fnfe.printStackTrace();
+      }
    }
 
    /**

Added: labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/java/org/jboss/test/maven/plugins/deploy/CompInfoVerifierTestCase.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/java/org/jboss/test/maven/plugins/deploy/CompInfoVerifierTestCase.java	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/java/org/jboss/test/maven/plugins/deploy/CompInfoVerifierTestCase.java	2007-04-08 14:31:01 UTC (rev 10823)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ * 
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.test.maven.plugins.deploy;
+
+import java.io.InputStream;
+
+import junit.framework.TestCase;
+
+import org.jboss.maven.plugins.deploy.CompInfoVerifier;
+import org.xml.sax.SAXException;
+
+public class CompInfoVerifierTestCase extends TestCase
+{
+
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+   }
+
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+   }
+
+   /** Verify a valid component info file */
+   public void testGoodCompInfo() throws Exception
+   {
+      boolean result=false;
+      CompInfoVerifier verifier = new CompInfoVerifier();
+      InputStream is = this.getClass().getResourceAsStream("component-info-test-good.xml_test");
+      try {
+         verifier.verifyCompInfo(is);
+         result= true;
+      } catch (SAXException e) {
+         e.printStackTrace();
+      }
+      assertTrue(result);
+   }
+
+   /** Fail on an invalid component info file */
+   public void testBadCompInfo() throws Exception
+   {
+      boolean result=false;
+      CompInfoVerifier verifier = new CompInfoVerifier();
+      InputStream is = this.getClass().getResourceAsStream("component-info-test-bad.xml_test");
+      try {
+         verifier.verifyCompInfo(is);
+      } catch (SAXException e) {
+         result= true;
+      }
+      assertTrue(result);
+   }
+
+}

Added: labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/resources/org/jboss/test/maven/plugins/deploy/component-info-test-bad.xml_test
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/resources/org/jboss/test/maven/plugins/deploy/component-info-test-bad.xml_test	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/resources/org/jboss/test/maven/plugins/deploy/component-info-test-bad.xml_test	2007-04-08 14:31:01 UTC (rev 10823)
@@ -0,0 +1,20 @@
+<project xmlns="http://www.jboss.org/component-info/1.0" 
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://www.jboss.org/component-info/1.0 component-info.xsd"
+  name="jboss/microcontainer-component-info">
+  <component id="test" licenseType="stuff" version="1.0">
+    <artifact id="test"/>
+    <artifact id="test2"/>
+    <import componentref="test">
+      <compatible version="1.2"/>
+    </import>
+    <export>
+      <include input="test"/>
+      <include input="test2"/>
+    </export>
+  </component>
+  <component>
+    <invalid>test</invalid>
+  </component>
+  
+</project>
\ No newline at end of file

Added: labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/resources/org/jboss/test/maven/plugins/deploy/component-info-test-good.xml_test
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/resources/org/jboss/test/maven/plugins/deploy/component-info-test-good.xml_test	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/test/resources/org/jboss/test/maven/plugins/deploy/component-info-test-good.xml_test	2007-04-08 14:31:01 UTC (rev 10823)
@@ -0,0 +1,37 @@
+<project xmlns="http://www.jboss.org/component-info/1.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://www.jboss.org/component-info/1.0 component-info.xsd"
+  name="jboss/microcontainer-component-info">
+  
+  <component id="jboss/microcontainer" licenseType="lgpl"
+    version="${jbossbuild.repository.version}">
+    <artifact id="jboss-aop-mc-int.jar"/>
+    <artifact id="jboss-container.jar"/>
+    <artifact id="jboss-dependency.jar"/>
+    <artifact id="jboss-deployers.jar"/>
+    <artifact id="jboss-managed.jar"/>
+    <artifact id="jboss-metatype.jar"/>
+    <artifact id="jboss-microcontainer.jar"/>
+    <artifact id="jboss-aop-mc-int-src.zip"/>
+    <artifact id="jboss-container-src.zip"/>
+    <artifact id="jboss-dependency-src.zip"/>
+    <artifact id="jboss-deployers-src.zip"/>
+    <artifact id="jboss-managed-src.zip"/>
+    <artifact id="jboss-metatype-src.zip"/>
+    <artifact id="jboss-microcontainer-src.zip"/>
+    <import componentref="javassist">
+      <compatible version="3.0beta"/>
+    </import>
+    <export>
+      <include input="jboss-aop-mc-int.jar"/>
+      <include input="jboss-container.jar"/>
+      <include input="jboss-dependency.jar"/>
+      <include input="jboss-deployers.jar"/>
+      <include input="jboss-managed.jar"/>
+      <include input="jboss-metatype.jar"/>
+      <include input="jboss-microcontainer.jar"/>
+    </export>
+  </component>
+  
+</project>
+




More information about the jboss-svn-commits mailing list