1 package hudson.model; 2 3 import hudson.EnvVars; 4 5 import java.io.File ; 6 import java.util.Map ; 7 8 13 public final class JDK { 14 private final String name; 15 private final String javaHome; 16 17 public JDK(String name, String javaHome) { 18 this.name = name; 19 this.javaHome = javaHome; 20 } 21 22 25 public String getJavaHome() { 26 return javaHome; 27 } 28 29 32 public String getName() { 33 return name; 34 } 35 36 39 public File getBinDir() { 40 return new File (getJavaHome(),"bin"); 41 } 42 45 private File getExecutable() { 46 String execName; 47 if(File.separatorChar=='\\') 48 execName = "java.exe"; 49 else 50 execName = "java"; 51 52 return new File (getJavaHome(),"bin/"+execName); 53 } 54 55 58 public boolean getExists() { 59 return getExecutable().exists(); 60 } 61 62 65 public void buildEnvVars(Map <String ,String > env) { 66 String 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 |