blob: 928c77eff6f17bfcdf4abd47713f127394f6f834 [file] [log] [blame]
package org.eclipse.jdt.internal.launching;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import java.util.HashMap;
import java.util.Hashtable;
import org.eclipse.core.internal.events.ResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IPluginDescriptor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.launching.IVMConnector;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.IVMInstallChangedListener;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.launching.sourcelookup.ArchiveSourceLocation;
public class LaunchingPlugin extends Plugin implements Preferences.IPropertyChangeListener, IVMInstallChangedListener, IResourceChangeListener {
/**
* Identifier for 'vmConnectors' extension point
*/
public static final String ID_EXTENSION_POINT_VM_CONNECTORS = getUniqueIdentifier() + ".vmConnectors"; //$NON-NLS-1$
private static LaunchingPlugin fgLaunchingPlugin;
private HashMap fVMConnectors = null;
public LaunchingPlugin(IPluginDescriptor descriptor) {
super(descriptor);
fgLaunchingPlugin= this;
}
/**
* Convenience method which returns the unique identifier of this plugin.
*/
public static String getUniqueIdentifier() {
if (getDefault() == null) {
// If the default instance is not yet initialized,
// return a static identifier. This identifier must
// match the plugin id defined in plugin.xml
return "org.eclipse.jdt.launching"; //$NON-NLS-1$
}
return getDefault().getDescriptor().getUniqueIdentifier();
}
public static LaunchingPlugin getDefault() {
return fgLaunchingPlugin;
}
public static void log(IStatus status) {
getDefault().getLog().log(status);
}
public static void log(String message) {
log(new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR, message, null));
}
public static void log(Throwable e) {
log(new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR, e.getMessage(), e));
}
/**
* Clears zip file cache.
* Shutdown the launch config helper.
*
* @see Plugin#shutdown()
*/
public void shutdown() throws CoreException {
ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
ArchiveSourceLocation.closeArchives();
getPluginPreferences().removePropertyChangeListener(this);
JavaRuntime.removeVMInstallChangedListener(this);
savePluginPreferences();
super.shutdown();
}
/**
* @see Plugin#startup()
*/
public void startup() throws CoreException {
super.startup();
// Exclude launch configurations from being copied to the output directory
String launchFilter = "*." + ILaunchConfiguration.LAUNCH_CONFIGURATION_FILE_EXTENSION; //$NON-NLS-1$
Hashtable optionsMap = JavaCore.getOptions();
String filters= (String)optionsMap.get("org.eclipse.jdt.core.builder.resourceCopyExclusionFilter"); //$NON-NLS-1$
boolean modified = false;
if (filters == null || filters.length() == 0) {
filters= launchFilter;
modified = true;
} else if (filters.indexOf(launchFilter) == -1) {
filters= filters + ',' + launchFilter; //$NON-NLS-1$
modified = true;
}
if (modified) {
optionsMap.put("org.eclipse.jdt.core.builder.resourceCopyExclusionFilter", filters); //$NON-NLS-1$
JavaCore.setOptions(optionsMap);
}
// set default preference values
getPluginPreferences().setDefault(JavaRuntime.PREF_CONNECT_TIMEOUT, JavaRuntime.DEF_CONNECT_TIMEOUT);
getPluginPreferences().addPropertyChangeListener(this);
JavaRuntime.addVMInstallChangedListener(this);
ResourcesPlugin.getWorkspace().addResourceChangeListener(this, ResourceChangeEvent.PRE_DELETE | ResourceChangeEvent.PRE_CLOSE);
}
/**
* Returns the VM connector with the specified id, or <code>null</code>
* if none.
*
* @param id connector identifier
* @return VM connector
*/
public IVMConnector getVMConnector(String id) {
if (fVMConnectors == null) {
initializeVMConnectors();
}
return (IVMConnector)fVMConnectors.get(id);
}
/**
* Returns all VM connector extensions.
*
* @return VM connectors
*/
public IVMConnector[] getVMConnectors() {
if (fVMConnectors == null) {
initializeVMConnectors();
}
return (IVMConnector[])fVMConnectors.values().toArray(new IVMConnector[fVMConnectors.size()]);
}
/**
* Loads VM connector extensions
*/
private void initializeVMConnectors() {
IExtensionPoint extensionPoint= Platform.getPluginRegistry().getExtensionPoint(ID_EXTENSION_POINT_VM_CONNECTORS);
IConfigurationElement[] configs= extensionPoint.getConfigurationElements();
MultiStatus status= new MultiStatus(getUniqueIdentifier(), IStatus.OK, LaunchingMessages.getString("LaunchingPlugin.Exception_occurred_reading_vmConnectors_extensions_1"), null); //$NON-NLS-1$
fVMConnectors = new HashMap(configs.length);
for (int i= 0; i < configs.length; i++) {
try {
IVMConnector vmConnector= (IVMConnector)configs[i].createExecutableExtension("class"); //$NON-NLS-1$
fVMConnectors.put(vmConnector.getIdentifier(), vmConnector);
} catch (CoreException e) {
status.add(e.getStatus());
}
}
if (!status.isOK()) {
LaunchingPlugin.log(status);
}
}
/**
* Save preferences whenever they change.
*
* @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
*/
public void propertyChange(PropertyChangeEvent event) {
if (event.getProperty().equals(JavaRuntime.PREF_CONNECT_TIMEOUT)) {
savePluginPreferences();
}
}
/**
* @see IVMInstallChangedListener#defaultVMInstallChanged(IVMInstall, IVMInstall)
*/
public void defaultVMInstallChanged(
IVMInstall previous,
IVMInstall current) {
}
/**
* @see IVMInstallChangedListener#vmAdded(IVMInstall)
*/
public void vmAdded(IVMInstall vm) {
}
/**
* @see IVMInstallChangedListener#vmChanged(PropertyChangeEvent)
*/
public void vmChanged(
org.eclipse.jdt.launching.PropertyChangeEvent event) {
}
/**
* @see IVMInstallChangedListener#vmRemoved(IVMInstall)
*/
public void vmRemoved(IVMInstall vm) {
JREContainerInitializer init = new JREContainerInitializer();
try {
init.updateRemovedVM(vm);
} catch (CoreException e) {
log(e);
}
}
/**
* Clear the archive cache when a project is about to be deleted.
*
* @see IResourceChangeListener#resourceChanged(IResourceChangeEvent)
*/
public void resourceChanged(IResourceChangeEvent event) {
ArchiveSourceLocation.closeArchives();
}
}