diff --git a/core/src/main/java/hudson/Main.java b/core/src/main/java/hudson/Main.java index 0c13ce670a..2ece9ebdd1 100644 --- a/core/src/main/java/hudson/Main.java +++ b/core/src/main/java/hudson/Main.java @@ -110,57 +110,60 @@ public class Main { // write the output to a temporary file first. File tmpFile = File.createTempFile("hudson","log"); - tmpFile.deleteOnExit(); - FileOutputStream os = new FileOutputStream(tmpFile); + try { + FileOutputStream os = new FileOutputStream(tmpFile); - Writer w = new OutputStreamWriter(os,"UTF-8"); - w.write(""); - w.write(""); - w.flush(); + Writer w = new OutputStreamWriter(os,"UTF-8"); + w.write(""); + w.write(""); + w.flush(); - // run the command - long start = System.currentTimeMillis(); + // run the command + long start = System.currentTimeMillis(); - List cmd = new ArrayList(); - for( int i=1; i cmd = new ArrayList(); + for( int i=1; i"+ret+""+(System.currentTimeMillis()-start)+""); - w.close(); + w.write(""+ret+""+(System.currentTimeMillis()-start)+""); + w.close(); - String location = home+"job/"+projectNameEnc+"/postBuildResult"; - while(true) { - try { - // start a remote connection - HttpURLConnection con = (HttpURLConnection) new URL(location).openConnection(); - if (auth != null) con.setRequestProperty("Authorization", auth); - con.setDoOutput(true); - // this tells HttpURLConnection not to buffer the whole thing - con.setFixedLengthStreamingMode((int)tmpFile.length()); - con.connect(); - // send the data - FileInputStream in = new FileInputStream(tmpFile); - Util.copyStream(in,con.getOutputStream()); - in.close(); + String location = home+"job/"+projectNameEnc+"/postBuildResult"; + while(true) { + try { + // start a remote connection + HttpURLConnection con = (HttpURLConnection) new URL(location).openConnection(); + if (auth != null) con.setRequestProperty("Authorization", auth); + con.setDoOutput(true); + // this tells HttpURLConnection not to buffer the whole thing + con.setFixedLengthStreamingMode((int)tmpFile.length()); + con.connect(); + // send the data + FileInputStream in = new FileInputStream(tmpFile); + Util.copyStream(in,con.getOutputStream()); + in.close(); - if(con.getResponseCode()!=200) { - Util.copyStream(con.getErrorStream(),System.err); + if(con.getResponseCode()!=200) { + Util.copyStream(con.getErrorStream(),System.err); + } + + return ret; + } catch (HttpRetryException e) { + if(e.getLocation()!=null) { + // retry with the new location + location = e.getLocation(); + continue; + } + // otherwise failed for reasons beyond us. + throw e; } - - return ret; - } catch (HttpRetryException e) { - if(e.getLocation()!=null) { - // retry with the new location - location = e.getLocation(); - continue; - } - // otherwise failed for reasons beyond us. - throw e; } + } finally { + tmpFile.delete(); } }