View | Details | Raw Unified | Return to bug 41353
Collapse All | Expand All

(-)core/org/eclipse/debug/core/ILaunchConfiguration.java (+31 lines)
Lines 596-599 Link Here
596
	 * @since 3.3
596
	 * @since 3.3
597
	 */
597
	 */
598
	public boolean isReadOnly();	
598
	public boolean isReadOnly();	
599
	
600
	/**
601
	 * Returns the template this launch configuration was created from
602
	 * or <code>null</code> if none.
603
	 * 
604
	 * @return the template this launch configuration was created from
605
	 *  or <code>null</code> if none
606
	 * @throws CoreException if the template could not be retrieved
607
	 *  or no longer exists
608
	 * @since 3.6
609
	 */
610
	public ILaunchConfiguration getTemplate() throws CoreException;
611
	
612
	/**
613
	 * Returns whether this configuration is a template.
614
	 * 
615
	 * @return whether this configuration is a template
616
	 * @throws CoreException if unable to determine if this configuration is a template
617
	 * @since 3.6
618
	 */
619
	public boolean isTemplate() throws CoreException;
620
	
621
	/**
622
	 * Returns all configurations made from this template, possibly an
623
	 * empty collection.
624
	 * 
625
	 * @return all configurations made from this template
626
	 * @throws CoreException
627
	 * @since 3.6
628
	 */
629
	public ILaunchConfiguration[] getTemplateChildren() throws CoreException;
599
}
630
}
(-)core/org/eclipse/debug/core/ILaunchConfigurationType.java (+56 lines)
Lines 16-21 Link Here
16
import org.eclipse.core.resources.IContainer;
16
import org.eclipse.core.resources.IContainer;
17
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IAdaptable;
18
import org.eclipse.core.runtime.IAdaptable;
19
import org.eclipse.core.runtime.preferences.IScopeContext;
19
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
20
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
20
import org.eclipse.debug.core.sourcelookup.ISourcePathComputer;
21
import org.eclipse.debug.core.sourcelookup.ISourcePathComputer;
21
22
Lines 307-311 Link Here
307
	 * @since 3.3
308
	 * @since 3.3
308
	 */
309
	 */
309
	public String getContributorName();
310
	public String getContributorName();
311
	
312
	/**
313
	 * Sets the template for this launch configuration type in the specified scope,
314
	 * or removes the template for the scope when the specified configuration is
315
	 * <code>null</code>.
316
	 * 
317
	 * @param configuration template for the specified scope, or <code>null</code> if none
318
	 * @param scope scope
319
	 * @throws CoreException if unable to to set/remove the template for the given scope 
320
	 * @since 3.6
321
	 */
322
	public void setTemplate(ILaunchConfiguration configuration, IScopeContext scope) throws CoreException;
310
323
324
	/**
325
	 * Returns the template for this launch configuration type in the specified scope
326
	 * or <code>null</code> if no template has been set for the scope.
327
	 * 
328
	 * @param scope scope
329
	 * @return template for the scope or <code>null</code>
330
	 * @throws CoreException if unable to retrieve the template for the scope
331
	 * @since 3.6
332
	 */
333
	public ILaunchConfiguration getTemplate(IScopeContext scope) throws CoreException;
334
	
335
	/**
336
	 * Returns all launch configuration templates of the this type, possibly
337
	 * an empty collection.
338
	 * 
339
	 * @return all launch configuration templates of the this type
340
	 * @throws CoreException if unable to retrieve the templates 
341
	 * @since 3.6
342
	 */
343
	public ILaunchConfiguration[] getTemplates() throws CoreException;	
344
	
345
	/**
346
	 * Returns a new launch configuration working copy of this type,
347
	 * that resides in the specified container, with the given name, initialized
348
	 * with values in the first template found in the given canonical scope order.
349
	 * When <code>container</code> is </code>null</code>, the configuration
350
	 * will reside locally in the metadata area.
351
	 * Note: a launch configuration is not actually created until the working copy is saved.
352
	 * 
353
	 * @param container the container in which the new configuration will
354
	 *  reside, or <code>null</code> if the configuration should reside
355
	 *  locally with the metadata.
356
	 * @param name name for the launch configuration
357
	 * @param scopes optional context objects to determine which scopes are search
358
	 *  for a launch configuration template, or <code>null</code> if template scopes
359
	 *  should not be considered
360
	 * @return a new launch configuration working copy instance of this type
361
	 * @exception CoreException if an instance of this type
362
	 *  of launch configuration could not be created for any
363
	 *  reason
364
	 * @since 3.6
365
	 */
366
	public ILaunchConfigurationWorkingCopy newInstance(IContainer container, String name, IScopeContext[] scopes) throws CoreException;	
311
}
367
}
(-)core/org/eclipse/debug/core/ILaunchConfigurationWorkingCopy.java (+30 lines)
Lines 263-266 Link Here
263
	 * @since 3.3
263
	 * @since 3.3
264
	 */
264
	 */
265
	public ILaunchConfigurationWorkingCopy getParent();
265
	public ILaunchConfigurationWorkingCopy getParent();
266
	
267
	/**
268
	 * Copies all attributes from the given template to this working.
269
	 * Overwrites any existing attributes with the same key.
270
	 * 
271
	 * @param template configuration template
272
	 * @exception CoreException if unable to retrieve attributes from the template
273
	 * @since 3.6
274
	 */
275
	public void copyAttributes(ILaunchConfiguration template) throws CoreException;
276
	
277
	/**
278
	 * Sets whether this configuration is to be considered as a template.
279
	 * 
280
	 * @param isTemplate whether this configuration is to be considered as a template
281
	 * @since 3.6
282
	 */
283
	public void setTemplate(boolean isTemplate);
284
	
285
	/**
286
	 * Sets the template that this configuration is associated with, possibly <code>null</code>.
287
	 * <p>
288
	 * When the specified template is <code>null</code>, this working copy is no longer
289
	 * associated with any template.
290
	 * </p>
291
	 * @param template template or <code>null</code>
292
	 * @exception CoreException if unable to generate a memento for the given configuration
293
	 * @since 3.6
294
	 */
295
	public void setTemplate(ILaunchConfiguration template) throws CoreException;
266
}
296
}
(-)core/org/eclipse/debug/internal/core/DebugCoreMessages.java (+4 lines)
Lines 51-56 Link Here
51
	public static String LaunchConfiguration_8;
51
	public static String LaunchConfiguration_8;
52
	public static String LaunchConfiguration_9;
52
	public static String LaunchConfiguration_9;
53
	public static String LaunchConfigurationInfo_35;
53
	public static String LaunchConfigurationInfo_35;
54
	public static String LaunchConfigurationType_0;
55
56
	public static String LaunchConfigurationType_1;
57
54
	public static String LaunchConfigurationType_7;
58
	public static String LaunchConfigurationType_7;
55
59
56
	public static String LaunchConfigurationWorkingCopy_0;
60
	public static String LaunchConfigurationWorkingCopy_0;
(-)core/org/eclipse/debug/internal/core/DebugCoreMessages.properties (+2 lines)
Lines 97-102 Link Here
97
ProcessMonitorJob_0=Process monitor
97
ProcessMonitorJob_0=Process monitor
98
RuntimeProcess_terminate_failed=Terminate failed
98
RuntimeProcess_terminate_failed=Terminate failed
99
RuntimeProcess_Exit_value_not_available_until_process_terminates__1=Exit value not available until process terminates.
99
RuntimeProcess_Exit_value_not_available_until_process_terminates__1=Exit value not available until process terminates.
100
LaunchConfigurationType_0=Error retrieving template
101
LaunchConfigurationType_1=Error setting template
100
LaunchConfigurationType_7=Launch mode not supported: {0}
102
LaunchConfigurationType_7=Launch mode not supported: {0}
101
WatchExpression_0=(Watch expressions not supported)
103
WatchExpression_0=(Watch expressions not supported)
102
NullStreamsProxy_0=Null Stream Monitor
104
NullStreamsProxy_0=Null Stream Monitor
(-)core/org/eclipse/debug/internal/core/LaunchConfiguration.java (+49 lines)
Lines 109-114 Link Here
109
	public static final String ATTR_PREFERRED_LAUNCHERS = DebugPlugin.getUniqueIdentifier() + ".preferred_launchers"; //$NON-NLS-1$	
109
	public static final String ATTR_PREFERRED_LAUNCHERS = DebugPlugin.getUniqueIdentifier() + ".preferred_launchers"; //$NON-NLS-1$	
110
	
110
	
111
	/**
111
	/**
112
	 * Launch configuration attribute storing a boolean indicating whether this 
113
	 * configuration is a template. Default value is <code>false</code>.
114
	 * 
115
	 * @since 3.6
116
	 */
117
	public static final String ATTR_IS_TEMPLATE = DebugPlugin.getUniqueIdentifier() + ".ATTR_IS_TEMPLATE"; //$NON-NLS-1$
118
	
119
	/**
120
	 * Launch configuration attribute storing a memento identifying the template
121
	 * this configuration was made from, possibly <code>null</code>.
122
	 * 
123
	 *  @since 3.6
124
	 */
125
	public static final String ATTR_TEMPLATE = DebugPlugin.getUniqueIdentifier() + ".ATTR_TEMPLATE"; //$NON-NLS-1$
126
	
127
	/**
112
	 * Status handler to prompt in the UI thread
128
	 * Status handler to prompt in the UI thread
113
	 * 
129
	 * 
114
	 * @since 3.3
130
	 * @since 3.3
Lines 950-955 Link Here
950
	public String toString() {
966
	public String toString() {
951
		return getName();
967
		return getName();
952
	}
968
	}
969
970
	/* (non-Javadoc)
971
	 * @see org.eclipse.debug.core.ILaunchConfiguration#getTemplate()
972
	 */
973
	public ILaunchConfiguration getTemplate() throws CoreException {
974
		String memento = getAttribute(ATTR_TEMPLATE, (String)null);
975
		if (memento != null) {
976
			return new LaunchConfiguration(memento);
977
		}
978
		return null;
979
	}
980
981
	/* (non-Javadoc)
982
	 * @see org.eclipse.debug.core.ILaunchConfiguration#getTemplateChildren()
983
	 */
984
	public ILaunchConfiguration[] getTemplateChildren() throws CoreException {
985
		ILaunchConfiguration[] configurations = getLaunchManager().getLaunchConfigurations(getType());
986
		List proteges = new ArrayList();
987
		for (int i = 0; i < configurations.length; i++) {
988
			ILaunchConfiguration config = configurations[i];
989
			if (this.equals(config.getTemplate())) {
990
				proteges.add(config);
991
			}
992
		}
993
		return (ILaunchConfiguration[]) proteges.toArray(new ILaunchConfiguration[proteges.size()]);
994
	}
995
996
	/* (non-Javadoc)
997
	 * @see org.eclipse.debug.core.ILaunchConfiguration#isTemplate()
998
	 */
999
	public boolean isTemplate() throws CoreException {
1000
		return getAttribute(ATTR_IS_TEMPLATE, false);
1001
	}
953
	
1002
	
954
}
1003
}
955
1004
(-)core/org/eclipse/debug/internal/core/LaunchConfigurationType.java (+104 lines)
Lines 11-16 Link Here
11
package org.eclipse.debug.internal.core;
11
package org.eclipse.debug.internal.core;
12
12
13
 
13
 
14
import java.util.ArrayList;
14
import java.util.Collections;
15
import java.util.Collections;
15
import java.util.HashMap;
16
import java.util.HashMap;
16
import java.util.HashSet;
17
import java.util.HashSet;
Lines 26-31 Link Here
26
import org.eclipse.core.runtime.IStatus;
27
import org.eclipse.core.runtime.IStatus;
27
import org.eclipse.core.runtime.PlatformObject;
28
import org.eclipse.core.runtime.PlatformObject;
28
import org.eclipse.core.runtime.Status;
29
import org.eclipse.core.runtime.Status;
30
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
31
import org.eclipse.core.runtime.preferences.IScopeContext;
29
import org.eclipse.debug.core.DebugPlugin;
32
import org.eclipse.debug.core.DebugPlugin;
30
import org.eclipse.debug.core.ILaunchConfiguration;
33
import org.eclipse.debug.core.ILaunchConfiguration;
31
import org.eclipse.debug.core.ILaunchConfigurationMigrationDelegate;
34
import org.eclipse.debug.core.ILaunchConfigurationMigrationDelegate;
Lines 36-41 Link Here
36
import org.eclipse.debug.core.ILaunchMode;
39
import org.eclipse.debug.core.ILaunchMode;
37
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
40
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
38
import org.eclipse.debug.core.sourcelookup.ISourcePathComputer;
41
import org.eclipse.debug.core.sourcelookup.ISourcePathComputer;
42
import org.osgi.service.prefs.BackingStoreException;
43
import org.osgi.service.prefs.Preferences;
39
44
40
import com.ibm.icu.text.MessageFormat;
45
import com.ibm.icu.text.MessageFormat;
41
46
Lines 105-110 Link Here
105
	private Map fPreferredDelegates = null;
110
	private Map fPreferredDelegates = null;
106
	
111
	
107
	/**
112
	/**
113
	 * A preference node that maps launch configuration type identifiers to
114
	 * default templates in that scope.
115
	 * 
116
	 * @since 3.6
117
	 */
118
	private static final String TEMPLATES_NODE = "TEMPLATES_NODE"; //$NON-NLS-1$
119
	
120
	/**
108
	 * Constructs a new launch configuration type on the
121
	 * Constructs a new launch configuration type on the
109
	 * given configuration element.
122
	 * given configuration element.
110
	 * 
123
	 * 
Lines 487-491 Link Here
487
		return fModeCombinations.contains(modes);
500
		return fModeCombinations.contains(modes);
488
	}
501
	}
489
502
503
	/* (non-Javadoc)
504
	 * @see org.eclipse.debug.core.ILaunchConfigurationType#getTemplate(org.eclipse.core.runtime.preferences.IScopeContext)
505
	 */
506
	public ILaunchConfiguration getTemplate(IScopeContext scope) throws CoreException {
507
		IEclipsePreferences node = scope.getNode(DebugPlugin.getUniqueIdentifier());
508
		try {
509
			if (node.nodeExists(TEMPLATES_NODE)) {
510
				Preferences templates = node.node(TEMPLATES_NODE);
511
				String memento = templates.get(getIdentifier(), null);
512
				if (memento != null) {
513
					return DebugPlugin.getDefault().getLaunchManager().getLaunchConfiguration(memento);
514
				}
515
			}
516
		} catch (BackingStoreException e) {
517
			throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugCoreMessages.LaunchConfigurationType_0, e));
518
		}
519
		return null;
520
	}
521
522
	/* (non-Javadoc)
523
	 * @see org.eclipse.debug.core.ILaunchConfigurationType#getTemplates()
524
	 */
525
	public ILaunchConfiguration[] getTemplates() throws CoreException {
526
		ILaunchConfiguration[] configurations = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(this);
527
		List templates = new ArrayList();
528
		for (int i = 0; i < configurations.length; i++) {
529
			ILaunchConfiguration config = configurations[i];
530
			if (config.isTemplate()) {
531
				templates.add(config);
532
			}
533
		}
534
		return (ILaunchConfiguration[]) templates.toArray(new ILaunchConfiguration[templates.size()]);
535
	}
536
537
	/* (non-Javadoc)
538
	 * @see org.eclipse.debug.core.ILaunchConfigurationType#newInstance(org.eclipse.core.resources.IContainer, java.lang.String, org.eclipse.core.runtime.preferences.IScopeContext[])
539
	 */
540
	public ILaunchConfigurationWorkingCopy newInstance(IContainer container, String name, IScopeContext[] scopes) throws CoreException {
541
		ILaunchConfiguration template = findTemplate(scopes);
542
		ILaunchConfigurationWorkingCopy wc = new LaunchConfigurationWorkingCopy(container, name, this);
543
		if (template != null) {
544
			wc.copyAttributes(template);
545
			wc.setTemplate(template);
546
		}
547
		return wc;
548
	}
549
	
550
	/**
551
	 * Returns the first template found in the given scopes or <code>null</code> if none.
552
	 * 
553
	 * @param contexts scopes to search in or <code>null</code>
554
	 * @return template or <code>null</code>
555
	 * @throws CoreException if unable to retrieve template
556
	 */
557
	private ILaunchConfiguration findTemplate(IScopeContext[] contexts) throws CoreException {
558
		if (contexts != null) {
559
			for (int i = 0; i < contexts.length; i++) {
560
				ILaunchConfiguration template = getTemplate(contexts[i]);
561
				if (template != null) {
562
					return template;
563
				}
564
			}
565
		}
566
		return null;
567
	}
568
569
	/* (non-Javadoc)
570
	 * @see org.eclipse.debug.core.ILaunchConfigurationType#setTemplate(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.runtime.preferences.IScopeContext)
571
	 */
572
	public void setTemplate(ILaunchConfiguration configuration, IScopeContext scope) throws CoreException {
573
		IEclipsePreferences node = scope.getNode(DebugPlugin.getUniqueIdentifier());
574
		Preferences templates = node.node(TEMPLATES_NODE);
575
		if (configuration == null) {
576
			templates.remove(getIdentifier());
577
			try {
578
				if (templates.keys().length == 0) {
579
					templates.removeNode();
580
				}
581
			} catch (BackingStoreException e) {
582
				throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugCoreMessages.LaunchConfigurationType_1, e));
583
			}
584
		} else {
585
			templates.put(getIdentifier(), configuration.getMemento());
586
		}
587
		try {
588
			node.flush();
589
		} catch (BackingStoreException e) {
590
			throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugCoreMessages.LaunchConfigurationType_1, e));
591
		}
592
	}
593
490
}
594
}
491
595
(-)core/org/eclipse/debug/internal/core/LaunchConfigurationWorkingCopy.java (+38 lines)
Lines 17-25 Link Here
17
import java.io.UnsupportedEncodingException;
17
import java.io.UnsupportedEncodingException;
18
import java.util.ArrayList;
18
import java.util.ArrayList;
19
import java.util.HashMap;
19
import java.util.HashMap;
20
import java.util.Iterator;
20
import java.util.List;
21
import java.util.List;
21
import java.util.Map;
22
import java.util.Map;
22
import java.util.Set;
23
import java.util.Set;
24
import java.util.Map.Entry;
23
25
24
import org.eclipse.core.filesystem.EFS;
26
import org.eclipse.core.filesystem.EFS;
25
import org.eclipse.core.filesystem.IFileStore;
27
import org.eclipse.core.filesystem.IFileStore;
Lines 715-719 Link Here
715
	public Object removeAttribute(String attributeName) {
717
	public Object removeAttribute(String attributeName) {
716
		return getInfo().removeAttribute(attributeName);
718
		return getInfo().removeAttribute(attributeName);
717
	}
719
	}
720
721
	/* (non-Javadoc)
722
	 * @see org.eclipse.debug.core.ILaunchConfigurationWorkingCopy#copyAttributes(org.eclipse.debug.core.ILaunchConfiguration)
723
	 */
724
	public void copyAttributes(ILaunchConfiguration template) throws CoreException {
725
		Map map = template.getAttributes();
726
		Iterator iterator = map.entrySet().iterator();
727
		LaunchConfigurationInfo info = getInfo();
728
		while (iterator.hasNext()) {
729
			Entry entry = (Entry) iterator.next();
730
			String attr = (String) entry.getKey();
731
			info.setAttribute(attr, entry.getValue());
732
		}
733
	}
734
735
	/* (non-Javadoc)
736
	 * @see org.eclipse.debug.core.ILaunchConfigurationWorkingCopy#setTemplate(boolean)
737
	 */
738
	public void setTemplate(boolean isTemplate) {
739
		if (!isTemplate) {
740
			removeAttribute(ATTR_IS_TEMPLATE);
741
		} else {
742
			setAttribute(ATTR_IS_TEMPLATE, isTemplate);
743
		}
744
	}
745
746
	/* (non-Javadoc)
747
	 * @see org.eclipse.debug.core.ILaunchConfigurationWorkingCopy#setTemplate(org.eclipse.debug.core.ILaunchConfiguration)
748
	 */
749
	public void setTemplate(ILaunchConfiguration template) throws CoreException {
750
		if (template == null) {
751
			removeAttribute(ATTR_TEMPLATE);
752
		} else {
753
			setAttribute(ATTR_TEMPLATE, template.getMemento());
754
		}
755
	}
718
}
756
}
719
757
(-)src/org/eclipe/debug/tests/launching/LaunchConfigurationTests.java (+174 lines)
Lines 30-39 Link Here
30
import org.eclipse.core.resources.IProject;
30
import org.eclipse.core.resources.IProject;
31
import org.eclipse.core.resources.IProjectDescription;
31
import org.eclipse.core.resources.IProjectDescription;
32
import org.eclipse.core.resources.IResource;
32
import org.eclipse.core.resources.IResource;
33
import org.eclipse.core.resources.ProjectScope;
33
import org.eclipse.core.resources.ResourcesPlugin;
34
import org.eclipse.core.resources.ResourcesPlugin;
34
import org.eclipse.core.runtime.CoreException;
35
import org.eclipse.core.runtime.CoreException;
35
import org.eclipse.core.runtime.IPath;
36
import org.eclipse.core.runtime.IPath;
36
import org.eclipse.core.runtime.Path;
37
import org.eclipse.core.runtime.Path;
38
import org.eclipse.core.runtime.preferences.IScopeContext;
39
import org.eclipse.core.runtime.preferences.InstanceScope;
37
import org.eclipse.debug.core.ILaunchConfiguration;
40
import org.eclipse.debug.core.ILaunchConfiguration;
38
import org.eclipse.debug.core.ILaunchConfigurationListener;
41
import org.eclipse.debug.core.ILaunchConfigurationListener;
39
import org.eclipse.debug.core.ILaunchConfigurationType;
42
import org.eclipse.debug.core.ILaunchConfigurationType;
Lines 140-145 Link Here
140
		 assertTrue("Should need saving", wc.isDirty()); //$NON-NLS-1$
143
		 assertTrue("Should need saving", wc.isDirty()); //$NON-NLS-1$
141
		 return wc;
144
		 return wc;
142
	}
145
	}
146
	
147
	/** 
148
	 * Creates and returns a new launch configuration with the given name, local
149
	 * or shared, with no attributes
150
	 */
151
	protected ILaunchConfigurationWorkingCopy newEmptyConfiguration(IContainer container, String name) throws CoreException {
152
		 ILaunchConfigurationType type = getLaunchManager().getLaunchConfigurationType(ID_TEST_LAUNCH_TYPE);
153
		 ILaunchConfigurationWorkingCopy wc = type.newInstance(container, name);
154
		 assertEquals("Should have no attributes", 0, wc.getAttributes().size());
155
		 return wc;
156
	}	
143
		
157
		
144
	/**
158
	/**
145
	 * Returns whether the given handle is contained in the specified
159
	 * Returns whether the given handle is contained in the specified
Lines 1034-1039 Link Here
1034
		IPath location = workingCopy.getLocation();
1048
		IPath location = workingCopy.getLocation();
1035
		assertEquals("Wrong path for local working copy", LaunchManager.LOCAL_LAUNCH_CONFIGURATION_CONTAINER_PATH.append("test-get-location.launch"), location);
1049
		assertEquals("Wrong path for local working copy", LaunchManager.LOCAL_LAUNCH_CONFIGURATION_CONTAINER_PATH.append("test-get-location.launch"), location);
1036
	}
1050
	}
1051
	
1052
	/**
1053
	 * Test copying attributes from one configuration to another.
1054
	 * 
1055
	 * @throws CoreException
1056
	 */
1057
	public void testCopyAttributes() throws CoreException {
1058
		ILaunchConfigurationWorkingCopy source = newConfiguration(null, "test-copy-attributes-source");
1059
		ILaunchConfigurationWorkingCopy dest = newEmptyConfiguration(null, "test-copy-attributes-dest");
1060
		dest.copyAttributes(source);
1061
		assertTrue("String1 should be String1", dest.getAttribute("String1", "Missing").equals("String1")); 
1062
		assertTrue("Int1 should be 1", dest.getAttribute("Int1", 0) == 1);
1063
		assertTrue("Boolean1 should be true", dest.getAttribute("Boolean1", false));
1064
		assertTrue("Boolean2 should be false", !dest.getAttribute("Boolean2", true));
1065
	}
1066
	
1067
	/**
1068
	 * Tests setting a default template in the project scope.
1069
	 * 
1070
	 * @throws CoreException
1071
	 */
1072
	public void testProjectScopeTemplate() throws CoreException {
1073
		ILaunchConfigurationWorkingCopy wc = newConfiguration(null, "test-project-scope");
1074
		ILaunchConfiguration template = wc.doSave();
1075
		ILaunchConfigurationType type = template.getType();
1076
		IScopeContext scope = new ProjectScope(getProject());
1077
		type.setTemplate(template, scope);
1078
		ILaunchConfiguration configuration = type.getTemplate(scope);
1079
		assertNotNull("No template found", configuration);
1080
		assertEquals("Wrong template", template, configuration);
1081
		// test removing scope
1082
		type.setTemplate(null, scope);
1083
		configuration = type.getTemplate(scope);
1084
		assertNull("Should no longer be a template", configuration);
1085
	}
1086
	
1087
	/**
1088
	 * Tests setting a default template in the project scope.
1089
	 * 
1090
	 * @throws CoreException
1091
	 */
1092
	public void testInstanceScopeTemplate() throws CoreException {
1093
		ILaunchConfigurationWorkingCopy wc = newConfiguration(null, "test-instance-scope");
1094
		ILaunchConfiguration template = wc.doSave();
1095
		ILaunchConfigurationType type = template.getType();
1096
		IScopeContext scope = new InstanceScope();
1097
		type.setTemplate(template, scope);
1098
		ILaunchConfiguration configuration = type.getTemplate(scope);
1099
		assertNotNull("No template found", configuration);
1100
		assertEquals("Wrong template", template, configuration);
1101
		// test removing scope
1102
		type.setTemplate(null, scope);
1103
		configuration = type.getTemplate(scope);
1104
		assertNull("Should no longer be a template", configuration);
1105
	}	
1106
	
1107
	/**
1108
	 * Tests that a default template in the project scope is used to initialize
1109
	 * values.
1110
	 * 
1111
	 * @throws CoreException
1112
	 */
1113
	public void testCreationFromProjectScopeTemplate() throws CoreException {
1114
		ILaunchConfigurationWorkingCopy pc = newConfiguration(null, "test-project-scope-creation");
1115
		pc.setAttribute("PROJECT", "PROJECT");
1116
		ILaunchConfiguration ptemplate = pc.doSave();
1117
		ILaunchConfigurationWorkingCopy ic = newConfiguration(null, "test-workspace-scope-creation");
1118
		ic.setAttribute("WORKSPACE", "WORKSPACE");
1119
		ILaunchConfiguration itemplate = ic.doSave();
1120
		ILaunchConfigurationType type = ptemplate.getType();
1121
		IScopeContext pscope = new ProjectScope(getProject());
1122
		IScopeContext wscope = new InstanceScope();
1123
		type.setTemplate(ptemplate, pscope);
1124
		type.setTemplate(itemplate, wscope);
1125
		
1126
		// create a new configuration in project scope priority
1127
		ILaunchConfigurationWorkingCopy config = type.newInstance(null, "test-scopes", new IScopeContext[]{pscope, wscope});
1128
		assertNotNull("Made from wrong template", config.getAttribute("PROJECT", (String)null));
1129
		assertEquals("Should refer to creation template", ptemplate, config.getTemplate());
1130
		
1131
		// Removing defaults
1132
		type.setTemplate(null, pscope);
1133
		type.setTemplate(null, wscope);
1134
		ILaunchConfiguration configuration = type.getTemplate(pscope);
1135
		assertNull("Should no longer be a project template", configuration);
1136
		configuration = type.getTemplate(wscope);
1137
		assertNull("Should no longer be a workspace template", configuration);
1138
	}	
1139
	
1140
	/**
1141
	 * Tests that a default template in the instance scope is used to initialize
1142
	 * values.
1143
	 * 
1144
	 * @throws CoreException
1145
	 */
1146
	public void testCreationFromInsatnceScopeTemplate() throws CoreException {
1147
		ILaunchConfigurationWorkingCopy ic = newConfiguration(null, "test-workspace-scope-creation");
1148
		ic.setAttribute("WORKSPACE", "WORKSPACE");
1149
		ILaunchConfiguration itemplate = ic.doSave();
1150
		ILaunchConfigurationType type = itemplate.getType();
1151
		IScopeContext pscope = new ProjectScope(getProject());
1152
		IScopeContext wscope = new InstanceScope();
1153
		type.setTemplate(itemplate, wscope);
1154
		
1155
		// create a new configuration in project scope priority, but picks up workspace scope
1156
		ILaunchConfigurationWorkingCopy config = type.newInstance(null, "test-scopes", new IScopeContext[]{pscope, wscope});
1157
		assertNotNull("Made from wrong template", config.getAttribute("WORKSPACE", (String)null));
1158
		assertEquals("Should refer to creation template", itemplate, config.getTemplate());
1159
		
1160
		// Removing defaults
1161
		type.setTemplate(null, wscope);
1162
		ILaunchConfiguration configuration = type.getTemplate(wscope);
1163
		assertNull("Should no longer be a workspace template", configuration);
1164
	}		
1165
	
1166
	/**
1167
	 * Tests setting the 'isTemplate' attribute.
1168
	 * 
1169
	 * @throws CoreException
1170
	 */
1171
	public void testIsTemplate() throws CoreException {
1172
		ILaunchConfigurationWorkingCopy wc = newConfiguration(null, "test-is-template");
1173
		wc.setTemplate(true);
1174
		ILaunchConfiguration template = wc.doSave();
1175
		assertTrue("Should be a template", template.isTemplate());
1176
		ILaunchConfiguration[] templates = wc.getType().getTemplates();
1177
		assertEquals("Expecting one template", 1, templates.length);
1178
		wc = template.getWorkingCopy();
1179
		wc.setTemplate(false);
1180
		template = wc.doSave();
1181
		assertFalse("Should not be a template", template.isTemplate());
1182
	}
1183
	
1184
	/**
1185
	 * Tests finding references to a template.
1186
	 * 
1187
	 * @throws CoreException
1188
	 */
1189
	public void testTemplateChildren() throws CoreException {
1190
		ILaunchConfigurationWorkingCopy wc = newConfiguration(null, "test-references");
1191
		ILaunchConfiguration template = wc.doSave();
1192
		
1193
		ILaunchConfigurationWorkingCopy r1 = newConfiguration(null, "referee-1");
1194
		ILaunchConfigurationWorkingCopy r2 = newConfiguration(null, "referee-2");
1195
		
1196
		r1.setTemplate(template);
1197
		r2.setTemplate(template);
1198
		
1199
		ILaunchConfiguration s1 = r1.doSave();
1200
		ILaunchConfiguration s2 = r2.doSave();
1201
		
1202
		ILaunchConfiguration[] children = template.getTemplateChildren();
1203
		assertEquals("Wrong number of template children", 2, children.length);
1204
		List list = new ArrayList();
1205
		for (int i = 0; i < children.length; i++) {
1206
			list.add(children[i]);		
1207
		}
1208
		assertTrue("Missing reference", list.contains(s1));
1209
		assertTrue("Missing reference", list.contains(s2));
1210
	}
1037
}
1211
}
1038
1212
1039
1213

Return to bug 41353