KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > scm > SCM


1 package hudson.scm;
2
3 import hudson.ExtensionPoint;
4 import hudson.FilePath;
5 import hudson.Launcher;
6 import hudson.model.AbstractBuild;
7 import hudson.model.AbstractProject;
8 import hudson.model.BuildListener;
9 import hudson.model.Describable;
10 import hudson.model.TaskListener;
11
12 import java.io.File JavaDoc;
13 import java.io.IOException JavaDoc;
14 import java.io.FileWriter JavaDoc;
15 import java.util.Map JavaDoc;
16
17 /**
18  * Captures the configuration information in it.
19  *
20  * <p>
21  * To register a custom {@link SCM} implementation from a plugin,
22  * add it to {@link SCMS#SCMS}.
23  *
24  * @author Kohsuke Kawaguchi
25  */

26 public abstract class SCM implements Describable<SCM>, ExtensionPoint {
27
28     /**
29      * Checks if there has been any changes to this module in the repository.
30      *
31      * TODO: we need to figure out a better way to communicate an error back,
32      * so that we won't keep retrying the same node (for example a slave might be down.)
33      *
34      * @param project
35      * The project to check for updates
36      * @param launcher
37      * Abstraction of the machine where the polling will take place.
38      * @param workspace
39      * The workspace directory that contains baseline files.
40      * @param listener
41      * Logs during the polling should be sent here.
42      *
43      * @return true
44      * if the change is detected.
45      *
46      * @throws InterruptedException
47      * interruption is usually caused by the user aborting the computation.
48      * this exception should be simply propagated all the way up.
49      */

50     public abstract boolean pollChanges(AbstractProject project, Launcher launcher, FilePath workspace, TaskListener listener) throws IOException JavaDoc, InterruptedException JavaDoc;
51
52     /**
53      * Obtains a fresh workspace of the module(s) into the specified directory
54      * of the specified machine.
55      *
56      * <p>
57      * The "update" operation can be performed instead of a fresh checkout if
58      * feasible.
59      *
60      * <p>
61      * This operation should also capture the information necessary to tag the workspace later.
62      *
63      * @param launcher
64      * Abstracts away the machine that the files will be checked out.
65      * @param workspace
66      * a directory to check out the source code. May contain left-over
67      * from the previous build.
68      * @param changelogFile
69      * Upon a successful return, this file should capture the changelog.
70      * When there's no change, this file should contain an empty entry.
71      * See {@link AbstractCVSFamilySCM#createEmptyChangeLog(File, BuildListener, String)}.
72      * @return
73      * false if the operation fails. The error should be reported to the listener.
74      * Otherwise return the changes included in this update (if this was an update.)
75      *
76      * @throws InterruptedException
77      * interruption is usually caused by the user aborting the build.
78      * this exception will cause the build to fail.
79      */

80     public abstract boolean checkout(AbstractBuild build, Launcher launcher, FilePath workspace, BuildListener listener, File JavaDoc changelogFile) throws IOException JavaDoc, InterruptedException JavaDoc;
81
82     /**
83      * Checks out (or updates) the code into the workspace, but without computing changelog.
84      *
85      * TODO: This is an ugly abstraction.
86      * come back and check if this abstraction is really making much sense.
87      */

88     public abstract boolean checkout(Launcher launcher, FilePath workspace, TaskListener listener) throws IOException JavaDoc, InterruptedException JavaDoc;
89
90     /**
91      * Adds environmental variables for the builds to the given map.
92      */

93     public abstract void buildEnvVars(Map JavaDoc<String JavaDoc,String JavaDoc> env);
94
95     /**
96      * Gets the top directory of the checked out module.
97      * @param workspace
98      */

99     public abstract FilePath getModuleRoot(FilePath workspace);
100
101     /**
102      * The returned object will be used to parse <tt>changelog.xml</tt>.
103      */

104     public abstract ChangeLogParser createChangeLogParser();
105
106     protected final boolean createEmptyChangeLog(File JavaDoc changelogFile, BuildListener listener, String JavaDoc rootTag) {
107         try {
108             FileWriter JavaDoc w = new FileWriter JavaDoc(changelogFile);
109             w.write("<"+rootTag +"/>");
110             w.close();
111             return true;
112         } catch (IOException JavaDoc e) {
113             e.printStackTrace(listener.error(e.getMessage()));
114             return false;
115         }
116     }
117
118     protected final String JavaDoc nullify(String JavaDoc s) {
119         if(s==null) return null;
120         if(s.trim().length()==0) return null;
121         return s;
122     }
123 }
124
Popular Tags