PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/hudson-test-framework/src/main/java/org/jvnet/hudson/test/MockBuilder.java

http://github.com/hudson/hudson
Java | 45 lines | 31 code | 9 blank | 5 comment | 0 complexity | 1b2e32254e65972abe8c8e4f12bf6b5f MD5 | raw file
 1package org.jvnet.hudson.test;
 2
 3import hudson.Extension;
 4import hudson.Launcher;
 5import hudson.model.AbstractBuild;
 6import hudson.model.BuildListener;
 7import hudson.model.Descriptor;
 8import hudson.model.Result;
 9import hudson.tasks.Builder;
10
11import java.io.IOException;
12
13import net.sf.json.JSONObject;
14import org.kohsuke.stapler.StaplerRequest;
15
16/**
17 * Forces the build result to be some pre-configured value.
18 *
19 * @author Kohsuke Kawaguchi
20 */
21public class MockBuilder extends Builder {
22    public final Result result;
23
24    public MockBuilder(Result result) {
25        this.result = result;
26    }
27
28    public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
29        listener.getLogger().println("Simulating a specific result code "+result);
30        build.setResult(result);
31        return true;
32    }
33
34    @Extension
35    public static final class DescriptorImpl extends Descriptor<Builder> {
36        public Builder newInstance(StaplerRequest req, JSONObject data) {
37            throw new UnsupportedOperationException();
38        }
39
40        public String getDisplayName() {
41            return "Force the build result";
42        }
43    }
44}
45