1 12 package org.eclipse.jdt.internal.launching.macosx; 13 14 import java.io.File ; 15 import java.io.IOException ; 16 import java.net.MalformedURLException ; 17 import java.net.URL ; 18 import java.text.MessageFormat ; 19 20 import org.eclipse.core.runtime.CoreException; 21 import org.eclipse.core.runtime.IPath; 22 import org.eclipse.core.runtime.IStatus; 23 import org.eclipse.core.runtime.Path; 24 import org.eclipse.core.runtime.Status; 25 26 import org.eclipse.jdt.internal.launching.LaunchingPlugin; 27 import org.eclipse.jdt.internal.launching.LibraryInfo; 28 import org.eclipse.jdt.internal.launching.StandardVMType; 29 30 import org.eclipse.jdt.launching.IVMInstall; 31 import org.eclipse.jdt.launching.JavaRuntime; 32 import org.eclipse.jdt.launching.VMStandin; 33 34 37 public class MacOSXVMInstallType extends StandardVMType { 38 39 57 58 private static final String JAVA_VM_NAME= "Java HotSpot(TM) Client VM"; 60 61 private static final String JVM_VERSION_LOC= "/System/Library/Frameworks/JavaVM.framework/Versions/"; 63 private static final String CURRENT_JVM= "CurrentJDK"; 65 private static final String JVM_ROOT= "Home"; 67 private static final String JAVADOC_LOC= "/Developer/Documentation/Java/Reference/"; 69 private static final String JAVADOC_SUBDIR= "/doc/api"; 71 72 public String getName() { 73 return MacOSXLaunchingPlugin.getString("MacOSXVMType.name"); } 75 76 public IVMInstall doCreateVMInstall(String id) { 77 return new MacOSXVMInstall(this, id); 78 } 79 80 83 public File detectInstallLocation() { 84 85 String javaVMName= System.getProperty("java.vm.name"); if (javaVMName == null || !JAVA_VM_NAME.equals(javaVMName)) 87 return null; 88 89 File defaultLocation= null; 91 File versionDir= new File (JVM_VERSION_LOC); 92 if (versionDir.exists() && versionDir.isDirectory()) { 93 File currentJDK= new File (versionDir, CURRENT_JVM); 94 try { 95 currentJDK= currentJDK.getCanonicalFile(); 96 } catch (IOException ex) { 97 } 99 File [] versions= versionDir.listFiles(); 100 for (int i= 0; i < versions.length; i++) { 101 String version= versions[i].getName(); 102 File home= new File (versions[i], JVM_ROOT); 103 if (home.exists()) { 104 boolean isDefault= currentJDK.equals(versions[i]); 105 IVMInstall install= findVMInstall(version); 106 if (install == null && !CURRENT_JVM.equals(version)) { 107 VMStandin vm= new VMStandin(this, version); 108 vm.setInstallLocation(home); 109 String format= MacOSXLaunchingPlugin.getString(isDefault 110 ? "MacOSXVMType.jvmDefaultName" : "MacOSXVMType.jvmName"); vm.setName(MessageFormat.format(format, new Object [] { version } )); 113 vm.setLibraryLocations(getDefaultLibraryLocations(home)); 114 URL doc= getDefaultJavadocLocation(home); 115 if (doc != null) 116 vm.setJavadocLocation(doc); 117 118 IVMInstall rvm= vm.convertToRealVM(); 119 if (isDefault) { 120 defaultLocation= home; 121 try { 122 JavaRuntime.setDefaultVMInstall(rvm, null); 123 } catch (CoreException e) { 124 LaunchingPlugin.log(e); 125 } 126 } 127 } else { 128 if (isDefault) { 129 defaultLocation= home; 130 try { 131 JavaRuntime.setDefaultVMInstall(install, null); 132 } catch (CoreException e) { 133 LaunchingPlugin.log(e); 134 } 135 } 136 } 137 } 138 } 139 } 140 return defaultLocation; 141 } 142 143 149 protected LibraryInfo getDefaultLibraryInfo(File installLocation) { 150 151 File classes = new File (installLocation, "../Classes"); File lib1= new File (classes, "classes.jar"); File lib2= new File (classes, "ui.jar"); 155 String [] libs = new String [] { lib1.toString(),lib2.toString() }; 156 157 File lib = new File (installLocation, "lib"); File extDir = new File (lib, "ext"); String [] dirs = null; 160 if (extDir == null) 161 dirs = new String [0]; 162 else 163 dirs = new String [] {extDir.getAbsolutePath()}; 164 165 File endDir = new File (lib, "endorsed"); String [] endDirs = null; 167 if (endDir == null) 168 endDirs = new String [0]; 169 else 170 endDirs = new String [] {endDir.getAbsolutePath()}; 171 172 return new LibraryInfo("???", libs, dirs, endDirs); } 174 175 protected IPath getDefaultSystemLibrarySource(File libLocation) { 176 File parent= libLocation.getParentFile(); 177 while (parent != null) { 178 File home= new File (parent, JVM_ROOT); 179 File parentsrc= new File (home, "src.jar"); if (parentsrc.isFile()) { 181 setDefaultRootPath("src"); return new Path(parentsrc.getPath()); 183 } 184 parentsrc= new File (home, "src.zip"); if (parentsrc.isFile()) { 186 setDefaultRootPath(""); return new Path(parentsrc.getPath()); 188 } 189 parent = parent.getParentFile(); 190 } 191 setDefaultRootPath(""); return Path.EMPTY; } 194 195 198 public IStatus validateInstallLocation(File javaHome) { 199 String id= MacOSXLaunchingPlugin.getUniqueIdentifier(); 200 File java= new File (javaHome, "bin"+File.separator+"java"); if (java.isFile()) 202 return new Status(IStatus.OK, id, 0, "ok", null); return new Status(IStatus.ERROR, id, 0, MacOSXLaunchingPlugin.getString("MacOSXVMType.error.notRoot"), null); } 205 206 209 public URL getDefaultJavadocLocation(File installLocation) { 210 211 String id= null; 213 try { 214 String post= File.separator + JVM_ROOT; 215 String path= installLocation.getCanonicalPath(); 216 if (path.startsWith(JVM_VERSION_LOC) && path.endsWith(post)) 217 id= path.substring(JVM_VERSION_LOC.length(), path.length()-post.length()); 218 } catch (IOException ex) { 219 } 221 if (id != null) { 222 String s= JAVADOC_LOC + id + JAVADOC_SUBDIR; File docLocation= new File (s); 224 if (!docLocation.exists()) { 225 s= JAVADOC_LOC + id; 226 docLocation= new File (s); 227 if (!docLocation.exists()) 228 s= null; 229 } 230 if (s != null) { 231 try { 232 return new URL ("file", "", s); } catch (MalformedURLException ex) { 234 } 236 } 237 } 238 239 return super.getDefaultJavadocLocation(installLocation); 241 } 242 } 243 | Popular Tags |