Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarin Wright2009-11-05 22:17:05 +0000
committerDarin Wright2009-11-05 22:17:05 +0000
commitc931835343e79e4dd8ca11bd7716274468ae3614 (patch)
treeeceecb66bfd1a258dc748917f7ff122ce75c2545
parenteda0918cf9babea35c355ef5d843a4437724b920 (diff)
downloadeclipse.platform.debug-c931835343e79e4dd8ca11bd7716274468ae3614.tar.gz
eclipse.platform.debug-c931835343e79e4dd8ca11bd7716274468ae3614.tar.xz
eclipse.platform.debug-c931835343e79e4dd8ca11bd7716274468ae3614.zip
Bug 41353 - [launching] Launch config templates
-rw-r--r--org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchConfiguration.java29
-rw-r--r--org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchManager.java52
-rw-r--r--org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfiguration.java22
-rw-r--r--org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfigurationInfo.java36
-rw-r--r--org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfigurationType.java11
-rw-r--r--org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfigurationWorkingCopy.java28
-rw-r--r--org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java40
-rw-r--r--org.eclipse.debug.tests/src/org/eclipe/debug/tests/launching/LaunchConfigurationTests.java18
8 files changed, 187 insertions, 49 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 d533f82ca..50a5395f4 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
@@ -107,6 +107,22 @@ public interface ILaunchConfiguration extends IAdaptable {
*/
public static final int UPDATE_TEMPLATE_CHILDREN = 1;
+ /**
+ * Type constant (bit mask value 1) which identifies a launch configuration.
+ *
+ * @see #getKind()
+ * @since 3.6
+ */
+ public static final int CONFIGURATION = 0x1;
+
+ /**
+ * Type constant (bit mask value 2) which identifies a template.
+ *
+ * @see #getKind()
+ * @since 3.6
+ */
+ public static final int TEMPLATE = 0x2;
+
/**
* Returns whether the contents of this launch configuration are
* equal to the contents of the given launch configuration.
@@ -651,6 +667,7 @@ public interface ILaunchConfiguration extends IAdaptable {
*
* @return whether this configuration is a template
* @throws CoreException if unable to determine if this configuration is a template
+ * or if this configuration does not exist
* @since 3.6
*/
public boolean isTemplate() throws CoreException;
@@ -664,4 +681,16 @@ public interface ILaunchConfiguration extends IAdaptable {
* @since 3.6
*/
public ILaunchConfiguration[] getTemplateChildren() throws CoreException;
+
+ /**
+ * Returns this configuration's kind. One of CONFIGURATION or TEMPLATE.
+ *
+ * @see #CONFIGURATION
+ * @see #TEMPLATE
+ *
+ * @return this configuration's kind
+ * @throws CoreException if unable to retrieve this configuration's kind
+ * @since 3.6
+ */
+ public int getKind() throws CoreException;
}
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchManager.java b/org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchManager.java
index bceb23ecb..4ed20fed0 100644
--- a/org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchManager.java
+++ b/org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchManager.java
@@ -207,7 +207,9 @@ public interface ILaunchManager {
* in the specified file. This method does not check if the specified <code>IFile</code> is
* a launch configuration file or that it exists in the local or
* remote file system.
- *
+ * <p>
+ * Since 3.6, the returned configuration may be a launch configuration template.
+ * </p>
* @param file launch configuration file
* @return a handle to the launch configuration contained
* in the specified file
@@ -217,7 +219,9 @@ public interface ILaunchManager {
/**
* Returns a handle to the launch configuration specified by
* the given memento. The configuration may not exist.
- *
+ * <p>
+ * Since 3.6, the returned configuration may be a launch configuration template.
+ * </p>
* @param memento launch configuration memento
* @return a handle to the launch configuration specified by
* the given memento
@@ -229,24 +233,64 @@ public interface ILaunchManager {
public ILaunchConfiguration getLaunchConfiguration(String memento) throws CoreException;
/**
* Returns all launch configurations defined in the workspace.
- *
+ * <p>
+ * Does not include launch configuration templates. Equivalent to
+ * #getLaunchConfigurations(ILaunchConfiguration.CONFIGURATION).
+ * </p>
* @return all launch configurations defined in the workspace
* @exception CoreException if an exception occurs retrieving configurations
* @since 2.0
+ * @see ILaunchConfigurationType#getTemplates()
*/
public ILaunchConfiguration[] getLaunchConfigurations() throws CoreException;
+
/**
- * Returns all launch configurations of the specified type defined in the workspace
+ * Returns all launch configurations defined in the workspace of the specified
+ * kind(s) (configurations and/or templates).
*
+ * @param kinds bit mask of kinds of configurations to consider
+ * @return all launch configurations defined in the workspace
+ * @exception CoreException if an exception occurs retrieving configurations
+ * @since 3.6
+ * @see ILaunchConfiguration#CONFIGURATION
+ * @see ILaunchConfiguration#TEMPLATE
+ * @see ILaunchConfiguration#getKind()
+ * @see ILaunchConfigurationType#getTemplates()
+ */
+ public ILaunchConfiguration[] getLaunchConfigurations(int kinds) throws CoreException;
+
+ /**
+ * Returns all launch configurations of the specified type defined in the workspace
+ * <p>
+ * Does not include launch configuration templates.
+ * </p>
* @param type a launch configuration type
* @return all launch configurations of the specified type defined in the workspace
* @exception CoreException if an error occurs while retrieving
* a launch configuration
* @since 2.0
+ * @see ILaunchConfigurationType#getTemplates()
*/
public ILaunchConfiguration[] getLaunchConfigurations(ILaunchConfigurationType type) throws CoreException;
/**
+ * Returns all launch configurations of the specified type defined in the workspace
+ * of the specified kind(s) (configurations and/or templates).
+ *
+ * @param type a launch configuration type
+ * @param kinds bit mask of kinds of configurations to consider
+ * @return all launch configurations of the specified type defined in the workspace
+ * @exception CoreException if an error occurs while retrieving
+ * a launch configuration
+ * @since 3.6
+ * @see ILaunchConfiguration#CONFIGURATION
+ * @see ILaunchConfiguration#TEMPLATE
+ * @see ILaunchConfiguration#getKind()
+ * @see ILaunchConfigurationType#getTemplates()
+ */
+ public ILaunchConfiguration[] getLaunchConfigurations(ILaunchConfigurationType type, int kinds) throws CoreException;
+
+ /**
* Returns the launch configuration type extension with the specified
* id, or <code>null</code> if it does not exist.
*
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 d36b0f7dc..acf5a9f16 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
@@ -107,15 +107,7 @@ public class LaunchConfiguration extends PlatformObject implements ILaunchConfig
* @since 3.3
*/
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>.
@@ -1013,7 +1005,17 @@ public class LaunchConfiguration extends PlatformObject implements ILaunchConfig
* @see org.eclipse.debug.core.ILaunchConfiguration#isTemplate()
*/
public boolean isTemplate() throws CoreException {
- return getAttribute(ATTR_IS_TEMPLATE, false);
+ return getInfo().isTemplate();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.ILaunchConfiguration#getKind()
+ */
+ public int getKind() throws CoreException {
+ if (isTemplate()) {
+ return TEMPLATE;
+ }
+ return CONFIGURATION;
}
}
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfigurationInfo.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfigurationInfo.java
index db79a6a4e..6fc01f3b1 100644
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfigurationInfo.java
+++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfigurationInfo.java
@@ -59,6 +59,7 @@ public class LaunchConfigurationInfo {
private static final String INT_ATTRIBUTE = "intAttribute"; //$NON-NLS-1$
private static final String STRING_ATTRIBUTE = "stringAttribute"; //$NON-NLS-1$
private static final String TYPE = "type"; //$NON-NLS-1$
+ private static final String TEMPLATE = "template"; //$NON-NLS-1$
/**
* This configurations attribute table. Keys are <code>String</code>s and
@@ -73,6 +74,11 @@ public class LaunchConfigurationInfo {
private ILaunchConfigurationType fType;
/**
+ * Whether this configuration is a template
+ */
+ private boolean fIsTemplate = false;
+
+ /**
* Whether running on Sun 1.4 VM - see bug 110215
*/
private static boolean fgIsSun14x = false;
@@ -307,6 +313,7 @@ public class LaunchConfigurationInfo {
LaunchConfigurationInfo copy = new LaunchConfigurationInfo();
copy.setType(getType());
copy.setAttributeTable(getAttributes());
+ copy.setTemplate(isTemplate());
return copy;
}
@@ -356,6 +363,9 @@ public class LaunchConfigurationInfo {
doc.appendChild(configRootElement);
configRootElement.setAttribute(TYPE, getType().getIdentifier());
+ if (isTemplate()) {
+ configRootElement.setAttribute(TEMPLATE, Boolean.TRUE.toString());
+ }
Iterator keys = getAttributeTable().keySet().iterator();
while (keys.hasNext()) {
@@ -507,6 +517,13 @@ public class LaunchConfigurationInfo {
}
setType(type);
+ String template = root.getAttribute(TEMPLATE);
+ boolean is = false;
+ if (template != null && template.length() > 0) {
+ is = Boolean.valueOf(template).booleanValue();
+ }
+ setTemplate(is);
+
NodeList list = root.getChildNodes();
Node node = null;
Element element = null;
@@ -790,5 +807,24 @@ public class LaunchConfigurationInfo {
}
return null;
}
+
+ /**
+ * Sets whether this info is a template.
+ *
+ * @param isTemplate
+ * @throws CoreException
+ */
+ void setTemplate(boolean isTemplate) {
+ fIsTemplate = isTemplate;
+ }
+
+ /**
+ * Returns whether this info is a template.
+ *
+ * @return whether a template
+ */
+ boolean isTemplate() {
+ return fIsTemplate;
+ }
}
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 84a06e153..ef31b20cf 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
@@ -11,7 +11,6 @@
package org.eclipse.debug.internal.core;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -492,15 +491,7 @@ public class LaunchConfigurationType extends PlatformObject implements ILaunchCo
* @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()]);
+ return DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(this, ILaunchConfiguration.TEMPLATE);
}
/* (non-Javadoc)
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 7c25e2e63..d65760f08 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
@@ -732,23 +732,6 @@ public class LaunchConfigurationWorkingCopy extends LaunchConfiguration implemen
}
}
- /**
- * Sets whether this working copy is a template.
- *
- * @param isTemplate
- * @throws CoreException
- */
- void setTemplate(boolean isTemplate) throws CoreException {
- if (!isTemplate) {
- removeAttribute(ATTR_IS_TEMPLATE);
- } else {
- if (getTemplate() != null) {
- throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugCoreMessages.LaunchConfigurationWorkingCopy_7));
- }
- setAttribute(ATTR_IS_TEMPLATE, isTemplate);
- }
- }
-
/* (non-Javadoc)
* @see org.eclipse.debug.core.ILaunchConfigurationWorkingCopy#setTemplate(org.eclipse.debug.core.ILaunchConfiguration, boolean)
*/
@@ -769,7 +752,6 @@ public class LaunchConfigurationWorkingCopy extends LaunchConfiguration implemen
copyAttributes(template);
}
setAttribute(ATTR_TEMPLATE, template.getMemento());
- setTemplate(false); // template attribute was copied, so now remove it
}
}
@@ -793,5 +775,15 @@ public class LaunchConfigurationWorkingCopy extends LaunchConfiguration implemen
}
return saved;
}
+
+ /**
+ * Sets whether this working copy is a template.
+ *
+ * @param template whether a template
+ * @since 3.6
+ */
+ void setTemplate(boolean template) {
+ getInfo().setTemplate(template);
+ }
}
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java
index 8ad00cb48..c0d1d62ac 100644
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java
+++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java
@@ -1108,7 +1108,8 @@ public class LaunchManager extends PlatformObject implements ILaunchManager, IRe
*/
protected synchronized String[] getAllSortedConfigNames() {
if (fSortedConfigNames == null) {
- ILaunchConfiguration[] configs = getLaunchConfigurations();
+ List collection = getAllLaunchConfigurations();
+ ILaunchConfiguration[] configs = (ILaunchConfiguration[]) collection.toArray(new ILaunchConfiguration[collection.size()]);
fSortedConfigNames = new String[configs.length];
for (int i = 0; i < configs.length; i++) {
fSortedConfigNames[i] = configs[i].getName();
@@ -1376,26 +1377,53 @@ public class LaunchManager extends PlatformObject implements ILaunchManager, IRe
/**
* @see ILaunchManager#getLaunchConfigurations()
*/
- public synchronized ILaunchConfiguration[] getLaunchConfigurations() {
- List allConfigs = getAllLaunchConfigurations();
- return (ILaunchConfiguration[])allConfigs.toArray(new ILaunchConfiguration[allConfigs.size()]);
+ public synchronized ILaunchConfiguration[] getLaunchConfigurations() throws CoreException {
+ return getLaunchConfigurations(ILaunchConfiguration.CONFIGURATION);
}
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.ILaunchManager#getLaunchConfigurations(int)
+ */
+ public ILaunchConfiguration[] getLaunchConfigurations(int kinds) throws CoreException {
+ List allConfigs = getAllLaunchConfigurations();
+ if (((kinds & ILaunchConfiguration.CONFIGURATION) > 0) && ((kinds & ILaunchConfiguration.TEMPLATE) > 0)) {
+ // all kinds
+ return (ILaunchConfiguration[])allConfigs.toArray(new ILaunchConfiguration[allConfigs.size()]);
+ } else {
+ List select = new ArrayList(allConfigs.size());
+ Iterator iterator = allConfigs.iterator();
+ while (iterator.hasNext()) {
+ ILaunchConfiguration config = (ILaunchConfiguration) iterator.next();
+ if ((config.getKind() & kinds) > 0) {
+ select.add(config);
+ }
+ }
+ return (ILaunchConfiguration[]) select.toArray(new ILaunchConfiguration[select.size()]);
+ }
+ }
+
/**
* @see ILaunchManager#getLaunchConfigurations(ILaunchConfigurationType)
*/
public synchronized ILaunchConfiguration[] getLaunchConfigurations(ILaunchConfigurationType type) throws CoreException {
+ return getLaunchConfigurations(type, ILaunchConfiguration.CONFIGURATION);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.ILaunchManager#getLaunchConfigurations(org.eclipse.debug.core.ILaunchConfigurationType, int)
+ */
+ public synchronized ILaunchConfiguration[] getLaunchConfigurations(ILaunchConfigurationType type, int kinds) throws CoreException {
Iterator iter = getAllLaunchConfigurations().iterator();
List configs = new ArrayList();
ILaunchConfiguration config = null;
while (iter.hasNext()) {
config = (ILaunchConfiguration)iter.next();
- if (config.getType().equals(type)) {
+ if (config.getType().equals(type) && ((config.getKind() & kinds) > 0)) {
configs.add(config);
}
}
return (ILaunchConfiguration[])configs.toArray(new ILaunchConfiguration[configs.size()]);
- }
+ }
/**
* Returns all launch configurations that are stored as resources
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 8789109fc..455d5bd00 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
@@ -180,7 +180,7 @@ public class LaunchConfigurationTests extends AbstractLaunchTest implements ILau
protected ILaunchConfigurationWorkingCopy newEmptyTemplate(IContainer container, String name) throws CoreException {
ILaunchConfigurationType type = getLaunchManager().getLaunchConfigurationType(ID_TEST_LAUNCH_TYPE);
ILaunchConfigurationWorkingCopy wc = type.newTemplate(container, name);
- assertEquals("Should have 1 attribute (IS_TEMPLATE)", 1, wc.getAttributes().size());
+ assertEquals("Should have no attributes", 0, wc.getAttributes().size());
return wc;
}
@@ -1221,6 +1221,11 @@ public class LaunchConfigurationTests extends AbstractLaunchTest implements ILau
assertTrue("Shoud not be able to nest templates", false);
}
+ /**
+ * Test that you cannot set a config's template to be a non-template.
+ *
+ * @throws CoreException
+ */
public void testIllegalTemplate() throws CoreException {
ILaunchConfigurationWorkingCopy c1 = newConfiguration(null, "test-config");
ILaunchConfigurationWorkingCopy t1 = newConfiguration(null, "test-not-a-template");
@@ -1234,6 +1239,17 @@ public class LaunchConfigurationTests extends AbstractLaunchTest implements ILau
assertTrue("Should not be able to set configration as template", false);
}
+ /**
+ * Test that a template can be duplicated (and results in a template).
+ *
+ * @throws CoreException
+ */
+ public void testCopyTemplate() throws CoreException {
+ ILaunchConfigurationWorkingCopy t1 = newEmptyTemplate(null, "template-to-duplicate");
+ ILaunchConfigurationWorkingCopy t2 = t1.copy("duplicate-template");
+ assertTrue(t2.isTemplate());
+ }
+
}

Back to the top