KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > model > JDK


1 package hudson.model;
2
3 import hudson.EnvVars;
4
5 import java.io.File JavaDoc;
6 import java.util.Map JavaDoc;
7
8 /**
9  * Information about JDK installation.
10  *
11  * @author Kohsuke Kawaguchi
12  */

13 public final class JDK {
14     private final String JavaDoc name;
15     private final String JavaDoc javaHome;
16
17     public JDK(String JavaDoc name, String JavaDoc javaHome) {
18         this.name = name;
19         this.javaHome = javaHome;
20     }
21
22     /**
23      * install directory.
24      */

25     public String JavaDoc getJavaHome() {
26         return javaHome;
27     }
28
29     /**
30      * Human readable display name.
31      */

32     public String JavaDoc getName() {
33         return name;
34     }
35
36     /**
37      * Gets the path to the bin directory.
38      */

39     public File JavaDoc getBinDir() {
40         return new File JavaDoc(getJavaHome(),"bin");
41     }
42     /**
43      * Gets the path to 'java'.
44      */

45     private File JavaDoc getExecutable() {
46         String JavaDoc execName;
47         if(File.separatorChar=='\\')
48             execName = "java.exe";
49         else
50             execName = "java";
51
52         return new File JavaDoc(getJavaHome(),"bin/"+execName);
53     }
54
55     /**
56      * Returns true if the executable exists.
57      */

58     public boolean getExists() {
59         return getExecutable().exists();
60     }
61
62     /**
63      * Sets PATH and JAVA_HOME from this JDK.
64      */

65     public void buildEnvVars(Map JavaDoc<String JavaDoc,String JavaDoc> env) {
66         String JavaDoc path = env.get("PATH");
67         if(path==null)
68             path = EnvVars.masterEnvVars.get("PATH");
69         
70         if(path==null)
71             path = getBinDir().getPath();
72         else
73             path = getBinDir().getPath()+File.pathSeparator+path;
74         env.put("PATH",path);
75         env.put("JAVA_HOME",javaHome);
76         if(!env.containsKey("HUDSON_HOME"))
77             env.put("HUDSON_HOME", Hudson.getInstance().getRootDir().getPath() );
78     }
79 }
80
Popular Tags