[jbpm-commits] JBoss JBPM SVN: r6438 - in jbpm4/trunk/modules: pvm/src/main/java/org/jbpm/pvm/internal/xml and 6 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Jun 28 19:26:56 EDT 2010


Author: alex.guizar at jboss.com
Date: 2010-06-28 19:26:55 -0400 (Mon, 28 Jun 2010)
New Revision: 6438

Added:
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/ant/
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/ant/DeployTaskTest.java
   jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/ant/
   jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/ant/build.xml
   jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/ant/valid.bar
   jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/ant/valid.jpdl.xml
   jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/ant/valid.zip
Modified:
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/ant/JbpmDeployTask.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/xml/ProblemList.java
   jbpm4/trunk/modules/test-db/pom.xml
   jbpm4/trunk/modules/test-pojo/.classpath
Log:
JBPM-2893: fix broken deploy ant task, provide unit test

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/ant/JbpmDeployTask.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/ant/JbpmDeployTask.java	2010-06-26 01:59:29 UTC (rev 6437)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/ant/JbpmDeployTask.java	2010-06-28 23:26:55 UTC (rev 6438)
@@ -24,7 +24,7 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
-import java.net.URLConnection;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -34,6 +34,7 @@
 import org.apache.tools.ant.DirectoryScanner;
 import org.apache.tools.ant.taskdefs.MatchingTask;
 import org.apache.tools.ant.types.FileSet;
+
 import org.jbpm.api.NewDeployment;
 import org.jbpm.api.ProcessEngine;
 import org.jbpm.api.RepositoryService;
@@ -84,29 +85,43 @@
 
   protected void deployFile(ProcessEngine processEngine, File processFile) {
     RepositoryService repositoryService = processEngine.getRepositoryService();
+    String fileName = processFile.getName();
+
     NewDeployment deployment = repositoryService.createDeployment();
-    deployment.setName(processFile.getName());
+    deployment.setName(fileName);
     deployment.setTimestamp(System.currentTimeMillis());
 
-    String contentType = URLConnection.guessContentTypeFromName(processFile.getName());
-    if (contentType.contains("xml")) {
-      log("deploying process file " + processFile.getName());
-      deployment.addResourceFromFile(processFile);
-    }
-    else if (contentType.contains("zip")) {
-      log("deploying business archive " + processFile.getName());
-      try {
-        FileInputStream fileInputStream = new FileInputStream(processFile);
-        ZipInputStream zipInputStream = new ZipInputStream(fileInputStream);
+    try {
+      String contentType = new URL("file", null, processFile.getPath()).openConnection()
+        .getContentType();
+      // XXX getContentType() is supposed to return null if not known,
+      // yet sun jdk returns "content/unknown"
+      if (contentType == null || "content/unknown".equals(contentType)) {
+        // guess content type from file name
+        if (fileName.endsWith(".bar") || fileName.endsWith(".jar") || fileName.endsWith(".zip"))
+          contentType = "application/zip";
+        else if (fileName.endsWith(".xml"))
+          contentType = "application/xml";
+        else
+          throw new BuildException("failed to determine content type of " + processFile);
+      }
+
+      if ("application/xml".equals(contentType)) {
+        log("deploying process file " + fileName);
+        deployment.addResourceFromFile(processFile);
+      }
+      else if ("application/zip".equals(contentType)) {
+        log("deploying business archive " + fileName);
+        ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(processFile));
         deployment.addResourcesFromZipInputStream(zipInputStream);
       }
-      catch (IOException e) {
-        throw new BuildException("failed to read process archive " + processFile, e);
+      else {
+        throw new BuildException("unsupported content type: " + contentType
+          + " - only xml and zip files are allowed");
       }
     }
-    else {
-      throw new BuildException("unsupported extension: " + processFile
-        + "  Only .xml files and .*ar archives are supported");
+    catch (IOException e) {
+      throw new BuildException("failed to read: " + processFile, e);
     }
     deployment.deploy();
   }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/xml/ProblemList.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/xml/ProblemList.java	2010-06-26 01:59:29 UTC (rev 6437)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/xml/ProblemList.java	2010-06-28 23:26:55 UTC (rev 6438)
@@ -41,7 +41,7 @@
 
   static final String NEWLINE = System.getProperty("line.separator");
 
-  protected List<ProblemImpl> problems;
+  protected List<Problem> problems;
 
   // problem constructor method ///////////////////////////////////////////////
   
@@ -93,13 +93,13 @@
     if (problems==null) {
       return Collections.emptyList();
     }
-    return (List) problems;
+    return problems;
   }
 
   /** to add parsing problems during XML parsing and DOM walking. */
   public void addProblem(ProblemImpl problem) {
     if (problems==null) {
-      problems = new ArrayList<ProblemImpl>();
+      problems = new ArrayList<Problem>();
     }
     problems.add(problem);
   }
@@ -107,14 +107,14 @@
   /** add all problems */
   public void addProblems(List<Problem> problems) {
     if (this.problems==null) {
-      this.problems = new ArrayList<ProblemImpl>();
+      this.problems = new ArrayList<Problem>();
     }
-    this.problems.addAll((List)problems);
+    this.problems.addAll(problems);
   }
 
   /** indicates presence of problems */
   public boolean hasProblems() {
-    return ((problems != null) && (problems.size() > 0));
+    return problems != null && !problems.isEmpty();
   }
 
   /** indicates presence of errors */
@@ -133,7 +133,7 @@
   /** allows to provide the list object that should be used to 
    * capture the parsing problems. */
   public void setProblems(List<Problem> problems) {
-    this.problems = (List)problems;
+    this.problems = problems;
   }
   
     
@@ -168,7 +168,7 @@
         errorMsg.append(p.toString());
 
         if (p.getCause()!=null) {
-          cause = new JbpmException(p.getCause());
+          cause = p.getCause();
         }
       }
     }

Modified: jbpm4/trunk/modules/test-db/pom.xml
===================================================================
--- jbpm4/trunk/modules/test-db/pom.xml	2010-06-26 01:59:29 UTC (rev 6437)
+++ jbpm4/trunk/modules/test-db/pom.xml	2010-06-28 23:26:55 UTC (rev 6438)
@@ -66,6 +66,11 @@
       <artifactId>spring</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.ant</groupId>
+      <artifactId>ant</artifactId>
+      <scope>provided</scope>
+    </dependency>
   </dependencies>
 
   <build>

Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/ant/DeployTaskTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/ant/DeployTaskTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/ant/DeployTaskTest.java	2010-06-28 23:26:55 UTC (rev 6438)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.test.ant;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.List;
+
+import org.apache.tools.ant.Main;
+
+import org.jbpm.api.Deployment;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ * @author Alejandro Guizar
+ */
+public class DeployTaskTest extends JbpmTestCase {
+
+  public void testDeployXml() {
+    runTarget("deploy-xml");
+    checkDeployment();
+  }
+
+  public void testDeployZip() {
+    runTarget("deploy-zip");
+    checkDeployment();
+  }
+
+  public void testDeployBar() {
+    runTarget("deploy-bar");
+    checkDeployment();
+  }
+
+  private void runTarget(String target) {
+    PrintStream stdout = System.out;
+    PrintStream stderr = System.err;
+
+    ByteArrayOutputStream memout = new ByteArrayOutputStream();
+    PrintStream prnout = new PrintStream(memout);
+
+    try {
+      System.setOut(prnout);
+      System.setErr(prnout);
+
+      Main antMain = new Main() {
+
+        protected void exit(int exitCode) {
+          // prevent ant from terminating the VM
+        }
+      };
+      String[] args = { "-f", getClass().getResource("build.xml").getPath(), target };
+      antMain.startAnt(args, System.getProperties(), getClass().getClassLoader());
+    }
+    finally {
+      System.setOut(stdout);
+      System.setErr(stderr);
+
+      log.info(new String(memout.toByteArray()));
+    }
+  }
+
+  private void checkDeployment() {
+    List<Deployment> deployments = repositoryService.createDeploymentQuery().list();
+    assertEquals(1, deployments.size());
+    repositoryService.deleteDeploymentCascade(deployments.get(0).getId());
+  }
+}


Property changes on: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/ant/DeployTaskTest.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Added: jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/ant/build.xml
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/ant/build.xml	                        (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/ant/build.xml	2010-06-28 23:26:55 UTC (rev 6438)
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<project name="test-ant">
+  <target name="init">
+    <taskdef name="jbpm-deploy" classname="org.jbpm.pvm.internal.ant.JbpmDeployTask" />
+  </target>
+
+  <target name="deploy-xml" depends="init">
+    <jbpm-deploy file="valid.jpdl.xml" />
+  </target>
+
+  <target name="deploy-zip" depends="init">
+    <jbpm-deploy file="valid.zip" />
+  </target>
+
+  <target name="deploy-bar" depends="init">
+    <jbpm-deploy file="valid.bar" />
+  </target>
+</project>
\ No newline at end of file


Property changes on: jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/ant/build.xml
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Added: jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/ant/valid.bar
===================================================================
(Binary files differ)


Property changes on: jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/ant/valid.bar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/ant/valid.jpdl.xml
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/ant/valid.jpdl.xml	                        (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/ant/valid.jpdl.xml	2010-06-28 23:26:55 UTC (rev 6438)
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<process name="Purchase order" xmlns="http://jbpm.org/4.3/jpdl">
+
+  <start g="46,33,80,40">
+    <transition to="a" />
+  </start>
+
+  <state name="a" g="169,36,80,40">
+    <transition name="Supplier ok" to="b" g="-85,-23"/>
+  </state>
+
+  <state name="b" g="169,145,80,40">
+    <transition name="nok" to="Error" g="-31,-23"/>
+    <transition name="ok" to="Completed" g="-22,-23"/>
+  </state>
+
+  <end name="Completed" g="350,142,80,40"/>
+
+  <end name="Error" g="186,253,80,40"/>
+
+</process>


Property changes on: jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/ant/valid.jpdl.xml
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Added: jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/ant/valid.zip
===================================================================
(Binary files differ)


Property changes on: jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/ant/valid.zip
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: jbpm4/trunk/modules/test-pojo/.classpath
===================================================================
--- jbpm4/trunk/modules/test-pojo/.classpath	2010-06-26 01:59:29 UTC (rev 6437)
+++ jbpm4/trunk/modules/test-pojo/.classpath	2010-06-28 23:26:55 UTC (rev 6438)
@@ -1,7 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
-	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
 	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
 	<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>



More information about the jbpm-commits mailing list