/*******************************************************************************
*
* Copyright (c) 2004-2009 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:
*
* Kohsuke Kawaguchi
*
*
*******************************************************************************/
package org.jvnet.hudson.test;
import hudson.Launcher;
import hudson.Extension;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.Descriptor;
import hudson.model.Result;
import hudson.tasks.Builder;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;
import java.io.IOException;
/**
* Mock {@link Builder} that always cause a build to fail.
*
* @author Kohsuke Kawaguchi
*/
public class UnstableBuilder extends Builder {
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
listener.getLogger().println("Simulating an unstable build");
build.setResult(Result.UNSTABLE);
return true;
}
@Extension
public static final class DescriptorImpl extends Descriptor<Builder> {
public String getDisplayName() {
return "Make build unstable";
}
public UnstableBuilder newInstance(StaplerRequest req, JSONObject data) {
return new UnstableBuilder();
}
}
}