Skip to content

Commit

Permalink
Fix JENKINS-20325
Browse files Browse the repository at this point in the history
Added fileNotFoundMessage paramter. The %s in the message will be replaced
with the filename.
  • Loading branch information
slide committed Nov 3, 2013
1 parent f4f1428 commit 178360e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Expand Up @@ -5,6 +5,7 @@
import hudson.model.TaskListener;
import hudson.plugins.emailext.plugins.EmailToken;
import java.io.IOException;
import org.codehaus.plexus.util.StringUtils;
import org.jenkinsci.plugins.tokenmacro.DataBoundTokenMacro;
import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException;

Expand All @@ -18,6 +19,8 @@
public class WorkspaceFileContent extends DataBoundTokenMacro {
@Parameter(required=true)
public String path = "";
@Parameter
public String fileNotFoundMessage = "";

public static final String MACRO_NAME = "FILE";

Expand All @@ -30,7 +33,7 @@ public boolean acceptsMacroName(String macroName) {
public String evaluate(AbstractBuild<?, ?> context, TaskListener listener, String macroName)
throws MacroEvaluationException, IOException, InterruptedException {
if(!context.getWorkspace().child(path).exists()) {
return "ERROR: File '" + path + "' does not exist";
return StringUtils.isNotBlank(fileNotFoundMessage) ? String.format(fileNotFoundMessage, path) : "ERROR: File '" + path + "' does not exist";
}

// do some environment variable substitution
Expand Down
Expand Up @@ -42,5 +42,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
assertEquals("Hello, world!", content.evaluate(build, listener, WorkspaceFileContent.MACRO_NAME));
content.path = "no-such-file";
assertEquals("ERROR: File 'no-such-file' does not exist", content.evaluate(build, listener, WorkspaceFileContent.MACRO_NAME));
content.fileNotFoundMessage = "No '%s' for you!";
assertEquals("No 'no-such-file' for you!", content.evaluate(build, listener, WorkspaceFileContent.MACRO_NAME));
}
}

0 comments on commit 178360e

Please sign in to comment.