01: /*******************************************************************************
02: * Copyright (c) 2000, 2004 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jsp.launching;
11:
12: import java.util.ArrayList;
13: import java.util.List;
14:
15: import org.eclipse.core.runtime.CoreException;
16: import org.eclipse.core.runtime.IPath;
17: import org.eclipse.core.runtime.Path;
18: import org.eclipse.debug.core.ILaunchConfiguration;
19: import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
20: import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
21: import org.eclipse.jdt.launching.IVMInstall;
22: import org.eclipse.jdt.launching.JavaRuntime;
23: import org.eclipse.jdt.launching.LibraryLocation;
24: import org.eclipse.jdt.launching.StandardClasspathProvider;
25:
26: /**
27: * TomcatClasspathProvider
28: */
29: public class TomcatClasspathProvider extends StandardClasspathProvider {
30:
31: /**
32: * Tomcat requires <code>tools.jar</code> and <code>bootstrap.jar</code> on its
33: * classpath.
34: *
35: * @see org.eclipse.jdt.launching.IRuntimeClasspathProvider#computeUnresolvedClasspath(org.eclipse.debug.core.ILaunchConfiguration)
36: */
37: public IRuntimeClasspathEntry[] computeUnresolvedClasspath(
38: ILaunchConfiguration configuration) throws CoreException {
39: boolean useDefault = configuration
40: .getAttribute(
41: IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH,
42: true);
43: if (useDefault) {
44: IRuntimeClasspathEntry[] defaults = super
45: .computeUnresolvedClasspath(configuration);
46: IVMInstall vm = JavaRuntime.computeVMInstall(configuration);
47: LibraryLocation[] libs = JavaRuntime
48: .getLibraryLocations(vm);
49: List rtes = new ArrayList();
50: for (int i = 0; i < defaults.length; i++) {
51: rtes.add(defaults[i]);
52: }
53: // add bootstrap.jar
54: String catalinaHome = TomcatLaunchDelegate
55: .getCatalinaHome();
56: IPath path = new Path(catalinaHome)
57: .append("bin").append("bootstrap.jar"); //$NON-NLS-1$ //$NON-NLS-2$
58: IRuntimeClasspathEntry r = JavaRuntime
59: .newArchiveRuntimeClasspathEntry(path);
60: r.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES);
61: rtes.add(r);
62: // add class libraries to bootpath
63: boolean tools = false; // keeps track of whether a tools.jar was found
64: for (int i = 0; i < libs.length; i++) {
65: LibraryLocation lib = libs[i];
66: if (lib.getSystemLibraryPath().toString().endsWith(
67: "tools.jar")) { //$NON-NLS-1$
68: tools = true;
69: }
70: }
71: if (!tools) {
72: // add a tools.jar
73: IPath toolsPath = new Path(vm.getInstallLocation()
74: .getAbsolutePath())
75: .append("lib").append("tools.jar"); //$NON-NLS-1$ //$NON-NLS-2$
76: if (toolsPath.toFile().exists()) {
77: r = JavaRuntime
78: .newArchiveRuntimeClasspathEntry(toolsPath);
79: r
80: .setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES);
81: rtes.add(r);
82: }
83: }
84: return (IRuntimeClasspathEntry[]) rtes
85: .toArray(new IRuntimeClasspathEntry[rtes.size()]);
86: } else {
87: // recover persisted classpath
88: return recoverRuntimePath(configuration,
89: IJavaLaunchConfigurationConstants.ATTR_CLASSPATH);
90: }
91: }
92:
93: }
|