Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(881)

Side by Side Diff: editor/tools/plugins/com.google.dart.tools.debug.core/src/com/google/dart/tools/debug/core/pubserve/PubServeLaunchConfigurationDelegate.java

Issue 166213002: Version 1.2.0-dev.5.7 (Closed) Base URL: http://dart.googlecode.com/svn/trunk/dart/
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013, the Dart project authors. 2 * Copyright (c) 2013, 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 14
15 package com.google.dart.tools.debug.core.pubserve; 15 package com.google.dart.tools.debug.core.pubserve;
16 16
17 import com.google.dart.engine.utilities.instrumentation.InstrumentationBuilder; 17 import com.google.dart.engine.utilities.instrumentation.InstrumentationBuilder;
18 import com.google.dart.tools.core.dart2js.ProcessRunner;
19 import com.google.dart.tools.core.model.DartSdkManager; 18 import com.google.dart.tools.core.model.DartSdkManager;
20 import com.google.dart.tools.debug.core.DartDebugCorePlugin; 19 import com.google.dart.tools.debug.core.DartDebugCorePlugin;
21 import com.google.dart.tools.debug.core.DartLaunchConfigWrapper; 20 import com.google.dart.tools.debug.core.DartLaunchConfigWrapper;
22 import com.google.dart.tools.debug.core.DartLaunchConfigurationDelegate; 21 import com.google.dart.tools.debug.core.DartLaunchConfigurationDelegate;
23 import com.google.dart.tools.debug.core.util.BrowserManager; 22 import com.google.dart.tools.debug.core.util.BrowserManager;
24 23
25 import org.eclipse.core.resources.IResource; 24 import org.eclipse.core.resources.IResource;
26 import org.eclipse.core.runtime.CoreException; 25 import org.eclipse.core.runtime.CoreException;
27 import org.eclipse.core.runtime.IProgressMonitor; 26 import org.eclipse.core.runtime.IProgressMonitor;
28 import org.eclipse.core.runtime.IStatus; 27 import org.eclipse.core.runtime.IStatus;
29 import org.eclipse.core.runtime.NullProgressMonitor;
30 import org.eclipse.core.runtime.Status; 28 import org.eclipse.core.runtime.Status;
31 import org.eclipse.debug.core.DebugPlugin; 29 import org.eclipse.debug.core.DebugException;
32 import org.eclipse.debug.core.ILaunch; 30 import org.eclipse.debug.core.ILaunch;
33 import org.eclipse.debug.core.ILaunchConfiguration; 31 import org.eclipse.debug.core.ILaunchConfiguration;
34 import org.eclipse.debug.core.ILaunchManager; 32 import org.eclipse.debug.core.ILaunchManager;
33 import org.eclipse.debug.core.model.IProcess;
34 import org.eclipse.debug.core.model.RuntimeProcess;
35 35
36 import java.io.File; 36 import java.io.File;
37 import java.io.IOException; 37 import java.io.IOException;
38 import java.util.ArrayList; 38 import java.util.ArrayList;
39 import java.util.Date;
40 import java.util.HashMap;
39 import java.util.List; 41 import java.util.List;
40 import java.util.Map; 42 import java.util.Map;
41 import java.util.concurrent.Semaphore; 43 import java.util.concurrent.Semaphore;
42 44
43 /** 45 /**
44 * A launch configuration delegate to launch application in Dartium and serve fi les using pub serve. 46 * A launch configuration delegate to launch application in Dartium and serve fi les using pub serve.
45 */ 47 */
46 public class PubServeLaunchConfigurationDelegate extends DartLaunchConfiguration Delegate { 48 public class PubServeLaunchConfigurationDelegate extends DartLaunchConfiguration Delegate {
47 49
48 private static Semaphore launchSemaphore = new Semaphore(1); 50 private static Semaphore launchSemaphore = new Semaphore(1);
49 51
50 private static ProcessRunner runner; 52 private static RuntimeProcess eclipseProcess;
51
52 public static void dispose() {
53 if (runner != null) {
54 runner.dispose();
55 }
56 }
57 53
58 @Override 54 @Override
59 public void doLaunch(ILaunchConfiguration configuration, String mode, ILaunch launch, 55 public void doLaunch(ILaunchConfiguration configuration, String mode, ILaunch launch,
60 IProgressMonitor monitor, InstrumentationBuilder instrumentation) throws C oreException { 56 IProgressMonitor monitor, InstrumentationBuilder instrumentation) throws C oreException {
61 57
62 if (!ILaunchManager.RUN_MODE.equals(mode)) { 58 if (!ILaunchManager.RUN_MODE.equals(mode)) {
63 throw new CoreException(DartDebugCorePlugin.createErrorStatus("Execution m ode '" + mode 59 throw new CoreException(DartDebugCorePlugin.createErrorStatus("Execution m ode '" + mode
64 + "' is not supported.")); 60 + "' is not supported."));
65 } 61 }
66 62
67 DartLaunchConfigWrapper launchConfig = new DartLaunchConfigWrapper(configura tion); 63 DartLaunchConfigWrapper launchConfig = new DartLaunchConfigWrapper(configura tion);
68 64
69 // If we're in the process of launching Dartium, don't allow a second launch to occur. 65 // If we're in the process of launching Dartium, don't allow a second launch to occur.
70 if (launchSemaphore.tryAcquire()) { 66 if (launchSemaphore.tryAcquire()) {
71 try { 67 try {
72 launchImpl(launchConfig, mode, launch, monitor); 68 launchImpl(launchConfig, mode, launch, monitor);
73 } finally { 69 } finally {
74 launchSemaphore.release(); 70 launchSemaphore.release();
75 } 71 }
76 } 72 }
77 } 73 }
78 74
75 private void dispose() {
76 if (eclipseProcess != null) {
77 try {
78 eclipseProcess.terminate();
79 } catch (DebugException e) {
80
81 }
82 eclipseProcess = null;
83 }
84 }
85
79 private void launchImpl(DartLaunchConfigWrapper launchConfig, String mode, ILa unch launch, 86 private void launchImpl(DartLaunchConfigWrapper launchConfig, String mode, ILa unch launch,
80 IProgressMonitor monitor) throws CoreException { 87 IProgressMonitor monitor) throws CoreException {
81 88
82 launchConfig.markAsLaunched(); 89 launchConfig.markAsLaunched();
83 90
84 // Launch the browser - show errors if we couldn't. 91 // Launch the browser - show errors if we couldn't.
85 IResource resource = null; 92 IResource resource = null;
86 93
87 resource = launchConfig.getApplicationResource(); 94 resource = launchConfig.getApplicationResource();
88 if (resource == null) { 95 if (resource == null) {
89 throw new CoreException(new Status( 96 throw new CoreException(new Status(
90 IStatus.ERROR, 97 IStatus.ERROR,
91 DartDebugCorePlugin.PLUGIN_ID, 98 DartDebugCorePlugin.PLUGIN_ID,
92 "HTML file could not be found")); 99 "HTML file could not be found"));
93 } 100 }
94 101
95 // launch pub serve 102 // launch pub serve
96 PubServeManager manager = PubServeManager.getManager(); 103 PubServeManager manager = PubServeManager.getManager();
97 104
98 if (!manager.startPubServe(launchConfig)) { 105 if (!manager.startPubServe(launchConfig)) {
99 throw new CoreException(new Status( 106 throw new CoreException(new Status(
100 IStatus.ERROR, 107 IStatus.ERROR,
101 DartDebugCorePlugin.PLUGIN_ID, 108 DartDebugCorePlugin.PLUGIN_ID,
102 "Could not start pub serve\n" + manager.getStdErrorString())); 109 "Could not start pub serve\n" + manager.getStdErrorString()));
103 } 110 }
104 111
105 String url = "http://localhost:" + PubServeManager.PORT_NUMBER; 112 String url = "http://localhost:" + PubServeManager.PORT_NUMBER;
106 113
107 launchInDartium(url + "/" + resource.getName(), launchConfig); 114 launchInDartium(url + "/" + resource.getName(), launch, launchConfig, monito r);
108
109 DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
110 115
111 } 116 }
112 117
113 private void launchInDartium(final String url, DartLaunchConfigWrapper launchC onfig) 118 private void launchInDartium(final String url, ILaunch launch,
114 throws CoreException { 119 DartLaunchConfigWrapper launchConfig, IProgressMonitor monitor) throws Cor eException {
115 120
116 // close a running instance of Dartium, if any 121 // close a running instance of Dartium, if any
117 dispose(); 122 dispose();
118 123
119 List<String> cmd = new ArrayList<String>();
120
121 File dartium = DartSdkManager.getManager().getSdk().getDartiumExecutable(); 124 File dartium = DartSdkManager.getManager().getSdk().getDartiumExecutable();
122 125
126 List<String> cmd = new ArrayList<String>();
123 cmd.add(dartium.getAbsolutePath()); 127 cmd.add(dartium.getAbsolutePath());
124
125 // In order to start up multiple Chrome processes, we need to specify a diff erent user dir. 128 // In order to start up multiple Chrome processes, we need to specify a diff erent user dir.
126 cmd.add("--user-data-dir=" + BrowserManager.getCreateUserDataDirectoryPath(" pubserve")); 129 cmd.add("--user-data-dir=" + BrowserManager.getCreateUserDataDirectoryPath(" pubserve"));
127 130
128 if (launchConfig.getUseWebComponents()) { 131 if (launchConfig.getUseWebComponents()) {
129 cmd.add("--enable-experimental-web-platform-features"); 132 cmd.add("--enable-experimental-web-platform-features");
130 cmd.add("--enable-html-imports"); 133 cmd.add("--enable-html-imports");
131 } 134 }
132
133 // Disables the default browser check. 135 // Disables the default browser check.
134 cmd.add("--no-default-browser-check"); 136 cmd.add("--no-default-browser-check");
135
136 // Bypass the error dialog when the profile lock couldn't be attained. 137 // Bypass the error dialog when the profile lock couldn't be attained.
137 cmd.add("--no-process-singleton-dialog"); 138 cmd.add("--no-process-singleton-dialog");
138
139 for (String arg : launchConfig.getArgumentsAsArray()) { 139 for (String arg : launchConfig.getArgumentsAsArray()) {
140 cmd.add(arg); 140 cmd.add(arg);
141 } 141 }
142 cmd.add(url); 142 cmd.add(url);
143 143
144 ProcessBuilder processBuilder = new ProcessBuilder(cmd);
145 Map<String, String> env = processBuilder.environment();
146 // Due to differences in 32bit and 64 bit environments, dartium 32bit launch does not work on
147 // linux with this property.
148 env.remove("LD_LIBRARY_PATH");
149 if (launchConfig.getCheckedMode()) {
150 env.put("DART_FLAGS", "--enable-checked-mode");
151 }
152
153 Process javaProcess = null;
154
144 try { 155 try {
145 ProcessBuilder builder = new ProcessBuilder(cmd); 156 javaProcess = processBuilder.start();
146 Map<String, String> env = builder.environment(); 157 } catch (IOException ioe) {
147 // Due to differences in 32bit and 64 bit environments, dartium 32bit laun ch does not work on
148 // linux with this property.
149 env.remove("LD_LIBRARY_PATH");
150
151 if (launchConfig.getCheckedMode()) {
152 env.put("DART_FLAGS", "--enable-checked-mode");
153 }
154
155 runner = new ProcessRunner(builder);
156 runner.runAsync();
157 runner.await(new NullProgressMonitor(), 500);
158
159 if (runner.getExitCode() != 0) {
160
161 throw new CoreException(new Status(
162 IStatus.ERROR,
163 DartDebugCorePlugin.PLUGIN_ID,
164 "Could not launch dartium : \n\n" + runner.getStdErr()));
165 }
166 } catch (IOException e) {
167 throw new CoreException(new Status( 158 throw new CoreException(new Status(
168 IStatus.ERROR, 159 IStatus.ERROR,
169 DartDebugCorePlugin.PLUGIN_ID, 160 DartDebugCorePlugin.PLUGIN_ID,
170 "Dartium not found", 161 ioe.getMessage(),
171 e)); 162 ioe));
172 } 163 }
164
165 eclipseProcess = null;
166
167 Map<String, String> processAttributes = new HashMap<String, String>();
168 String programName = "dartium";
169 processAttributes.put(IProcess.ATTR_PROCESS_TYPE, programName);
170
171 if (javaProcess != null) {
172 monitor.beginTask("Dartium", IProgressMonitor.UNKNOWN);
173
174 eclipseProcess = new RuntimeProcess(launch, javaProcess, launchConfig.getA pplicationName()
175 + " (" + new Date() + ")", processAttributes);
176
177 }
178
179 if (javaProcess == null || eclipseProcess == null) {
180 if (javaProcess != null) {
181 javaProcess.destroy();
182 }
183
184 throw new CoreException(
185 DartDebugCorePlugin.createErrorStatus("Error starting Dartium browser" ));
186 }
187
173 } 188 }
174 } 189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698