37
|
1 |
/*******************************************************************************
|
|
2 |
* Copyright (c) 2005, 2008 QNX Software Systems 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 |
* QNX Software Systems - initial API and implementation
|
|
10 |
* Andrew Ferguson (andrew.ferguson@arm.com) - bug 123997
|
|
11 |
* Ken Ryall (Nokia) - bug 178731
|
|
12 |
* Anton Leherbauer (Wind River Systems) - bug 224187
|
|
13 |
*******************************************************************************/
|
|
14 |
package org.eclipse.cdt.launch;
|
|
15 |
|
|
16 |
import java.io.File;
|
|
17 |
import java.io.FileNotFoundException;
|
|
18 |
import java.util.ArrayList;
|
|
19 |
import java.util.Arrays;
|
|
20 |
import java.util.Date;
|
|
21 |
import java.util.HashMap;
|
|
22 |
import java.util.HashSet;
|
|
23 |
import java.util.Iterator;
|
|
24 |
import java.util.List;
|
|
25 |
import java.util.Map;
|
|
26 |
import java.util.Properties;
|
|
27 |
import java.util.Map.Entry;
|
|
28 |
import java.util.concurrent.atomic.AtomicBoolean;
|
|
29 |
|
|
30 |
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
|
|
31 |
import org.eclipse.cdt.core.model.ICModelMarker;
|
|
32 |
import org.eclipse.cdt.core.model.ICProject;
|
|
33 |
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
|
34 |
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
|
35 |
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
|
|
36 |
import org.eclipse.cdt.debug.core.CDebugUtils;
|
|
37 |
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
|
|
38 |
import org.eclipse.cdt.debug.core.ICDebugConfiguration;
|
|
39 |
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
|
|
40 |
import org.eclipse.cdt.launch.internal.ui.LaunchMessages;
|
|
41 |
import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
|
|
42 |
import org.eclipse.cdt.ui.newui.CDTPropertyManager;
|
|
43 |
import org.eclipse.core.resources.IContainer;
|
|
44 |
import org.eclipse.core.resources.IFile;
|
|
45 |
import org.eclipse.core.resources.IMarker;
|
|
46 |
import org.eclipse.core.resources.IProject;
|
|
47 |
import org.eclipse.core.resources.IResource;
|
|
48 |
import org.eclipse.core.resources.IWorkspace;
|
|
49 |
import org.eclipse.core.resources.IncrementalProjectBuilder;
|
|
50 |
import org.eclipse.core.resources.ResourcesPlugin;
|
|
51 |
import org.eclipse.core.runtime.CoreException;
|
|
52 |
import org.eclipse.core.runtime.IPath;
|
|
53 |
import org.eclipse.core.runtime.IProgressMonitor;
|
|
54 |
import org.eclipse.core.runtime.IStatus;
|
|
55 |
import org.eclipse.core.runtime.MultiStatus;
|
|
56 |
import org.eclipse.core.runtime.NullProgressMonitor;
|
|
57 |
import org.eclipse.core.runtime.Path;
|
|
58 |
import org.eclipse.core.runtime.Status;
|
|
59 |
import org.eclipse.core.runtime.SubProgressMonitor;
|
|
60 |
import org.eclipse.core.runtime.jobs.Job;
|
|
61 |
import org.eclipse.debug.core.DebugPlugin;
|
|
62 |
import org.eclipse.debug.core.ILaunch;
|
|
63 |
import org.eclipse.debug.core.ILaunchConfiguration;
|
|
64 |
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
|
65 |
import org.eclipse.debug.core.ILaunchManager;
|
|
66 |
import org.eclipse.debug.core.IStatusHandler;
|
|
67 |
import org.eclipse.debug.core.Launch;
|
|
68 |
import org.eclipse.debug.core.model.IPersistableSourceLocator;
|
|
69 |
import org.eclipse.debug.core.model.IProcess;
|
|
70 |
import org.eclipse.debug.core.model.ISourceLocator;
|
|
71 |
import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
|
|
72 |
import org.eclipse.debug.ui.RefreshTab;
|
|
73 |
|
|
74 |
import com.ibm.icu.text.DateFormat;
|
|
75 |
import com.ibm.icu.text.MessageFormat;
|
|
76 |
|
|
77 |
abstract public class AbstractCLaunchDelegate extends LaunchConfigurationDelegate {
|
|
78 |
|
|
79 |
/**
|
|
80 |
* @since 6.0
|
|
81 |
*/
|
|
82 |
public class CLaunch extends Launch {
|
|
83 |
|
|
84 |
private final AtomicBoolean fRefreshDone;
|
|
85 |
|
|
86 |
public CLaunch(ILaunchConfiguration launchConfiguration, String mode, ISourceLocator locator) {
|
|
87 |
super(launchConfiguration, mode, locator);
|
|
88 |
fRefreshDone = new AtomicBoolean(false);
|
|
89 |
}
|
|
90 |
|
|
91 |
public void refresh() {
|
|
92 |
if (fRefreshDone.compareAndSet(false, true)) {
|
|
93 |
final ILaunchConfiguration config = getLaunchConfiguration();
|
|
94 |
try {
|
|
95 |
if (RefreshTab.getRefreshScope(config) != null) {
|
|
96 |
Job refreshJob = new Job("Refresh"){
|
|
97 |
|
|
98 |
/* (non-Javadoc)
|
|
99 |
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
|
|
100 |
*/
|
|
101 |
@Override
|
|
102 |
protected IStatus run(IProgressMonitor monitor) {
|
|
103 |
try {
|
|
104 |
RefreshTab.refreshResources(config, monitor);
|
|
105 |
} catch (CoreException e) {
|
|
106 |
return new Status(IStatus.ERROR, LaunchUIPlugin.PLUGIN_ID, 1, e.getLocalizedMessage(), e);
|
|
107 |
}
|
|
108 |
return Status.OK_STATUS;
|
|
109 |
}};
|
|
110 |
refreshJob.setSystem(true);
|
|
111 |
refreshJob.schedule();
|
|
112 |
}
|
|
113 |
}
|
|
114 |
catch(CoreException e) {
|
|
115 |
LaunchUIPlugin.log( e.getStatus() );
|
|
116 |
}
|
|
117 |
}
|
|
118 |
}
|
|
119 |
}
|
|
120 |
|
|
121 |
/* (non-Javadoc)
|
|
122 |
* @see org.eclipse.debug.core.model.LaunchConfigurationDelegate#getLaunch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String)
|
|
123 |
*/
|
|
124 |
@Override
|
|
125 |
public ILaunch getLaunch(ILaunchConfiguration configuration, String mode) throws CoreException {
|
|
126 |
return new CLaunch(configuration, mode, null);
|
|
127 |
}
|
|
128 |
|
|
129 |
/**
|
|
130 |
* The project containing the programs file being launched
|
|
131 |
*/
|
|
132 |
private IProject project;
|
|
133 |
/**
|
|
134 |
* A list of prequisite projects ordered by their build order.
|
|
135 |
*/
|
|
136 |
private List orderedProjects;
|
|
137 |
private String preLaunchBuildConfiguration;
|
|
138 |
|
54
|
139 |
/**
|
|
140 |
* Used in conjunction with build before launch settings in the main tab.
|
|
141 |
*/
|
62
|
142 |
private boolean workspaceBuildBeforeLaunch;
|
|
143 |
|
37
|
144 |
abstract public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
|
|
145 |
throws CoreException;
|
|
146 |
|
|
147 |
/**
|
|
148 |
* Returns the working directory specified by the given launch
|
|
149 |
* configuration, or <code>null</code> if none.
|
|
150 |
*
|
|
151 |
* @deprecated Should use getWorkingDirectory()
|
|
152 |
* @param configuration
|
|
153 |
* launch configuration
|
|
154 |
* @return the working directory specified by the given launch
|
|
155 |
* configuration, or <code>null</code> if none
|
|
156 |
* @exception CoreException
|
|
157 |
* if unable to retrieve the attribute
|
|
158 |
*/
|
|
159 |
@Deprecated
|
|
160 |
public File getWorkingDir(ILaunchConfiguration configuration) throws CoreException {
|
|
161 |
return getWorkingDirectory(configuration);
|
|
162 |
}
|
|
163 |
|
|
164 |
/**
|
|
165 |
* Returns the working directory specified by the given launch
|
|
166 |
* configuration, or <code>null</code> if none.
|
|
167 |
*
|
|
168 |
* @param configuration
|
|
169 |
* launch configuration
|
|
170 |
* @return the working directory specified by the given launch
|
|
171 |
* configuration, or <code>null</code> if none
|
|
172 |
* @exception CoreException
|
|
173 |
* if unable to retrieve the attribute
|
|
174 |
*/
|
|
175 |
public File getWorkingDirectory(ILaunchConfiguration configuration) throws CoreException {
|
|
176 |
return verifyWorkingDirectory(configuration);
|
|
177 |
}
|
|
178 |
|
|
179 |
/**
|
|
180 |
* Expands and returns the working directory attribute of the given launch
|
|
181 |
* configuration. Returns <code>null</code> if a working directory is not
|
|
182 |
* specified. If specified, the working is verified to point to an existing
|
|
183 |
* directory in the local file system.
|
|
184 |
*
|
|
185 |
* @param configuration launch configuration
|
|
186 |
* @return an absolute path to a directory in the local file system, or
|
|
187 |
* <code>null</code> if unspecified
|
|
188 |
* @throws CoreException if unable to retrieve the associated launch
|
|
189 |
* configuration attribute, if unable to resolve any variables, or if the
|
|
190 |
* resolved location does not point to an existing directory in the local
|
|
191 |
* file system
|
|
192 |
*/
|
|
193 |
protected IPath getWorkingDirectoryPath(ILaunchConfiguration config) throws CoreException {
|
|
194 |
String location = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String)null);
|
|
195 |
if (location != null) {
|
|
196 |
String expandedLocation = LaunchUtils.getStringVariableManager().performStringSubstitution(location);
|
|
197 |
if (expandedLocation.length() > 0) {
|
|
198 |
return new Path(expandedLocation);
|
|
199 |
}
|
|
200 |
}
|
|
201 |
return null;
|
|
202 |
}
|
|
203 |
|
|
204 |
/**
|
|
205 |
* Throws a core exception with an error status object built from the given
|
|
206 |
* message, lower level exception, and error code.
|
|
207 |
*
|
|
208 |
* @param message
|
|
209 |
* the status message
|
|
210 |
* @param exception
|
|
211 |
* lower level exception associated with the error, or
|
|
212 |
* <code>null</code> if none
|
|
213 |
* @param code
|
|
214 |
* error code
|
|
215 |
*/
|
|
216 |
protected void abort(String message, Throwable exception, int code) throws CoreException {
|
|
217 |
IStatus status;
|
|
218 |
if (exception != null) {
|
|
219 |
MultiStatus multiStatus = new MultiStatus(getPluginID(), code, message, exception);
|
|
220 |
multiStatus.add(new Status(IStatus.ERROR, getPluginID(), code, exception.getLocalizedMessage(), exception));
|
|
221 |
status= multiStatus;
|
|
222 |
} else {
|
|
223 |
status= new Status(IStatus.ERROR, getPluginID(), code, message, null);
|
|
224 |
}
|
|
225 |
throw new CoreException(status);
|
|
226 |
}
|
|
227 |
|
|
228 |
protected void cancel(String message, int code) throws CoreException {
|
|
229 |
throw new CoreException(new Status(IStatus.OK, getPluginID(), code, message, null));
|
|
230 |
}
|
|
231 |
|
|
232 |
abstract protected String getPluginID();
|
|
233 |
|
|
234 |
/**
|
|
235 |
* @deprecated Use {@link org.eclipse.cdt.debug.core.CDebugUtils} instead.
|
|
236 |
*/
|
|
237 |
@Deprecated
|
|
238 |
public static ICProject getCProject(ILaunchConfiguration configuration) throws CoreException {
|
|
239 |
return CDebugUtils.getCProject(configuration);
|
|
240 |
}
|
|
241 |
|
|
242 |
/**
|
|
243 |
* @deprecated Use {@link org.eclipse.cdt.debug.core.CDebugUtils} instead.
|
|
244 |
*/
|
|
245 |
@Deprecated
|
|
246 |
public static String getProjectName(ILaunchConfiguration configuration) throws CoreException {
|
|
247 |
return CDebugUtils.getProjectName(configuration);
|
|
248 |
}
|
|
249 |
|
|
250 |
/**
|
|
251 |
* @deprecated Use {@link org.eclipse.cdt.debug.core.CDebugUtils} instead.
|
|
252 |
*/
|
|
253 |
@Deprecated
|
|
254 |
public static String getProgramName(ILaunchConfiguration configuration) throws CoreException {
|
|
255 |
return CDebugUtils.getProgramName(configuration);
|
|
256 |
}
|
|
257 |
|
|
258 |
/**
|
|
259 |
* @deprecated Use {@link org.eclipse.cdt.debug.core.CDebugUtils} instead.
|
|
260 |
*/
|
|
261 |
@Deprecated
|
|
262 |
public static IPath getProgramPath(ILaunchConfiguration configuration) throws CoreException {
|
|
263 |
return CDebugUtils.getProgramPath(configuration);
|
|
264 |
}
|
|
265 |
|
|
266 |
/**
|
|
267 |
* @param launch
|
|
268 |
* @param config
|
|
269 |
* @throws CoreException
|
|
270 |
* @deprecated
|
|
271 |
*/
|
|
272 |
@Deprecated
|
|
273 |
protected void setSourceLocator(ILaunch launch, ILaunchConfiguration config) throws CoreException {
|
|
274 |
setDefaultSourceLocator(launch, config);
|
|
275 |
}
|
|
276 |
|
|
277 |
/**
|
|
278 |
* Assigns a default source locator to the given launch if a source locator
|
|
279 |
* has not yet been assigned to it, and the associated launch configuration
|
|
280 |
* does not specify a source locator.
|
|
281 |
*
|
|
282 |
* @param launch
|
|
283 |
* launch object
|
|
284 |
* @param configuration
|
|
285 |
* configuration being launched
|
|
286 |
* @exception CoreException
|
|
287 |
* if unable to set the source locator
|
|
288 |
*/
|
|
289 |
protected void setDefaultSourceLocator(ILaunch launch, ILaunchConfiguration configuration) throws CoreException {
|
|
290 |
// set default source locator if none specified
|
|
291 |
if (launch.getSourceLocator() == null) {
|
|
292 |
IPersistableSourceLocator sourceLocator;
|
|
293 |
String id = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, (String)null);
|
|
294 |
if (id == null) {
|
|
295 |
ICProject cProject = CDebugUtils.getCProject(configuration);
|
|
296 |
if (cProject == null) {
|
|
297 |
abort(LaunchMessages.getString("Launch.common.Project_does_not_exist"), null, //$NON-NLS-1$
|
|
298 |
ICDTLaunchConfigurationConstants.ERR_NOT_A_C_PROJECT);
|
|
299 |
}
|
|
300 |
sourceLocator = CDebugUIPlugin.createDefaultSourceLocator();
|
|
301 |
sourceLocator.initializeDefaults(configuration);
|
|
302 |
} else {
|
|
303 |
sourceLocator = DebugPlugin.getDefault().getLaunchManager().newSourceLocator(id);
|
|
304 |
String memento = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, (String)null);
|
|
305 |
if (memento == null) {
|
|
306 |
sourceLocator.initializeDefaults(configuration);
|
|
307 |
} else {
|
|
308 |
sourceLocator.initializeFromMemento(memento);
|
|
309 |
}
|
|
310 |
}
|
|
311 |
launch.setSourceLocator(sourceLocator);
|
|
312 |
}
|
|
313 |
}
|
|
314 |
|
|
315 |
/**
|
|
316 |
* Returns the program arguments as a String.
|
|
317 |
*
|
|
318 |
* @return the program arguments as a String
|
|
319 |
*/
|
|
320 |
public String getProgramArguments(ILaunchConfiguration config) throws CoreException {
|
|
321 |
return LaunchUtils.getProgramArguments(config);
|
|
322 |
}
|
|
323 |
|
|
324 |
/**
|
|
325 |
* Returns the program arguments as an array of individual arguments.
|
|
326 |
*
|
|
327 |
* @return the program arguments as an array of individual arguments
|
|
328 |
*/
|
|
329 |
public String[] getProgramArgumentsArray(ILaunchConfiguration config) throws CoreException {
|
|
330 |
return LaunchUtils.getProgramArgumentsArray(config);
|
|
331 |
}
|
|
332 |
|
|
333 |
protected ICDebugConfiguration getDebugConfig(ILaunchConfiguration config) throws CoreException {
|
|
334 |
ICDebugConfiguration dbgCfg = null;
|
|
335 |
try {
|
|
336 |
dbgCfg = CDebugCorePlugin.getDefault().getDebugConfiguration(
|
|
337 |
config.getAttribute(
|
|
338 |
ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID,
|
|
339 |
"")); //$NON-NLS-1$
|
|
340 |
} catch (CoreException e) {
|
|
341 |
IStatus status = new Status(IStatus.ERROR, LaunchUIPlugin.getUniqueIdentifier(),
|
|
342 |
ICDTLaunchConfigurationConstants.ERR_DEBUGGER_NOT_INSTALLED,
|
|
343 |
LaunchMessages.getString("AbstractCLaunchDelegate.Debugger_not_installed"), //$NON-NLS-1$
|
|
344 |
e);
|
|
345 |
IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(status);
|
|
346 |
|
|
347 |
if (handler != null) {
|
|
348 |
Object result = handler.handleStatus(status, this);
|
|
349 |
if (result instanceof String) {
|
|
350 |
// this could return the new debugger id to use?
|
|
351 |
}
|
|
352 |
}
|
|
353 |
throw e;
|
|
354 |
}
|
|
355 |
return dbgCfg;
|
|
356 |
}
|
|
357 |
|
|
358 |
protected String renderTargetLabel(ICDebugConfiguration debugConfig) {
|
|
359 |
String format = "{0} ({1})"; //$NON-NLS-1$
|
|
360 |
String timestamp = DateFormat.getInstance().format(new Date(System.currentTimeMillis()));
|
|
361 |
return MessageFormat.format(format, new String[]{debugConfig.getName(), timestamp});
|
|
362 |
}
|
|
363 |
|
|
364 |
protected String renderProcessLabel(String commandLine) {
|
|
365 |
String format = "{0} ({1})"; //$NON-NLS-1$
|
|
366 |
String timestamp = DateFormat.getInstance().format(new Date(System.currentTimeMillis()));
|
|
367 |
return MessageFormat.format(format, new String[]{commandLine, timestamp});
|
|
368 |
}
|
|
369 |
|
|
370 |
// temporary fix for #66015
|
|
371 |
/**
|
|
372 |
* @deprecated
|
|
373 |
*/
|
|
374 |
@Deprecated
|
|
375 |
protected String renderDebuggerProcessLabel() {
|
|
376 |
String format = "{0} ({1})"; //$NON-NLS-1$
|
|
377 |
String timestamp = DateFormat.getInstance().format(new Date(System.currentTimeMillis()));
|
|
378 |
return MessageFormat.format(format, new String[]{
|
|
379 |
LaunchMessages.getString("AbstractCLaunchDelegate.Debugger_Process"), timestamp}); //$NON-NLS-1$
|
|
380 |
}
|
|
381 |
|
|
382 |
|
|
383 |
/**
|
|
384 |
* @param config
|
|
385 |
* @return
|
|
386 |
* @throws CoreException
|
|
387 |
* @deprecated Use <code>verifyProgramFile</code> instead.
|
|
388 |
*/
|
|
389 |
@Deprecated
|
|
390 |
protected IFile getProgramFile(ILaunchConfiguration config) throws CoreException {
|
|
391 |
ICProject cproject = verifyCProject(config);
|
|
392 |
String fileName = CDebugUtils.getProgramName(config);
|
|
393 |
if (fileName == null) {
|
|
394 |
abort(LaunchMessages.getString("AbstractCLaunchDelegate.Program_file_not_specified"), null, //$NON-NLS-1$
|
|
395 |
ICDTLaunchConfigurationConstants.ERR_UNSPECIFIED_PROGRAM);
|
|
396 |
}
|
|
397 |
|
|
398 |
IFile programPath = ((IProject)cproject.getResource()).getFile(fileName);
|
|
399 |
if (programPath == null || !programPath.exists() || !programPath.getLocation().toFile().exists()) {
|
|
400 |
abort(
|
|
401 |
LaunchMessages.getString("AbstractCLaunchDelegate.Program_file_does_not_exist"), //$NON-NLS-1$
|
|
402 |
new FileNotFoundException(
|
|
403 |
LaunchMessages.getFormattedString(
|
|
404 |
"AbstractCLaunchDelegate.PROGRAM_PATH_not_found", programPath.getLocation().toOSString())), //$NON-NLS-1$
|
|
405 |
ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_EXIST);
|
|
406 |
}
|
|
407 |
return programPath;
|
|
408 |
}
|
|
409 |
|
|
410 |
protected ICProject verifyCProject(ILaunchConfiguration config) throws CoreException {
|
|
411 |
String name = CDebugUtils.getProjectName(config);
|
|
412 |
if (name == null) {
|
|
413 |
abort(LaunchMessages.getString("AbstractCLaunchDelegate.C_Project_not_specified"), null, //$NON-NLS-1$
|
|
414 |
ICDTLaunchConfigurationConstants.ERR_UNSPECIFIED_PROJECT);
|
|
415 |
}
|
|
416 |
ICProject cproject = CDebugUtils.getCProject(config);
|
|
417 |
if (cproject == null) {
|
|
418 |
IProject proj = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
|
|
419 |
if (!proj.exists()) {
|
|
420 |
abort(
|
|
421 |
LaunchMessages.getFormattedString("AbstractCLaunchDelegate.Project_NAME_does_not_exist", name), null, //$NON-NLS-1$
|
|
422 |
ICDTLaunchConfigurationConstants.ERR_NOT_A_C_PROJECT);
|
|
423 |
} else if (!proj.isOpen()) {
|
|
424 |
abort(LaunchMessages.getFormattedString("AbstractCLaunchDelegate.Project_NAME_is_closed", name), null, //$NON-NLS-1$
|
|
425 |
ICDTLaunchConfigurationConstants.ERR_NOT_A_C_PROJECT);
|
|
426 |
}
|
|
427 |
abort(LaunchMessages.getString("AbstractCLaunchDelegate.Not_a_C_CPP_project"), null, //$NON-NLS-1$
|
|
428 |
ICDTLaunchConfigurationConstants.ERR_NOT_A_C_PROJECT);
|
|
429 |
}
|
|
430 |
return cproject;
|
|
431 |
}
|
|
432 |
|
|
433 |
protected IPath verifyProgramPath(ILaunchConfiguration config) throws CoreException {
|
|
434 |
ICProject cproject = verifyCProject(config);
|
|
435 |
IPath programPath = CDebugUtils.getProgramPath(config);
|
|
436 |
if (programPath == null || programPath.isEmpty()) {
|
|
437 |
abort(LaunchMessages.getString("AbstractCLaunchDelegate.Program_file_not_specified"), null, //$NON-NLS-1$
|
|
438 |
ICDTLaunchConfigurationConstants.ERR_UNSPECIFIED_PROGRAM);
|
|
439 |
}
|
|
440 |
if (!programPath.isAbsolute()) {
|
|
441 |
IPath location = cproject.getProject().getLocation();
|
|
442 |
if (location != null) {
|
|
443 |
programPath = location.append(programPath);
|
|
444 |
if (!programPath.toFile().exists()) {
|
|
445 |
// Try the old way, which is required to support linked resources.
|
|
446 |
IFile projFile = null;
|
|
447 |
try {
|
|
448 |
projFile = project.getFile(CDebugUtils.getProgramPath(config));
|
|
449 |
}
|
|
450 |
catch (IllegalArgumentException exc) {} // thrown if relative path that resolves to a root file (e.g., "..\somefile")
|
|
451 |
if (projFile != null && projFile.exists()) {
|
|
452 |
programPath = projFile.getLocation();
|
|
453 |
}
|
|
454 |
}
|
|
455 |
}
|
|
456 |
}
|
|
457 |
if (!programPath.toFile().exists()) {
|
|
458 |
abort(
|
|
459 |
LaunchMessages.getString("AbstractCLaunchDelegate.Program_file_does_not_exist"), //$NON-NLS-1$
|
|
460 |
new FileNotFoundException(
|
|
461 |
LaunchMessages.getFormattedString(
|
|
462 |
"AbstractCLaunchDelegate.PROGRAM_PATH_not_found", programPath.toOSString())), //$NON-NLS-1$
|
|
463 |
ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_EXIST);
|
|
464 |
}
|
|
465 |
return programPath;
|
|
466 |
}
|
|
467 |
|
|
468 |
protected IPath verifyProgramFile(ILaunchConfiguration config) throws CoreException {
|
|
469 |
return getProgramFile(config).getLocation();
|
|
470 |
}
|
|
471 |
|
|
472 |
/**
|
|
473 |
* Verifies the working directory specified by the given launch
|
|
474 |
* configuration exists, and returns the working directory, or
|
|
475 |
* <code>null</code> if none is specified.
|
|
476 |
*
|
|
477 |
* @param configuration
|
|
478 |
* launch configuration
|
|
479 |
* @return the working directory specified by the given launch
|
|
480 |
* configuration, or <code>null</code> if none
|
|
481 |
* @exception CoreException
|
|
482 |
* if unable to retrieve the attribute
|
|
483 |
*/
|
|
484 |
public File verifyWorkingDirectory(ILaunchConfiguration configuration) throws CoreException {
|
|
485 |
IPath path = getWorkingDirectoryPath(configuration);
|
|
486 |
if (path == null) {
|
|
487 |
// default working dir is the project if this config has a project
|
|
488 |
ICProject cp = CDebugUtils.getCProject(configuration);
|
|
489 |
if (cp != null) {
|
|
490 |
IProject p = cp.getProject();
|
|
491 |
return p.getLocation().toFile();
|
|
492 |
}
|
|
493 |
} else {
|
|
494 |
if (path.isAbsolute()) {
|
|
495 |
File dir = new File(path.toOSString());
|
|
496 |
if (dir.isDirectory()) {
|
|
497 |
return dir;
|
|
498 |
}
|
|
499 |
abort(
|
|
500 |
LaunchMessages.getString("AbstractCLaunchDelegate.Working_directory_does_not_exist"), //$NON-NLS-1$
|
|
501 |
new FileNotFoundException(
|
|
502 |
LaunchMessages.getFormattedString(
|
|
503 |
"AbstractCLaunchDelegate.WORKINGDIRECTORY_PATH_not_found", path.toOSString())), //$NON-NLS-1$
|
|
504 |
ICDTLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_DOES_NOT_EXIST);
|
|
505 |
} else {
|
|
506 |
IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
|
|
507 |
if (res instanceof IContainer && res.exists()) {
|
|
508 |
return res.getLocation().toFile();
|
|
509 |
}
|
|
510 |
abort(
|
|
511 |
LaunchMessages.getString("AbstractCLaunchDelegate.Working_directory_does_not_exist"), //$NON-NLS-1$
|
|
512 |
new FileNotFoundException(
|
|
513 |
LaunchMessages.getFormattedString(
|
|
514 |
"AbstractCLaunchDelegate.WORKINGDIRECTORY_PATH_not_found", path.toOSString())), //$NON-NLS-1$
|
|
515 |
ICDTLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_DOES_NOT_EXIST);
|
|
516 |
}
|
|
517 |
}
|
|
518 |
return null;
|
|
519 |
}
|
|
520 |
|
|
521 |
/**
|
|
522 |
* Recursively creates a set of projects referenced by the current project
|
|
523 |
*
|
|
524 |
* @param proj
|
|
525 |
* The current project
|
|
526 |
* @param referencedProjSet
|
|
527 |
* A set of referenced projects
|
|
528 |
* @throws CoreException
|
|
529 |
* if an error occurs while getting referenced projects from the
|
|
530 |
* current project
|
|
531 |
*/
|
|
532 |
private void getReferencedProjectSet(IProject proj, HashSet referencedProjSet) throws CoreException {
|
|
533 |
IProject[] projects = proj.getReferencedProjects();
|
|
534 |
for (int i = 0; i < projects.length; i++) {
|
|
535 |
IProject refProject = projects[i];
|
|
536 |
if (refProject.exists() && !referencedProjSet.contains(refProject)) {
|
|
537 |
referencedProjSet.add(refProject);
|
|
538 |
getReferencedProjectSet(refProject, referencedProjSet);
|
|
539 |
}
|
|
540 |
}
|
|
541 |
|
|
542 |
}
|
|
543 |
|
|
544 |
/**
|
|
545 |
* creates a list of project ordered by their build order from an unordered
|
|
546 |
* list of projects.
|
|
547 |
*
|
|
548 |
* @param resourceCollection
|
|
549 |
* The list of projects to sort.
|
|
550 |
* @return A new list of projects, ordered by build order.
|
|
551 |
*/
|
|
552 |
private List getBuildOrder(List resourceCollection) {
|
|
553 |
String[] orderedNames = ResourcesPlugin.getWorkspace().getDescription().getBuildOrder();
|
|
554 |
if (orderedNames != null) {
|
|
555 |
List orderedProjs = new ArrayList(resourceCollection.size());
|
|
556 |
//Projects may not be in the build order but should be built if
|
|
557 |
// selected
|
|
558 |
List unorderedProjects = new ArrayList(resourceCollection.size());
|
|
559 |
unorderedProjects.addAll(resourceCollection);
|
|
560 |
|
|
561 |
for (int i = 0; i < orderedNames.length; i++) {
|
|
562 |
String projectName = orderedNames[i];
|
|
563 |
for (int j = 0; j < resourceCollection.size(); j++) {
|
|
564 |
IProject proj = (IProject)resourceCollection.get(j);
|
|
565 |
if (proj.getName().equals(projectName)) {
|
|
566 |
orderedProjs.add(proj);
|
|
567 |
unorderedProjects.remove(proj);
|
|
568 |
break;
|
|
569 |
}
|
|
570 |
}
|
|
571 |
}
|
|
572 |
//Add anything not specified before we return
|
|
573 |
orderedProjs.addAll(unorderedProjects);
|
|
574 |
return orderedProjs;
|
|
575 |
}
|
|
576 |
|
|
577 |
// Try the project prerequisite order then
|
|
578 |
IProject[] projects = new IProject[resourceCollection.size()];
|
|
579 |
projects = (IProject[])resourceCollection.toArray(projects);
|
|
580 |
IWorkspace.ProjectOrder po = ResourcesPlugin.getWorkspace().computeProjectOrder(projects);
|
|
581 |
ArrayList orderedProjs = new ArrayList();
|
|
582 |
orderedProjs.addAll(Arrays.asList(po.projects));
|
|
583 |
return orderedProjs;
|
|
584 |
}
|
|
585 |
|
|
586 |
/**
|
|
587 |
* Builds the current project and all of it's prerequisite projects if
|
|
588 |
* necessary. Respects specified build order if any exists.
|
|
589 |
*
|
|
590 |
* @param configuration
|
|
591 |
* the configuration being launched
|
|
592 |
* @param mode
|
|
593 |
* the mode the configuration is being launched in
|
|
594 |
* @param monitor
|
|
595 |
* progress monitor
|
|
596 |
* @return whether the debug platform should perform an incremental
|
|
597 |
* workspace build before the launch
|
|
598 |
* @throws CoreException
|
54
|
599 |
* if an exception occurs while building
|
37
|
600 |
*/
|
|
601 |
@Override
|
|
602 |
public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
|
54
|
603 |
|
62
|
604 |
workspaceBuildBeforeLaunch = true;
|
54
|
605 |
|
|
606 |
// check the build before launch setting and honor it
|
|
607 |
int buildBeforeLaunchValue = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_BUILD_BEFORE_LAUNCH,
|
|
608 |
ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_USE_WORKSPACE_SETTING);
|
|
609 |
|
|
610 |
// we shouldn't be getting called if the workspace setting is disabled, so assume we need to
|
|
611 |
// build unless the user explicitly disabled it in the main tab of the launch.
|
|
612 |
if (buildBeforeLaunchValue == ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_DISABLED) {
|
|
613 |
return false;
|
|
614 |
}
|
|
615 |
|
|
616 |
//This matches the old code, but I don't know that it is the right behavior.
|
37
|
617 |
//We should be building the local project as well, not just the ordered projects
|
|
618 |
if(orderedProjects == null) {
|
|
619 |
return false;
|
|
620 |
}
|
|
621 |
|
|
622 |
if(monitor == null) {
|
|
623 |
monitor = new NullProgressMonitor();
|
|
624 |
}
|
|
625 |
|
|
626 |
int scale = 1000;
|
|
627 |
int totalWork = (orderedProjects.size() + 1) * scale;
|
|
628 |
|
|
629 |
try {
|
|
630 |
monitor.beginTask(LaunchMessages.getString("AbstractCLaunchDelegate.building_projects"), totalWork); //$NON-NLS-1$
|
|
631 |
|
|
632 |
for (Iterator i = orderedProjects.iterator(); i.hasNext();) {
|
|
633 |
IProject proj = (IProject)i.next();
|
|
634 |
monitor.subTask(LaunchMessages.getString("AbstractCLaunchDelegate.building") + proj.getName()); //$NON-NLS-1$
|
|
635 |
proj.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new SubProgressMonitor(monitor, scale));
|
|
636 |
}
|
|
637 |
|
|
638 |
monitor.subTask(LaunchMessages.getString("AbstractCLaunchDelegate.building") + project.getName()); //$NON-NLS-1$
|
|
639 |
setBuildConfiguration(configuration, project);
|
|
640 |
project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new SubProgressMonitor(monitor, scale));
|
|
641 |
} finally {
|
|
642 |
monitor.done();
|
|
643 |
}
|
|
644 |
|
|
645 |
return false;
|
|
646 |
}
|
|
647 |
|
|
648 |
/**
|
|
649 |
* Sets up a project for building by making sure the active configuration is the one used
|
|
650 |
* when the launch was created.
|
|
651 |
* @param configuration
|
|
652 |
* @param buildProject
|
|
653 |
*/
|
|
654 |
private void setBuildConfiguration(ILaunchConfiguration configuration, IProject buildProject) {
|
|
655 |
|
|
656 |
try {
|
|
657 |
String buildConfigID = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_ID, ""); //$NON-NLS-1$
|
|
658 |
ICProjectDescription projDes = CDTPropertyManager.getProjectDescription(buildProject);
|
|
659 |
|
|
660 |
if (buildConfigID.length() > 0 && projDes != null)
|
|
661 |
{
|
|
662 |
ICConfigurationDescription buildConfiguration = projDes.getConfigurationById(buildConfigID);
|
|
663 |
if (buildConfiguration != null) {
|
|
664 |
preLaunchBuildConfiguration = projDes.getActiveConfiguration().getId();
|
|
665 |
buildConfiguration.setActive();
|
|
666 |
CDTPropertyManager.performOk(null);
|
|
667 |
}
|
|
668 |
}
|
|
669 |
|
|
670 |
} catch (CoreException e) {}
|
|
671 |
}
|
|
672 |
|
|
673 |
/**
|
|
674 |
* Searches for compile errors in the current project and any of its
|
|
675 |
* prerequisite projects. If any compile errors, give the user a chance to
|
|
676 |
* abort the launch and correct the errors.
|
|
677 |
*
|
|
678 |
* @param configuration
|
|
679 |
* @param mode
|
|
680 |
* @param monitor
|
|
681 |
* @return whether the launch should proceed
|
|
682 |
* @throws CoreException
|
|
683 |
* if an exception occurs while checking for compile errors.
|
|
684 |
*/
|
|
685 |
@Override
|
|
686 |
public boolean finalLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
|
54
|
687 |
|
62
|
688 |
if (!workspaceBuildBeforeLaunch) {
|
54
|
689 |
// buildForLaunch was not called which means that the workspace pref is disabled. see if the user enabled the
|
|
690 |
// launch specific setting in the main tab. if so, we do call buildBeforeLaunch here.
|
|
691 |
if (ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_ENABLED == configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_BUILD_BEFORE_LAUNCH,
|
|
692 |
ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_USE_WORKSPACE_SETTING)) {
|
|
693 |
|
|
694 |
IProgressMonitor buildMonitor = new SubProgressMonitor(monitor, 10, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
|
|
695 |
buildMonitor.beginTask(LaunchMessages.getString("AbstractCLaunchDelegate.BuildBeforeLaunch"), 10); //$NON-NLS-1$
|
|
696 |
buildMonitor.subTask(LaunchMessages.getString("AbstractCLaunchDelegate.PerformingBuild")); //$NON-NLS-1$
|
|
697 |
if (buildForLaunch(configuration, mode, new SubProgressMonitor(buildMonitor, 7))) {
|
|
698 |
buildMonitor.subTask(LaunchMessages.getString("AbstractCLaunchDelegate.PerformingIncrementalBuild")); //$NON-NLS-1$
|
|
699 |
ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new SubProgressMonitor(buildMonitor, 3));
|
|
700 |
}
|
|
701 |
else {
|
|
702 |
buildMonitor.worked(3); /* No incremental build required */
|
|
703 |
}
|
|
704 |
}
|
|
705 |
}
|
|
706 |
|
37
|
707 |
boolean continueLaunch = true;
|
|
708 |
if(orderedProjects == null) {
|
|
709 |
return continueLaunch;
|
|
710 |
}
|
|
711 |
|
|
712 |
if(monitor == null) {
|
|
713 |
monitor = new NullProgressMonitor();
|
|
714 |
}
|
|
715 |
|
|
716 |
int scale = 1000;
|
|
717 |
int totalWork = (orderedProjects.size() + 1) * scale;
|
|
718 |
try {
|
|
719 |
monitor.beginTask(LaunchMessages.getString("AbstractCLaunchDelegate.searching_for_errors"), totalWork); //$NON-NLS-1$
|
|
720 |
|
|
721 |
boolean compileErrorsInProjs = false;
|
|
722 |
|
|
723 |
//check prerequisite projects for compile errors.
|
|
724 |
for (Iterator i = orderedProjects.iterator(); i.hasNext();) {
|
|
725 |
IProject proj = (IProject)i.next();
|
|
726 |
monitor.subTask(LaunchMessages.getString("AbstractCLaunchDelegate.searching_for_errors_in" + proj.getName())); //$NON-NLS-1$
|
|
727 |
monitor.worked(scale);
|
|
728 |
compileErrorsInProjs = existsErrors(proj);
|
|
729 |
if (compileErrorsInProjs) {
|
|
730 |
break;
|
|
731 |
}
|
|
732 |
}
|
|
733 |
|
|
734 |
//check current project, if prerequite projects were ok
|
|
735 |
if (!compileErrorsInProjs) {
|
|
736 |
monitor.subTask(LaunchMessages.getString("AbstractCLaunchDelegate.searching_for_errors_in" + project.getName())); //$NON-NLS-1$
|
|
737 |
monitor.worked(scale);
|
|
738 |
compileErrorsInProjs = existsErrors(project);
|
|
739 |
}
|
|
740 |
|
|
741 |
//if compile errors exist, ask the user before continuing.
|
|
742 |
if (compileErrorsInProjs) {
|
|
743 |
IStatusHandler prompter = DebugPlugin.getDefault().getStatusHandler(promptStatus);
|
|
744 |
if (prompter != null) {
|
|
745 |
continueLaunch = ((Boolean)prompter.handleStatus(complileErrorPromptStatus, null)).booleanValue();
|
|
746 |
}
|
|
747 |
}
|
|
748 |
} finally {
|
|
749 |
monitor.done();
|
|
750 |
}
|
|
751 |
|
|
752 |
if (continueLaunch) // If no problems then restore the previous build configuration. Otherwise leave it so the user can fix the build issues.
|
|
753 |
resetBuildConfiguration(project);
|
|
754 |
|
|
755 |
return continueLaunch;
|
|
756 |
}
|
|
757 |
|
|
758 |
private void resetBuildConfiguration(IProject buildProject) {
|
|
759 |
// Restore the active configuration if it was changed for the launch
|
|
760 |
if (preLaunchBuildConfiguration != null) {
|
|
761 |
ICProjectDescription projDes = CDTPropertyManager.getProjectDescription(buildProject);
|
|
762 |
|
|
763 |
if (preLaunchBuildConfiguration.length() > 0 && projDes != null)
|
|
764 |
{
|
|
765 |
ICConfigurationDescription buildConfiguration = projDes.getConfigurationById(preLaunchBuildConfiguration);
|
|
766 |
if (buildConfiguration != null) {
|
|
767 |
buildConfiguration.setActive();
|
|
768 |
CDTPropertyManager.performOk(null);
|
|
769 |
}
|
|
770 |
}
|
|
771 |
|
|
772 |
}
|
|
773 |
preLaunchBuildConfiguration = null;
|
|
774 |
}
|
|
775 |
|
|
776 |
/**
|
|
777 |
* Searches for compile errors in the specified project
|
|
778 |
*
|
|
779 |
* @param proj
|
|
780 |
* The project to search
|
|
781 |
* @return true if compile errors exist, otherwise false
|
|
782 |
* @since 6.0
|
|
783 |
*/
|
|
784 |
protected boolean existsErrors(IProject proj) throws CoreException {
|
|
785 |
IMarker[] markers = proj.findMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
|
|
786 |
|
|
787 |
if (markers.length > 0) {
|
|
788 |
for (int j = 0; j < markers.length; j++) {
|
|
789 |
Object severityAttribute = markers[j].getAttribute(IMarker.SEVERITY);
|
|
790 |
if (severityAttribute != null && ((Integer) severityAttribute).intValue() == IMarker.SEVERITY_ERROR) {
|
|
791 |
return true;
|
|
792 |
}
|
|
793 |
}
|
|
794 |
}
|
|
795 |
|
|
796 |
return false;
|
|
797 |
}
|
|
798 |
|
|
799 |
/*
|
|
800 |
* (non-Javadoc)
|
|
801 |
*
|
|
802 |
* @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate2#preLaunchCheck(org.eclipse.debug.core.ILaunchConfiguration,
|
|
803 |
* java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
|
|
804 |
*/
|
|
805 |
@Override
|
|
806 |
public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
|
|
807 |
if(monitor == null) {
|
|
808 |
monitor = new NullProgressMonitor();
|
|
809 |
}
|
|
810 |
|
62
|
811 |
workspaceBuildBeforeLaunch = false;
|
54
|
812 |
|
37
|
813 |
int scale = 1000;
|
|
814 |
int totalWork = 2 * scale;
|
|
815 |
|
|
816 |
try {
|
|
817 |
monitor.beginTask(LaunchMessages.getString("AbstractCLaunchDelegate.20"), totalWork); //$NON-NLS-1$
|
|
818 |
|
|
819 |
// build project list
|
|
820 |
orderedProjects = null;
|
|
821 |
ICProject cProject = CDebugUtils.getCProject(configuration);
|
|
822 |
if (cProject != null) {
|
|
823 |
project = cProject.getProject();
|
|
824 |
HashSet projectSet = new HashSet();
|
|
825 |
getReferencedProjectSet(project, projectSet);
|
|
826 |
orderedProjects = getBuildOrder(new ArrayList(projectSet));
|
|
827 |
}
|
|
828 |
monitor.worked(scale);
|
|
829 |
|
|
830 |
// do generic launch checks
|
|
831 |
return super.preLaunchCheck(configuration, mode, new SubProgressMonitor(monitor, scale));
|
|
832 |
} finally {
|
|
833 |
monitor.done();
|
|
834 |
}
|
|
835 |
}
|
|
836 |
|
|
837 |
/**
|
|
838 |
* @param project
|
|
839 |
* @param exePath
|
|
840 |
* @return
|
|
841 |
* @throws CoreException
|
|
842 |
*/
|
|
843 |
protected IBinaryObject verifyBinary(ICProject proj, IPath exePath) throws CoreException {
|
|
844 |
Exception exception;
|
|
845 |
try {
|
|
846 |
return LaunchUtils.getBinary(proj.getProject(), exePath);
|
|
847 |
} catch (ClassCastException e) {
|
|
848 |
exception = e;
|
|
849 |
}
|
|
850 |
Status status = new Status(IStatus.ERROR,getPluginID(),
|
|
851 |
ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_BINARY,
|
|
852 |
LaunchMessages.getString("AbstractCLaunchDelegate.Program_is_not_a_recongnized_executable") + " " + exePath.toOSString(), //$NON-NLS-1$
|
|
853 |
exception);
|
|
854 |
throw new CoreException(status);
|
|
855 |
}
|
|
856 |
|
|
857 |
/**
|
|
858 |
* @param config
|
|
859 |
* @return
|
|
860 |
* @throws CoreException
|
|
861 |
*/
|
|
862 |
protected Properties getEnvironmentAsProperty(ILaunchConfiguration config) throws CoreException {
|
|
863 |
String[] envp = getEnvironment(config);
|
|
864 |
Properties p = new Properties( );
|
|
865 |
for( int i = 0; i < envp.length; i++ ) {
|
|
866 |
int idx = envp[i].indexOf('=');
|
|
867 |
if (idx != -1) {
|
|
868 |
String key = envp[i].substring(0, idx);
|
|
869 |
String value = envp[i].substring(idx + 1);
|
|
870 |
p.setProperty(key, value);
|
|
871 |
} else {
|
|
872 |
p.setProperty(envp[i], ""); //$NON-NLS-1$
|
|
873 |
}
|
|
874 |
}
|
|
875 |
return p;
|
|
876 |
}
|
|
877 |
|
|
878 |
/**
|
|
879 |
* Return the save environment variables in the configuration. The array
|
|
880 |
* does not include the default environment of the target. array[n] :
|
|
881 |
* name=value
|
|
882 |
* @throws CoreException
|
|
883 |
*/
|
|
884 |
protected String[] getEnvironment(ILaunchConfiguration config) throws CoreException {
|
|
885 |
try {
|
|
886 |
// Migrate old env settings to new.
|
|
887 |
Map map = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map)null);
|
|
888 |
ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
|
|
889 |
if (map != null) {
|
|
890 |
wc.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map);
|
|
891 |
wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map)null);
|
|
892 |
config = wc.doSave();
|
|
893 |
}
|
|
894 |
boolean append = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_INHERIT, true);
|
|
895 |
wc.setAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, append);
|
|
896 |
} catch (CoreException e) {
|
|
897 |
}
|
|
898 |
String[] array = DebugPlugin.getDefault().getLaunchManager().getEnvironment(config);
|
|
899 |
if (array == null) {
|
|
900 |
return new String[0];
|
|
901 |
}
|
|
902 |
return array;
|
|
903 |
}
|
|
904 |
|
|
905 |
/**
|
|
906 |
* Return the save environment variables in the configuration. The array
|
|
907 |
* does not include the default environment of the target. array[n] :
|
|
908 |
* name=value
|
|
909 |
* @deprecated
|
|
910 |
*/
|
|
911 |
@Deprecated
|
|
912 |
protected String[] getEnvironmentArray(ILaunchConfiguration config) {
|
|
913 |
Map env = null;
|
|
914 |
try {
|
|
915 |
env = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map)null);
|
|
916 |
} catch (CoreException e) {
|
|
917 |
}
|
|
918 |
if (env == null) {
|
|
919 |
return new String[0];
|
|
920 |
}
|
|
921 |
String[] array = new String[env.size()];
|
|
922 |
Iterator entries = env.entrySet().iterator();
|
|
923 |
Entry entry;
|
|
924 |
for (int i = 0; entries.hasNext() && i < array.length; i++) {
|
|
925 |
entry = (Entry)entries.next();
|
|
926 |
array[i] = ((String)entry.getKey()) + "=" + ((String)entry.getValue()); //$NON-NLS-1$
|
|
927 |
}
|
|
928 |
return array;
|
|
929 |
}
|
|
930 |
|
|
931 |
/**
|
|
932 |
* Return the save environment variables of this configuration. The array
|
|
933 |
* does not include the default environment of the target.
|
|
934 |
* @deprecated
|
|
935 |
*/
|
|
936 |
@Deprecated
|
|
937 |
protected Properties getEnvironmentProperty(ILaunchConfiguration config) {
|
|
938 |
Properties prop = new Properties();
|
|
939 |
Map env = null;
|
|
940 |
try {
|
|
941 |
env = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map)null);
|
|
942 |
} catch (CoreException e) {
|
|
943 |
}
|
|
944 |
if (env == null)
|
|
945 |
return prop;
|
|
946 |
Iterator entries = env.entrySet().iterator();
|
|
947 |
Entry entry;
|
|
948 |
while (entries.hasNext()) {
|
|
949 |
entry = (Entry)entries.next();
|
|
950 |
prop.setProperty((String)entry.getKey(), (String)entry.getValue());
|
|
951 |
}
|
|
952 |
return prop;
|
|
953 |
}
|
|
954 |
|
|
955 |
/**
|
|
956 |
* Returns the default process attribute map for C/C++ processes.
|
|
957 |
*
|
|
958 |
* @return default process attribute map for C/C++ processes
|
|
959 |
*/
|
|
960 |
protected Map getDefaultProcessMap() {
|
|
961 |
Map map = new HashMap();
|
|
962 |
map.put( IProcess.ATTR_PROCESS_TYPE, ICDTLaunchConfigurationConstants.ID_PROGRAM_PROCESS_TYPE );
|
|
963 |
return map;
|
|
964 |
}
|
|
965 |
}
|