1 package hudson.model; 2 3 import hudson.model.RunMap.Constructor; 4 import org.kohsuke.stapler.StaplerRequest; 5 import org.kohsuke.stapler.StaplerResponse; 6 7 import javax.servlet.ServletException ; 8 import javax.servlet.http.HttpServletResponse ; 9 import java.io.File ; 10 import java.io.IOException ; 11 import java.util.logging.Logger ; 12 13 20 public class ExternalJob extends ViewJob<ExternalJob,ExternalRun> implements TopLevelItem { 21 public ExternalJob(String name) { 22 super(Hudson.getInstance(),name); 23 } 24 25 @Override 26 public Hudson getParent() { 27 return (Hudson)super.getParent(); 28 } 29 30 @Override 31 protected void reload() { 32 this.runs.load(this,new Constructor<ExternalRun>() { 33 public ExternalRun create(File dir) throws IOException { 34 return new ExternalRun(ExternalJob.this,dir); 35 } 36 }); 37 } 38 39 40 45 public ExternalRun newBuild() throws IOException { 46 ExternalRun run = new ExternalRun(this); 47 runs.put(run); 48 return run; 49 } 50 51 54 public void doAcceptBuildResult( StaplerRequest req, StaplerResponse rsp ) throws IOException , ServletException { 55 rsp.setStatus(HttpServletResponse.SC_OK); 56 } 57 58 61 public void doPostBuildResult( StaplerRequest req, StaplerResponse rsp ) throws IOException , ServletException { 62 ExternalRun run = newBuild(); 63 run.acceptRemoteSubmission(req.getReader()); 64 rsp.setStatus(HttpServletResponse.SC_OK); 65 } 66 67 68 private static final Logger logger = Logger.getLogger(ExternalJob.class.getName()); 69 70 public TopLevelItemDescriptor getDescriptor() { 71 return DESCRIPTOR; 72 } 73 74 public static final TopLevelItemDescriptor DESCRIPTOR = new DescriptorImpl(); 75 76 public static final class DescriptorImpl extends TopLevelItemDescriptor { 77 private DescriptorImpl() { 78 super(ExternalJob.class); 79 } 80 81 public String getDisplayName() { 82 return "Monitor an external job"; 83 } 84 85 public ExternalJob newInstance(String name) { 86 return new ExternalJob(name); 87 } 88 } 89 } 90 | Popular Tags |