diff --git a/pom.xml b/pom.xml index 44b4a7f..24df80b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.jenkins-ci.plugins plugin - 1.480 + 1.577 text-finder diff --git a/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java b/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java index 9d0f0a4..ee3d64d 100644 --- a/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java +++ b/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java @@ -4,11 +4,13 @@ import hudson.Launcher; import hudson.Util; import hudson.Extension; +import hudson.FilePath; + import static hudson.Util.fixEmpty; -import hudson.model.AbstractBuild; import hudson.model.AbstractProject; -import hudson.model.BuildListener; import hudson.model.Result; +import hudson.model.Run; +import hudson.model.TaskListener; import hudson.remoting.RemoteOutputStream; import hudson.remoting.VirtualChannel; import hudson.tasks.BuildStepDescriptor; @@ -16,6 +18,8 @@ import hudson.tasks.Publisher; import hudson.tasks.Recorder; import hudson.util.FormValidation; +import jenkins.tasks.SimpleBuildStep; + import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.types.FileSet; import org.apache.commons.io.IOUtils; @@ -39,7 +43,7 @@ * * @author Santiago.PericasGeertsen@sun.com */ -public class TextFinderPublisher extends Recorder implements Serializable { +public class TextFinderPublisher extends Recorder implements Serializable, SimpleBuildStep { public final String fileSet; public final String regexp; @@ -52,7 +56,7 @@ public class TextFinderPublisher extends Recorder implements Serializable { @DataBoundConstructor public TextFinderPublisher(String fileSet, String regexp, boolean succeedIfFound, boolean unstableIfFound, boolean alsoCheckConsoleOutput) { - this.fileSet = Util.fixEmpty(fileSet.trim()); + this.fileSet = fileSet != null ? Util.fixEmpty(fileSet.trim()) : null; this.regexp = regexp; this.succeedIfFound = succeedIfFound; this.unstableIfFound = unstableIfFound; @@ -69,11 +73,12 @@ public TextFinderPublisher(String fileSet, String regexp, boolean succeedIfFound public BuildStepMonitor getRequiredMonitorService() { return BuildStepMonitor.NONE; } - - public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { - findText(build, listener.getLogger()); - return true; - } + + @Override + public void perform(Run run, FilePath workspace, Launcher launcher, + TaskListener listener) throws InterruptedException, IOException { + findText(run, workspace, listener.getLogger()); + } /** * Indicates an orderly abortion of the processing. @@ -81,13 +86,13 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListen private static final class AbortException extends RuntimeException { } - private void findText(AbstractBuild build, PrintStream logger) throws IOException, InterruptedException { + private void findText(Run run, FilePath workspace, PrintStream logger) throws IOException, InterruptedException { try { boolean foundText = false; if(alsoCheckConsoleOutput) { logger.println("Checking console output"); - foundText |= checkFile(build.getLogFile(), compilePattern(logger), logger, true); + foundText |= checkFile(run.getLogFile(), compilePattern(logger), logger, true); } else { // printing this when checking console output will cause the plugin // to find this line, which would be pointless. @@ -98,7 +103,7 @@ private void findText(AbstractBuild build, PrintStream logger) throws IOExceptio final RemoteOutputStream ros = new RemoteOutputStream(logger); if(fileSet!=null) { - foundText |= build.getWorkspace().act(new FileCallable() { + foundText |= workspace.act(new FileCallable() { public Boolean invoke(File ws, VirtualChannel channel) throws IOException { PrintStream logger = new PrintStream(ros); @@ -145,10 +150,10 @@ public Boolean invoke(File ws, VirtualChannel channel) throws IOException { } if (foundText != succeedIfFound) - build.setResult(unstableIfFound ? Result.UNSTABLE : Result.FAILURE); + run.setResult(unstableIfFound ? Result.UNSTABLE : Result.FAILURE); } catch (AbortException e) { // no test file found - build.setResult(Result.UNSTABLE); + run.setResult(Result.UNSTABLE); } }