diff options
author | Darin Wright | 2009-10-14 20:06:43 +0000 |
---|---|---|
committer | Darin Wright | 2009-10-14 20:06:43 +0000 |
commit | 8781f64dc6b3a1620d3e314d92a0274c5aac0ba0 (patch) | |
tree | 7c96df7c34cb25f0b801bc50e1ac36addea7ae4f /org.eclipse.debug.core/core/org | |
parent | 6d4b7abfdbbdcc593158ba6915917e5c0c3aa297 (diff) | |
download | eclipse.platform.debug-8781f64dc6b3a1620d3e314d92a0274c5aac0ba0.tar.gz eclipse.platform.debug-8781f64dc6b3a1620d3e314d92a0274c5aac0ba0.tar.xz eclipse.platform.debug-8781f64dc6b3a1620d3e314d92a0274c5aac0ba0.zip |
Bug 41353 - [launching] Launch config templates
Diffstat (limited to 'org.eclipse.debug.core/core/org')
8 files changed, 318 insertions, 4 deletions
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchConfiguration.java b/org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchConfiguration.java index 5dbbf4e0d..97d5ff7d4 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchConfiguration.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -596,4 +596,35 @@ public interface ILaunchConfiguration extends IAdaptable { * @since 3.3 */ public boolean isReadOnly(); + + /** + * Returns the template this launch configuration was created from + * or <code>null</code> if none. + * + * @return the template this launch configuration was created from + * or <code>null</code> if none + * @throws CoreException if the template could not be retrieved + * or no longer exists + * @since 3.6 + */ + public ILaunchConfiguration getTemplate() throws CoreException; + + /** + * Returns whether this configuration is a template. + * + * @return whether this configuration is a template + * @throws CoreException if unable to determine if this configuration is a template + * @since 3.6 + */ + public boolean isTemplate() throws CoreException; + + /** + * Returns all configurations made from this template, possibly an + * empty collection. + * + * @return all configurations made from this template + * @throws CoreException + * @since 3.6 + */ + public ILaunchConfiguration[] getTemplateChildren() throws CoreException; } diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchConfigurationType.java b/org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchConfigurationType.java index ded6948a1..4cf7e9c82 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchConfigurationType.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchConfigurationType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -16,6 +16,7 @@ import java.util.Set; import org.eclipse.core.resources.IContainer; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.preferences.IScopeContext; import org.eclipse.debug.core.model.ILaunchConfigurationDelegate; import org.eclipse.debug.core.sourcelookup.ISourcePathComputer; @@ -307,5 +308,60 @@ public interface ILaunchConfigurationType extends IAdaptable { * @since 3.3 */ public String getContributorName(); + + /** + * Sets the template for this launch configuration type in the specified scope, + * or removes the template for the scope when the specified configuration is + * <code>null</code>. + * + * @param configuration template for the specified scope, or <code>null</code> if none + * @param scope scope + * @throws CoreException if unable to to set/remove the template for the given scope + * @since 3.6 + */ + public void setTemplate(ILaunchConfiguration configuration, IScopeContext scope) throws CoreException; + /** + * Returns the template for this launch configuration type in the specified scope + * or <code>null</code> if no template has been set for the scope. + * + * @param scope scope + * @return template for the scope or <code>null</code> + * @throws CoreException if unable to retrieve the template for the scope + * @since 3.6 + */ + public ILaunchConfiguration getTemplate(IScopeContext scope) throws CoreException; + + /** + * Returns all launch configuration templates of the this type, possibly + * an empty collection. + * + * @return all launch configuration templates of the this type + * @throws CoreException if unable to retrieve the templates + * @since 3.6 + */ + public ILaunchConfiguration[] getTemplates() throws CoreException; + + /** + * Returns a new launch configuration working copy of this type, + * that resides in the specified container, with the given name, initialized + * with values in the first template found in the given canonical scope order. + * When <code>container</code> is </code>null</code>, the configuration + * will reside locally in the metadata area. + * Note: a launch configuration is not actually created until the working copy is saved. + * + * @param container the container in which the new configuration will + * reside, or <code>null</code> if the configuration should reside + * locally with the metadata. + * @param name name for the launch configuration + * @param scopes optional context objects to determine which scopes are search + * for a launch configuration template, or <code>null</code> if template scopes + * should not be considered + * @return a new launch configuration working copy instance of this type + * @exception CoreException if an instance of this type + * of launch configuration could not be created for any + * reason + * @since 3.6 + */ + public ILaunchConfigurationWorkingCopy newInstance(IContainer container, String name, IScopeContext[] scopes) throws CoreException; } diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchConfigurationWorkingCopy.java b/org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchConfigurationWorkingCopy.java index 2a8ac2a89..978a74f4f 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchConfigurationWorkingCopy.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchConfigurationWorkingCopy.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -263,4 +263,34 @@ public interface ILaunchConfigurationWorkingCopy extends ILaunchConfiguration, I * @since 3.3 */ public ILaunchConfigurationWorkingCopy getParent(); + + /** + * Copies all attributes from the given template to this working. + * Overwrites any existing attributes with the same key. + * + * @param template configuration template + * @exception CoreException if unable to retrieve attributes from the template + * @since 3.6 + */ + public void copyAttributes(ILaunchConfiguration template) throws CoreException; + + /** + * Sets whether this configuration is to be considered as a template. + * + * @param isTemplate whether this configuration is to be considered as a template + * @since 3.6 + */ + public void setTemplate(boolean isTemplate); + + /** + * Sets the template that this configuration is associated with, possibly <code>null</code>. + * <p> + * When the specified template is <code>null</code>, this working copy is no longer + * associated with any template. + * </p> + * @param template template or <code>null</code> + * @exception CoreException if unable to generate a memento for the given configuration + * @since 3.6 + */ + public void setTemplate(ILaunchConfiguration template) throws CoreException; } diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/DebugCoreMessages.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/DebugCoreMessages.java index 950fa0da9..2e3514d5a 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/DebugCoreMessages.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/DebugCoreMessages.java @@ -51,6 +51,10 @@ public class DebugCoreMessages extends NLS { public static String LaunchConfiguration_8; public static String LaunchConfiguration_9; public static String LaunchConfigurationInfo_35; + public static String LaunchConfigurationType_0; + + public static String LaunchConfigurationType_1; + public static String LaunchConfigurationType_7; public static String LaunchConfigurationWorkingCopy_0; diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/DebugCoreMessages.properties b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/DebugCoreMessages.properties index 0daf6dcf4..e7c72b9ef 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/DebugCoreMessages.properties +++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/DebugCoreMessages.properties @@ -97,6 +97,8 @@ OutputStreamMonitor_label=Output Stream Monitor ProcessMonitorJob_0=Process monitor RuntimeProcess_terminate_failed=Terminate failed RuntimeProcess_Exit_value_not_available_until_process_terminates__1=Exit value not available until process terminates. +LaunchConfigurationType_0=Error retrieving template +LaunchConfigurationType_1=Error setting template LaunchConfigurationType_7=Launch mode not supported: {0} WatchExpression_0=(Watch expressions not supported) NullStreamsProxy_0=Null Stream Monitor diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfiguration.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfiguration.java index 141f43e12..4f546e2ab 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfiguration.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfiguration.java @@ -109,6 +109,22 @@ public class LaunchConfiguration extends PlatformObject implements ILaunchConfig public static final String ATTR_PREFERRED_LAUNCHERS = DebugPlugin.getUniqueIdentifier() + ".preferred_launchers"; //$NON-NLS-1$ /** + * Launch configuration attribute storing a boolean indicating whether this + * configuration is a template. Default value is <code>false</code>. + * + * @since 3.6 + */ + public static final String ATTR_IS_TEMPLATE = DebugPlugin.getUniqueIdentifier() + ".ATTR_IS_TEMPLATE"; //$NON-NLS-1$ + + /** + * Launch configuration attribute storing a memento identifying the template + * this configuration was made from, possibly <code>null</code>. + * + * @since 3.6 + */ + public static final String ATTR_TEMPLATE = DebugPlugin.getUniqueIdentifier() + ".ATTR_TEMPLATE"; //$NON-NLS-1$ + + /** * Status handler to prompt in the UI thread * * @since 3.3 @@ -950,6 +966,39 @@ public class LaunchConfiguration extends PlatformObject implements ILaunchConfig public String toString() { return getName(); } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.ILaunchConfiguration#getTemplate() + */ + public ILaunchConfiguration getTemplate() throws CoreException { + String memento = getAttribute(ATTR_TEMPLATE, (String)null); + if (memento != null) { + return new LaunchConfiguration(memento); + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.ILaunchConfiguration#getTemplateChildren() + */ + public ILaunchConfiguration[] getTemplateChildren() throws CoreException { + ILaunchConfiguration[] configurations = getLaunchManager().getLaunchConfigurations(getType()); + List proteges = new ArrayList(); + for (int i = 0; i < configurations.length; i++) { + ILaunchConfiguration config = configurations[i]; + if (this.equals(config.getTemplate())) { + proteges.add(config); + } + } + return (ILaunchConfiguration[]) proteges.toArray(new ILaunchConfiguration[proteges.size()]); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.ILaunchConfiguration#isTemplate() + */ + public boolean isTemplate() throws CoreException { + return getAttribute(ATTR_IS_TEMPLATE, false); + } } diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfigurationType.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfigurationType.java index a33a579c6..f976c1466 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfigurationType.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfigurationType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,6 +11,7 @@ package org.eclipse.debug.internal.core; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -26,6 +27,8 @@ import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.IScopeContext; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationMigrationDelegate; @@ -36,6 +39,8 @@ import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.core.ILaunchMode; import org.eclipse.debug.core.model.ILaunchConfigurationDelegate; import org.eclipse.debug.core.sourcelookup.ISourcePathComputer; +import org.osgi.service.prefs.BackingStoreException; +import org.osgi.service.prefs.Preferences; import com.ibm.icu.text.MessageFormat; @@ -105,6 +110,14 @@ public class LaunchConfigurationType extends PlatformObject implements ILaunchCo private Map fPreferredDelegates = null; /** + * A preference node that maps launch configuration type identifiers to + * default templates in that scope. + * + * @since 3.6 + */ + private static final String TEMPLATES_NODE = "TEMPLATES_NODE"; //$NON-NLS-1$ + + /** * Constructs a new launch configuration type on the * given configuration element. * @@ -487,5 +500,96 @@ public class LaunchConfigurationType extends PlatformObject implements ILaunchCo return fModeCombinations.contains(modes); } + /* (non-Javadoc) + * @see org.eclipse.debug.core.ILaunchConfigurationType#getTemplate(org.eclipse.core.runtime.preferences.IScopeContext) + */ + public ILaunchConfiguration getTemplate(IScopeContext scope) throws CoreException { + IEclipsePreferences node = scope.getNode(DebugPlugin.getUniqueIdentifier()); + try { + if (node.nodeExists(TEMPLATES_NODE)) { + Preferences templates = node.node(TEMPLATES_NODE); + String memento = templates.get(getIdentifier(), null); + if (memento != null) { + return DebugPlugin.getDefault().getLaunchManager().getLaunchConfiguration(memento); + } + } + } catch (BackingStoreException e) { + throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugCoreMessages.LaunchConfigurationType_0, e)); + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.ILaunchConfigurationType#getTemplates() + */ + public ILaunchConfiguration[] getTemplates() throws CoreException { + ILaunchConfiguration[] configurations = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(this); + List templates = new ArrayList(); + for (int i = 0; i < configurations.length; i++) { + ILaunchConfiguration config = configurations[i]; + if (config.isTemplate()) { + templates.add(config); + } + } + return (ILaunchConfiguration[]) templates.toArray(new ILaunchConfiguration[templates.size()]); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.ILaunchConfigurationType#newInstance(org.eclipse.core.resources.IContainer, java.lang.String, org.eclipse.core.runtime.preferences.IScopeContext[]) + */ + public ILaunchConfigurationWorkingCopy newInstance(IContainer container, String name, IScopeContext[] scopes) throws CoreException { + ILaunchConfiguration template = findTemplate(scopes); + ILaunchConfigurationWorkingCopy wc = new LaunchConfigurationWorkingCopy(container, name, this); + if (template != null) { + wc.copyAttributes(template); + wc.setTemplate(template); + } + return wc; + } + + /** + * Returns the first template found in the given scopes or <code>null</code> if none. + * + * @param contexts scopes to search in or <code>null</code> + * @return template or <code>null</code> + * @throws CoreException if unable to retrieve template + */ + private ILaunchConfiguration findTemplate(IScopeContext[] contexts) throws CoreException { + if (contexts != null) { + for (int i = 0; i < contexts.length; i++) { + ILaunchConfiguration template = getTemplate(contexts[i]); + if (template != null) { + return template; + } + } + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.ILaunchConfigurationType#setTemplate(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.runtime.preferences.IScopeContext) + */ + public void setTemplate(ILaunchConfiguration configuration, IScopeContext scope) throws CoreException { + IEclipsePreferences node = scope.getNode(DebugPlugin.getUniqueIdentifier()); + Preferences templates = node.node(TEMPLATES_NODE); + if (configuration == null) { + templates.remove(getIdentifier()); + try { + if (templates.keys().length == 0) { + templates.removeNode(); + } + } catch (BackingStoreException e) { + throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugCoreMessages.LaunchConfigurationType_1, e)); + } + } else { + templates.put(getIdentifier(), configuration.getMemento()); + } + try { + node.flush(); + } catch (BackingStoreException e) { + throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugCoreMessages.LaunchConfigurationType_1, e)); + } + } + } diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfigurationWorkingCopy.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfigurationWorkingCopy.java index fffc54a7c..104a2d5fe 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfigurationWorkingCopy.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfigurationWorkingCopy.java @@ -17,9 +17,11 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.Map.Entry; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileStore; @@ -715,5 +717,41 @@ public class LaunchConfigurationWorkingCopy extends LaunchConfiguration implemen public Object removeAttribute(String attributeName) { return getInfo().removeAttribute(attributeName); } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.ILaunchConfigurationWorkingCopy#copyAttributes(org.eclipse.debug.core.ILaunchConfiguration) + */ + public void copyAttributes(ILaunchConfiguration template) throws CoreException { + Map map = template.getAttributes(); + Iterator iterator = map.entrySet().iterator(); + LaunchConfigurationInfo info = getInfo(); + while (iterator.hasNext()) { + Entry entry = (Entry) iterator.next(); + String attr = (String) entry.getKey(); + info.setAttribute(attr, entry.getValue()); + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.ILaunchConfigurationWorkingCopy#setTemplate(boolean) + */ + public void setTemplate(boolean isTemplate) { + if (!isTemplate) { + removeAttribute(ATTR_IS_TEMPLATE); + } else { + setAttribute(ATTR_IS_TEMPLATE, isTemplate); + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.ILaunchConfigurationWorkingCopy#setTemplate(org.eclipse.debug.core.ILaunchConfiguration) + */ + public void setTemplate(ILaunchConfiguration template) throws CoreException { + if (template == null) { + removeAttribute(ATTR_TEMPLATE); + } else { + setAttribute(ATTR_TEMPLATE, template.getMemento()); + } + } } |