Skip to content
Permalink
Browse files

JENKINS-46132 - Bring FileContent and FilePathContent closer.

`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 b28c11e9ff8d91e0e7e22c6d1d980ab46dafe5f6
Showing with 22 additions and 5 deletions.
  1. +22 −5 src/main/java/com/cloudbees/jenkins/support/api/FilePathContent.java
@@ -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
@@ -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;
}
}
}

@@ -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.
You can’t perform that action at this time.