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 |
|