Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added pipeline support #10

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.480</version>
<version>1.577</version>
</parent>

<artifactId>text-finder</artifactId>
Expand Down
33 changes: 19 additions & 14 deletions src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@
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;
import hudson.tasks.BuildStepMonitor;
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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -69,25 +73,26 @@ 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.
*/
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.
Expand All @@ -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<Boolean>() {
foundText |= workspace.act(new FileCallable<Boolean>() {
public Boolean invoke(File ws, VirtualChannel channel) throws IOException {
PrintStream logger = new PrintStream(ros);

Expand Down Expand Up @@ -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);
}
}

Expand Down