KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > model > ExternalJob


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 JavaDoc;
8 import javax.servlet.http.HttpServletResponse JavaDoc;
9 import java.io.File JavaDoc;
10 import java.io.IOException JavaDoc;
11 import java.util.logging.Logger JavaDoc;
12
13 /**
14  * Job that runs outside Hudson whose result is submitted to Hudson
15  * (either via web interface, or simply by placing files on the file system,
16  * for compatibility.)
17  *
18  * @author Kohsuke Kawaguchi
19  */

20 public class ExternalJob extends ViewJob<ExternalJob,ExternalRun> implements TopLevelItem {
21     public ExternalJob(String JavaDoc name) {
22         super(Hudson.getInstance(),name);
23     }
24
25     @Override JavaDoc
26     public Hudson getParent() {
27         return (Hudson)super.getParent();
28     }
29
30     @Override JavaDoc
31     protected void reload() {
32         this.runs.load(this,new Constructor<ExternalRun>() {
33             public ExternalRun create(File JavaDoc dir) throws IOException JavaDoc {
34                 return new ExternalRun(ExternalJob.this,dir);
35             }
36         });
37     }
38
39
40     /**
41      * Creates a new build of this project for immediate execution.
42      *
43      * Needs to be synchronized so that two {@link #newBuild()} invocations serialize each other.
44      */

45     public ExternalRun newBuild() throws IOException JavaDoc {
46         ExternalRun run = new ExternalRun(this);
47         runs.put(run);
48         return run;
49     }
50
51     /**
52      * Used to check if this is an external job and ready to accept a build result.
53      */

54     public void doAcceptBuildResult( StaplerRequest req, StaplerResponse rsp ) throws IOException JavaDoc, ServletException JavaDoc {
55         rsp.setStatus(HttpServletResponse.SC_OK);
56     }
57
58     /**
59      * Used to post the build result from a remote machine.
60      */

61     public void doPostBuildResult( StaplerRequest req, StaplerResponse rsp ) throws IOException JavaDoc, ServletException JavaDoc {
62         ExternalRun run = newBuild();
63         run.acceptRemoteSubmission(req.getReader());
64         rsp.setStatus(HttpServletResponse.SC_OK);
65     }
66
67
68     private static final Logger JavaDoc 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 JavaDoc getDisplayName() {
82             return "Monitor an external job";
83         }
84
85         public ExternalJob newInstance(String JavaDoc name) {
86             return new ExternalJob(name);
87         }
88     }
89 }
90
Popular Tags