KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > scm > AbstractCVSFamilySCM


1 package hudson.scm;
2
3 import hudson.EnvVars;
4 import hudson.FilePath;
5 import hudson.Launcher;
6 import hudson.Proc;
7 import hudson.model.BuildListener;
8 import hudson.model.TaskListener;
9 import hudson.util.ArgumentListBuilder;
10
11 import java.io.File JavaDoc;
12 import java.io.FileWriter JavaDoc;
13 import java.io.IOException JavaDoc;
14 import java.io.OutputStream JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.Map JavaDoc;
17
18 /**
19  * Common implementation between {@link CVSSCM} and {@link SubversionSCM}.
20  *
21  * @author Kohsuke Kawaguchi
22  */

23 abstract class AbstractCVSFamilySCM extends SCM {
24     /**
25      * Invokes the command with the specified command line option and wait for its completion.
26      *
27      * @param dir
28      * if launching locally this is a local path, otherwise a remote path.
29      * @param out
30      * Receives output from the executed program.
31      */

32     protected final boolean run(Launcher launcher, ArgumentListBuilder cmd, TaskListener listener, FilePath dir, OutputStream JavaDoc out) throws IOException JavaDoc {
33         Map JavaDoc<String JavaDoc,String JavaDoc> env = createEnvVarMap(true);
34
35         int r = launcher.launch(cmd.toCommandArray(),env,out,dir).join();
36         if(r!=0)
37             listener.fatalError(getDescriptor().getDisplayName()+" failed. exit code="+r);
38
39         return r==0;
40     }
41
42     protected final boolean run(Launcher launcher, ArgumentListBuilder cmd, TaskListener listener, FilePath dir) throws IOException JavaDoc {
43         return run(launcher,cmd,listener,dir,listener.getLogger());
44     }
45
46
47     /**
48      *
49      * @param overrideOnly
50      * true to indicate that the returned map shall only contain
51      * properties that need to be overridden. This is for use with {@link Launcher}.
52      * false to indicate that the map should contain complete map.
53      * This is to invoke {@link Proc} directly.
54      */

55     protected final Map JavaDoc<String JavaDoc,String JavaDoc> createEnvVarMap(boolean overrideOnly) {
56         Map JavaDoc<String JavaDoc,String JavaDoc> env = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
57         if(!overrideOnly)
58             env.putAll(EnvVars.masterEnvVars);
59         buildEnvVars(env);
60         return env;
61     }
62 }
63
Popular Tags