OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012, the Dart project authors. | 2 * Copyright (c) 2012, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
11 * or implied. See the License for the specific language governing permissions a
nd limitations under | 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
12 * the License. | 12 * the License. |
13 */ | 13 */ |
14 package com.google.dart.tools.debug.ui.internal.util; | 14 package com.google.dart.tools.debug.ui.internal.util; |
15 | 15 |
16 import com.google.dart.tools.core.DartCore; | 16 import com.google.dart.tools.core.DartCore; |
17 import com.google.dart.tools.core.internal.model.DartLibraryImpl; | 17 import com.google.dart.tools.core.internal.model.DartLibraryImpl; |
18 import com.google.dart.tools.core.internal.model.DartProjectImpl; | 18 import com.google.dart.tools.core.internal.model.DartProjectImpl; |
19 import com.google.dart.tools.core.model.CompilationUnit; | 19 import com.google.dart.tools.core.model.CompilationUnit; |
20 import com.google.dart.tools.core.model.DartElement; | 20 import com.google.dart.tools.core.model.DartElement; |
21 import com.google.dart.tools.core.model.DartLibrary; | 21 import com.google.dart.tools.core.model.DartLibrary; |
22 import com.google.dart.tools.core.model.DartModelException; | 22 import com.google.dart.tools.core.model.DartModelException; |
23 import com.google.dart.tools.core.model.HTMLFile; | 23 import com.google.dart.tools.core.model.HTMLFile; |
24 import com.google.dart.tools.debug.core.DartDebugCorePlugin; | 24 import com.google.dart.tools.debug.core.DartDebugCorePlugin; |
25 import com.google.dart.tools.debug.core.DartLaunchConfigWrapper; | 25 import com.google.dart.tools.debug.core.DartLaunchConfigWrapper; |
26 import com.google.dart.tools.debug.ui.internal.DartDebugUIPlugin; | 26 import com.google.dart.tools.debug.ui.internal.DartDebugUIPlugin; |
27 import com.google.dart.tools.debug.ui.internal.DartUtil; | 27 import com.google.dart.tools.debug.ui.internal.DartUtil; |
28 import com.google.dart.tools.debug.ui.internal.DebugErrorHandler; | |
29 import com.google.dart.tools.debug.ui.internal.browser.BrowserLaunchShortcut; | 28 import com.google.dart.tools.debug.ui.internal.browser.BrowserLaunchShortcut; |
30 import com.google.dart.tools.debug.ui.internal.dartium.DartiumLaunchShortcut; | 29 import com.google.dart.tools.debug.ui.internal.dartium.DartiumLaunchShortcut; |
31 import com.google.dart.tools.debug.ui.internal.server.DartServerLaunchShortcut; | 30 import com.google.dart.tools.debug.ui.internal.server.DartServerLaunchShortcut; |
32 | 31 |
33 import org.apache.commons.lang3.ObjectUtils; | 32 import org.apache.commons.lang3.ObjectUtils; |
| 33 import org.eclipse.core.resources.IFile; |
34 import org.eclipse.core.resources.IProject; | 34 import org.eclipse.core.resources.IProject; |
35 import org.eclipse.core.resources.IResource; | 35 import org.eclipse.core.resources.IResource; |
| 36 import org.eclipse.core.resources.ResourcesPlugin; |
36 import org.eclipse.core.runtime.CoreException; | 37 import org.eclipse.core.runtime.CoreException; |
37 import org.eclipse.core.runtime.IConfigurationElement; | 38 import org.eclipse.core.runtime.IConfigurationElement; |
38 import org.eclipse.core.runtime.IExtensionPoint; | 39 import org.eclipse.core.runtime.IExtensionPoint; |
39 import org.eclipse.core.runtime.IProgressMonitor; | 40 import org.eclipse.core.runtime.OperationCanceledException; |
40 import org.eclipse.core.runtime.IStatus; | |
41 import org.eclipse.core.runtime.Platform; | 41 import org.eclipse.core.runtime.Platform; |
42 import org.eclipse.core.runtime.Status; | 42 import org.eclipse.core.runtime.jobs.IJobManager; |
43 import org.eclipse.core.runtime.jobs.Job; | 43 import org.eclipse.core.runtime.jobs.Job; |
44 import org.eclipse.debug.core.DebugPlugin; | 44 import org.eclipse.debug.core.DebugPlugin; |
45 import org.eclipse.debug.core.ILaunchConfiguration; | 45 import org.eclipse.debug.core.ILaunchConfiguration; |
46 import org.eclipse.debug.internal.ui.views.console.ProcessConsole; | 46 import org.eclipse.debug.internal.ui.views.console.ProcessConsole; |
47 import org.eclipse.debug.ui.DebugUITools; | 47 import org.eclipse.debug.ui.DebugUITools; |
48 import org.eclipse.debug.ui.IDebugModelPresentation; | 48 import org.eclipse.debug.ui.IDebugModelPresentation; |
49 import org.eclipse.debug.ui.IDebugUIConstants; | 49 import org.eclipse.debug.ui.IDebugUIConstants; |
50 import org.eclipse.debug.ui.ILaunchShortcut; | 50 import org.eclipse.debug.ui.ILaunchShortcut; |
51 import org.eclipse.jface.viewers.ISelection; | 51 import org.eclipse.jface.viewers.ISelection; |
52 import org.eclipse.jface.viewers.ISelectionProvider; | 52 import org.eclipse.jface.viewers.ISelectionProvider; |
53 import org.eclipse.jface.viewers.IStructuredSelection; | 53 import org.eclipse.jface.viewers.IStructuredSelection; |
54 import org.eclipse.jface.window.Window; | 54 import org.eclipse.jface.window.Window; |
55 import org.eclipse.swt.widgets.Display; | |
56 import org.eclipse.ui.IEditorPart; | 55 import org.eclipse.ui.IEditorPart; |
57 import org.eclipse.ui.IWorkbenchPage; | 56 import org.eclipse.ui.IWorkbenchPage; |
58 import org.eclipse.ui.IWorkbenchPart; | 57 import org.eclipse.ui.IWorkbenchPart; |
59 import org.eclipse.ui.IWorkbenchPartSite; | 58 import org.eclipse.ui.IWorkbenchPartSite; |
60 import org.eclipse.ui.IWorkbenchWindow; | 59 import org.eclipse.ui.IWorkbenchWindow; |
61 import org.eclipse.ui.PlatformUI; | 60 import org.eclipse.ui.PlatformUI; |
62 import org.eclipse.ui.console.ConsolePlugin; | 61 import org.eclipse.ui.console.ConsolePlugin; |
63 import org.eclipse.ui.console.IConsole; | 62 import org.eclipse.ui.console.IConsole; |
64 import org.eclipse.ui.dialogs.ElementListSelectionDialog; | 63 import org.eclipse.ui.dialogs.ElementListSelectionDialog; |
65 import org.eclipse.ui.ide.IDE; | 64 import org.eclipse.ui.ide.IDE; |
(...skipping 11 matching lines...) Expand all Loading... |
77 * A utility class for launching and launch configurations. | 76 * A utility class for launching and launch configurations. |
78 */ | 77 */ |
79 @SuppressWarnings("restriction") | 78 @SuppressWarnings("restriction") |
80 public class LaunchUtils { | 79 public class LaunchUtils { |
81 | 80 |
82 public static final String DARTIUM_LAUNCH_NAME = "Dartium launch"; | 81 public static final String DARTIUM_LAUNCH_NAME = "Dartium launch"; |
83 | 82 |
84 private static List<ILaunchShortcut> shortcuts; | 83 private static List<ILaunchShortcut> shortcuts; |
85 | 84 |
86 /** | 85 /** |
| 86 * Returns true if the given launch config can be launched w/o waiting on the
builder. |
| 87 */ |
| 88 public static boolean canFastLaunch(ILaunchConfiguration config) { |
| 89 DartLaunchConfigWrapper wrapper = new DartLaunchConfigWrapper(config); |
| 90 IProject project = wrapper.getProject(); |
| 91 |
| 92 if (project == null) { |
| 93 return false; |
| 94 } |
| 95 |
| 96 // if pubspec.yaml is not up-to-date, return false |
| 97 IFile pubspecYamlFile = project.getFile(DartCore.PUBSPEC_FILE_NAME); |
| 98 |
| 99 if (pubspecYamlFile.exists()) { |
| 100 IFile pubspecLockFile = project.getFile(DartCore.PUBSPEC_LOCK_FILE_NAME); |
| 101 |
| 102 if (!pubspecLockFile.exists()) { |
| 103 return false; |
| 104 } |
| 105 |
| 106 if (pubspecLockFile.getLocalTimeStamp() < pubspecYamlFile.getLocalTimeStam
p()) { |
| 107 return false; |
| 108 } |
| 109 } |
| 110 |
| 111 return true; |
| 112 } |
| 113 |
| 114 /** |
87 * Allow the user to choose one from a set of launch configurations. | 115 * Allow the user to choose one from a set of launch configurations. |
88 * | 116 * |
89 * @param configList | 117 * @param configList |
90 * @return | 118 * @return |
91 */ | 119 */ |
92 public static ILaunchConfiguration chooseConfiguration(List<ILaunchConfigurati
on> configList) { | 120 public static ILaunchConfiguration chooseConfiguration(List<ILaunchConfigurati
on> configList) { |
93 IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentati
on(); | 121 IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentati
on(); |
94 | 122 |
95 ElementListSelectionDialog dialog = new ElementListSelectionDialog( | 123 ElementListSelectionDialog dialog = new ElementListSelectionDialog( |
96 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), | 124 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 return false; | 479 return false; |
452 } | 480 } |
453 | 481 |
454 /** | 482 /** |
455 * Launches the given launch configuration in the specified mode in a backgrou
nd job. | 483 * Launches the given launch configuration in the specified mode in a backgrou
nd job. |
456 * | 484 * |
457 * @param config the config to launch | 485 * @param config the config to launch |
458 * @param mode the launch mode | 486 * @param mode the launch mode |
459 */ | 487 */ |
460 public static void launch(final ILaunchConfiguration config, final String mode
) { | 488 public static void launch(final ILaunchConfiguration config, final String mode
) { |
461 if (DartDebugCorePlugin.canFastLaunch(config)) { | 489 // If there are any dirty editors for the given project, save them now. |
462 // If there are any dirty editors for the given project, save them now. | 490 DartLaunchConfigWrapper wrapper = new DartLaunchConfigWrapper(config); |
463 DartLaunchConfigWrapper wrapper = new DartLaunchConfigWrapper(config); | 491 IProject project = wrapper.getProject(); |
464 IProject project = wrapper.getProject(); | |
465 | 492 |
466 if (project != null) { | 493 if (project != null) { |
467 IDE.saveAllEditors(new IResource[] {project}, false); | 494 IDE.saveAllEditors(new IResource[] {project}, false); |
| 495 } |
| 496 |
| 497 if (!canFastLaunch(config)) { |
| 498 try { |
| 499 // Wait on any existing builds (i.e., something like provisioning pub). |
| 500 IJobManager jobManager = Job.getJobManager(); |
| 501 |
| 502 jobManager.join(ResourcesPlugin.FAMILY_MANUAL_BUILD, null); |
| 503 jobManager.join(ResourcesPlugin.FAMILY_AUTO_BUILD, null); |
| 504 } catch (OperationCanceledException e) { |
| 505 // user cancelled |
| 506 |
| 507 } catch (InterruptedException e) { |
| 508 DartDebugCorePlugin.logError(e); |
468 } | 509 } |
| 510 } |
469 | 511 |
470 Job launchJob = new Job("Launching " + config.getName()) { | 512 DebugUITools.launch(config, mode); |
471 @Override | |
472 protected IStatus run(IProgressMonitor monitor) { | |
473 try { | |
474 config.launch(mode, monitor, false); | |
475 } catch (final CoreException e) { | |
476 Display.getDefault().asyncExec(new Runnable() { | |
477 @Override | |
478 public void run() { | |
479 DebugErrorHandler.errorDialog( | |
480 null, | |
481 "Error Launching " + config.getName(), | |
482 e.toString(), | |
483 e.getStatus()); | |
484 } | |
485 }); | |
486 } | |
487 | |
488 monitor.done(); | |
489 | |
490 return Status.OK_STATUS; | |
491 } | |
492 }; | |
493 | |
494 launchJob.schedule(); | |
495 } else { | |
496 DebugUITools.launch(config, mode); | |
497 } | |
498 } | 513 } |
499 | 514 |
500 /** | 515 /** |
501 * Check if the given launch configuration - server/client can launch the libr
ary specified. This | 516 * Check if the given launch configuration - server/client can launch the libr
ary specified. This |
502 * check will catch changes made to library client <=> server after configurat
ion has been | 517 * check will catch changes made to library client <=> server after configurat
ion has been |
503 * created. | 518 * created. |
504 */ | 519 */ |
505 private static boolean isCorrectLaunchConfigType(ILaunchConfiguration config, | 520 private static boolean isCorrectLaunchConfigType(ILaunchConfiguration config, |
506 DartLibrary testLibrary) { | 521 DartLibrary testLibrary) { |
507 | 522 |
(...skipping 12 matching lines...) Expand all Loading... |
520 DartDebugUIPlugin.logError(e); | 535 DartDebugUIPlugin.logError(e); |
521 } | 536 } |
522 return false; | 537 return false; |
523 } | 538 } |
524 | 539 |
525 private LaunchUtils() { | 540 private LaunchUtils() { |
526 | 541 |
527 } | 542 } |
528 | 543 |
529 } | 544 } |
OLD | NEW |