1 package org.enhydra.kelp.ant.deployer; 2 import org.enhydra.kelp.common.*; 4 import org.enhydra.kelp.common.event.WriteListener; 5 import org.enhydra.kelp.ant.AntFacade; 6 7 import org.enhydra.tool.common.ToolException; 9 10 import java.io.File ; 12 import java.io.IOException ; 13 import java.io.PrintWriter ; 14 import java.io.InputStream ; 15 import java.io.BufferedReader ; 16 import java.io.InputStreamReader ; 17 import org.enhydra.kelp.ant.node.AntProject; 18 import java.io.FileWriter ; 19 import java.io.BufferedWriter ; 20 import java.util.Date ; 21 import org.enhydra.kelp.ant.ErrorReader; 22 23 24 32 33 public class AntDeployBuilder extends AbstractEchoBuilder { 34 35 public AntDeployBuilder() { 36 super(null); 37 } 38 39 public AntDeployBuilder(WriteListener listener) { 40 super(listener); 41 } 42 43 public AntDeployBuilder(WriteListener listener, boolean buffer) { 44 super(listener, buffer); 45 } 46 47 public AntDeployBuilder(WriteListener[] listeners) { 48 super(); 49 for (int i = 0; i < listeners.length; i++) { 50 addWriteListener(listeners[i]); 51 } 52 } 53 54 protected void buildImpl() throws org.enhydra.tool.common.ToolException { 56 File root = new File (getProject().getWorkingPath()); 57 try{ 58 String enhydraDir = getProject().getProperty(AntProject.ENHYDRA_DIR); 59 String execLine = enhydraDir + "/bin/ant"; 60 if (System.getProperty("os.name").toLowerCase().startsWith("windows")) { 61 execLine += ".bat"; 62 } 63 Process process = Runtime.getRuntime().exec(execLine + " deploy", null, root); 64 65 InputStream inputStream = process.getInputStream(); 66 InputStream errorStream = process.getErrorStream(); 67 BufferedReader bufferedReader = new BufferedReader (new InputStreamReader (inputStream)); 68 BufferedReader errorBufferedReader = new BufferedReader (new InputStreamReader (errorStream)); 69 File logFile = null; 71 FileWriter logFileWriter = null; 72 BufferedWriter logBuffer = null; 73 PrintWriter logPrint = null; 74 boolean logFileOK = false; 75 String logFileName = ((AntProject)getProject()).getOutputFilename(); 76 if (logFileName != null) { 77 logFile = new File (logFileName); 78 } 79 if ((logFile != null) && (!logFile.isDirectory()) 80 && ((AntProject)getProject()).isOutputFileEnabled()) { 81 if (logFile.length() > 1e6) { 82 logFileWriter = new FileWriter (logFile, false ); 83 } else { 84 logFileWriter = new FileWriter (logFile, true ); 85 } 86 logBuffer = new BufferedWriter (logFileWriter, 4096); 87 logPrint = new PrintWriter (logBuffer, false ); 88 logPrint.println("------------------------------ "+(new Date ()).toString()+" ----------------------"); 89 logFileOK = true; 90 } 91 92 String s = null; 93 94 (new ErrorReader(errorBufferedReader,this,logPrint)).start(); 95 96 97 while((s = bufferedReader.readLine()) != null){ 98 if(s != null){ 99 getEchoWriter().println(s); 100 if (logFileOK) { 101 logPrint.println(s); 102 } 103 s = null; 104 } 105 } 106 107 process.waitFor(); 108 int k = process.exitValue(); 109 if (logFileOK) { 110 logPrint.flush(); 111 logPrint.close(); 112 } 113 114 }catch(Exception e){ 115 throw new ToolException(e,"Deployer error: "+e.toString()); 116 } 117 } 118 119 } | Popular Tags |