@Override public void initializeFrom(ILaunchConfiguration configuration) { SDBGLaunchConfigWrapper dartLauncher = new SDBGLaunchConfigWrapper(configuration); htmlText.setText(dartLauncher.appendQueryParams(dartLauncher.getApplicationName())); argumentText.setText(dartLauncher.getArguments()); }
public WebkitDebugTarget connect( ILaunch launch, ILaunchConfiguration configuration, IResourceResolver resourceResolver, IBrowserTabChooser browserTabChooser, String host, int port, IProgressMonitor monitor) throws CoreException { try { SDBGLaunchConfigWrapper launchConfig = new SDBGLaunchConfigWrapper(configuration); LogTimer timer = new LogTimer("Chrome debug connect"); try { timer.startTask("connect"); try { launchConfig.markAsLaunched(); return connectToChromiumDebug( "Chrome Remote Connection", launch, launchConfig, null /*url*/, monitor, null /*runtimeProcess*/, timer, true /*enableBreakpoints*/, host, port, 0L /*maxStartupDelay*/, null /*browserOutput*/, null /*processDescription*/, resourceResolver, browserTabChooser, true /*remote*/); } finally { timer.stopTask(); } } finally { timer.stopTimer(); } } catch (CoreException e) { DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch); throw e; } }
@Override protected IProject[] getBuildOrder(ILaunchConfiguration configuration, String mode) throws CoreException { // indicate which project to save before launch SDBGLaunchConfigWrapper launchConfig = new SDBGLaunchConfigWrapper(configuration); IResource resource = launchConfig.getApplicationResource(); if (resource != null) { return new IProject[] {resource.getProject()}; } if (launchConfig.getProject() != null) { return new IProject[] {launchConfig.getProject()}; } return null; }
protected String resolveLaunchUrl( IResourceResolver resourceResolver, SDBGLaunchConfigWrapper launchConfig) throws CoreException { String url; if (launchConfig.getShouldLaunchFile()) { IResource resource = launchConfig.getApplicationResource(); if (resource == null) { throw new CoreException( new Status( IStatus.ERROR, SDBGDebugCorePlugin.PLUGIN_ID, "HTML file could not be found")); } if (resource instanceof IFile) { url = resourceResolver.getUrlForResource(resource); } else { url = resource.getLocationURI().toString(); } } else { url = launchConfig.getUrl(); } return launchConfig.appendQueryParams(url); }
@Override public void performApply(ILaunchConfigurationWorkingCopy configuration) { SDBGLaunchConfigWrapper dartLauncher = new SDBGLaunchConfigWrapper(configuration); dartLauncher.setShouldLaunchFile(true); String fileUrl = htmlText.getText().trim(); if (fileUrl.indexOf('?') == -1) { dartLauncher.setApplicationName(fileUrl); dartLauncher.setUrlQueryParams(""); } else { int index = fileUrl.indexOf('?'); dartLauncher.setApplicationName(fileUrl.substring(0, index)); dartLauncher.setUrlQueryParams(fileUrl.substring(index + 1)); } dartLauncher.setArguments(argumentText.getText().trim()); }
private List<String> buildArgumentsList( SDBGLaunchConfigWrapper launchConfig, String url, int devToolsPortNumber, List<String> extraArguments) { List<String> arguments = new ArrayList<String>(); arguments.add(getBrowserExecutable().getAbsolutePath()); if (devToolsPortNumber > -1) { // Enable remote debug over HTTP on the specified port. arguments.add("--remote-debugging-port=" + devToolsPortNumber); } // In order to start up multiple Chrome processes, we need to specify a different user dir. arguments.add( "--user-data-dir=" + getCreateUserDataDirectory(browserDataDirName).getAbsolutePath()); // Whether or not it's actually the first run. arguments.add("--no-first-run"); // Disables the default browser check. arguments.add("--no-default-browser-check"); // Bypass the error dialog when the profile lock couldn't be attained. arguments.add("--no-process-singleton-dialog"); arguments.addAll(extraArguments); for (String arg : launchConfig.getArgumentsAsArray()) { arguments.add(arg); } if (url != null) { arguments.add(url); } return arguments; }
@Override public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { SDBGLaunchConfigWrapper dartLauncher = new SDBGLaunchConfigWrapper(configuration); dartLauncher.setShouldLaunchFile(true); dartLauncher.setApplicationName(""); // $NON-NLS-1$ }
protected IResourceResolver getResourceResolver(SDBGLaunchConfigWrapper launchConfig) throws CoreException { return launchConfig.getShouldLaunchFile() ? getResourceServer() : new LaunchConfigResourceResolver(launchConfig); }
private WebkitDebugTarget connectToChromiumDebug( String browserName, ILaunch launch, SDBGLaunchConfigWrapper launchConfig, String url, IProgressMonitor monitor, Process runtimeProcess, LogTimer timer, boolean enableBreakpoints, String host, int port, long maxStartupDelay, ListeningStream browserOutput, String processDescription, IResourceResolver resolver, IBrowserTabChooser browserTabChooser, boolean remote) throws CoreException { monitor.worked(1); // avg: 383ms timer.startTask("get chromium tabs"); ChromiumTabInfo tab; try { tab = getChromiumTab( runtimeProcess, browserTabChooser, host, port, maxStartupDelay, browserOutput); } catch (IOException e) { SDBGDebugCorePlugin.logError(e); throw new CoreException( new Status( IStatus.ERROR, SDBGDebugCorePlugin.PLUGIN_ID, "Unable to connect to Chrome at address " + (host != null ? host : "") + ":" + port + "; error: " + e.getMessage(), e)); } monitor.worked(2); timer.stopTask(); // avg: 46ms timer.startTask("open WIP connection"); if (tab == null) { throw new DebugException( new Status( IStatus.INFO, SDBGDebugCorePlugin.PLUGIN_ID, "No Chrome tab was chosen. Connection cancelled.")); } if (tab.getWebSocketDebuggerUrl() == null) { throw new DebugException( new Status( IStatus.ERROR, SDBGDebugCorePlugin.PLUGIN_ID, "Unable to connect to Chrome" + (remote ? ".\n\nPossible reason: another debugger (e.g. Chrome DevTools) or another Eclipse debugging session is already attached to that particular Chrome tab." : ""))); } // Even when Chrome has reported all the debuggable tabs to us, the debug server // may not yet have started up. Delay a small fixed amount of time. sleep(100); if (resolver == null) { resolver = createResourceResolver(launch, launchConfig.getConfig(), tab); } try { WebkitConnection connection = new WebkitConnection(tab.getHost(), tab.getPort(), tab.getWebSocketDebuggerFile()); final WebkitDebugTarget debugTarget = new WebkitDebugTarget( browserName, connection, launch, runtimeProcess, launchConfig.getProject(), resolver, adbManager, enableBreakpoints, remote); monitor.worked(1); registerProcess(launch, launchConfig, debugTarget.getProcess(), processDescription); launch.addDebugTarget(debugTarget); if (browserOutput != null && launchConfig.getShowLaunchOutput()) { browserOutput.setListener( new StreamListener() { @Override public void handleStreamData(String data) { debugTarget.writeToStdout(data); } }); } if (browserOutput != null) { debugTarget.openConnection(url, true); } else { debugTarget.openConnection(); } trace("Connected to WIP debug agent on host " + host + " and port " + port); timer.stopTask(); monitor.worked(1); return debugTarget; } catch (IOException e) { SDBGDebugCorePlugin.logError(e); throw new CoreException( new Status( IStatus.ERROR, SDBGDebugCorePlugin.PLUGIN_ID, "Unable to connect to Chrome tab at address " + (tab.getHost() != null ? tab.getHost() : "") + ":" + tab.getPort() + " (" + tab.getWebSocketDebuggerFile() + "): " + e.getMessage(), e)); } }
public void launchBrowser( ILaunch launch, ILaunchConfiguration configuration, IResourceResolver resourceResolver, IBrowserTabChooser browserTabChooser, String url, IProgressMonitor monitor, boolean enableDebugging, List<String> extraCommandLineArgs) throws CoreException { try { if (launchSemaphore.tryAcquire()) { try { SDBGLaunchConfigWrapper launchConfig = new SDBGLaunchConfigWrapper(configuration); launchConfig.markAsLaunched(); monitor.beginTask("Launching Chrome...", enableDebugging ? 7 : 2); // avg: 0.434 sec (old: 0.597) LogTimer timer = new LogTimer("Chrome debug startup"); // avg: 55ms timer.startTask("Chrome startup"); // for now, check if browser is open, and connection is alive boolean restart = browserProcess == null || isProcessTerminated(browserProcess) || WebkitDebugTarget.getActiveTarget() == null || !WebkitDebugTarget.getActiveTarget().canTerminate(); // we only re-cycle the debug connection if we're launching the same launch configuration if (!restart) { if (!WebkitDebugTarget.getActiveTarget() .getLaunch() .getLaunchConfiguration() .equals(launch.getLaunchConfiguration())) { restart = true; } } if (!restart) { if (enableDebugging != WebkitDebugTarget.getActiveTarget().getEnableBreakpoints()) { restart = true; } } CoreLaunchUtils.removeTerminatedLaunches(); File browserExecutable = getBrowserExecutable(); if (!restart && url != null && resourceResolver != null) { DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch); try { WebkitDebugTarget.getActiveTarget() .navigateToUrl( launch.getLaunchConfiguration(), url, true /*enableBreakpoints*/, resourceResolver); } catch (IOException e) { SDBGDebugCorePlugin.logError(e); } } else { terminateExistingBrowserProcess(); StringBuilder processDescription = new StringBuilder(); int[] devToolsPortNumberHolder = new int[1]; ListeningStream browserOutput = startNewBrowserProcess( launchConfig, url, monitor, enableDebugging, processDescription, extraCommandLineArgs, devToolsPortNumberHolder); sleep(100); monitor.worked(1); if (isProcessTerminated(browserProcess)) { SDBGDebugCorePlugin.logError("Browser output: " + browserOutput.toString()); throw new CoreException( new Status( IStatus.ERROR, SDBGDebugCorePlugin.PLUGIN_ID, "Could not launch browser - process terminated on startup" + getProcessStreamMessage(browserOutput.toString()))); } if (enableDebugging) { connectToChromiumDebug( browserExecutable.getName(), launch, launchConfig, url, monitor, browserProcess, timer, true /*enableBreakpoints*/, null, devToolsPortNumberHolder[0], 20 * 1000L /*maxStartupDelay*/, browserOutput, processDescription.toString(), resourceResolver, browserTabChooser, false /*remote*/); } else { registerProcess( launch, launchConfig, DebugPlugin.newProcess( launch, browserProcess, browserExecutable.getName() + " - run only, debugging DISABLED (" + new Date() + ")"), processDescription.toString()); } } DebugUIHelper.getHelper().activateApplication(browserExecutable, "Chrome"); timer.stopTask(); timer.stopTimer(); monitor.done(); } finally { launchSemaphore.release(); } } } catch (CoreException e) { DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch); throw e; } }
public WebkitDebugTarget connect( ILaunch launch, ILaunchConfiguration configuration, IResourceResolver resourceResolver, IDeviceChooser deviceChooser, IBrowserTabChooser browserTabChooser, IProgressMonitor monitor) throws CoreException { try { SDBGLaunchConfigWrapper launchConfig = new SDBGLaunchConfigWrapper(configuration); LogTimer timer = new LogTimer("Chrome debug connect"); try { timer.startTask("connect"); try { launchConfig.markAsLaunched(); List<? extends IDeviceInfo> devices = adbManager.getDevices(); if (devices.isEmpty()) { throw new DebugException( new Status( IStatus.ERROR, SDBGDebugCorePlugin.PLUGIN_ID, "No USB-attached Android devices found.\n\nPlease make sure you have enabled USB debugging on your device and you have attached it to the PC via USB.")); } IDeviceInfo device = deviceChooser.chooseDevice(devices); if (device != null) { int port = NetUtils.findUnusedPort(DEVTOOLS_PORT_NUMBER); MobileBrowserUtils.addChromiumForward(adbManager, device.getId(), port); try { final String url = launchConfig.getUrl(); boolean launchTab = launchConfig.isLaunchTabWithUrl() && url != null && url.length() > 0; if (launchTab) { MobileBrowserUtils.launchChromeBrowser(adbManager, device.getId()); IBrowserTabInfo tab = getChromiumTab( null /*runtimeProcess*/, new IBrowserTabChooser() { @Override public IBrowserTabInfo chooseTab(List<? extends IBrowserTabInfo> tabs) throws CoreException { for (IBrowserTabInfo tab : tabs) { if (tab.getUrl() != null && tab.getUrl().toLowerCase().contains(url.toLowerCase())) { return tab; } } return null; } }, "127.0.0.1", port, 10 * 1000L /*maxStartupDelay*/, null /*output*/); if (tab == null) { MobileBrowserUtils.launchChromeBrowser( adbManager, device.getId(), launchConfig.getUrl()); } } return connectToChromiumDebug( "Mobile Chrome Remote Connection", launch, launchConfig, null /*url*/, monitor, null /*runtimeProcess*/, timer, true /*enableBreakpoints*/, "127.0.0.1", port, launchTab ? 10 * 1000L : 0L /*maxStartupDelay*/, null /*browserOutput*/, null /*processDescription*/, resourceResolver, browserTabChooser, true /*remote*/); } catch (IOException e) { adbManager.removeAllForwards(); throw new CoreException( new Status( IStatus.ERROR, SDBGDebugCorePlugin.PLUGIN_ID, "Unable to connect to debugger in Chrome: " + e.getMessage(), e)); } catch (CoreException e) { adbManager.removeAllForwards(); throw e; } } else { throw new DebugException( new Status( IStatus.INFO, SDBGDebugCorePlugin.PLUGIN_ID, "No Android device was chosen. Connection cancelled.")); } } finally { timer.stopTask(); } } finally { timer.stopTimer(); } } catch (CoreException e) { DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch); throw e; } }
/** * @param launchConfig * @param url * @param monitor * @param enableDebugging * @param browserLocation * @param browserName * @throws CoreException */ private ListeningStream startNewBrowserProcess( SDBGLaunchConfigWrapper launchConfig, String url, IProgressMonitor monitor, boolean enableDebugging, StringBuilder argDescription, List<String> extraArguments, int[] devToolsPortNumberHolder) throws CoreException { Process process = null; monitor.worked(1); ProcessBuilder builder = new ProcessBuilder(); Map<String, String> env = builder.environment(); // Due to differences in 32bit and 64 bit environments, dartium 32bit launch does not work on // linux with this property. env.remove("LD_LIBRARY_PATH"); Map<String, String> wrapperEnv = launchConfig.getEnvironment(); if (!wrapperEnv.isEmpty()) { for (String key : wrapperEnv.keySet()) { env.put(key, wrapperEnv.get(key)); } } int devToolsPortNumber = -1; if (enableDebugging) { devToolsPortNumber = NetUtils.findUnusedPort(DEVTOOLS_PORT_NUMBER); if (devToolsPortNumber == -1) { throw new CoreException( new Status( IStatus.ERROR, SDBGDebugCorePlugin.PLUGIN_ID, "Unable to locate an available port for the browser debugger")); } } devToolsPortNumberHolder[0] = devToolsPortNumber; List<String> arguments = buildArgumentsList( launchConfig, enableDebugging && url != null ? INITIAL_PAGE : url, devToolsPortNumber, extraArguments); builder.command(arguments); builder.redirectErrorStream(true); describe(arguments, argDescription); try { process = builder.start(); } catch (IOException e) { SDBGDebugCorePlugin.logError("Exception while starting browser", e); throw new CoreException( new Status( IStatus.ERROR, SDBGDebugCorePlugin.PLUGIN_ID, "Could not launch browser: " + e.toString())); } browserProcess = process; return readFromProcessPipes(browserProcess.getInputStream()); }