/******************************************************************************* * * Copyright (c) 2004-2010 Oracle Corporation. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * * *******************************************************************************/ package org.jvnet.hudson.test; import hudson.Extension; import hudson.Launcher; import hudson.model.AbstractBuild; import hudson.model.BuildListener; import hudson.model.Descriptor; import hudson.model.Result; import hudson.tasks.Builder; import java.io.IOException; import net.sf.json.JSONObject; import org.kohsuke.stapler.StaplerRequest; /** * Forces the build result to be some pre-configured value. * * @author Kohsuke Kawaguchi */ public class MockBuilder extends Builder { public final Result result; public MockBuilder(Result result) { this.result = result; } public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { listener.getLogger().println("Simulating a specific result code " + result); build.setResult(result); return true; } @Extension public static final class DescriptorImpl extends Descriptor<Builder> { public Builder newInstance(StaplerRequest req, JSONObject data) { throw new UnsupportedOperationException(); } public String getDisplayName() { return "Force the build result"; } } }