1 package org.jbpm.ant; 2 3 import java.io.File ; 4 import java.io.FileInputStream ; 5 import java.io.FileNotFoundException ; 6 import java.io.IOException ; 7 import java.util.ArrayList ; 8 import java.util.Iterator ; 9 import java.util.List ; 10 import java.util.zip.ZipInputStream ; 11 12 import org.apache.tools.ant.BuildException; 13 import org.apache.tools.ant.DirectoryScanner; 14 import org.apache.tools.ant.taskdefs.MatchingTask; 15 import org.apache.tools.ant.types.FileSet; 16 import org.jbpm.db.JbpmSessionFactory; 17 import org.jbpm.jpdl.par.ProcessArchiveDeployer; 18 19 22 public class DeployParTask extends MatchingTask { 23 24 private String cfg = null; 25 private String properties = null; 26 private String par = null; 27 private List fileSets = new ArrayList (); 28 29 public void execute() throws BuildException { 30 try { 31 JbpmSessionFactory jbpmSessionFactory = AntTaskJbpmSessionFactory.getJbpmSessionFactory(cfg,properties); 33 34 if (par!=null) { 36 log( "deploying par "+par+" ..." ); 37 File file = new File (par); 38 deploy(file, jbpmSessionFactory); 39 } 40 41 Iterator iter = fileSets.iterator(); 43 while (iter.hasNext()) { 44 FileSet fileSet = (FileSet) iter.next(); 45 DirectoryScanner dirScanner = fileSet.getDirectoryScanner(getProject()); 46 String [] fileSetFiles = dirScanner.getIncludedFiles(); 47 48 for (int i = 0; i < fileSetFiles.length; i++) { 49 String fileName = fileSetFiles[i]; 50 File file = new File (fileName); 51 if ( !file.isFile() ) { 52 file = new File ( dirScanner.getBasedir(), fileName ); 53 } 54 55 log( "deploying process archive "+file+" ..." ); 57 deploy(file, jbpmSessionFactory); 58 } 59 } 60 61 } catch (Exception e) { 62 e.printStackTrace(); 63 throw new BuildException( "couldn't deploy process archives : " + e.getMessage() ); 64 } 65 } 66 67 private void deploy(File file, JbpmSessionFactory jbpmSessionFactory) throws IOException , FileNotFoundException { 68 ZipInputStream zipInputStream = new ZipInputStream (new FileInputStream (file)); 69 ProcessArchiveDeployer.deployZipInputStream(zipInputStream,jbpmSessionFactory); 70 } 71 72 public void addFileset(FileSet fileSet) { 73 this.fileSets.add(fileSet); 74 } 75 public void setCfg(String cfg) { 76 this.cfg = cfg; 77 } 78 public void setProperties(String properties) { 79 this.properties = properties; 80 } 81 public void setPar(String par) { 82 this.par = par; 83 } 84 } 85 | Popular Tags |