author | dadubrow |
Wed, 03 Mar 2010 08:25:45 -0600 | |
branch | RCL_2_4 |
changeset 1066 | 4791b1e2e6ef |
parent 1041 | 7c4362faca1e |
child 1068 | 21b582a02214 |
permissions | -rw-r--r-- |
911 | 1 |
/* |
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 |
* All rights reserved. |
|
4 |
* This component and the accompanying materials are made available |
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
|
6 |
* which accompanies this distribution, and is available |
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
* |
|
9 |
* Initial Contributors: |
|
10 |
* Nokia Corporation - initial contribution. |
|
11 |
* |
|
12 |
* Contributors: |
|
13 |
* |
|
14 |
* Description: |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
package com.nokia.cdt.internal.debug.launch.newwizard; |
|
19 |
||
953 | 20 |
import java.util.Collection; |
911 | 21 |
import java.util.List; |
22 |
||
953 | 23 |
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; |
911 | 24 |
import org.eclipse.core.resources.IProject; |
953 | 25 |
import org.eclipse.core.runtime.CoreException; |
911 | 26 |
import org.eclipse.core.runtime.IPath; |
27 |
import org.eclipse.core.runtime.IStatus; |
|
28 |
import org.eclipse.core.runtime.Path; |
|
29 |
import org.eclipse.core.runtime.Platform; |
|
30 |
import org.eclipse.core.runtime.Status; |
|
31 |
import org.eclipse.core.runtime.preferences.InstanceScope; |
|
953 | 32 |
import org.eclipse.debug.core.DebugPlugin; |
33 |
import org.eclipse.debug.core.ILaunchConfigurationType; |
|
34 |
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; |
|
911 | 35 |
import org.eclipse.debug.core.ILaunchManager; |
36 |
import org.eclipse.debug.ui.IDebugUIConstants; |
|
37 |
import org.osgi.service.prefs.Preferences; |
|
38 |
||
953 | 39 |
import com.freescale.cdt.debug.cw.core.RemoteConnectionsTRKHelper; |
40 |
import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; |
|
41 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService; |
|
911 | 42 |
import com.nokia.carbide.remoteconnections.interfaces.IConnection; |
43 |
import com.nokia.carbide.remoteconnections.interfaces.IService; |
|
953 | 44 |
import com.nokia.carbide.remoteconnections.internal.api.IConnectedService2; |
45 |
import com.nokia.carbide.remoteconnections.internal.registry.Registry; |
|
46 |
import com.nokia.cdt.debug.cw.symbian.SettingsData; |
|
47 |
import com.nokia.cdt.internal.debug.launch.wizard.LaunchOptions; |
|
911 | 48 |
import com.nokia.cpp.internal.api.utils.core.TextUtils; |
49 |
||
953 | 50 |
import cwdbg.PreferenceConstants; |
51 |
||
911 | 52 |
/** |
53 |
* Data manipulated by the launch wizard and its dialogs. |
|
54 |
*/ |
|
953 | 55 |
@SuppressWarnings("restriction") |
56 |
public class LaunchWizardData extends LaunchOptions { |
|
911 | 57 |
public interface IPathValidator { |
58 |
/** |
|
59 |
* @param path IPath |
|
60 |
* @return Error string or <code>null</code> if is valid |
|
61 |
*/ |
|
62 |
String isValidPath(IPath path); |
|
63 |
} |
|
64 |
||
65 |
private final IService service; |
|
66 |
||
67 |
// overall target |
|
68 |
public static class LaunchType { |
|
69 |
private final String launchId; |
|
70 |
||
71 |
public LaunchType(String launchId) { |
|
72 |
this.launchId = launchId; |
|
73 |
} |
|
74 |
||
953 | 75 |
public boolean isApplicable(LaunchWizardData data) { |
911 | 76 |
return true; |
77 |
} |
|
78 |
||
79 |
public String getLaunchId() { |
|
80 |
return launchId; |
|
81 |
} |
|
82 |
}; |
|
83 |
||
84 |
public final static LaunchType APP_TRK = new LaunchType(null); |
|
85 |
public final static LaunchType SYS_TRK = new LaunchType(null); |
|
86 |
public final static LaunchType ATTACH_TO_PROCESS_LAUNCH = new LaunchType(null); |
|
87 |
public final static LaunchType PLATSIM_RUN_MODE = new LaunchType(null); |
|
88 |
public final static LaunchType PLATSIM_STOP_MODE = new LaunchType(null); |
|
89 |
||
90 |
// settings made in Debug/Run Process section |
|
91 |
enum EExeSelection { |
|
92 |
USE_PROJECT_EXECUTABLE, |
|
93 |
USE_REMOTE_EXECUTABLE, |
|
94 |
ATTACH_TO_PROCESS, |
|
95 |
}; |
|
96 |
||
97 |
private EExeSelection exeSelection; |
|
98 |
private IPath exeSelectionPath = Path.EMPTY; |
|
99 |
private EBuildBeforeLaunchOption buildBeforeLaunch; |
|
100 |
private boolean installPackage; |
|
101 |
private String sisPath; |
|
953 | 102 |
private IConnection connection; |
911 | 103 |
|
104 |
// settings made in the Other Settings section |
|
105 |
enum EBuildBeforeLaunchOption { |
|
106 |
ALWAYS, |
|
107 |
NEVER, |
|
108 |
USE_WORKSPACE_SETTING, |
|
109 |
} |
|
110 |
||
953 | 111 |
public LaunchWizardData(LaunchOptions launchOptions, IService trkService) { |
112 |
this.mmps = launchOptions.mmps; |
|
113 |
this.exes = launchOptions.exes; |
|
114 |
this.defaultExecutable = launchOptions.defaultExecutable; |
|
115 |
this.project = launchOptions.project; |
|
116 |
this.configurationName = launchOptions.configurationName; |
|
117 |
this.isEmulation = launchOptions.isEmulation; |
|
118 |
this.emulatorOnly = launchOptions.emulatorOnly; |
|
119 |
this.mode = launchOptions.mode; |
|
911 | 120 |
this.service = trkService; |
121 |
} |
|
122 |
||
123 |
/** |
|
124 |
* @return the service |
|
125 |
*/ |
|
126 |
public IService getService() { |
|
127 |
return service; |
|
128 |
} |
|
129 |
||
130 |
/** |
|
131 |
* @return |
|
132 |
*/ |
|
133 |
public boolean isDebug() { |
|
134 |
return mode.equals(ILaunchManager.DEBUG_MODE); |
|
135 |
} |
|
136 |
||
137 |
public String getModeLabel() { |
|
138 |
if (mode.equals(ILaunchManager.RUN_MODE)) |
|
966 | 139 |
return Messages.getString("LaunchWizardData.RunModeLabel"); //$NON-NLS-1$ |
911 | 140 |
else if (mode.equals(ILaunchManager.DEBUG_MODE)) |
966 | 141 |
return Messages.getString("LaunchWizardData.DebugModeLabel"); //$NON-NLS-1$ |
911 | 142 |
else |
143 |
return TextUtils.titleCase(mode); |
|
144 |
||
145 |
} |
|
146 |
||
147 |
/** |
|
148 |
* Validate the detected and/or configured data |
|
149 |
* @return IStatus, never <code>null</code> |
|
150 |
*/ |
|
151 |
public IStatus validate() { |
|
152 |
return Status.OK_STATUS; |
|
153 |
} |
|
154 |
||
155 |
/** |
|
156 |
* @return |
|
157 |
* @return |
|
158 |
*/ |
|
159 |
public List<IPath> getExes() { |
|
160 |
return exes; |
|
161 |
} |
|
162 |
||
163 |
/** |
|
164 |
* @return the defaultExecutable |
|
165 |
*/ |
|
166 |
public IPath getDefaultExecutable() { |
|
167 |
return defaultExecutable; |
|
168 |
} |
|
169 |
||
170 |
/** |
|
171 |
* Set the executable selection mode |
|
172 |
* @param selection |
|
173 |
*/ |
|
174 |
public void setExeSelection(EExeSelection selection) { |
|
175 |
this.exeSelection = selection; |
|
176 |
} |
|
177 |
/** |
|
178 |
* Set the path for the exe |
|
179 |
* @param path or <code>null</code> |
|
180 |
*/ |
|
181 |
public void setExeSelectionPath(IPath path) { |
|
182 |
this.exeSelectionPath = path != null ? path : Path.EMPTY; |
|
183 |
} |
|
184 |
||
185 |
/** |
|
186 |
* @return |
|
187 |
*/ |
|
188 |
public EExeSelection getExeSelection() { |
|
189 |
return exeSelection; |
|
190 |
} |
|
191 |
||
192 |
public IPath getExeSelectionPath() { |
|
193 |
return exeSelectionPath; |
|
194 |
} |
|
195 |
||
196 |
public String getConnectionName() { |
|
197 |
IConnection connection = getConnection(); |
|
198 |
if (connection == null) |
|
199 |
return null; |
|
200 |
return connection.getDisplayName(); |
|
201 |
} |
|
202 |
||
203 |
public void setBuildBeforeLaunchOption( |
|
204 |
EBuildBeforeLaunchOption setting) { |
|
205 |
this.buildBeforeLaunch = setting; |
|
206 |
} |
|
207 |
||
208 |
public EBuildBeforeLaunchOption getBuildBeforeLaunch() { |
|
209 |
return buildBeforeLaunch; |
|
210 |
} |
|
211 |
||
212 |
/** Get current workspace setting */ |
|
213 |
public boolean isWorkspaceBuildBeforeLaunch() { |
|
214 |
// here's how to get the prefs from a plugin's #getPreferenceStore() without violating access |
|
215 |
String prefId = IDebugUIConstants.PREF_BUILD_BEFORE_LAUNCH; |
|
216 |
int idx = prefId.lastIndexOf('.'); |
|
217 |
String plugin = prefId.substring(0, idx); |
|
218 |
Preferences node = Platform.getPreferencesService().getRootNode().node(InstanceScope.SCOPE).node(plugin); |
|
219 |
return node.getBoolean(prefId, true); |
|
220 |
} |
|
221 |
||
222 |
/** Get actual launch-time setting */ |
|
223 |
public boolean isCurrentBuildBeforeLaunch() { |
|
224 |
if (buildBeforeLaunch != EBuildBeforeLaunchOption.USE_WORKSPACE_SETTING) |
|
225 |
return buildBeforeLaunch == EBuildBeforeLaunchOption.ALWAYS; |
|
226 |
return isWorkspaceBuildBeforeLaunch(); |
|
227 |
} |
|
228 |
||
229 |
/** |
|
230 |
* @param selection |
|
231 |
*/ |
|
232 |
public void setInstallPackage(boolean selection) { |
|
233 |
this.installPackage = selection; |
|
234 |
} |
|
235 |
||
236 |
/** |
|
237 |
* @return the installPackage |
|
238 |
*/ |
|
239 |
public boolean isInstallPackage() { |
|
240 |
return installPackage; |
|
241 |
} |
|
242 |
||
243 |
/** |
|
244 |
* @return |
|
245 |
*/ |
|
246 |
public IProject getProject() { |
|
247 |
return project; |
|
248 |
} |
|
249 |
||
250 |
/** |
|
251 |
* @param sisPath |
|
252 |
*/ |
|
253 |
public void setSisPath(String sisPath) { |
|
254 |
this.sisPath = sisPath; |
|
255 |
} |
|
256 |
||
257 |
/** |
|
953 | 258 |
* @return |
259 |
*/ |
|
260 |
public String getSisPath() { |
|
261 |
return sisPath; |
|
262 |
} |
|
263 |
||
264 |
/** |
|
911 | 265 |
* Copy the data, for use by a transient dialog. |
266 |
* @return new copy of data |
|
267 |
*/ |
|
953 | 268 |
public LaunchWizardData copy() { |
269 |
LaunchOptions launchOptions = new LaunchOptions(); |
|
270 |
launchOptions.mmps = mmps; |
|
271 |
launchOptions.exes = exes; |
|
272 |
launchOptions.defaultExecutable = defaultExecutable; |
|
273 |
launchOptions.project = project; |
|
274 |
launchOptions.configurationName = configurationName; |
|
275 |
launchOptions.isEmulation = isEmulation; |
|
276 |
launchOptions.emulatorOnly = emulatorOnly; |
|
277 |
launchOptions.mode = mode; |
|
278 |
LaunchWizardData d = new LaunchWizardData(launchOptions, service); |
|
911 | 279 |
d.exeSelection = exeSelection; |
280 |
d.exeSelectionPath = exeSelectionPath; |
|
281 |
d.buildBeforeLaunch = buildBeforeLaunch; |
|
282 |
d.installPackage = installPackage; |
|
283 |
d.sisPath = sisPath; |
|
284 |
d.connection = connection; |
|
285 |
return d; |
|
286 |
} |
|
287 |
||
288 |
/** |
|
289 |
* Apply the given data to the receiver (when a transient dialog is accepted) |
|
290 |
* @param dialogData |
|
291 |
*/ |
|
953 | 292 |
public void apply(LaunchWizardData dialogData) { |
911 | 293 |
exeSelection = dialogData.exeSelection; |
294 |
exeSelectionPath = dialogData.exeSelectionPath; |
|
295 |
buildBeforeLaunch = dialogData.buildBeforeLaunch; |
|
296 |
installPackage = dialogData.installPackage; |
|
297 |
sisPath = dialogData.sisPath; |
|
298 |
connection = dialogData.connection; |
|
299 |
} |
|
300 |
||
301 |
/** |
|
302 |
* @return |
|
303 |
*/ |
|
304 |
public boolean requiresInstallPackage() { |
|
953 | 305 |
return !isSysTRKConnection() || installPackage; |
911 | 306 |
} |
307 |
||
308 |
public void setConnection(IConnection connection) { |
|
309 |
this.connection = connection; |
|
310 |
} |
|
311 |
||
312 |
public IConnection getConnection() { |
|
313 |
return connection; |
|
314 |
} |
|
315 |
||
953 | 316 |
public ILaunchConfigurationWorkingCopy createConfiguration() throws CoreException { |
317 |
String launchTypeId = getApplicableLaunchTypeId(); |
|
318 |
ILaunchConfigurationType launchType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(launchTypeId); |
|
319 |
ILaunchConfigurationWorkingCopy config = launchType.newInstance(null, configurationName); |
|
320 |
initializeConfigSettings(launchTypeId, config); |
|
321 |
||
322 |
return config; |
|
323 |
} |
|
324 |
||
325 |
private void initializeConfigSettings(String launchTypeId, ILaunchConfigurationWorkingCopy config) { |
|
326 |
IPath exePath = getExePath(); |
|
327 |
IPath mmpPath = getMmpPath(exePath); |
|
328 |
if (launchTypeId.equals(SettingsData.APP_TRK_LAUNCH_TYPE_ID)) { |
|
329 |
SettingsData.setDefaults(config, SettingsData.LaunchConfig_AppTRK, project, mmpPath, exePath); |
|
330 |
} |
|
331 |
else if (launchTypeId.equals(SettingsData.SYS_TRK_LAUNCH_TYPE_ID)) { |
|
332 |
SettingsData.setDefaults(config, SettingsData.LaunchConfig_SysTRK, project, mmpPath, exePath); |
|
333 |
} |
|
334 |
else if (launchTypeId.equals(SettingsData.ATTACH_LAUNCH_TYPE_ID)) { |
|
335 |
SettingsData.setDefaults(config, SettingsData.LaunchConfig_AppTRK, project, mmpPath, exePath); |
|
336 |
} |
|
1041
7c4362faca1e
bugs 10806 + 10807 fix problems with program to launch
dadubrow
parents:
966
diff
changeset
|
337 |
if (exeSelection.equals(EExeSelection.USE_REMOTE_EXECUTABLE)) |
7c4362faca1e
bugs 10806 + 10807 fix problems with program to launch
dadubrow
parents:
966
diff
changeset
|
338 |
SettingsData.setProcessToLaunch(config, exeSelectionPath); |
7c4362faca1e
bugs 10806 + 10807 fix problems with program to launch
dadubrow
parents:
966
diff
changeset
|
339 |
|
953 | 340 |
addBuildOptions(config); |
341 |
// always set the current connection id |
|
342 |
config.setAttribute(RemoteConnectionsTRKHelper.CONNECTION_ATTRIBUTE, Registry.CURRENT_CONNECTION_ID); |
|
343 |
if (installPackage) |
|
344 |
config.setAttribute(PreferenceConstants.J_PN_SisFileHostPath, sisPath); |
|
345 |
} |
|
346 |
||
347 |
private IPath getMmpPath(IPath exePath) { |
|
348 |
if (!mmps.isEmpty()) { |
|
349 |
for (int i = 0; i < exes.size(); i++) { |
|
350 |
IPath exe = exes.get(i); |
|
351 |
if (exe.lastSegment().equals(exePath.lastSegment())) |
|
352 |
return mmps.get(i); |
|
353 |
} |
|
354 |
} |
|
355 |
return null; |
|
356 |
} |
|
357 |
||
1066
4791b1e2e6ef
10809 - generating warning for missing sis file or missing exe
dadubrow
parents:
1041
diff
changeset
|
358 |
public IPath getExePath() { |
1041
7c4362faca1e
bugs 10806 + 10807 fix problems with program to launch
dadubrow
parents:
966
diff
changeset
|
359 |
// if attach, doesn't matter so return first exe |
953 | 360 |
if (exeSelection.equals(EExeSelection.ATTACH_TO_PROCESS)) |
1041
7c4362faca1e
bugs 10806 + 10807 fix problems with program to launch
dadubrow
parents:
966
diff
changeset
|
361 |
return exes.isEmpty() ? Path.EMPTY : exes.get(0); |
7c4362faca1e
bugs 10806 + 10807 fix problems with program to launch
dadubrow
parents:
966
diff
changeset
|
362 |
|
7c4362faca1e
bugs 10806 + 10807 fix problems with program to launch
dadubrow
parents:
966
diff
changeset
|
363 |
// otherwise, see if we can use the selected path - process to launch string |
7c4362faca1e
bugs 10806 + 10807 fix problems with program to launch
dadubrow
parents:
966
diff
changeset
|
364 |
// by checking if the file name matches any of the ones in our list of exes |
7c4362faca1e
bugs 10806 + 10807 fix problems with program to launch
dadubrow
parents:
966
diff
changeset
|
365 |
String filename = exeSelectionPath.lastSegment(); |
7c4362faca1e
bugs 10806 + 10807 fix problems with program to launch
dadubrow
parents:
966
diff
changeset
|
366 |
for (IPath exePath : exes) { |
7c4362faca1e
bugs 10806 + 10807 fix problems with program to launch
dadubrow
parents:
966
diff
changeset
|
367 |
if (filename.equalsIgnoreCase(exePath.lastSegment())) { |
7c4362faca1e
bugs 10806 + 10807 fix problems with program to launch
dadubrow
parents:
966
diff
changeset
|
368 |
return exePath; |
7c4362faca1e
bugs 10806 + 10807 fix problems with program to launch
dadubrow
parents:
966
diff
changeset
|
369 |
} |
7c4362faca1e
bugs 10806 + 10807 fix problems with program to launch
dadubrow
parents:
966
diff
changeset
|
370 |
} |
7c4362faca1e
bugs 10806 + 10807 fix problems with program to launch
dadubrow
parents:
966
diff
changeset
|
371 |
// none could be found matching the selected path, so use the first in the list |
7c4362faca1e
bugs 10806 + 10807 fix problems with program to launch
dadubrow
parents:
966
diff
changeset
|
372 |
return exes.isEmpty() ? Path.EMPTY : exes.get(0); |
953 | 373 |
} |
374 |
||
375 |
private IConnectedService getConnectedService() { |
|
376 |
if (connection != null) { |
|
377 |
Collection<IConnectedService> connectedServices = |
|
378 |
RemoteConnectionsActivator.getConnectionsManager().getConnectedServices(connection); |
|
379 |
for (IConnectedService connectedService : connectedServices) { |
|
380 |
if (connectedService.getService().getIdentifier().equals(service.getIdentifier())) |
|
381 |
return connectedService; |
|
382 |
} |
|
383 |
} |
|
384 |
return null; |
|
385 |
} |
|
386 |
||
387 |
public boolean isSysTRKConnection() { |
|
388 |
IConnectedService connectedService = getConnectedService(); |
|
389 |
if (connectedService instanceof IConnectedService2) { |
|
390 |
String value = ((IConnectedService2) connectedService).getProperties().get("is-system-trk"); //$NON-NLS-1$ |
|
391 |
return Boolean.parseBoolean(value); |
|
392 |
} |
|
393 |
return false; |
|
394 |
} |
|
395 |
||
396 |
private String getApplicableLaunchTypeId() { |
|
397 |
if (exeSelection.equals(EExeSelection.ATTACH_TO_PROCESS)) |
|
398 |
return SettingsData.ATTACH_LAUNCH_TYPE_ID; |
|
399 |
else if (!installPackage || isSysTRKConnection()) |
|
400 |
return SettingsData.SYS_TRK_LAUNCH_TYPE_ID; |
|
401 |
else |
|
402 |
return SettingsData.APP_TRK_LAUNCH_TYPE_ID; |
|
403 |
} |
|
404 |
||
405 |
private void addBuildOptions(ILaunchConfigurationWorkingCopy config) { |
|
406 |
int buildBeforeLaunchValue = ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_USE_WORKSPACE_SETTING; |
|
407 |
switch (buildBeforeLaunch) { |
|
408 |
case NEVER: |
|
409 |
buildBeforeLaunchValue = ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_DISABLED; |
|
410 |
break; |
|
411 |
case ALWAYS: |
|
412 |
buildBeforeLaunchValue = ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_ENABLED; |
|
413 |
break; |
|
414 |
} |
|
415 |
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_BUILD_BEFORE_LAUNCH, buildBeforeLaunchValue); |
|
416 |
} |
|
911 | 417 |
} |
953 | 418 |