mirror of https://github.com/jenkinsci/jenkins.git
Improved handling when TaskListener is null (#4201)
This commit is contained in:
parent
7aa09f4674
commit
5c10c6c055
|
|
@ -844,10 +844,13 @@ public final class FilePath implements SerializableOnlyOverRemoting {
|
|||
* @since 1.299
|
||||
*/
|
||||
public boolean installIfNecessaryFrom(@Nonnull URL archive, @CheckForNull TaskListener listener, @Nonnull String message) throws IOException, InterruptedException {
|
||||
if (listener == null) {
|
||||
listener = TaskListener.NULL;
|
||||
}
|
||||
return installIfNecessaryFrom(archive, listener, message, MAX_REDIRECTS);
|
||||
}
|
||||
|
||||
private boolean installIfNecessaryFrom(@Nonnull URL archive, @CheckForNull TaskListener listener, @Nonnull String message, int maxRedirects) throws InterruptedException, IOException {
|
||||
private boolean installIfNecessaryFrom(@Nonnull URL archive, @Nonnull TaskListener listener, @Nonnull String message, int maxRedirects) throws InterruptedException, IOException {
|
||||
try {
|
||||
FilePath timestamp = this.child(".timestamp");
|
||||
long lastModified = timestamp.lastModified();
|
||||
|
|
@ -861,9 +864,7 @@ public final class FilePath implements SerializableOnlyOverRemoting {
|
|||
} catch (IOException x) {
|
||||
if (this.exists()) {
|
||||
// Cannot connect now, so assume whatever was last unpacked is still OK.
|
||||
if (listener != null) {
|
||||
listener.getLogger().println("Skipping installation of " + archive + " to " + remote + ": " + x);
|
||||
}
|
||||
listener.getLogger().println("Skipping installation of " + archive + " to " + remote + ": " + x);
|
||||
return false;
|
||||
} else {
|
||||
throw x;
|
||||
|
|
@ -905,8 +906,7 @@ public final class FilePath implements SerializableOnlyOverRemoting {
|
|||
this.mkdirs();
|
||||
}
|
||||
|
||||
if(listener!=null)
|
||||
listener.getLogger().println(message);
|
||||
listener.getLogger().println(message);
|
||||
|
||||
if (isRemote()) {
|
||||
// First try to download from the agent machine.
|
||||
|
|
@ -915,9 +915,7 @@ public final class FilePath implements SerializableOnlyOverRemoting {
|
|||
timestamp.touch(sourceTimestamp);
|
||||
return true;
|
||||
} catch (IOException x) {
|
||||
if (listener != null) {
|
||||
Functions.printStackTrace(x, listener.error("Failed to download " + archive + " from agent; will retry from master"));
|
||||
}
|
||||
Functions.printStackTrace(x, listener.error("Failed to download " + archive + " from agent; will retry from master"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -664,9 +664,8 @@ public class FilePathTest {
|
|||
when(con2.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK);
|
||||
when(con2.getInputStream()).thenReturn(someZippedContent());
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
String message = "going ahead";
|
||||
assertTrue(d.installIfNecessaryFrom(url, new StreamTaskListener(baos), message));
|
||||
assertTrue(d.installIfNecessaryFrom(url, null, message));
|
||||
}
|
||||
|
||||
private URL someUrlToZipFile(final URLConnection con) throws IOException {
|
||||
|
|
|
|||
Loading…
Reference in New Issue