1 package hudson.model; 2 3 import hudson.Proc; 4 import hudson.util.DecodingStream; 5 import hudson.util.DualOutputStream; 6 import org.xmlpull.mxp1.MXParser; 7 import org.xmlpull.v1.XmlPullParser; 8 9 import java.io.File ; 10 import java.io.IOException ; 11 import java.io.PrintStream ; 12 import java.io.Reader ; 13 14 19 public class ExternalRun extends Run<ExternalJob,ExternalRun> { 20 23 ExternalRun(ExternalJob owner, File runDir) throws IOException { 24 super(owner,runDir); 25 } 26 27 30 ExternalRun(ExternalJob project) throws IOException { 31 super(project); 32 } 33 34 38 public void run(final String [] cmd) { 39 run(new Runner() { 40 public Result run(BuildListener listener) throws Exception { 41 Proc proc = new Proc.LocalProc(cmd,getEnvVars(),System.in,new DualOutputStream(System.out,listener.getLogger())); 42 return proc.join()==0?Result.SUCCESS:Result.FAILURE; 43 } 44 45 public void post(BuildListener listener) { 46 } 48 }); 49 } 50 51 62 public void acceptRemoteSubmission(final Reader in) { 63 final long[] duration = new long[1]; 64 run(new Runner() { 65 public Result run(BuildListener listener) throws Exception { 66 PrintStream logger = new PrintStream (new DecodingStream(listener.getLogger())); 67 68 XmlPullParser xpp = new MXParser(); 69 xpp.setInput(in); 70 xpp.nextTag(); xpp.nextTag(); while(xpp.nextToken()!=XmlPullParser.END_TAG) { 73 int type = xpp.getEventType(); 74 if(type==XmlPullParser.TEXT 75 || type==XmlPullParser.CDSECT) 76 logger.print(xpp.getText()); 77 } 78 xpp.nextTag(); 80 Result r = Integer.parseInt(xpp.nextText())==0?Result.SUCCESS:Result.FAILURE; 81 82 xpp.nextTag(); if(xpp.getEventType()==XmlPullParser.START_TAG 84 && xpp.getName().equals("duration")) { 85 duration[0] = Long.parseLong(xpp.nextText()); 86 } 87 88 return r; 89 } 90 91 public void post(BuildListener listener) { 92 } 94 }); 95 96 if(duration[0]!=0) 97 super.duration = duration[0]; 98 } 99 100 } 101 | Popular Tags |