Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 114563 | Differences between
and this patch

Collapse All | Expand All

(-)External (+204 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.tests.ui.externaltools;
12
13
import java.util.HashMap;
14
import java.util.Map;
15
16
import junit.framework.Test;
17
18
import org.eclipse.ant.launching.IAntLaunchConstants;
19
import org.eclipse.ant.tests.ui.testplugin.AbstractAntUITest;
20
import org.eclipse.core.externaltools.internal.IExternalToolConstants;
21
import org.eclipse.core.externaltools.internal.model.BuilderCoreUtils;
22
import org.eclipse.core.externaltools.internal.registry.ExternalToolMigration;
23
import org.eclipse.core.resources.ICommand;
24
import org.eclipse.core.resources.IFolder;
25
import org.eclipse.core.resources.IProject;
26
import org.eclipse.debug.core.ILaunchConfiguration;
27
import org.eclipse.debug.core.ILaunchConfigurationType;
28
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
29
import org.eclipse.ui.externaltools.internal.model.BuilderUtils;
30
31
/**
32
 * Abstract {@link Test} class for external tools
33
 * 
34
 * @since 3.5.100 org.eclipse.ant.tests.ui
35
 */
36
public abstract class AbstractExternalToolTest extends AbstractAntUITest {
37
38
	static final String EXT_BUILD_FILE_NAME = "ext-builders.xml";
39
	
40
	/**
41
	 * Constructor
42
	 * @param name
43
	 */
44
	public AbstractExternalToolTest(String name) {
45
		super(name);
46
	}
47
	
48
	/**
49
	 * Creates a new external tool builder for the given project from the given {@link ILaunchConfiguration}
50
	 * 
51
	 * @param project the parent project
52
	 * @param name the name of the config
53
	 * @param args the argument map to set in the new configuration
54
	 * @return a new Ant build {@link ILaunchConfiguration} or <code>null</code>
55
	 * @throws Exception
56
	 */
57
	protected ILaunchConfiguration createExternalToolBuilder(IProject project, String name, Map args) throws Exception {
58
		IFolder dir = getProject().getFolder(BuilderCoreUtils.BUILDER_FOLDER_NAME);
59
		if(!dir.exists()) {
60
			dir.create(true, true, null);
61
		}
62
		ILaunchConfigurationType type = AbstractAntUITest.getLaunchManager().getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE);
63
		if(type != null) {
64
			ILaunchConfigurationWorkingCopy config = type.newInstance(dir, name);
65
			config.setAttributes(args);
66
			return config.doSave();
67
		}
68
		return null;
69
	}
70
	
71
	/**
72
	 * Creates a new external tool Ant build configuration that has never been saved
73
	 * @param project
74
	 * @param name
75
	 * @param args
76
	 * @return
77
	 * @throws Exception
78
	 */
79
	protected ILaunchConfigurationWorkingCopy createExternalToolBuilderWorkingCopy(IProject project, String name, Map args) throws Exception {
80
		IFolder dir = getProject().getFolder(BuilderCoreUtils.BUILDER_FOLDER_NAME);
81
		if(!dir.exists()) {
82
			dir.create(true, true, null);
83
		}
84
		ILaunchConfigurationType type = AbstractAntUITest.getLaunchManager().getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE);
85
		if(type != null) {
86
			ILaunchConfigurationWorkingCopy config = type.newInstance(dir, name);
87
			config.setAttributes(args);
88
			return config;
89
		}
90
		return null;
91
	}
92
	
93
	/**
94
	 * Creates a new empty {@link ICommand}
95
	 * @return the new build {@link ICommand}
96
	 * @throws Exception
97
	 */
98
	protected ICommand createEmptyBuildCommand() throws Exception {
99
		return getProject().getDescription().newCommand();
100
	}
101
	
102
	/**
103
	 * Creates a new builder {@link ICommand}
104
	 * @param config
105
	 * @return the new builder {@link ICommand}
106
	 * @throws Exception
107
	 */
108
	protected ICommand createBuildCommand(ILaunchConfiguration config) throws Exception {
109
		return BuilderUtils.commandFromLaunchConfig(getProject(), config);
110
	}
111
	
112
	/**
113
	 * Returns a map of arguments for an Ant buildfile using
114
	 * Eclipse 2.0 arguments.
115
	 * 
116
	 * @return a map of 2.0 arguments for an Ant buildfile.
117
	 */
118
	protected Map get20AntArgumentMap() {
119
		HashMap arguments= new HashMap();
120
		arguments.put(ExternalToolMigration.TAG_VERSION, "2.0");
121
		arguments.put(ExternalToolMigration.TAG_TOOL_TYPE, "org.eclipse.ui.externaltools.type.ant");
122
		arguments.put(ExternalToolMigration.TAG_TOOL_NAME, "ant tool");
123
		arguments.put(ExternalToolMigration.TAG_TOOL_LOCATION, "location");
124
		arguments.put(ExternalToolMigration.TAG_TOOL_REFRESH, "refresh scope");
125
		arguments.put(ExternalToolMigration.TAG_TOOL_ARGUMENTS, "arg ${ant_target:target1} ${ant_target:target2}");
126
		arguments.put(ExternalToolMigration.TAG_TOOL_SHOW_LOG, "true");
127
		arguments.put(ExternalToolMigration.TAG_TOOL_BLOCK, "false");
128
		arguments.put(ExternalToolMigration.TAG_TOOL_BUILD_TYPES, "build kinds");
129
		arguments.put(ExternalToolMigration.TAG_TOOL_DIRECTORY, "working dir");
130
		return arguments;
131
	}
132
	
133
	/**
134
	 * Returns a map of arguments for executing a program
135
	 * using Eclipse 2.0 arguments.
136
	 * 
137
	 * @return a map of 2.0 arguments for a program
138
	 */
139
	protected Map get20ProgramArgumentMap() {
140
		HashMap arguments= new HashMap();
141
		arguments.put(ExternalToolMigration.TAG_VERSION, "2.0");
142
		arguments.put(ExternalToolMigration.TAG_TOOL_TYPE, "org.eclipse.ui.externaltools.type.program");
143
		arguments.put(ExternalToolMigration.TAG_TOOL_NAME, "program tool");
144
		arguments.put(ExternalToolMigration.TAG_TOOL_LOCATION, "location");
145
		arguments.put(ExternalToolMigration.TAG_TOOL_REFRESH, "refresh scope");
146
		arguments.put(ExternalToolMigration.TAG_TOOL_ARGUMENTS, "arg ${ant_target:target1} ${ant_target:target2}");
147
		arguments.put(ExternalToolMigration.TAG_TOOL_SHOW_LOG, "true");
148
		arguments.put(ExternalToolMigration.TAG_TOOL_BLOCK, "false");
149
		arguments.put(ExternalToolMigration.TAG_TOOL_BUILD_TYPES, "build kinds");
150
		arguments.put(ExternalToolMigration.TAG_TOOL_DIRECTORY, "working dir");
151
		return arguments;
152
	}
153
	
154
	/**
155
	 * Returns a map of arguments for executing an Ant
156
	 * buildfile using Eclipse 2.1 arguments.
157
	 * 
158
	 * @return a map of 2.1 arguments for an Ant buildfile
159
	 */
160
	protected Map get21AntArgumentMap() {
161
		HashMap arguments= new HashMap();
162
		arguments.put(ExternalToolMigration.TAG_VERSION, "2.1");
163
		arguments.put(ExternalToolMigration.TAG_NAME, "ant config");
164
		arguments.put(ExternalToolMigration.TAG_TYPE, ExternalToolMigration.TOOL_TYPE_ANT_BUILD);
165
		arguments.put(ExternalToolMigration.TAG_LOCATION, "location");
166
		arguments.put(ExternalToolMigration.TAG_WORK_DIR, "working directory");
167
		arguments.put(ExternalToolMigration.TAG_CAPTURE_OUTPUT, "true");
168
		arguments.put(ExternalToolMigration.TAG_SHOW_CONSOLE, "true");
169
		arguments.put(ExternalToolMigration.TAG_SHOW_CONSOLE, "true");
170
		arguments.put(ExternalToolMigration.TAG_RUN_BKGRND, "true");
171
		arguments.put(ExternalToolMigration.TAG_PROMPT_ARGS, "true");
172
		arguments.put(ExternalToolMigration.TAG_REFRESH_SCOPE, "refresh scope");
173
		arguments.put(ExternalToolMigration.TAG_REFRESH_RECURSIVE, "true");
174
		arguments.put(ExternalToolMigration.TAG_RUN_BUILD_KINDS, "build kinds");
175
		arguments.put(ExternalToolMigration.TAG_ARGS, "arg1 arg2");
176
		arguments.put(ExternalToolMigration.TAG_EXTRA_ATTR, ExternalToolMigration.RUN_TARGETS_ATTRIBUTE + "=target1,target2");
177
		return arguments;
178
	}
179
	
180
	/**
181
	 * Returns a map of arguments for executing a program
182
	 * buildfile using Eclipse 2.1 arguments.
183
	 * 
184
	 * @return a map of 2.1 arguments for a program
185
	 */
186
	protected Map get21ProgramArgumentMap() {
187
		HashMap arguments= new HashMap();
188
		arguments.put(ExternalToolMigration.TAG_VERSION, "2.1");
189
		arguments.put(ExternalToolMigration.TAG_NAME, "program config");
190
		arguments.put(ExternalToolMigration.TAG_TYPE, IExternalToolConstants.TOOL_TYPE_PROGRAM);
191
		arguments.put(ExternalToolMigration.TAG_LOCATION, "location");
192
		arguments.put(ExternalToolMigration.TAG_WORK_DIR, "working directory");
193
		arguments.put(ExternalToolMigration.TAG_CAPTURE_OUTPUT, "true");
194
		arguments.put(ExternalToolMigration.TAG_SHOW_CONSOLE, "true");
195
		arguments.put(ExternalToolMigration.TAG_SHOW_CONSOLE, "true");
196
		arguments.put(ExternalToolMigration.TAG_RUN_BKGRND, "true");
197
		arguments.put(ExternalToolMigration.TAG_PROMPT_ARGS, "true");
198
		arguments.put(ExternalToolMigration.TAG_REFRESH_SCOPE, "refresh scope");
199
		arguments.put(ExternalToolMigration.TAG_REFRESH_RECURSIVE, "true");
200
		arguments.put(ExternalToolMigration.TAG_RUN_BUILD_KINDS, "build kinds");
201
		arguments.put(ExternalToolMigration.TAG_ARGS, "arg1 arg2");
202
		return arguments;
203
	}
204
}
(-)External (+486 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.tests.ui.externaltools;
12
13
import java.util.HashMap;
14
import java.util.Map;
15
16
import org.eclipse.ant.internal.launching.AntLaunchingUtil;
17
import org.eclipse.ant.launching.IAntLaunchConstants;
18
import org.eclipse.ant.tests.ui.testplugin.AbstractAntUITest;
19
import org.eclipse.core.externaltools.internal.IExternalToolConstants;
20
import org.eclipse.core.externaltools.internal.model.BuilderCoreUtils;
21
import org.eclipse.core.resources.ICommand;
22
import org.eclipse.core.resources.IncrementalProjectBuilder;
23
import org.eclipse.debug.core.ILaunchConfiguration;
24
import org.eclipse.debug.core.ILaunchConfigurationType;
25
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
26
27
/**
28
 * Tests for {@link BuilderCoreUtils}
29
 * 
30
 * @since 3.5.100 org.eclipse.ant.tests.ui
31
 */
32
public class BuilderCoreUtilsTests extends AbstractExternalToolTest {
33
	
34
	/**
35
	 * Constructor
36
	 */
37
	public BuilderCoreUtilsTests() {
38
		super("BuilderCoreUtils Tests");
39
	}
40
41
	/* (non-Javadoc)
42
	 * @see org.eclipse.ant.tests.ui.testplugin.AbstractAntUITest#setUp()
43
	 */
44
	protected void setUp() throws Exception {
45
		super.setUp();
46
		//create the external tool builder dir
47
		BuilderCoreUtils.getBuilderFolder(getProject(), true);
48
	}
49
	
50
	/**
51
	 * Tests the {@link BuilderCoreUtils#configFromBuildCommandArgs(org.eclipse.core.resources.IProject, java.util.Map, String[])}
52
	 * method.
53
	 * <br><br>
54
	 * Tests the argument map missing the {@link BuilderCoreUtils#LAUNCH_CONFIG_HANDLE} attribute and all other config arguments
55
	 * @throws Exception
56
	 */
57
	public void testConfigFromBuildCommandArgs1() throws Exception {
58
		ILaunchConfiguration config = BuilderCoreUtils.configFromBuildCommandArgs(getProject(), new HashMap(), new String[] {BuilderCoreUtils.VERSION_1_0});
59
		assertNull("There should be no configuration returned without the config handle and arguments", config);
60
	}
61
	
62
	/**
63
	 * Tests the {@link BuilderCoreUtils#configFromBuildCommandArgs(org.eclipse.core.resources.IProject, java.util.Map, String[])}
64
	 * method.
65
	 * <br><br>
66
	 * Tests the argument map missing the {@link BuilderCoreUtils#LAUNCH_CONFIG_HANDLE} attribute only
67
	 * @throws Exception
68
	 */
69
	public void testConfigFromBuildCommandArgs2() throws Exception {
70
		Map args = get20AntArgumentMap();
71
		ILaunchConfiguration config = BuilderCoreUtils.configFromBuildCommandArgs(getProject(), args, new String[] {BuilderCoreUtils.VERSION_2_1});
72
		assertNotNull("There should be a migrated configuration returned", config);
73
	}
74
	
75
	/**
76
	 * Tests the {@link BuilderCoreUtils#configFromBuildCommandArgs(org.eclipse.core.resources.IProject, java.util.Map, String[])}
77
	 * method.
78
	 * <br><br>
79
	 * Tests the argument map with an invalid {@link BuilderCoreUtils#LAUNCH_CONFIG_HANDLE} attribute
80
	 * @throws Exception
81
	 */
82
	public void testConfigFromBuildCommandArgs3() throws Exception {
83
		Map args = new HashMap();
84
		args.put(BuilderCoreUtils.LAUNCH_CONFIG_HANDLE, "foo");
85
		ILaunchConfiguration config = BuilderCoreUtils.configFromBuildCommandArgs(getProject(), args, new String[] {BuilderCoreUtils.VERSION_2_1});
86
		assertNull("There should be no configuration returned", config);
87
	}
88
	
89
	/**
90
	 * Tests the {@link BuilderCoreUtils#configFromBuildCommandArgs(org.eclipse.core.resources.IProject, java.util.Map, String[])}
91
	 * method.
92
	 * <br><br>
93
	 * Tests the argument map with a valid {@link BuilderCoreUtils#LAUNCH_CONFIG_HANDLE} attribute with no project prefix, but does
94
	 * include the .externalToolBuilders dir name - causes a lookup in the launch manager which fails because of the extra path prefix
95
	 * @throws Exception
96
	 */
97
	public void testConfigFromBuildCommandArgs4() throws Exception {
98
		createExternalToolBuilder(getProject(), "testConfigFromBuildCommandArgs4", null);
99
		Map args = new HashMap();
100
		args.put(BuilderCoreUtils.LAUNCH_CONFIG_HANDLE, "/.externalToolBuilders/testConfigFromBuildCommandArgs4.launch");
101
		ILaunchConfiguration config = BuilderCoreUtils.configFromBuildCommandArgs(getProject(), args, new String[] {BuilderCoreUtils.VERSION_2_1});
102
		assertNull("There should be no configuration returned", config);
103
	}
104
	
105
	/**
106
	 * Tests the {@link BuilderCoreUtils#configFromBuildCommandArgs(org.eclipse.core.resources.IProject, java.util.Map, String[])}
107
	 * method.
108
	 * <br><br>
109
	 * Tests the argument map with a valid {@link BuilderCoreUtils#LAUNCH_CONFIG_HANDLE} attribute with no project prefix - 
110
	 * causes a lookup in the launch manager returns the config
111
	 * @throws Exception
112
	 */
113
	public void testConfigFromBuildCommandArgs5() throws Exception {
114
		createExternalToolBuilder(getProject(), "testConfigFromBuildCommandArgs5", null);
115
		Map args = new HashMap();
116
		args.put(BuilderCoreUtils.LAUNCH_CONFIG_HANDLE, "testConfigFromBuildCommandArgs5.launch");
117
		ILaunchConfiguration config = BuilderCoreUtils.configFromBuildCommandArgs(getProject(), args, new String[] {BuilderCoreUtils.VERSION_2_1});
118
		assertNotNull("There should be a configuration returned", config);
119
	}
120
	
121
	/**
122
	 * Tests the {@link BuilderCoreUtils#configFromBuildCommandArgs(org.eclipse.core.resources.IProject, java.util.Map, String[])}
123
	 * method.
124
	 * <br><br>
125
	 * Tests the argument map with a valid {@link BuilderCoreUtils#LAUNCH_CONFIG_HANDLE} attribute with the project prefix but
126
	 * not including the .externalToolBuilder path segment
127
	 * @throws Exception
128
	 */
129
	public void testConfigFromBuildCommandArgs6() throws Exception {
130
		createExternalToolBuilder(getProject(), "testConfigFromBuildCommandArgs6", null);
131
		Map args = new HashMap();
132
		args.put(BuilderCoreUtils.LAUNCH_CONFIG_HANDLE, "<project>/testConfigFromBuildCommandArgs6.launch");
133
		ILaunchConfiguration config = BuilderCoreUtils.configFromBuildCommandArgs(getProject(), args, new String[] {BuilderCoreUtils.VERSION_2_1});
134
		assertNull("There should be no configuration returned", config);
135
	}
136
	
137
	/**
138
	 * Tests the {@link BuilderCoreUtils#configFromBuildCommandArgs(org.eclipse.core.resources.IProject, java.util.Map, String[])}
139
	 * method.
140
	 * <br><br>
141
	 * Tests the argument map with a valid {@link BuilderCoreUtils#LAUNCH_CONFIG_HANDLE} attribute with the project prefix and 
142
	 * a valid config path
143
	 * @throws Exception
144
	 */
145
	public void testConfigFromBuildCommandArgs7() throws Exception {
146
		createExternalToolBuilder(getProject(), "testConfigFromBuildCommandArgs7", null);
147
		Map args = new HashMap();
148
		args.put(BuilderCoreUtils.LAUNCH_CONFIG_HANDLE, "<project>/.externalToolBuilders/testConfigFromBuildCommandArgs7.launch");
149
		ILaunchConfiguration config = BuilderCoreUtils.configFromBuildCommandArgs(getProject(), args, new String[] {BuilderCoreUtils.VERSION_2_1});
150
		assertNotNull("There should be a configuration returned", config);
151
	}
152
	
153
	/**
154
	 * Tests the {@link BuilderCoreUtils#configureTriggers(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.resources.ICommand)}
155
	 * method
156
	 * <br><br>
157
	 * Tests that the triggers are configured for a full build of the default target after a clean
158
	 * @throws Exception
159
	 */
160
	public void testConfigureTriggers1() throws Exception {
161
		Map args = new HashMap();
162
		args.put(IAntLaunchConstants.ATTR_ANT_AFTER_CLEAN_TARGETS, null);
163
		args.put(IExternalToolConstants.ATTR_LOCATION, getBuildFile(EXT_BUILD_FILE_NAME).getAbsolutePath());
164
		args.put(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, IExternalToolConstants.BUILD_TYPE_FULL);
165
		ILaunchConfiguration config = createExternalToolBuilder(getProject(), "testConfigureTriggers1", args);
166
		assertNotNull("the test builder must not be null", config);
167
		ICommand command = createBuildCommand(config);
168
		assertNotNull("the test build command must not be null", command);
169
		assertTrue("the command must be building FULL builds", command.isBuilding(IncrementalProjectBuilder.FULL_BUILD));
170
		String[] names = AntLaunchingUtil.getTargetNames(config);
171
		assertNull("should be no target names resolved from the config - null given for target names", names);
172
	}
173
	
174
	/**
175
	 * Tests the {@link BuilderCoreUtils#configureTriggers(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.resources.ICommand)}
176
	 * method
177
	 * <br><br>
178
	 * Tests that the triggers are configured for a full build of a specific targets 'def' and 'clean'
179
	 * @throws Exception
180
	 */
181
	public void testConfigureTriggers2() throws Exception {
182
		Map args = new HashMap();
183
		args.put(IAntLaunchConstants.ATTR_ANT_AFTER_CLEAN_TARGETS, "def,clean");
184
		args.put(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, IExternalToolConstants.BUILD_TYPE_FULL);
185
		ILaunchConfiguration config = createExternalToolBuilder(getProject(), "testConfigureTriggers2", args);
186
		assertNotNull("the test builder must not be null", config);
187
		ICommand command = createBuildCommand(config);
188
		assertNotNull("the test build command must not be null", command);
189
		assertTrue("the command must be building FULL builds", command.isBuilding(IncrementalProjectBuilder.FULL_BUILD));
190
		String[] names = AntLaunchingUtil.getTargetNames(config);
191
		assertNull("should be no target names resolved from the config - only available during a build", names);
192
	}
193
	
194
	/**
195
	 * Tests the {@link BuilderCoreUtils#configureTriggers(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.resources.ICommand)}
196
	 * method
197
	 * <br><br>
198
	 * Tests that the triggers are configured for an incremental AND full build with default targets
199
	 * <br><br>
200
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=114563
201
	 * @throws Exception
202
	 */
203
	public void testConfigureTriggers3() throws Exception {
204
		Map args = new HashMap();
205
		args.put(IAntLaunchConstants.ATTR_ANT_MANUAL_TARGETS, null);
206
		args.put(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, IExternalToolConstants.BUILD_TYPE_INCREMENTAL);
207
		ILaunchConfiguration config = createExternalToolBuilder(getProject(), "testConfigureTriggers3", args);
208
		assertNotNull("the test builder must not be null", config);
209
		ICommand command = createBuildCommand(config);
210
		assertNotNull("the test build command must not be null", command);
211
		assertTrue("the command must be building INCREMENTAL builds", command.isBuilding(IncrementalProjectBuilder.INCREMENTAL_BUILD));
212
		assertTrue("the command must be building FULL builds", command.isBuilding(IncrementalProjectBuilder.FULL_BUILD));
213
		String[] names = AntLaunchingUtil.getTargetNames(config);
214
		assertNull("should be no target names resolved from the config - null given for target names", names);
215
	}
216
	
217
	/**
218
	 * Tests the {@link BuilderCoreUtils#configureTriggers(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.resources.ICommand)}
219
	 * method
220
	 * <br><br>
221
	 * Tests that the triggers are configured for an incremental AND full build with the targets 'def' and 'inc'
222
	 * <br><br>
223
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=114563
224
	 * @throws Exception
225
	 */
226
	public void testConfigureTriggers4() throws Exception {
227
		Map args = new HashMap();
228
		args.put(IAntLaunchConstants.ATTR_ANT_MANUAL_TARGETS, "def,inc");
229
		args.put(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, IExternalToolConstants.BUILD_TYPE_INCREMENTAL);
230
		ILaunchConfiguration config = createExternalToolBuilder(getProject(), "testConfigureTriggers4", args);
231
		assertNotNull("the test builder must not be null", config);
232
		ICommand command = createBuildCommand(config);
233
		assertNotNull("the test build command must not be null", command);
234
		assertTrue("the command must be building INCREMENTAL builds", command.isBuilding(IncrementalProjectBuilder.INCREMENTAL_BUILD));
235
		assertTrue("the command must be building FULL builds", command.isBuilding(IncrementalProjectBuilder.FULL_BUILD));
236
		String[] names = AntLaunchingUtil.getTargetNames(config);
237
		assertNull("should be no target names resolved from the config - only available during a build", names);
238
	}
239
	
240
	/**
241
	 * Tests the {@link BuilderCoreUtils#configureTriggers(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.resources.ICommand)}
242
	 * method
243
	 * <br><br>
244
	 * Tests that the triggers are configured for an auto build
245
	 * @throws Exception
246
	 */
247
	public void testConfigureTriggers5() throws Exception {
248
		Map args = new HashMap();
249
		args.put(IAntLaunchConstants.ATTR_ANT_AUTO_TARGETS, null);
250
		args.put(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, IExternalToolConstants.BUILD_TYPE_AUTO);
251
		ILaunchConfiguration config = createExternalToolBuilder(getProject(), "testConfigureTriggers5", args);
252
		assertNotNull("the test builder must not be null", config);
253
		ICommand command = createBuildCommand(config);
254
		assertNotNull("the test build command must not be null", command);
255
		assertTrue("the command must be building AUTO builds", command.isBuilding(IncrementalProjectBuilder.AUTO_BUILD));
256
		String[] names = AntLaunchingUtil.getTargetNames(config);
257
		assertNull("should be no target names resolved from the config - null given for target names", names);
258
	}
259
	
260
	/**
261
	 * Tests the {@link BuilderCoreUtils#configureTriggers(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.resources.ICommand)}
262
	 * method
263
	 * <br><br>
264
	 * Tests that the triggers are configured for an auto build with the targets 'def' and 'auto'
265
	 * @throws Exception
266
	 */
267
	public void testConfigureTriggers6() throws Exception {
268
		Map args = new HashMap();
269
		args.put(IAntLaunchConstants.ATTR_ANT_AUTO_TARGETS, "def,auto");
270
		args.put(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, IExternalToolConstants.BUILD_TYPE_AUTO);
271
		ILaunchConfiguration config = createExternalToolBuilder(getProject(), "testConfigureTriggers6", args);
272
		assertNotNull("the test builder must not be null", config);
273
		ICommand command = createBuildCommand(config);
274
		assertNotNull("the test build command must not be null", command);
275
		assertTrue("the command must be building AUTO builds", command.isBuilding(IncrementalProjectBuilder.AUTO_BUILD));
276
		String[] names = AntLaunchingUtil.getTargetNames(config);
277
		assertNull("should be no target names resolved from the config - only available during a build", names);
278
	}
279
	
280
	/**
281
	 * Tests the {@link BuilderCoreUtils#configureTriggers(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.resources.ICommand)}
282
	 * method
283
	 * <br><br>
284
	 * Tests that the triggers are configured for a clean build
285
	 * @throws Exception
286
	 */
287
	public void testConfigureTriggers7() throws Exception {
288
		Map args = new HashMap();
289
		args.put(IAntLaunchConstants.ATTR_ANT_CLEAN_TARGETS, null);
290
		args.put(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, IExternalToolConstants.BUILD_TYPE_CLEAN);
291
		ILaunchConfiguration config = createExternalToolBuilder(getProject(), "testConfigureTriggers7", args);
292
		assertNotNull("the test builder must not be null", config);
293
		ICommand command = createBuildCommand(config);
294
		assertNotNull("the test build command must not be null", command);
295
		assertTrue("the command must be building CLEAN builds", command.isBuilding(IncrementalProjectBuilder.CLEAN_BUILD));
296
		String[] names = AntLaunchingUtil.getTargetNames(config);
297
		assertNull("should be no target names resolved from the config - null given for target names", names);
298
	}
299
	
300
	/**
301
	 * Tests the {@link BuilderCoreUtils#configureTriggers(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.resources.ICommand)}
302
	 * method
303
	 * <br><br>
304
	 * Tests that the triggers are configured for a clean build with the targets 'def' and 'clean'
305
	 * @throws Exception
306
	 */
307
	public void testConfigureTriggers8() throws Exception {
308
		Map args = new HashMap();
309
		args.put(IAntLaunchConstants.ATTR_ANT_CLEAN_TARGETS, "def,clean");
310
		args.put(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, IExternalToolConstants.BUILD_TYPE_CLEAN);
311
		ILaunchConfiguration config = createExternalToolBuilder(getProject(), "testConfigureTriggers6", args);
312
		assertNotNull("the test builder must not be null", config);
313
		ICommand command = createBuildCommand(config);
314
		assertNotNull("the test build command must not be null", command);
315
		assertTrue("the command must be building CLEAN builds", command.isBuilding(IncrementalProjectBuilder.CLEAN_BUILD));
316
		String[] names = AntLaunchingUtil.getTargetNames(config);
317
		assertNull("should be no target names resolved from the config - only available during a build", names);
318
	}
319
	
320
	/**
321
	 * Tests the {@link BuilderCoreUtils#configureTriggers(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.resources.ICommand)}
322
	 * method
323
	 * <br><br>
324
	 * Tests that the triggers are configured for a full + incremental build with the targets 'def' and 'inc' specified 
325
	 * for after clean targets and manual targets respectively
326
	 * @throws Exception
327
	 */
328
	public void testConfigureTriggers9() throws Exception {
329
		Map args = new HashMap();
330
		args.put(IAntLaunchConstants.ATTR_ANT_AFTER_CLEAN_TARGETS, "def");
331
		args.put(IAntLaunchConstants.ATTR_ANT_MANUAL_TARGETS, "inc");
332
		args.put(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, IExternalToolConstants.BUILD_TYPE_CLEAN+","+IExternalToolConstants.BUILD_TYPE_INCREMENTAL);
333
		ILaunchConfiguration config = createExternalToolBuilder(getProject(), "testConfigureTriggers9", args);
334
		assertNotNull("the test builder must not be null", config);
335
		ICommand command = createBuildCommand(config);
336
		assertNotNull("the test build command must not be null", command);
337
		assertTrue("the command must be building CLEAN builds", command.isBuilding(IncrementalProjectBuilder.FULL_BUILD));
338
		assertTrue("the command must be building CLEAN builds", command.isBuilding(IncrementalProjectBuilder.INCREMENTAL_BUILD));
339
		String[] names = AntLaunchingUtil.getTargetNames(config);
340
		assertNull("should be no target names resolved from the config - only available during a build", names);
341
	}
342
	
343
	/**
344
	 * Tests the {@link BuilderCoreUtils#configureTriggers(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.resources.ICommand)}
345
	 * method
346
	 * <br><br>
347
	 * Tests that the triggers are configured for a full + incremental build with the targets 'def' and 'inc' specified 
348
	 * for after clean targets and manual targets respectively
349
	 * @throws Exception
350
	 */
351
	public void testConfigureTriggers10() throws Exception {
352
		Map args = new HashMap();
353
		args.put(IAntLaunchConstants.ATTR_ANT_AFTER_CLEAN_TARGETS, "def");
354
		args.put(IAntLaunchConstants.ATTR_ANT_MANUAL_TARGETS, "inc");
355
		args.put(IAntLaunchConstants.ATTR_ANT_AUTO_TARGETS, "auto");
356
		args.put(IAntLaunchConstants.ATTR_ANT_CLEAN_TARGETS, "clean");
357
		String kinds = IExternalToolConstants.BUILD_TYPE_CLEAN+","+
358
				IExternalToolConstants.BUILD_TYPE_INCREMENTAL+","+
359
				IExternalToolConstants.BUILD_TYPE_AUTO+","+
360
				IExternalToolConstants.BUILD_TYPE_FULL;
361
		args.put(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, kinds);
362
		ILaunchConfiguration config = createExternalToolBuilder(getProject(), "testConfigureTriggers10", args);
363
		assertNotNull("the test builder must not be null", config);
364
		ICommand command = createBuildCommand(config);
365
		assertNotNull("the test build command must not be null", command);
366
		assertTrue("the command must be building CLEAN builds", command.isBuilding(IncrementalProjectBuilder.FULL_BUILD));
367
		assertTrue("the command must be building CLEAN builds", command.isBuilding(IncrementalProjectBuilder.INCREMENTAL_BUILD));
368
		assertTrue("the command must be building CLEAN builds", command.isBuilding(IncrementalProjectBuilder.CLEAN_BUILD));
369
		assertTrue("the command must be building CLEAN builds", command.isBuilding(IncrementalProjectBuilder.AUTO_BUILD));
370
		String[] names = AntLaunchingUtil.getTargetNames(config);
371
		assertNull("should be no target names resolved from the config - only available during a build", names);
372
	}
373
	
374
	/**
375
	 * Tests the {@link BuilderCoreUtils#isUnmigratedConfig(org.eclipse.debug.core.ILaunchConfiguration)} method
376
	 * @throws Exception
377
	 */
378
	public void testIsUnmigratedConfig1() throws Exception {
379
		ILaunchConfigurationType type = AbstractAntUITest.getLaunchManager().getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE);
380
		if(type != null) {
381
			ILaunchConfigurationWorkingCopy config = type.newInstance(BuilderCoreUtils.getBuilderFolder(getProject(), true), "testIsUnmigratedConfig1");
382
			assertTrue("should be considered 'unmigrated'", BuilderCoreUtils.isUnmigratedConfig(config));
383
		}
384
		else {
385
			fail("could not find the Ant builder launch configuration type");
386
		}
387
	}
388
	
389
	/**
390
	 * Tests the {@link BuilderCoreUtils#isUnmigratedConfig(org.eclipse.debug.core.ILaunchConfiguration)} method
391
	 * @throws Exception
392
	 */
393
	public void testIsUnmigratedConfig2() throws Exception {
394
		ILaunchConfiguration config = createExternalToolBuilder(getProject(), "testIsUnmigratedConfig2", null);
395
		assertFalse("Shoudl not be considered 'unmigrated'", BuilderCoreUtils.isUnmigratedConfig(config));
396
	}
397
	
398
	/**
399
	 * Tests the {@link BuilderCoreUtils#toBuildCommand(org.eclipse.core.resources.IProject, org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.resources.ICommand)}
400
	 * method
401
	 * <br><br>
402
	 * Tests the case of a new un-saved {@link ILaunchConfiguration}
403
	 * @throws Exception
404
	 */
405
	public void testToBuildCommand1() throws Exception {
406
		ILaunchConfigurationWorkingCopy copy = createExternalToolBuilderWorkingCopy(getProject(), "testToBuildCommand1", null);
407
		ICommand command = BuilderCoreUtils.toBuildCommand(getProject(), copy, getProject().getDescription().newCommand());
408
		assertNotNull("There should have been a new build command created", command);
409
	}
410
	
411
	/**
412
	 * Tests the {@link BuilderCoreUtils#toBuildCommand(org.eclipse.core.resources.IProject, org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.resources.ICommand)}
413
	 * method
414
	 * <br><br>
415
	 * Tests the case of an existing configuration
416
	 * @throws Exception
417
	 */
418
	public void testToBuildCommand2() throws Exception {
419
		Map args = new HashMap();
420
		ILaunchConfiguration copy = createExternalToolBuilder(getProject(), "testToBuildCommand2", args);
421
		ICommand command = BuilderCoreUtils.toBuildCommand(getProject(), copy, getProject().getDescription().newCommand());
422
		assertNotNull("There should have been a new build command created", command);
423
	}
424
	
425
	/**
426
	 * Tests the {@link BuilderCoreUtils#toBuildCommand(org.eclipse.core.resources.IProject, org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.resources.ICommand)}
427
	 * method
428
	 * <br><br>
429
	 * Tests the case of the working copy of an existing configuration
430
	 * @throws Exception
431
	 */
432
	public void testToBuildCommand3() throws Exception {
433
		Map args = new HashMap();
434
		ILaunchConfiguration copy = createExternalToolBuilder(getProject(), "testToBuildCommand3", args);
435
		ICommand command = BuilderCoreUtils.toBuildCommand(getProject(), copy.getWorkingCopy(), getProject().getDescription().newCommand());
436
		assertNotNull("There should have been a new build command created", command);
437
	}
438
	
439
	/**
440
	 * Tests the {@link BuilderCoreUtils#migrateBuilderConfiguration(org.eclipse.core.resources.IProject, org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)}
441
	 * method
442
	 * @throws Exception
443
	 */
444
	public void testMigrateBuilderConfiguration1() throws Exception {
445
		ILaunchConfigurationWorkingCopy copy = createExternalToolBuilderWorkingCopy(getProject(), "testMigrateBuilderConfiguration1", null);
446
		ILaunchConfiguration config = BuilderCoreUtils.migrateBuilderConfiguration(getProject(), copy);
447
		assertNotNull("The un-saved working copy should have been migrated", config);
448
		assertTrue("The name of the migrated configuration should be testMigrateBuilderConfiguration1", config.getName().equals("testMigrateBuilderConfiguration1"));
449
	}
450
	
451
	/**
452
	 * Tests the {@link BuilderCoreUtils#migrateBuilderConfiguration(org.eclipse.core.resources.IProject, org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)}
453
	 * method
454
	 * @throws Exception
455
	 */
456
	public void testMigrateBuilderConfiguration2() throws Exception {
457
		ILaunchConfigurationWorkingCopy copy = createExternalToolBuilderWorkingCopy(getProject(), "testMigra/teBuilderConfi/guration2", null);
458
		ILaunchConfiguration config = BuilderCoreUtils.migrateBuilderConfiguration(getProject(), copy);
459
		assertNotNull("The un-saved working copy should have been migrated", config);
460
		assertTrue("The name of the migrated configuration should be testMigra.teBuilderConfi.guration2", config.getName().equals("testMigra.teBuilderConfi.guration2"));
461
	}
462
	
463
	/**
464
	 * Tests the {@link BuilderCoreUtils#buildTypesToArray(String)} method
465
	 * @throws Exception
466
	 */
467
	public void testBuildTypesToArray1() throws Exception {
468
		String kinds = IExternalToolConstants.BUILD_TYPE_CLEAN+","+
469
				IExternalToolConstants.BUILD_TYPE_INCREMENTAL+","+
470
				IExternalToolConstants.BUILD_TYPE_AUTO+","+
471
				IExternalToolConstants.BUILD_TYPE_FULL;
472
		int[] array = BuilderCoreUtils.buildTypesToArray(kinds);
473
		assertNotNull("The build kinds array cannot be null", array);
474
		boolean contains = true;
475
		for (int i = 0; i < array.length; i++) {
476
			contains &= (array[i] == IncrementalProjectBuilder.AUTO_BUILD) |
477
					(array[i] == IncrementalProjectBuilder.CLEAN_BUILD) |
478
					(array[i] == IncrementalProjectBuilder.FULL_BUILD) |
479
					(array[i] == IncrementalProjectBuilder.INCREMENTAL_BUILD);
480
			if(!contains) {
481
				break;
482
			}
483
		}
484
		assertTrue("All of the build kinds should have been found", contains);
485
	}
486
}
(-)External Tools/org/eclipse/ant/tests/ui/externaltools/MigrationTests.java (-98 / +8 lines)
Lines 10-20 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ant.tests.ui.externaltools;
11
package org.eclipse.ant.tests.ui.externaltools;
12
12
13
import java.util.HashMap;
14
import java.util.Map;
13
import java.util.Map;
15
14
16
import junit.framework.TestCase;
17
18
import org.eclipse.ant.internal.launching.AntLaunchingUtil;
15
import org.eclipse.ant.internal.launching.AntLaunchingUtil;
19
import org.eclipse.ant.launching.IAntLaunchConstants;
16
import org.eclipse.ant.launching.IAntLaunchConstants;
20
import org.eclipse.core.externaltools.internal.IExternalToolConstants;
17
import org.eclipse.core.externaltools.internal.IExternalToolConstants;
Lines 29-37 Link Here
29
 * Tests migration of Ant and External Tool configurations from old
26
 * Tests migration of Ant and External Tool configurations from old
30
 * formats to the current format.
27
 * formats to the current format.
31
 */
28
 */
32
public class MigrationTests extends TestCase {
29
public class MigrationTests extends AbstractExternalToolTest {
33
	
30
	
34
	/**
31
	/**
32
	 * Constructor
33
	 */
34
	public MigrationTests() {
35
		super("Migration Tests");
36
	}
37
38
	/**
35
	 * Tests migration of arguments from an Eclipse 2.0 Ant buildfile
39
	 * Tests migration of arguments from an Eclipse 2.0 Ant buildfile
36
	 * configuration to a current launch configuration.
40
	 * configuration to a current launch configuration.
37
	 * 
41
	 * 
Lines 59-85 Link Here
59
	}
63
	}
60
	
64
	
61
	/**
65
	/**
62
	 * Returns a map of arguments for an Ant buildfile using
63
	 * Eclipse 2.0 arguments.
64
	 * 
65
	 * @return a map of 2.0 arguments for an Ant buildfile.
66
	 */
67
	private Map get20AntArgumentMap() {
68
		HashMap arguments= new HashMap();
69
		arguments.put(ExternalToolMigration.TAG_VERSION, "2.0");
70
		arguments.put(ExternalToolMigration.TAG_TOOL_TYPE, "org.eclipse.ui.externaltools.type.ant");
71
		arguments.put(ExternalToolMigration.TAG_TOOL_NAME, "ant tool");
72
		arguments.put(ExternalToolMigration.TAG_TOOL_LOCATION, "location");
73
		arguments.put(ExternalToolMigration.TAG_TOOL_REFRESH, "refresh scope");
74
		arguments.put(ExternalToolMigration.TAG_TOOL_ARGUMENTS, "arg ${ant_target:target1} ${ant_target:target2}");
75
		arguments.put(ExternalToolMigration.TAG_TOOL_SHOW_LOG, "true");
76
		arguments.put(ExternalToolMigration.TAG_TOOL_BLOCK, "false");
77
		arguments.put(ExternalToolMigration.TAG_TOOL_BUILD_TYPES, "build kinds");
78
		arguments.put(ExternalToolMigration.TAG_TOOL_DIRECTORY, "working dir");
79
		return arguments;
80
	}
81
82
	/**
83
	 * Tests migration of arguments from an Eclipse 2.0 Ant buildfile
66
	 * Tests migration of arguments from an Eclipse 2.0 Ant buildfile
84
	 * configuration to a current launch configuration.
67
	 * configuration to a current launch configuration.
85
	 * 
68
	 * 
Lines 100-126 Link Here
100
	}
83
	}
101
	
84
	
102
	/**
85
	/**
103
	 * Returns a map of arguments for executing a program
104
	 * using Eclipse 2.0 arguments.
105
	 * 
106
	 * @return a map of 2.0 arguments for a program
107
	 */
108
	private Map get20ProgramArgumentMap() {
109
		HashMap arguments= new HashMap();
110
		arguments.put(ExternalToolMigration.TAG_VERSION, "2.0");
111
		arguments.put(ExternalToolMigration.TAG_TOOL_TYPE, "org.eclipse.ui.externaltools.type.program");
112
		arguments.put(ExternalToolMigration.TAG_TOOL_NAME, "program tool");
113
		arguments.put(ExternalToolMigration.TAG_TOOL_LOCATION, "location");
114
		arguments.put(ExternalToolMigration.TAG_TOOL_REFRESH, "refresh scope");
115
		arguments.put(ExternalToolMigration.TAG_TOOL_ARGUMENTS, "arg ${ant_target:target1} ${ant_target:target2}");
116
		arguments.put(ExternalToolMigration.TAG_TOOL_SHOW_LOG, "true");
117
		arguments.put(ExternalToolMigration.TAG_TOOL_BLOCK, "false");
118
		arguments.put(ExternalToolMigration.TAG_TOOL_BUILD_TYPES, "build kinds");
119
		arguments.put(ExternalToolMigration.TAG_TOOL_DIRECTORY, "working dir");
120
		return arguments;
121
	}
122
	
123
	/**
124
	 * Tests migration of arguments from an Eclipse 2.1 Ant buildfile
86
	 * Tests migration of arguments from an Eclipse 2.1 Ant buildfile
125
	 * configuration to a current launch configuration.
87
	 * configuration to a current launch configuration.
126
	 * 
88
	 * 
Lines 150-181 Link Here
150
	}
112
	}
151
	
113
	
152
	/**
114
	/**
153
	 * Returns a map of arguments for executing an Ant
154
	 * buildfile using Eclipse 2.1 arguments.
155
	 * 
156
	 * @return a map of 2.1 arguments for an Ant buildfile
157
	 */
158
	private Map get21AntArgumentMap() {
159
		HashMap arguments= new HashMap();
160
		arguments.put(ExternalToolMigration.TAG_VERSION, "2.1");
161
		arguments.put(ExternalToolMigration.TAG_NAME, "ant config");
162
		arguments.put(ExternalToolMigration.TAG_TYPE, ExternalToolMigration.TOOL_TYPE_ANT_BUILD);
163
		arguments.put(ExternalToolMigration.TAG_LOCATION, "location");
164
		arguments.put(ExternalToolMigration.TAG_WORK_DIR, "working directory");
165
		arguments.put(ExternalToolMigration.TAG_CAPTURE_OUTPUT, "true");
166
		arguments.put(ExternalToolMigration.TAG_SHOW_CONSOLE, "true");
167
		arguments.put(ExternalToolMigration.TAG_SHOW_CONSOLE, "true");
168
		arguments.put(ExternalToolMigration.TAG_RUN_BKGRND, "true");
169
		arguments.put(ExternalToolMigration.TAG_PROMPT_ARGS, "true");
170
		arguments.put(ExternalToolMigration.TAG_REFRESH_SCOPE, "refresh scope");
171
		arguments.put(ExternalToolMigration.TAG_REFRESH_RECURSIVE, "true");
172
		arguments.put(ExternalToolMigration.TAG_RUN_BUILD_KINDS, "build kinds");
173
		arguments.put(ExternalToolMigration.TAG_ARGS, "arg1 arg2");
174
		arguments.put(ExternalToolMigration.TAG_EXTRA_ATTR, ExternalToolMigration.RUN_TARGETS_ATTRIBUTE + "=target1,target2");
175
		return arguments;
176
	}
177
	
178
	/**
179
	 * Tests migration of arguments from an Eclipse 2.1 program
115
	 * Tests migration of arguments from an Eclipse 2.1 program
180
	 * configuration to a current launch configuration.
116
	 * configuration to a current launch configuration.
181
	 * 
117
	 * 
Lines 199-228 Link Here
199
		assertEquals("build kinds", config.getAttribute(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, ""));
135
		assertEquals("build kinds", config.getAttribute(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, ""));
200
		assertEquals("arg1 arg2", config.getAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, ""));
136
		assertEquals("arg1 arg2", config.getAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, ""));
201
	}
137
	}
202
	
203
	/**
204
	 * Returns a map of arguments for executing a program
205
	 * buildfile using Eclipse 2.1 arguments.
206
	 * 
207
	 * @return a map of 2.1 arguments for a program
208
	 */
209
	private Map get21ProgramArgumentMap() {
210
		HashMap arguments= new HashMap();
211
		arguments.put(ExternalToolMigration.TAG_VERSION, "2.1");
212
		arguments.put(ExternalToolMigration.TAG_NAME, "program config");
213
		arguments.put(ExternalToolMigration.TAG_TYPE, IExternalToolConstants.TOOL_TYPE_PROGRAM);
214
		arguments.put(ExternalToolMigration.TAG_LOCATION, "location");
215
		arguments.put(ExternalToolMigration.TAG_WORK_DIR, "working directory");
216
		arguments.put(ExternalToolMigration.TAG_CAPTURE_OUTPUT, "true");
217
		arguments.put(ExternalToolMigration.TAG_SHOW_CONSOLE, "true");
218
		arguments.put(ExternalToolMigration.TAG_SHOW_CONSOLE, "true");
219
		arguments.put(ExternalToolMigration.TAG_RUN_BKGRND, "true");
220
		arguments.put(ExternalToolMigration.TAG_PROMPT_ARGS, "true");
221
		arguments.put(ExternalToolMigration.TAG_REFRESH_SCOPE, "refresh scope");
222
		arguments.put(ExternalToolMigration.TAG_REFRESH_RECURSIVE, "true");
223
		arguments.put(ExternalToolMigration.TAG_RUN_BUILD_KINDS, "build kinds");
224
		arguments.put(ExternalToolMigration.TAG_ARGS, "arg1 arg2");
225
		return arguments;
226
	}
227
	
228
}
138
}
(-)test plugin/org/eclipse/ant/tests/ui/testplugin/AntUITests.java (-1 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2002, 2008 GEBIT Gesellschaft fuer EDV-Beratung
2
 * Copyright (c) 2002, 2011 GEBIT Gesellschaft fuer EDV-Beratung
3
 * und Informatik-Technologien mbH, 
3
 * und Informatik-Technologien mbH, 
4
 * Berlin, Duesseldorf, Frankfurt (Germany) and others.
4
 * Berlin, Duesseldorf, Frankfurt (Germany) and others.
5
 * All rights reserved. This program and the accompanying materials 
5
 * All rights reserved. This program and the accompanying materials 
Lines 33-38 Link Here
33
import org.eclipse.ant.tests.ui.editor.formatter.XmlDocumentFormatterTest;
33
import org.eclipse.ant.tests.ui.editor.formatter.XmlDocumentFormatterTest;
34
import org.eclipse.ant.tests.ui.editor.formatter.XmlFormatterTest;
34
import org.eclipse.ant.tests.ui.editor.formatter.XmlFormatterTest;
35
import org.eclipse.ant.tests.ui.editor.formatter.XmlTagFormatterTest;
35
import org.eclipse.ant.tests.ui.editor.formatter.XmlTagFormatterTest;
36
import org.eclipse.ant.tests.ui.externaltools.BuilderCoreUtilsTests;
36
import org.eclipse.ant.tests.ui.externaltools.MigrationTests;
37
import org.eclipse.ant.tests.ui.externaltools.MigrationTests;
37
import org.eclipse.ant.tests.ui.separateVM.SeparateVMTests;
38
import org.eclipse.ant.tests.ui.separateVM.SeparateVMTests;
38
39
Lines 52-57 Link Here
52
        suite.addTest(new TestSuite(TaskDescriptionProviderTest.class));
53
        suite.addTest(new TestSuite(TaskDescriptionProviderTest.class));
53
        suite.addTest(new TestSuite(AntEditorContentOutlineTests.class));
54
        suite.addTest(new TestSuite(AntEditorContentOutlineTests.class));
54
        suite.addTest(new TestSuite(MigrationTests.class));
55
        suite.addTest(new TestSuite(MigrationTests.class));
56
        suite.addTest(new TestSuite(BuilderCoreUtilsTests.class));
55
        suite.addTest(new TestSuite(FormattingPreferencesTest.class));
57
        suite.addTest(new TestSuite(FormattingPreferencesTest.class));
56
        suite.addTest(new TestSuite(XmlDocumentFormatterTest.class));
58
        suite.addTest(new TestSuite(XmlDocumentFormatterTest.class));
57
        suite.addTest(new TestSuite(XmlTagFormatterTest.class));
59
        suite.addTest(new TestSuite(XmlTagFormatterTest.class));
(-)testbuildfiles/ext-builders.xml (+27 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project name="project-builder" default="def">
3
    <description>
4
            Builder
5
    </description>
6
7
    <target name="def" description="description">
8
        <echo>DEFAULT</echo>
9
    </target>
10
11
    <target name="full">
12
        <echo>FULL</echo>
13
    </target>
14
15
    <target name="inc">
16
        <echo>INCREMENTAL</echo>
17
    </target>
18
19
    <target name="auto">
20
        <echo>AUTO</echo>
21
    </target>
22
23
    <target name="clean">
24
        <echo>CLEAN</echo>
25
    </target>
26
27
</project>
(-)src/org/eclipse/core/externaltools/internal/model/BuilderCoreUtils.java (-28 / +34 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 39-44 Link Here
39
public class BuilderCoreUtils {
39
public class BuilderCoreUtils {
40
40
41
	public static final String LAUNCH_CONFIG_HANDLE = "LaunchConfigHandle"; //$NON-NLS-1$
41
	public static final String LAUNCH_CONFIG_HANDLE = "LaunchConfigHandle"; //$NON-NLS-1$
42
	/**
43
	 * Constant added to the build command to determine if we are doing an incremental build after a clean
44
	 * 
45
	 * @since 3.7
46
	 */
47
	public static final String INC_CLEAN = "incclean"; //$NON-NLS-1$
42
48
43
	/**
49
	/**
44
	 * Constant used to find a builder using the 3.0-interim format
50
	 * Constant used to find a builder using the 3.0-interim format
Lines 113-153 Link Here
113
		return configuration;
119
		return configuration;
114
	}
120
	}
115
121
116
	public static void configureTriggers(ILaunchConfiguration config,
122
	public static void configureTriggers(ILaunchConfiguration config, ICommand newCommand) throws CoreException {
117
			ICommand newCommand) throws CoreException {
118
		newCommand.setBuilding(IncrementalProjectBuilder.FULL_BUILD, false);
123
		newCommand.setBuilding(IncrementalProjectBuilder.FULL_BUILD, false);
119
		newCommand.setBuilding(IncrementalProjectBuilder.INCREMENTAL_BUILD,
124
		newCommand.setBuilding(IncrementalProjectBuilder.INCREMENTAL_BUILD, false);
120
				false);
121
		newCommand.setBuilding(IncrementalProjectBuilder.AUTO_BUILD, false);
125
		newCommand.setBuilding(IncrementalProjectBuilder.AUTO_BUILD, false);
122
		newCommand.setBuilding(IncrementalProjectBuilder.CLEAN_BUILD, false);
126
		newCommand.setBuilding(IncrementalProjectBuilder.CLEAN_BUILD, false);
123
		String buildKinds = config.getAttribute(
127
		Map args = newCommand.getArguments();
124
				IExternalToolConstants.ATTR_RUN_BUILD_KINDS, (String) null);
128
		String buildKinds = config.getAttribute(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, (String) null);
125
		int[] triggers = BuilderCoreUtils.buildTypesToArray(buildKinds);
129
		int[] triggers = buildTypesToArray(buildKinds);
130
		boolean isfull = false, isinc = false;
126
		for (int i = 0; i < triggers.length; i++) {
131
		for (int i = 0; i < triggers.length; i++) {
127
			switch (triggers[i]) {
132
			switch (triggers[i]) {
128
			case IncrementalProjectBuilder.FULL_BUILD:
133
				case IncrementalProjectBuilder.FULL_BUILD:
129
				newCommand.setBuilding(IncrementalProjectBuilder.FULL_BUILD,
134
					newCommand.setBuilding(IncrementalProjectBuilder.FULL_BUILD, true);
130
						true);
135
					isfull = true;
131
				break;
136
					break;
132
			case IncrementalProjectBuilder.INCREMENTAL_BUILD:
137
				case IncrementalProjectBuilder.INCREMENTAL_BUILD:
133
				newCommand.setBuilding(
138
					newCommand.setBuilding(IncrementalProjectBuilder.INCREMENTAL_BUILD, true);
134
						IncrementalProjectBuilder.INCREMENTAL_BUILD, true);
139
					isinc = true;
135
				break;
140
					break;
136
			case IncrementalProjectBuilder.AUTO_BUILD:
141
				case IncrementalProjectBuilder.AUTO_BUILD:
137
				newCommand.setBuilding(IncrementalProjectBuilder.AUTO_BUILD,
142
					newCommand.setBuilding(IncrementalProjectBuilder.AUTO_BUILD, true);
138
						true);
143
					break;
139
				break;
144
				case IncrementalProjectBuilder.CLEAN_BUILD:
140
			case IncrementalProjectBuilder.CLEAN_BUILD:
145
					newCommand.setBuilding(IncrementalProjectBuilder.CLEAN_BUILD, true);
141
				newCommand.setBuilding(IncrementalProjectBuilder.CLEAN_BUILD,
146
					break;
142
						true);
143
				break;
144
			}
147
			}
145
		}
148
		}
146
		if (!config.getAttribute(
149
		if(!isfull && isinc) {
147
				IExternalToolConstants.ATTR_TRIGGERS_CONFIGURED, false)) {
150
			newCommand.setBuilding(IncrementalProjectBuilder.FULL_BUILD, true);
151
			args.put(INC_CLEAN, Boolean.TRUE.toString());
152
			newCommand.setArguments(args);
153
		}
154
		if (!config.getAttribute(IExternalToolConstants.ATTR_TRIGGERS_CONFIGURED, false)) {
148
			ILaunchConfigurationWorkingCopy copy = config.getWorkingCopy();
155
			ILaunchConfigurationWorkingCopy copy = config.getWorkingCopy();
149
			copy.setAttribute(IExternalToolConstants.ATTR_TRIGGERS_CONFIGURED,
156
			copy.setAttribute(IExternalToolConstants.ATTR_TRIGGERS_CONFIGURED, true);
150
					true);
151
			copy.doSave();
157
			copy.doSave();
152
		}
158
		}
153
	}
159
	}
(-)src/org/eclipse/core/externaltools/internal/model/ExternalToolBuilder.java (-11 / +18 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 85-91 Link Here
85
		}
85
		}
86
        boolean kindCompatible= commandConfiguredForKind(config, kind);
86
        boolean kindCompatible= commandConfiguredForKind(config, kind);
87
        if (kindCompatible && configEnabled(config)) {
87
        if (kindCompatible && configEnabled(config)) {
88
            doBuildBasedOnScope(resources, kind, config, monitor);
88
            doBuildBasedOnScope(resources, kind, config, args, monitor);
89
        }
89
        }
90
        
90
        
91
		return projectsWithinScope;
91
		return projectsWithinScope;
Lines 157-163 Link Here
157
		return true;
157
		return true;
158
	}
158
	}
159
159
160
	private void doBuildBasedOnScope(IResource[] resources, int kind, ILaunchConfiguration config, IProgressMonitor monitor) throws CoreException {
160
	private void doBuildBasedOnScope(IResource[] resources, int kind, ILaunchConfiguration config, Map args, IProgressMonitor monitor) throws CoreException {
161
		boolean buildForChange = true;
161
		boolean buildForChange = true;
162
		if (kind != FULL_BUILD) { //scope not applied for full builds
162
		if (kind != FULL_BUILD) { //scope not applied for full builds
163
			if (resources != null && resources.length > 0) {
163
			if (resources != null && resources.length > 0) {
Lines 166-184 Link Here
166
		}
166
		}
167
167
168
		if (buildForChange) {
168
		if (buildForChange) {
169
			launchBuild(kind, config, monitor);
169
			launchBuild(kind, config, args, monitor);
170
		}
170
		}
171
	}
171
	}
172
	
172
	
173
	private void launchBuild(int kind, ILaunchConfiguration config, IProgressMonitor monitor) throws CoreException {
173
	private void launchBuild(int kind, ILaunchConfiguration config, Map args, IProgressMonitor monitor) throws CoreException {
174
		monitor.subTask(NLS.bind(ExternalToolsModelMessages.ExternalToolBuilder_Running__0_____1, new String[] { config.getName()}));
174
		monitor.subTask(NLS.bind(ExternalToolsModelMessages.ExternalToolBuilder_Running__0_____1, new String[] { config.getName()}));
175
		buildStarted(kind);
175
		buildStarted(kind, args);
176
		// The default value for "launch in background" is true in debug core. If
176
		// The default value for "launch in background" is true in debug core. If
177
		// the user doesn't go through the UI, the new attribute won't be set. This means
177
		// the user doesn't go through the UI, the new attribute won't be set. This means
178
		// that existing Ant builders will try to run in the background (and likely conflict with
178
		// that existing Ant builders will try to run in the background (and likely conflict with
179
		// each other) without migration.
179
		// each other) without migration.
180
		config= ExternalToolMigration.migrateRunInBackground(config);
180
		ILaunchConfiguration newconfig= ExternalToolMigration.migrateRunInBackground(config);
181
		config.launch(ILaunchManager.RUN_MODE, monitor);
181
		newconfig.launch(ILaunchManager.RUN_MODE, monitor);
182
		buildEnded();
182
		buildEnded();
183
	}
183
	}
184
184
Lines 215-229 Link Here
215
	/**
215
	/**
216
	 * Stores the currently active build kind and build project when a build begins
216
	 * Stores the currently active build kind and build project when a build begins
217
	 * @param buildKind
217
	 * @param buildKind
218
	 * @param args the arguments passed into the builder
218
	 */
219
	 */
219
	private void buildStarted(int buildKind) {
220
	private void buildStarted(int buildKind, Map args) {
220
		switch (buildKind) {
221
		switch (buildKind) {
221
			case IncrementalProjectBuilder.INCREMENTAL_BUILD :
222
			case IncrementalProjectBuilder.INCREMENTAL_BUILD :
222
				buildType = IExternalToolConstants.BUILD_TYPE_INCREMENTAL;
223
				buildType = IExternalToolConstants.BUILD_TYPE_INCREMENTAL;
223
				buildDelta = getDelta(getProject());
224
				buildDelta = getDelta(getProject());
224
				break;
225
				break;
225
			case IncrementalProjectBuilder.FULL_BUILD :
226
			case IncrementalProjectBuilder.FULL_BUILD :
226
				buildType = IExternalToolConstants.BUILD_TYPE_FULL;
227
				if(args != null && args.containsKey(BuilderCoreUtils.INC_CLEAN)) {
228
					buildType = IExternalToolConstants.BUILD_TYPE_INCREMENTAL;
229
					buildDelta = getDelta(getProject());
230
				}
231
				else {
232
					buildType = IExternalToolConstants.BUILD_TYPE_FULL;
233
				}
227
				break;
234
				break;
228
			case IncrementalProjectBuilder.AUTO_BUILD :
235
			case IncrementalProjectBuilder.AUTO_BUILD :
229
				buildType = IExternalToolConstants.BUILD_TYPE_AUTO;
236
				buildType = IExternalToolConstants.BUILD_TYPE_AUTO;
Lines 285-290 Link Here
285
            return;
292
            return;
286
        }
293
        }
287
	
294
	
288
		launchBuild(IncrementalProjectBuilder.CLEAN_BUILD, config, monitor);
295
		launchBuild(IncrementalProjectBuilder.CLEAN_BUILD, config, null, monitor);
289
    }
296
    }
290
}
297
}
(-)External Tools Base/org/eclipse/ui/externaltools/internal/launchConfigurations/ExternalToolsBuilderTab.java (-19 / +8 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 12-20 Link Here
12
package org.eclipse.ui.externaltools.internal.launchConfigurations;
12
package org.eclipse.ui.externaltools.internal.launchConfigurations;
13
13
14
14
15
import java.util.HashSet;
16
import java.util.Iterator;
17
18
import org.eclipse.core.externaltools.internal.IExternalToolConstants;
15
import org.eclipse.core.externaltools.internal.IExternalToolConstants;
19
import org.eclipse.core.externaltools.internal.launchConfigurations.ExternalToolsCoreUtil;
16
import org.eclipse.core.externaltools.internal.launchConfigurations.ExternalToolsCoreUtil;
20
import org.eclipse.core.resources.IResource;
17
import org.eclipse.core.resources.IResource;
Lines 390-422 Link Here
390
        fVariables.setEnabled(haveOutputFile);
387
        fVariables.setEnabled(haveOutputFile);
391
        fAppend.setEnabled(haveOutputFile);
388
        fAppend.setEnabled(haveOutputFile);
392
    }
389
    }
393
    
390
394
	/* (non-Javadoc)
391
	/* (non-Javadoc)
395
	 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
392
	 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
396
	 */
393
	 */
397
	public void performApply(ILaunchConfigurationWorkingCopy configuration) {
394
	public void performApply(ILaunchConfigurationWorkingCopy configuration) {
398
        if (fCreateBuildScheduleComponent) {
395
        if (fCreateBuildScheduleComponent) {
399
        	HashSet kinds = new HashSet(4);
396
        	StringBuffer buffer= new StringBuffer();
400
    		if (afterClean.getSelection()) {
397
    		if (afterClean.getSelection()) {
401
    			kinds.add(IExternalToolConstants.BUILD_TYPE_FULL);
398
    			buffer.append(IExternalToolConstants.BUILD_TYPE_FULL).append(',');
402
    		} 
399
    		} 
403
    		if(manualBuild.getSelection()){
400
    		if (manualBuild.getSelection()){
404
    			kinds.add(IExternalToolConstants.BUILD_TYPE_FULL);
401
    			buffer.append(IExternalToolConstants.BUILD_TYPE_INCREMENTAL).append(','); 
405
    			kinds.add(IExternalToolConstants.BUILD_TYPE_INCREMENTAL); 
406
    		} 
402
    		} 
407
    		if (autoBuildButton.getSelection()) {
403
    		if (autoBuildButton.getSelection()) {
408
    			kinds.add(IExternalToolConstants.BUILD_TYPE_AUTO);
404
    			buffer.append(IExternalToolConstants.BUILD_TYPE_AUTO).append(',');
409
    		}
405
    		}
410
    		
406
    		
411
    		if (fDuringClean.getSelection()) {
407
    		if (fDuringClean.getSelection()) {
412
    			kinds.add(IExternalToolConstants.BUILD_TYPE_CLEAN);
408
    			buffer.append(IExternalToolConstants.BUILD_TYPE_CLEAN);
413
    		}
414
    		StringBuffer buffer= new StringBuffer();
415
    		for(Iterator i = kinds.iterator(); i.hasNext();) {
416
    			buffer.append(i.next());
417
    			if(i.hasNext()) {
418
    				buffer.append(',');
419
    			}
420
    		}
409
    		}
421
    		configuration.setAttribute(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, buffer.toString());
410
    		configuration.setAttribute(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, buffer.toString());
422
        }
411
        }

Return to bug 114563