|
1 package com.nokia.cdt.debug.common.internal.source.lookup; |
|
2 |
|
3 import java.util.ArrayList; |
|
4 import java.util.Arrays; |
|
5 import java.util.Iterator; |
|
6 |
|
7 import org.eclipse.core.runtime.CoreException; |
|
8 import org.eclipse.core.runtime.Path; |
|
9 import org.eclipse.debug.core.DebugPlugin; |
|
10 import org.eclipse.debug.core.ILaunchConfiguration; |
|
11 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; |
|
12 import org.eclipse.debug.core.ILaunchManager; |
|
13 import org.eclipse.debug.core.model.ISourceLocator; |
|
14 import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector; |
|
15 import org.eclipse.debug.core.sourcelookup.ISourceContainer; |
|
16 |
|
17 |
|
18 public class SourceMappingUtils { |
|
19 |
|
20 /** Name kept for legacy launch config settings purposes */ |
|
21 private static final String EPOCROOT_SETTING = "com.nokia.cdt.debug.cw.symbian.Epoc_Root" ; //$NON-NLS-1$ |
|
22 |
|
23 /** |
|
24 * Add the source mapping for the workign copy of the launch config. Clients should ensure to call doSave() after this call. |
|
25 * @param configuration |
|
26 * @throws CoreException |
|
27 */ |
|
28 public static void addSourceMappingToLaunch(ILaunchConfigurationWorkingCopy configuration) throws CoreException { |
|
29 String memento = null; |
|
30 String type = null; |
|
31 |
|
32 memento = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, (String) null); |
|
33 type = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, (String) null); |
|
34 if (type == null) { |
|
35 type = configuration.getType().getSourceLocatorId(); |
|
36 } |
|
37 ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); |
|
38 ISourceLocator locator = launchManager.newSourceLocator(type); |
|
39 if (locator instanceof AbstractSourceLookupDirector) { |
|
40 AbstractSourceLookupDirector director = (AbstractSourceLookupDirector) locator; |
|
41 if (memento == null) { |
|
42 director.initializeDefaults(configuration); |
|
43 } else { |
|
44 director.initializeFromMemento(memento, configuration); |
|
45 } |
|
46 |
|
47 addSourceMappingToDirector(director, configuration); |
|
48 |
|
49 configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, director.getMemento()); |
|
50 configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, director.getId()); |
|
51 } |
|
52 } |
|
53 |
|
54 private static void addSourceMappingToDirector(AbstractSourceLookupDirector director, ILaunchConfiguration configuration) throws CoreException { |
|
55 |
|
56 ArrayList containerList = new ArrayList(Arrays.asList(director.getSourceContainers())); |
|
57 |
|
58 boolean hasSymbianContainer = false; |
|
59 |
|
60 SymbianSourceContainer symbianContainer = null; |
|
61 |
|
62 for (Iterator iter = containerList.iterator(); iter.hasNext() && !hasSymbianContainer;) { |
|
63 ISourceContainer container = (ISourceContainer) iter.next(); |
|
64 if (container instanceof SymbianSourceContainer) |
|
65 { |
|
66 hasSymbianContainer = true; |
|
67 } |
|
68 } |
|
69 |
|
70 if (!hasSymbianContainer) { |
|
71 |
|
72 String epocRootPath = configuration.getAttribute( EPOCROOT_SETTING, (String)null ); |
|
73 if (epocRootPath != null) |
|
74 { |
|
75 symbianContainer = new SymbianSourceContainer(new Path(epocRootPath)); |
|
76 symbianContainer.init(director); |
|
77 containerList.add(symbianContainer); |
|
78 } |
|
79 } |
|
80 |
|
81 director.setSourceContainers((ISourceContainer[]) containerList.toArray(new ISourceContainer[containerList.size()])); |
|
82 } |
|
83 |
|
84 |
|
85 } |