Skip to content

Commit

Permalink
JENKINS-46132 - Bring FileContent and FilePathContent closer.
Browse files Browse the repository at this point in the history
`FileContent` handles the `FileNotFoundException` gracefully while
`FilePathContent` wasn't doing it. This resulted in a number of warning
logged which is breaking `SupportActionTest` which expects none.
  • Loading branch information
duemir committed Dec 18, 2017
1 parent a1b81f2 commit b28c11e
Showing 1 changed file with 22 additions and 5 deletions.
Expand Up @@ -24,11 +24,10 @@

package com.cloudbees.jenkins.support.api;

import com.cloudbees.jenkins.support.SupportLogFormatter;
import hudson.FilePath;
import hudson.util.IOException2;

import java.io.IOException;
import java.io.OutputStream;
import java.io.*;

/**
* Content that is stored as a file on a remote disk
Expand All @@ -49,7 +48,25 @@ public void writeTo(OutputStream os) throws IOException {
try {
file.copyTo(os);
} catch (InterruptedException e) {
throw new IOException2(e);
throw new IOException(e);
} catch (IOException e) {
if (e instanceof FileNotFoundException || e.getCause() instanceof FileNotFoundException) {
OutputStreamWriter osw = new OutputStreamWriter(os, "utf-8");
try {
PrintWriter pw = new PrintWriter(osw, true);
try {
pw.println("--- WARNING: Could not attach " + file.getRemote() + " as it cannot currently be found ---");
pw.println();
SupportLogFormatter.printStackTrace(e, pw);
} finally {
pw.flush();
}
} finally {
osw.flush();
}
} else {
throw e;
}
}
}

Expand All @@ -58,7 +75,7 @@ public long getTime() throws IOException {
try {
return file.lastModified();
} catch (InterruptedException e) {
throw new IOException2(e);
throw new IOException(e);
}
}
}

0 comments on commit b28c11e

Please sign in to comment.