📄 tomcatlauncherplugin.java
字号:
package com.sysdeo.eclipse.tomcat;
/*
* (c) Copyright Sysdeo SA 2001, 2002.
* All Rights Reserved.
*/
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.MissingResourceException;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IPluginDescriptor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import com.sysdeo.eclipse.tomcat.editors.ProjectListElement;
/**
* The main plugin class to be used in the desktop.
*/
public class TomcatLauncherPlugin extends AbstractUIPlugin {
public static final String PLUGIN_ID = "com.sysdeo.eclipse.tomcat" ;
public static final String NATURE_ID = PLUGIN_ID + ".tomcatnature" ;
static final String TOMCAT_PREF_HOME_KEY = "tomcatDir";
static final String TOMCAT_PREF_BASE_KEY = "tomcatBase";
static final String TOMCAT_PREF_CONFIGFILE_KEY = "tomcatConfigFile";
static final String TOMCAT_PREF_VERSION_KEY = "tomcatVersion";
static final String TOMCAT_PREF_JRE_KEY = "tomcatJRE";
static final String TOMCAT_PREF_JVM_PARAMETERS_KEY = "jvmParameters";
static final String TOMCAT_PREF_JVM_CLASSPATH_KEY = "jvmClasspath";
static final String TOMCAT_PREF_JVM_BOOTCLASSPATH_KEY = "jvmBootClasspath";
static final String TOMCAT_PREF_PROJECTSINCP_KEY = "projectsInCp";
static final String TOMCAT_PREF_PROJECTSINSOURCEPATH_KEY = "projectsInSourcePath";
static final String TOMCAT_PREF_COMPUTESOURCEPATH_KEY = "computeSourcePath";
static final String TOMCAT_PREF_DEBUGMODE_KEY = "tomcatDebugMode";
static final String TOMCAT_PREF_TARGETPERSPECTIVE = "targetPerspective";
static final String TOMCAT_PREF_SECURITYMANAGER = "enabledSecurityManager";
static final String TOMCAT_PREF_MANAGER_URL = "managerUrl";
static final String TOMCAT_PREF_MANAGER_USER = "managerUser";
static final String TOMCAT_PREF_MANAGER_PASSWORD = "managerPassword";
static final String TOMCAT_VERSION3 = "tomcatV3";
static final String TOMCAT_VERSION4 = "tomcatV4";
static final String TOMCAT_VERSION41 = "tomcatV41";
static final String TOMCAT_VERSION5 = "tomcatV5";
static final String TOMCAT_VERSION6 = "tomcatV6";
static final String TOMCAT_PREF_CONFMODE_KEY = "configMode";
static final String SERVERXML_MODE = "serverFile";
static final String CONTEXTFILES_MODE = "contextFiles";
static final String TOMCAT_PREF_CONTEXTSDIR_KEY = "contextsDir";
private static final String TOMCAT_HOME_CLASSPATH_VARIABLE = "TOMCAT_HOME";
//The shared instance.
private static TomcatLauncherPlugin plugin;
//Resource bundle.
private ResourceBundle resourceBundle;
/**
* The constructor.
*/
public TomcatLauncherPlugin(IPluginDescriptor descriptor) {
super(descriptor);
plugin = this;
try {
resourceBundle= PropertyResourceBundle.getBundle("resources");
} catch (MissingResourceException x) {
resourceBundle = null;
}
this.getWorkspace().addResourceChangeListener(new TomcatProjectChangeListener(), IResourceChangeEvent.PRE_DELETE);
}
/**
* Remove TOMCAT_HOME variable from Tomcat projects build path
* (Eclipse 3 will not compile Tomcat projects without this fix)
*/
private void fixTomcatHomeBug() {
if(this.getPreferenceStore().getString("fixTomcatHomeBug").equals("")) {
this.getPreferenceStore().setValue("fixTomcatHomeBug", "fixed");
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject[] projects = root.getProjects();
try {
for (int i = 0; i < projects.length; i++) {
if(projects[i].hasNature(NATURE_ID)) {
List cp = new ArrayList(projects.length - 1);
IJavaProject javaProject = JavaCore.create(projects[i]);
IClasspathEntry[] classpath = javaProject.getRawClasspath();
cp.addAll(Arrays.asList(classpath));
for (int j = 0; j < classpath.length; j++) {
if(classpath[j].getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
if(classpath[j].getPath().equals(TomcatLauncherPlugin.getDefault().getTomcatIPath()))
cp.remove(classpath[j]);
}
}
javaProject.setRawClasspath((IClasspathEntry[])cp.toArray(new IClasspathEntry[cp.size()]), null);
}
}
} catch (Exception e) {
log(e);
}
}
}
/**
* Returns the shared instance.
*/
public static TomcatLauncherPlugin getDefault() {
return plugin;
}
/**
* Returns the workspace instance.
*/
public static IWorkspace getWorkspace() {
return ResourcesPlugin.getWorkspace();
}
/**
* Returns the active shell for this plugin.
*/
public static Shell getShell() {
return getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
}
/**
* Returns the string from the plugin's resource bundle,
* or 'key' if not found.
*/
public static String getResourceString(String key) {
ResourceBundle bundle= TomcatLauncherPlugin.getDefault().getResourceBundle();
try {
return bundle.getString(key);
} catch (MissingResourceException e) {
return key;
}
}
/**
* Returns the plugin's resource bundle,
*/
public ResourceBundle getResourceBundle() {
try {
resourceBundle= PropertyResourceBundle.getBundle("resources");
} catch (MissingResourceException x) {
resourceBundle = null;
}
return resourceBundle;
}
public String getTomcatDir() {
IPreferenceStore pref = TomcatLauncherPlugin.getDefault().getPreferenceStore();
return pref.getString(TOMCAT_PREF_HOME_KEY);
}
public String getTomcatBase() {
IPreferenceStore pref = TomcatLauncherPlugin.getDefault().getPreferenceStore();
return pref.getString(TOMCAT_PREF_BASE_KEY);
}
public String getConfigFile() {
IPreferenceStore pref = TomcatLauncherPlugin.getDefault().getPreferenceStore();
return pref.getString(TOMCAT_PREF_CONFIGFILE_KEY);
}
public String getConfigMode() {
IPreferenceStore pref = TomcatLauncherPlugin.getDefault().getPreferenceStore();
return pref.getString(TOMCAT_PREF_CONFMODE_KEY);
}
public String getContextsDir() {
IPreferenceStore pref = TomcatLauncherPlugin.getDefault().getPreferenceStore();
return pref.getString(TOMCAT_PREF_CONTEXTSDIR_KEY);
}
public String getTomcatVersion() {
IPreferenceStore pref = TomcatLauncherPlugin.getDefault().getPreferenceStore();
String result = pref.getString(TOMCAT_PREF_VERSION_KEY);
if (result.equals(""))
result = TOMCAT_VERSION4;
return result;
}
public String getTomcatJRE() {
IPreferenceStore pref = TomcatLauncherPlugin.getDefault().getPreferenceStore();
String result = pref.getString(TOMCAT_PREF_JRE_KEY);
if (result.equals(""))
result = JavaRuntime.getDefaultVMInstall().getId();
return result;
}
public boolean isDebugMode() {
IPreferenceStore pref = TomcatLauncherPlugin.getDefault().getPreferenceStore();
return !pref.getBoolean(TOMCAT_PREF_DEBUGMODE_KEY);
}
public String getTargetPerspective() {
IPreferenceStore pref = TomcatLauncherPlugin.getDefault().getPreferenceStore();
return pref.getString(TOMCAT_PREF_TARGETPERSPECTIVE);
}
public boolean isSecurityManagerEnabled() {
IPreferenceStore pref = TomcatLauncherPlugin.getDefault().getPreferenceStore();
return pref.getBoolean(TOMCAT_PREF_SECURITYMANAGER);
}
public String getJvmParamaters() {
IPreferenceStore pref = TomcatLauncherPlugin.getDefault().getPreferenceStore();
return pref.getString(TOMCAT_PREF_JVM_PARAMETERS_KEY);
}
public String getJvmClasspath() {
IPreferenceStore pref = TomcatLauncherPlugin.getDefault().getPreferenceStore();
return pref.getString(TOMCAT_PREF_JVM_CLASSPATH_KEY);
}
public String getJvmBootClasspath() {
IPreferenceStore pref = TomcatLauncherPlugin.getDefault().getPreferenceStore();
return pref.getString(TOMCAT_PREF_JVM_BOOTCLASSPATH_KEY);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -