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.io.File;
13: import java.text.MessageFormat;
14:
15: import org.eclipse.core.runtime.CoreException;
16: import org.eclipse.core.runtime.IStatus;
17: import org.eclipse.core.runtime.Status;
18: import org.eclipse.core.variables.IValueVariable;
19: import org.eclipse.core.variables.VariablesPlugin;
20: import org.eclipse.jdt.launching.JavaLaunchDelegate;
21: import org.eclipse.jsp.JspUIPlugin;
22:
23: /**
24: * Launch delegate for a local Tomcat server
25: */
26: public class TomcatLaunchDelegate extends JavaLaunchDelegate {
27:
28: /**
29: * Identifier for Tomcat launch configurations.
30: */
31: public static final String ID_TOMCAT_LAUNCH_CONFIGURATION_TYPE = "org.eclipse.jsp.TomcatConfigurationType"; //$NON-NLS-1$
32:
33: /**
34: * Identifier for Tomcat classpath provider.
35: */
36: public static final String ID_TOMCAT_CLASSPATH_PROVIDER = "org.eclipse.jsp.tomcatClasspathProvider"; //$NON-NLS-1$
37:
38: /**
39: * Launch configuration attribute - value is path to local installation of Tomcat.
40: * The path may be encoded in a launch variable.
41: */
42: public static final String ATTR_CATALINA_HOME = "org.eclipse.jsp.CATALINA_HOME"; //$NON-NLS-1$
43:
44: /**
45: * Constructs a new launch delegate
46: */
47: public TomcatLaunchDelegate() {
48: super ();
49: }
50:
51: /**
52: * Returns the value of the <code>${catalina_home}</code> launch variable.
53: *
54: * @return the value of the <code>${catalina_home}</code> launch variable
55: * @exception CoreException if the variable or value is undefined
56: */
57: public static String getCatalinaHome() throws CoreException {
58: IValueVariable variable = VariablesPlugin.getDefault()
59: .getStringVariableManager().getValueVariable(
60: "catalina_home"); //$NON-NLS-1$
61: IStatus err = null;
62: if (variable == null) {
63: err = new Status(IStatus.ERROR, JspUIPlugin.getDefault()
64: .getDescriptor().getUniqueIdentifier(), 0,
65: LaunchingMessages.TomcatLaunchDelegate_9, null);
66: } else {
67: String home = variable.getValue();
68: if (home != null && home.length() > 0) {
69: File file = new File(home);
70: if (file.exists() && file.isDirectory()) {
71: return home;
72: } else {
73: err = new Status(
74: IStatus.ERROR,
75: JspUIPlugin.getDefault().getDescriptor()
76: .getUniqueIdentifier(),
77: 0,
78: MessageFormat
79: .format(
80: LaunchingMessages.TomcatLaunchDelegate_7,
81: new String[] { home }),
82: null);
83: }
84: } else {
85: err = new Status(IStatus.ERROR, JspUIPlugin
86: .getDefault().getDescriptor()
87: .getUniqueIdentifier(), 0,
88: LaunchingMessages.TomcatLaunchDelegate_8, null);
89: }
90: }
91: throw new CoreException(err);
92: }
93: }
|