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
|
* @since 1.299
|
||||||
*/
|
*/
|
||||||
public boolean installIfNecessaryFrom(@Nonnull URL archive, @CheckForNull TaskListener listener, @Nonnull String message) throws IOException, InterruptedException {
|
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);
|
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 {
|
try {
|
||||||
FilePath timestamp = this.child(".timestamp");
|
FilePath timestamp = this.child(".timestamp");
|
||||||
long lastModified = timestamp.lastModified();
|
long lastModified = timestamp.lastModified();
|
||||||
|
|
@ -861,9 +864,7 @@ public final class FilePath implements SerializableOnlyOverRemoting {
|
||||||
} catch (IOException x) {
|
} catch (IOException x) {
|
||||||
if (this.exists()) {
|
if (this.exists()) {
|
||||||
// Cannot connect now, so assume whatever was last unpacked is still OK.
|
// 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;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
throw x;
|
throw x;
|
||||||
|
|
@ -905,8 +906,7 @@ public final class FilePath implements SerializableOnlyOverRemoting {
|
||||||
this.mkdirs();
|
this.mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(listener!=null)
|
listener.getLogger().println(message);
|
||||||
listener.getLogger().println(message);
|
|
||||||
|
|
||||||
if (isRemote()) {
|
if (isRemote()) {
|
||||||
// First try to download from the agent machine.
|
// First try to download from the agent machine.
|
||||||
|
|
@ -915,9 +915,7 @@ public final class FilePath implements SerializableOnlyOverRemoting {
|
||||||
timestamp.touch(sourceTimestamp);
|
timestamp.touch(sourceTimestamp);
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException x) {
|
} 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.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK);
|
||||||
when(con2.getInputStream()).thenReturn(someZippedContent());
|
when(con2.getInputStream()).thenReturn(someZippedContent());
|
||||||
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
||||||
String message = "going ahead";
|
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 {
|
private URL someUrlToZipFile(final URLConnection con) throws IOException {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue