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