Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchConfiguration.java33
-rw-r--r--org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchConfigurationType.java58
-rw-r--r--org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchConfigurationWorkingCopy.java32
-rw-r--r--org.eclipse.debug.core/core/org/eclipse/debug/internal/core/DebugCoreMessages.java4
-rw-r--r--org.eclipse.debug.core/core/org/eclipse/debug/internal/core/DebugCoreMessages.properties2
-rw-r--r--org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfiguration.java49
-rw-r--r--org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfigurationType.java106
-rw-r--r--org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfigurationWorkingCopy.java38
-rw-r--r--org.eclipse.debug.tests/src/org/eclipe/debug/tests/launching/LaunchConfigurationTests.java174
9 files changed, 492 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());
+ }
+ }
}
diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/launching/LaunchConfigurationTests.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/launching/LaunchConfigurationTests.java
index 42f770fe1..c341c0d7c 100644
--- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/launching/LaunchConfigurationTests.java
+++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/launching/LaunchConfigurationTests.java
@@ -30,10 +30,13 @@ import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationListener;
import org.eclipse.debug.core.ILaunchConfigurationType;
@@ -140,6 +143,17 @@ public class LaunchConfigurationTests extends AbstractLaunchTest implements ILau
assertTrue("Should need saving", wc.isDirty()); //$NON-NLS-1$
return wc;
}
+
+ /**
+ * Creates and returns a new launch configuration with the given name, local
+ * or shared, with no attributes
+ */
+ protected ILaunchConfigurationWorkingCopy newEmptyConfiguration(IContainer container, String name) throws CoreException {
+ ILaunchConfigurationType type = getLaunchManager().getLaunchConfigurationType(ID_TEST_LAUNCH_TYPE);
+ ILaunchConfigurationWorkingCopy wc = type.newInstance(container, name);
+ assertEquals("Should have no attributes", 0, wc.getAttributes().size());
+ return wc;
+ }
/**
* Returns whether the given handle is contained in the specified
@@ -1034,6 +1048,166 @@ public class LaunchConfigurationTests extends AbstractLaunchTest implements ILau
IPath location = workingCopy.getLocation();
assertEquals("Wrong path for local working copy", LaunchManager.LOCAL_LAUNCH_CONFIGURATION_CONTAINER_PATH.append("test-get-location.launch"), location);
}
+
+ /**
+ * Test copying attributes from one configuration to another.
+ *
+ * @throws CoreException
+ */
+ public void testCopyAttributes() throws CoreException {
+ ILaunchConfigurationWorkingCopy source = newConfiguration(null, "test-copy-attributes-source");
+ ILaunchConfigurationWorkingCopy dest = newEmptyConfiguration(null, "test-copy-attributes-dest");
+ dest.copyAttributes(source);
+ assertTrue("String1 should be String1", dest.getAttribute("String1", "Missing").equals("String1"));
+ assertTrue("Int1 should be 1", dest.getAttribute("Int1", 0) == 1);
+ assertTrue("Boolean1 should be true", dest.getAttribute("Boolean1", false));
+ assertTrue("Boolean2 should be false", !dest.getAttribute("Boolean2", true));
+ }
+
+ /**
+ * Tests setting a default template in the project scope.
+ *
+ * @throws CoreException
+ */
+ public void testProjectScopeTemplate() throws CoreException {
+ ILaunchConfigurationWorkingCopy wc = newConfiguration(null, "test-project-scope");
+ ILaunchConfiguration template = wc.doSave();
+ ILaunchConfigurationType type = template.getType();
+ IScopeContext scope = new ProjectScope(getProject());
+ type.setTemplate(template, scope);
+ ILaunchConfiguration configuration = type.getTemplate(scope);
+ assertNotNull("No template found", configuration);
+ assertEquals("Wrong template", template, configuration);
+ // test removing scope
+ type.setTemplate(null, scope);
+ configuration = type.getTemplate(scope);
+ assertNull("Should no longer be a template", configuration);
+ }
+
+ /**
+ * Tests setting a default template in the project scope.
+ *
+ * @throws CoreException
+ */
+ public void testInstanceScopeTemplate() throws CoreException {
+ ILaunchConfigurationWorkingCopy wc = newConfiguration(null, "test-instance-scope");
+ ILaunchConfiguration template = wc.doSave();
+ ILaunchConfigurationType type = template.getType();
+ IScopeContext scope = new InstanceScope();
+ type.setTemplate(template, scope);
+ ILaunchConfiguration configuration = type.getTemplate(scope);
+ assertNotNull("No template found", configuration);
+ assertEquals("Wrong template", template, configuration);
+ // test removing scope
+ type.setTemplate(null, scope);
+ configuration = type.getTemplate(scope);
+ assertNull("Should no longer be a template", configuration);
+ }
+
+ /**
+ * Tests that a default template in the project scope is used to initialize
+ * values.
+ *
+ * @throws CoreException
+ */
+ public void testCreationFromProjectScopeTemplate() throws CoreException {
+ ILaunchConfigurationWorkingCopy pc = newConfiguration(null, "test-project-scope-creation");
+ pc.setAttribute("PROJECT", "PROJECT");
+ ILaunchConfiguration ptemplate = pc.doSave();
+ ILaunchConfigurationWorkingCopy ic = newConfiguration(null, "test-workspace-scope-creation");
+ ic.setAttribute("WORKSPACE", "WORKSPACE");
+ ILaunchConfiguration itemplate = ic.doSave();
+ ILaunchConfigurationType type = ptemplate.getType();
+ IScopeContext pscope = new ProjectScope(getProject());
+ IScopeContext wscope = new InstanceScope();
+ type.setTemplate(ptemplate, pscope);
+ type.setTemplate(itemplate, wscope);
+
+ // create a new configuration in project scope priority
+ ILaunchConfigurationWorkingCopy config = type.newInstance(null, "test-scopes", new IScopeContext[]{pscope, wscope});
+ assertNotNull("Made from wrong template", config.getAttribute("PROJECT", (String)null));
+ assertEquals("Should refer to creation template", ptemplate, config.getTemplate());
+
+ // Removing defaults
+ type.setTemplate(null, pscope);
+ type.setTemplate(null, wscope);
+ ILaunchConfiguration configuration = type.getTemplate(pscope);
+ assertNull("Should no longer be a project template", configuration);
+ configuration = type.getTemplate(wscope);
+ assertNull("Should no longer be a workspace template", configuration);
+ }
+
+ /**
+ * Tests that a default template in the instance scope is used to initialize
+ * values.
+ *
+ * @throws CoreException
+ */
+ public void testCreationFromInsatnceScopeTemplate() throws CoreException {
+ ILaunchConfigurationWorkingCopy ic = newConfiguration(null, "test-workspace-scope-creation");
+ ic.setAttribute("WORKSPACE", "WORKSPACE");
+ ILaunchConfiguration itemplate = ic.doSave();
+ ILaunchConfigurationType type = itemplate.getType();
+ IScopeContext pscope = new ProjectScope(getProject());
+ IScopeContext wscope = new InstanceScope();
+ type.setTemplate(itemplate, wscope);
+
+ // create a new configuration in project scope priority, but picks up workspace scope
+ ILaunchConfigurationWorkingCopy config = type.newInstance(null, "test-scopes", new IScopeContext[]{pscope, wscope});
+ assertNotNull("Made from wrong template", config.getAttribute("WORKSPACE", (String)null));
+ assertEquals("Should refer to creation template", itemplate, config.getTemplate());
+
+ // Removing defaults
+ type.setTemplate(null, wscope);
+ ILaunchConfiguration configuration = type.getTemplate(wscope);
+ assertNull("Should no longer be a workspace template", configuration);
+ }
+
+ /**
+ * Tests setting the 'isTemplate' attribute.
+ *
+ * @throws CoreException
+ */
+ public void testIsTemplate() throws CoreException {
+ ILaunchConfigurationWorkingCopy wc = newConfiguration(null, "test-is-template");
+ wc.setTemplate(true);
+ ILaunchConfiguration template = wc.doSave();
+ assertTrue("Should be a template", template.isTemplate());
+ ILaunchConfiguration[] templates = wc.getType().getTemplates();
+ assertEquals("Expecting one template", 1, templates.length);
+ wc = template.getWorkingCopy();
+ wc.setTemplate(false);
+ template = wc.doSave();
+ assertFalse("Should not be a template", template.isTemplate());
+ }
+
+ /**
+ * Tests finding references to a template.
+ *
+ * @throws CoreException
+ */
+ public void testTemplateChildren() throws CoreException {
+ ILaunchConfigurationWorkingCopy wc = newConfiguration(null, "test-references");
+ ILaunchConfiguration template = wc.doSave();
+
+ ILaunchConfigurationWorkingCopy r1 = newConfiguration(null, "referee-1");
+ ILaunchConfigurationWorkingCopy r2 = newConfiguration(null, "referee-2");
+
+ r1.setTemplate(template);
+ r2.setTemplate(template);
+
+ ILaunchConfiguration s1 = r1.doSave();
+ ILaunchConfiguration s2 = r2.doSave();
+
+ ILaunchConfiguration[] children = template.getTemplateChildren();
+ assertEquals("Wrong number of template children", 2, children.length);
+ List list = new ArrayList();
+ for (int i = 0; i < children.length; i++) {
+ list.add(children[i]);
+ }
+ assertTrue("Missing reference", list.contains(s1));
+ assertTrue("Missing reference", list.contains(s2));
+ }
}

Back to the top