KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > launching > StandardVMType


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.launching;
12
13
14 import java.io.File JavaDoc;
15 import java.io.IOException JavaDoc;
16 import java.net.MalformedURLException JavaDoc;
17 import java.net.URL JavaDoc;
18 import java.util.ArrayList JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.HashSet JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.ListIterator JavaDoc;
24 import java.util.Map JavaDoc;
25 import java.util.Map.Entry;
26
27 import org.eclipse.core.runtime.CoreException;
28 import org.eclipse.core.runtime.IPath;
29 import org.eclipse.core.runtime.IStatus;
30 import org.eclipse.core.runtime.Path;
31 import org.eclipse.core.runtime.Platform;
32 import org.eclipse.core.runtime.Status;
33 import org.eclipse.debug.core.DebugPlugin;
34 import org.eclipse.debug.core.ILaunchManager;
35 import org.eclipse.debug.core.Launch;
36 import org.eclipse.debug.core.model.IProcess;
37 import org.eclipse.debug.core.model.IStreamsProxy;
38 import org.eclipse.jdt.launching.AbstractVMInstallType;
39 import org.eclipse.jdt.launching.IVMInstall;
40 import org.eclipse.jdt.launching.LibraryLocation;
41 import org.eclipse.osgi.service.environment.Constants;
42
43 import com.ibm.icu.text.MessageFormat;
44
45 /**
46  * A VM install type for VMs the conform to the standard
47  * JDK installation layout.
48  */

49 public class StandardVMType extends AbstractVMInstallType {
50     
51     public static final String JavaDoc ID_STANDARD_VM_TYPE = "org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType"; //$NON-NLS-1$
52

53     /**
54      * The root path for the attached source
55      */

56     private String JavaDoc fDefaultRootPath;
57     
58     /**
59      * Map of the install path for which we were unable to generate
60      * the library info during this session.
61      */

62     private static Map JavaDoc fgFailedInstallPath = new HashMap JavaDoc();
63         
64     /**
65      * Convenience handle to the system-specific file separator character
66      */

67     private static final char fgSeparator = File.separatorChar;
68
69     /**
70      * The list of locations in which to look for the java executable in candidate
71      * VM install locations, relative to the VM install location.
72      */

73     private static final String JavaDoc[] fgCandidateJavaFiles = {"javaw", "javaw.exe", "java", "java.exe", "j9w", "j9w.exe", "j9", "j9.exe"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
74
private static final String JavaDoc[] fgCandidateJavaLocations = {"bin" + fgSeparator, "jre" + fgSeparator + "bin" + fgSeparator}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
75

76     /**
77      * Starting in the specified VM install location, attempt to find the 'java' executable
78      * file. If found, return the corresponding <code>File</code> object, otherwise return
79      * <code>null</code>.
80      */

81     public static File JavaDoc findJavaExecutable(File JavaDoc vmInstallLocation) {
82         // Try each candidate in order. The first one found wins. Thus, the order
83
// of fgCandidateJavaLocations and fgCandidateJavaFiles is significant.
84
for (int i = 0; i < fgCandidateJavaFiles.length; i++) {
85             for (int j = 0; j < fgCandidateJavaLocations.length; j++) {
86                 File JavaDoc javaFile = new File JavaDoc(vmInstallLocation, fgCandidateJavaLocations[j] + fgCandidateJavaFiles[i]);
87                 if (javaFile.isFile()) {
88                     return javaFile;
89                 }
90             }
91         }
92         return null;
93     }
94     
95     /* (non-Javadoc)
96      * @see org.eclipse.jdt.launching.IVMInstallType#getName()
97      */

98     public String JavaDoc getName() {
99         return LaunchingMessages.StandardVMType_Standard_VM_3;
100     }
101
102     /* (non-Javadoc)
103      * @see org.eclipse.jdt.launching.AbstractVMInstallType#doCreateVMInstall(java.lang.String)
104      */

105     protected IVMInstall doCreateVMInstall(String JavaDoc id) {
106         return new StandardVM(this, id);
107     }
108     
109     /**
110      * Return library information corresponding to the specified install
111      * location. If the info does not exist, create it using the given Java
112      * executable.
113      */

114     protected synchronized LibraryInfo getLibraryInfo(File JavaDoc javaHome, File JavaDoc javaExecutable) {
115         
116         // See if we already know the info for the requested VM. If not, generate it.
117
String JavaDoc installPath = javaHome.getAbsolutePath();
118         LibraryInfo info = LaunchingPlugin.getLibraryInfo(installPath);
119         if (info == null) {
120             info= (LibraryInfo)fgFailedInstallPath.get(installPath);
121             if (info == null) {
122                 info = generateLibraryInfo(javaHome, javaExecutable);
123                 if (info == null) {
124                     info = getDefaultLibraryInfo(javaHome);
125                     fgFailedInstallPath.put(installPath, info);
126                 } else {
127                     // only persist if we were able to generate info - see bug 70011
128
LaunchingPlugin.setLibraryInfo(installPath, info);
129                 }
130             }
131         }
132         return info;
133     }
134     
135     /**
136      * Return <code>true</code> if the appropriate system libraries can be found for the
137      * specified java executable, <code>false</code> otherwise.
138      */

139     protected boolean canDetectDefaultSystemLibraries(File JavaDoc javaHome, File JavaDoc javaExecutable) {
140         LibraryLocation[] locations = getDefaultLibraryLocations(javaHome);
141         String JavaDoc version = getVMVersion(javaHome, javaExecutable);
142         return locations.length > 0 && !version.startsWith("1.1"); //$NON-NLS-1$
143
}
144     
145     /**
146      * Returns the version of the VM at the given location, with the given
147      * executable.
148      *
149      * @param javaHome
150      * @param javaExecutable
151      * @return String
152      */

153     protected String JavaDoc getVMVersion(File JavaDoc javaHome, File JavaDoc javaExecutable) {
154         LibraryInfo info = getLibraryInfo(javaHome, javaExecutable);
155         return info.getVersion();
156     }
157         
158     /* (non-Javadoc)
159      * @see org.eclipse.jdt.launching.IVMInstallType#detectInstallLocation()
160      */

161     public File JavaDoc detectInstallLocation() {
162         // do not detect on the Mac OS
163
if (Platform.getOS().equals(Constants.OS_MACOSX)) {
164             return null;
165         }
166         
167         // Retrieve the 'java.home' system property. If that directory doesn't exist,
168
// return null.
169
File JavaDoc javaHome;
170         try {
171             javaHome= new File JavaDoc (System.getProperty("java.home")).getCanonicalFile(); //$NON-NLS-1$
172
} catch (IOException JavaDoc e) {
173             LaunchingPlugin.log(e);
174             return null;
175         }
176         if (!javaHome.exists()) {
177             return null;
178         }
179
180         // Find the 'java' executable file under the java home directory. If it can't be
181
// found, return null.
182
File JavaDoc javaExecutable = findJavaExecutable(javaHome);
183         if (javaExecutable == null) {
184             return null;
185         }
186         
187         // If the reported java home directory terminates with 'jre', first see if
188
// the parent directory contains the required libraries
189
boolean foundLibraries = false;
190         if (javaHome.getName().equalsIgnoreCase("jre")) { //$NON-NLS-1$
191
File JavaDoc parent= new File JavaDoc(javaHome.getParent());
192             if (canDetectDefaultSystemLibraries(parent, javaExecutable)) {
193                 javaHome = parent;
194                 foundLibraries = true;
195             }
196         }
197         
198         // If we haven't already found the libraries, look in the reported java home dir
199
if (!foundLibraries) {
200             if (!canDetectDefaultSystemLibraries(javaHome, javaExecutable)) {
201                 return null;
202             }
203         }
204         
205         return javaHome;
206     }
207
208     /**
209      * Return an <code>IPath</code> corresponding to the single library file containing the
210      * standard Java classes for most VMs version 1.2 and above.
211      */

212     protected IPath getDefaultSystemLibrary(File JavaDoc javaHome) {
213         IPath jreLibPath= new Path(javaHome.getPath()).append("lib").append("rt.jar"); //$NON-NLS-2$ //$NON-NLS-1$
214
if (jreLibPath.toFile().isFile()) {
215             return jreLibPath;
216         }
217         return new Path(javaHome.getPath()).append("jre").append("lib").append("rt.jar"); //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$
218
}
219     
220     /**
221      * Returns a path to the source attachment for the given libaray, or
222      * an empty path if none.
223      *
224      * @param libLocation
225      * @return a path to the source attachment for the given library, or
226      * an empty path if none
227      */

228     protected IPath getDefaultSystemLibrarySource(File JavaDoc libLocation) {
229         File JavaDoc parent= libLocation.getParentFile();
230         while (parent != null) {
231             File JavaDoc parentsrc= new File JavaDoc(parent, "src.jar"); //$NON-NLS-1$
232
if (parentsrc.isFile()) {
233                 setDefaultRootPath("src");//$NON-NLS-1$
234
return new Path(parentsrc.getPath());
235             }
236             parentsrc= new File JavaDoc(parent, "src.zip"); //$NON-NLS-1$
237
if (parentsrc.isFile()) {
238                 setDefaultRootPath(""); //$NON-NLS-1$
239
return new Path(parentsrc.getPath());
240             }
241             parent = parent.getParentFile();
242         }
243         // if we didn't find any of the normal source files, look for J9 source
244
IPath result = checkForJ9LibrarySource(libLocation);
245         if (result != null)
246             return result;
247         setDefaultRootPath(""); //$NON-NLS-1$
248
return Path.EMPTY;
249     }
250
251     // J9 has a known/fixed structure for its libs and source locations. Here just
252
// look for the source associated with each lib.
253
private IPath checkForJ9LibrarySource(File JavaDoc libLocation) {
254         File JavaDoc parent= libLocation.getParentFile();
255         String JavaDoc name = libLocation.getName();
256         if (name.equalsIgnoreCase("classes.zip")) { //$NON-NLS-1$
257
File JavaDoc source = new File JavaDoc(parent, "source/source.zip"); //$NON-NLS-1$
258
return source.isFile() ? new Path(source.getPath()) : Path.EMPTY;
259         }
260         if (name.equalsIgnoreCase("locale.zip")) { //$NON-NLS-1$
261
File JavaDoc source = new File JavaDoc(parent, "source/locale-src.zip"); //$NON-NLS-1$
262
return source.isFile() ? new Path(source.getPath()) : Path.EMPTY;
263         }
264         if (name.equalsIgnoreCase("charconv.zip")) { //$NON-NLS-1$
265
File JavaDoc source = new File JavaDoc(parent, "charconv-src.zip"); //$NON-NLS-1$
266
return source.isFile() ? new Path(source.getPath()) : Path.EMPTY;
267         }
268         return null;
269     }
270
271     protected IPath getDefaultPackageRootPath() {
272         return new Path(getDefaultRootPath());
273     }
274
275     /**
276      * NOTE: We do not add libraries from the "endorsed" directory explicitly, as
277      * the bootpath contains these entries already (if they exist).
278      *
279      * @see org.eclipse.jdt.launching.IVMInstallType#getDefaultLibraryLocations(File)
280      */

281     public LibraryLocation[] getDefaultLibraryLocations(File JavaDoc installLocation) {
282
283         // Determine the java executable that corresponds to the specified install location
284
// and use this to generate library info. If no java executable was found,
285
// the 'standard' libraries will be returned.
286
File JavaDoc javaExecutable = findJavaExecutable(installLocation);
287         LibraryInfo libInfo;
288         if (javaExecutable == null) {
289             libInfo = getDefaultLibraryInfo(installLocation);
290         } else {
291             libInfo = getLibraryInfo(installLocation, javaExecutable);
292         }
293         
294         // Add all endorsed libraries - they are first, as they replace
295
List JavaDoc allLibs = new ArrayList JavaDoc(gatherAllLibraries(libInfo.getEndorsedDirs()));
296         
297         // next is the boot path libraries
298
String JavaDoc[] bootpath = libInfo.getBootpath();
299         List JavaDoc boot = new ArrayList JavaDoc(bootpath.length);
300         URL JavaDoc url = getDefaultJavadocLocation(installLocation);
301         for (int i = 0; i < bootpath.length; i++) {
302             IPath path = new Path(bootpath[i]);
303             File JavaDoc lib = path.toFile();
304             if (lib.exists() && lib.isFile()) {
305                 LibraryLocation libraryLocation = new LibraryLocation(path,
306                                 getDefaultSystemLibrarySource(lib),
307                                 getDefaultPackageRootPath(),
308                                 url);
309                 boot.add(libraryLocation);
310             }
311         }
312         allLibs.addAll(boot);
313                 
314         // Add all extension libraries
315
allLibs.addAll(gatherAllLibraries(libInfo.getExtensionDirs()));
316         
317         //remove duplicates
318
HashSet JavaDoc set = new HashSet JavaDoc();
319         LibraryLocation lib = null;
320         for(ListIterator JavaDoc liter = allLibs.listIterator(); liter.hasNext();) {
321             lib = (LibraryLocation) liter.next();
322             IPath systemLibraryPath = lib.getSystemLibraryPath();
323             String JavaDoc device = systemLibraryPath.getDevice();
324             if (device != null) {
325                 // @see Bug 197866 - Installed JRE Wizard creates duplicate system libraries when drive letter is lower case
326
systemLibraryPath = systemLibraryPath.setDevice(device.toUpperCase());
327             }
328             if(!set.add(systemLibraryPath.toOSString())) {
329                 //did not add it, duplicate
330
liter.remove();
331             }
332         }
333         return (LibraryLocation[])allLibs.toArray(new LibraryLocation[allLibs.size()]);
334     }
335     
336     /**
337      * Returns default library info for the given install location.
338      *
339      * @param installLocation
340      * @return LibraryInfo
341      */

342     protected LibraryInfo getDefaultLibraryInfo(File JavaDoc installLocation) {
343         IPath rtjar = getDefaultSystemLibrary(installLocation);
344         File JavaDoc extDir = getDefaultExtensionDirectory(installLocation);
345         File JavaDoc endDir = getDefaultEndorsedDirectory(installLocation);
346         String JavaDoc[] dirs = null;
347         if (extDir == null) {
348             dirs = new String JavaDoc[0];
349         } else {
350             dirs = new String JavaDoc[] {extDir.getAbsolutePath()};
351         }
352         String JavaDoc[] endDirs = null;
353         if (endDir == null) {
354             endDirs = new String JavaDoc[0];
355         } else {
356             endDirs = new String JavaDoc[] {endDir.getAbsolutePath()};
357         }
358         return new LibraryInfo("???", new String JavaDoc[] {rtjar.toOSString()}, dirs, endDirs); //$NON-NLS-1$
359
}
360     
361     /**
362      * Returns a list of all zips and jars contained in the given directories.
363      *
364      * @param dirPaths a list of absolute paths of directories to search
365      * @return List of all zips and jars
366      */

367     protected List JavaDoc gatherAllLibraries(String JavaDoc[] dirPaths) {
368         List JavaDoc libraries = new ArrayList JavaDoc();
369         for (int i = 0; i < dirPaths.length; i++) {
370             File JavaDoc extDir = new File JavaDoc(dirPaths[i]);
371             if (extDir.exists() && extDir.isDirectory()) {
372                 String JavaDoc[] names = extDir.list();
373                 for (int j = 0; j < names.length; j++) {
374                     String JavaDoc name = names[j];
375                     File JavaDoc jar = new File JavaDoc(extDir, name);
376                     if (jar.isFile()) {
377                         int length = name.length();
378                         if (length > 4) {
379                             String JavaDoc suffix = name.substring(length - 4);
380                             if (suffix.equalsIgnoreCase(".zip") || suffix.equalsIgnoreCase(".jar")) { //$NON-NLS-1$ //$NON-NLS-2$
381
try {
382                                     IPath libPath = new Path(jar.getCanonicalPath());
383                                     LibraryLocation library = new LibraryLocation(libPath, Path.EMPTY, Path.EMPTY, null);
384                                     libraries.add(library);
385                                 } catch (IOException JavaDoc e) {
386                                     LaunchingPlugin.log(e);
387                                 }
388                             }
389                         }
390                     }
391                 }
392             }
393         }
394         return libraries;
395     }
396         
397     /**
398      * Returns the default location of the extension directory, based on the given
399      * install location. The resulting file may not exist, or be <code>null</code>
400      * if an extension directory is not supported.
401      *
402      * @param installLocation
403      * @return default extension directory or <code>null</code>
404      */

405     protected File JavaDoc getDefaultExtensionDirectory(File JavaDoc installLocation) {
406         File JavaDoc jre = null;
407         if (installLocation.getName().equalsIgnoreCase("jre")) { //$NON-NLS-1$
408
jre = installLocation;
409         } else {
410             jre = new File JavaDoc(installLocation, "jre"); //$NON-NLS-1$
411
}
412         File JavaDoc lib = new File JavaDoc(jre, "lib"); //$NON-NLS-1$
413
File JavaDoc ext = new File JavaDoc(lib, "ext"); //$NON-NLS-1$
414
return ext;
415     }
416
417     /**
418      * Returns the default location of the endorsed directory, based on the
419      * given install location. The resulting file may not exist, or be
420      * <code>null</code> if an endorsed directory is not supported.
421      *
422      * @param installLocation
423      * @return default endorsed directory or <code>null</code>
424      */

425     protected File JavaDoc getDefaultEndorsedDirectory(File JavaDoc installLocation) {
426         File JavaDoc lib = new File JavaDoc(installLocation, "lib"); //$NON-NLS-1$
427
File JavaDoc ext = new File JavaDoc(lib, "endorsed"); //$NON-NLS-1$
428
return ext;
429     }
430
431     protected String JavaDoc getDefaultRootPath() {
432         return fDefaultRootPath;
433     }
434
435     protected void setDefaultRootPath(String JavaDoc defaultRootPath) {
436         fDefaultRootPath = defaultRootPath;
437     }
438     
439     /* (non-Javadoc)
440      * @see org.eclipse.jdt.launching.IVMInstallType#validateInstallLocation(java.io.File)
441      */

442     public IStatus validateInstallLocation(File JavaDoc javaHome) {
443         IStatus status = null;
444         if (Platform.getOS().equals(Constants.OS_MACOSX)) {
445             status = new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(), 0, LaunchingMessages.StandardVMType_Standard_VM_not_supported_on_MacOS__1, null);
446         } else {
447             File JavaDoc javaExecutable = findJavaExecutable(javaHome);
448             if (javaExecutable == null) {
449                 status = new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(), 0, LaunchingMessages.StandardVMType_Not_a_JDK_Root__Java_executable_was_not_found_1, null); //
450
} else {
451                 if (canDetectDefaultSystemLibraries(javaHome, javaExecutable)) {
452                     status = new Status(IStatus.OK, LaunchingPlugin.getUniqueIdentifier(), 0, LaunchingMessages.StandardVMType_ok_2, null);
453                 } else {
454                     status = new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(), 0, LaunchingMessages.StandardVMType_Not_a_JDK_root__System_library_was_not_found__1, null);
455                 }
456             }
457         }
458         return status;
459     }
460
461     /**
462      * Generates library information for the given java executable. A main
463      * program is run (<code>org.eclipse.jdt.internal.launching.support.
464      * LibraryDetector</code>), that dumps the system properties for bootpath
465      * and extension directories. This output is then parsed and cached for
466      * future reference.
467      *
468      * @return library info or <code>null</code> if none
469      */

470     protected LibraryInfo generateLibraryInfo(File JavaDoc javaHome, File JavaDoc javaExecutable) {
471         LibraryInfo info = null;
472         
473         // if this is 1.1.X, the properties will not exist
474
IPath classesZip = new Path(javaHome.getAbsolutePath()).append("lib").append("classes.zip"); //$NON-NLS-1$ //$NON-NLS-2$
475
if (classesZip.toFile().exists()) {
476             return new LibraryInfo("1.1.x", new String JavaDoc[] {classesZip.toOSString()}, new String JavaDoc[0], new String JavaDoc[0]); //$NON-NLS-1$
477
}
478         //locate the launching support jar - it contains the main program to run
479
File JavaDoc file = LaunchingPlugin.getFileInPlugin(new Path("lib/launchingsupport.jar")); //$NON-NLS-1$
480
if (file.exists()) {
481             String JavaDoc javaExecutablePath = javaExecutable.getAbsolutePath();
482             String JavaDoc[] cmdLine = new String JavaDoc[] {javaExecutablePath, "-classpath", file.getAbsolutePath(), "org.eclipse.jdt.internal.launching.support.LibraryDetector"}; //$NON-NLS-1$ //$NON-NLS-2$
483
Process JavaDoc p = null;
484             try {
485                 String JavaDoc envp[] = null;
486                 if (Platform.OS_MACOSX.equals(Platform.getOS())) {
487                     Map JavaDoc map = DebugPlugin.getDefault().getLaunchManager().getNativeEnvironmentCasePreserved();
488                     if (map.remove(StandardVMDebugger.JAVA_JVM_VERSION) != null) {
489                         envp = new String JavaDoc[map.size()];
490                         Iterator JavaDoc iterator = map.entrySet().iterator();
491                         int i = 0;
492                         while (iterator.hasNext()) {
493                             Entry entry = (Entry) iterator.next();
494                             envp[i] = (String JavaDoc)entry.getKey() + "=" + (String JavaDoc)entry.getValue(); //$NON-NLS-1$
495
i++;
496                         }
497                     }
498                 }
499                 p = DebugPlugin.exec(cmdLine, null, envp);
500                 IProcess process = DebugPlugin.newProcess(new Launch(null, ILaunchManager.RUN_MODE, null), p, "Library Detection"); //$NON-NLS-1$
501
for (int i= 0; i < 200; i++) {
502                     // Wait no more than 10 seconds (200 * 50 mils)
503
if (process.isTerminated()) {
504                         break;
505                     }
506                     try {
507                         Thread.sleep(50);
508                     } catch (InterruptedException JavaDoc e) {
509                     }
510                 }
511                 info = parseLibraryInfo(process);
512             } catch (CoreException ioe) {
513                 LaunchingPlugin.log(ioe);
514             } finally {
515                 if (p != null) {
516                     p.destroy();
517                 }
518             }
519         }
520         if (info == null) {
521             // log error that we were unable to generate library info - see bug 70011
522
LaunchingPlugin.log(MessageFormat.format("Failed to retrieve default libraries for {0}", new String JavaDoc[]{javaHome.getAbsolutePath()})); //$NON-NLS-1$
523
}
524         return info;
525     }
526     
527     /**
528      * Parses the output from 'LibraryDetector'.
529      */

530     protected LibraryInfo parseLibraryInfo(IProcess process) {
531         IStreamsProxy streamsProxy = process.getStreamsProxy();
532         String JavaDoc text = null;
533         if (streamsProxy != null) {
534             text = streamsProxy.getOutputStreamMonitor().getContents();
535         }
536         if (text != null && text.length() > 0) {
537             int index = text.indexOf("|"); //$NON-NLS-1$
538
if (index > 0) {
539                 String JavaDoc version = text.substring(0, index);
540                 text = text.substring(index + 1);
541                 index = text.indexOf("|"); //$NON-NLS-1$
542
if (index > 0) {
543                     String JavaDoc bootPaths = text.substring(0, index);
544                     String JavaDoc[] bootPath = parsePaths(bootPaths);
545                      
546                     text = text.substring(index + 1);
547                     index = text.indexOf("|"); //$NON-NLS-1$
548

549                     if (index > 0) {
550                         String JavaDoc extDirPaths = text.substring(0, index);
551                         String JavaDoc endorsedDirsPath = text.substring(index + 1);
552                         String JavaDoc[] extDirs = parsePaths(extDirPaths);
553                         String JavaDoc[] endDirs = parsePaths(endorsedDirsPath);
554                         return new LibraryInfo(version, bootPath, extDirs, endDirs);
555                     }
556                 }
557             }
558         }
559         return null;
560     }
561     
562     protected String JavaDoc[] parsePaths(String JavaDoc paths) {
563         List JavaDoc list = new ArrayList JavaDoc();
564         int pos = 0;
565         int index = paths.indexOf(File.pathSeparatorChar, pos);
566         while (index > 0) {
567             String JavaDoc path = paths.substring(pos, index);
568             list.add(path);
569             pos = index + 1;
570             index = paths.indexOf(File.pathSeparatorChar, pos);
571         }
572         String JavaDoc path = paths.substring(pos);
573         if (!path.equals("null")) { //$NON-NLS-1$
574
list.add(path);
575         }
576         return (String JavaDoc[])list.toArray(new String JavaDoc[list.size()]);
577     }
578     
579     /* (non-Javadoc)
580      * @see org.eclipse.jdt.launching.IVMInstallType#disposeVMInstall(java.lang.String)
581      */

582     public void disposeVMInstall(String JavaDoc id) {
583         IVMInstall vm = findVMInstall(id);
584         if (vm != null) {
585             String JavaDoc path = vm.getInstallLocation().getAbsolutePath();
586             LaunchingPlugin.setLibraryInfo(path, null);
587             fgFailedInstallPath.remove(path);
588         }
589         super.disposeVMInstall(id);
590     }
591
592     /* (non-Javadoc)
593      * @see org.eclipse.jdt.launching.AbstractVMInstallType#getDefaultJavadocLocation(java.io.File)
594      */

595     public URL JavaDoc getDefaultJavadocLocation(File JavaDoc installLocation) {
596         File JavaDoc javaExecutable = findJavaExecutable(installLocation);
597         if (javaExecutable != null) {
598             LibraryInfo libInfo = getLibraryInfo(installLocation, javaExecutable);
599             if (libInfo != null) {
600                 String JavaDoc version = libInfo.getVersion();
601                 if (version != null) {
602                     try {
603                         if (version.startsWith("1.6")) { //$NON-NLS-1$
604
return new URL JavaDoc("http://java.sun.com/javase/6/docs/api/"); //$NON-NLS-1$
605
} else if (version.startsWith("1.5")) { //$NON-NLS-1$
606
return new URL JavaDoc("http://java.sun.com/j2se/1.5.0/docs/api/"); //$NON-NLS-1$
607
} else if (version.startsWith("1.4")) { //$NON-NLS-1$
608
return new URL JavaDoc("http://java.sun.com/j2se/1.4.2/docs/api/"); //$NON-NLS-1$
609
} else if (version.startsWith("1.3")) { //$NON-NLS-1$
610
return new URL JavaDoc("http://java.sun.com/j2se/1.3/docs/api/"); //$NON-NLS-1$
611
} else if (version.startsWith("1.2")) { //$NON-NLS-1$
612
return new URL JavaDoc("http://java.sun.com/products/jdk/1.2/docs/api"); //$NON-NLS-1$
613
}
614                     } catch (MalformedURLException JavaDoc e) {
615                     }
616                 }
617             }
618         }
619         return null;
620     }
621
622 }
623
Popular Tags