Skip to content

Commit

Permalink
Package Chrome + Refactorings
Browse files Browse the repository at this point in the history
Refactorings for debugTab's and DebugDelegates

Signed-off-by: Andrew Obuchowicz <aobuchow@redhat.com>
  • Loading branch information
AObuchow committed Sep 11, 2019
1 parent ba82523 commit 1add0b5
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 316 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,69 @@
/*******************************************************************************
* Copyright (c) 2019 Red Hat Inc. and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Andrew Obuchowicz (Red Hat Inc.)
*******************************************************************************/
package org.eclipse.wildwebdeveloper.debug;

import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.lsp4e.debug.DSPPlugin;
import org.eclipse.lsp4e.debug.launcher.DSPLaunchDelegate;
import org.eclipse.swt.widgets.Display;
import org.eclipse.wildwebdeveloper.Activator;
import org.eclipse.wildwebdeveloper.InitializeLaunchConfigurations;

public final class AbstractDebugDelegate {
public class AbstractDebugDelegate extends DSPLaunchDelegate{
public static final String PROGRAM = "program"; //$NON-NLS-1$
public static final String ARGUMENTS = "runtimeArgs"; //$NON-NLS-1$
public static final String CWD = DebugPlugin.ATTR_WORKING_DIRECTORY;
public static final String CWD = DebugPlugin.ATTR_WORKING_DIRECTORY; //$NON-NLS-1$
public static final String ENV = ILaunchManager.ATTR_ENVIRONMENT_VARIABLES;
public static final String SOURCE_MAPS = "sourceMaps";
public static final String PORT = "port"; //$NON-NLS-1$
public static final String REQUEST = "request"; //$NON-NLS-1$

public void launchWithParameters(ILaunchConfiguration configuration, String mode, ILaunch launch,
IProgressMonitor monitor, Map<String, Object> param, File debugAdapter) throws CoreException {
try {
List<String> debugCmdArgs = Collections.singletonList(debugAdapter.getAbsolutePath());

DSPLaunchDelegateLaunchBuilder builder = new DSPLaunchDelegateLaunchBuilder(configuration, mode, launch,
monitor);
builder.setLaunchDebugAdapter(InitializeLaunchConfigurations.getNodeJsLocation(), debugCmdArgs);
builder.setMonitorDebugAdapter(configuration.getAttribute(DSPPlugin.ATTR_DSP_MONITOR_DEBUG_ADAPTER, false));
builder.setDspParameters(param);

super.launch(builder);
} catch (Exception e) {
IStatus errorStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
Activator.getDefault().getLog().log(errorStatus);
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
ErrorDialog.openError(Display.getDefault().getActiveShell(), "Debug error", e.getMessage(), errorStatus); //$NON-NLS-1$
}
});

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Contributors:
* Mickael Istria (Red Hat Inc.) - initial implementation
*******************************************************************************/
package org.eclipse.wildwebdeveloper.debug.chrome;
package org.eclipse.wildwebdeveloper.debug;

import static org.eclipse.wildwebdeveloper.debug.SelectionUtils.getSelectedFile;
import static org.eclipse.wildwebdeveloper.debug.SelectionUtils.getSelectedProject;
Expand All @@ -19,7 +19,6 @@
import java.io.File;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
Expand All @@ -37,18 +36,16 @@
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wildwebdeveloper.Activator;
import org.eclipse.wildwebdeveloper.debug.AbstractDebugAdapterLaunchShortcut;
import org.eclipse.wildwebdeveloper.debug.AbstractDebugDelegate;
import org.eclipse.wildwebdeveloper.debug.Messages;
import org.eclipse.wildwebdeveloper.debug.chrome.ChromeRunDebugLaunchShortcut;

public class RunHTMLDebugTab extends AbstractLaunchConfigurationTab {

private Text programPathText;
private Text argumentsText;
private Text workingDirectoryText;
private Button verboseConsoleOutput;
Composite resComposite;
private final AbstractDebugAdapterLaunchShortcut shortcut = new ChromeRunDebugLaunchShortcut(); // contains many
protected Composite resComposite;
protected AbstractDebugAdapterLaunchShortcut shortcut = new ChromeRunDebugLaunchShortcut(); // contains many
// utilities

public RunHTMLDebugTab() {
Expand Down Expand Up @@ -149,7 +146,7 @@ public void initializeFrom(ILaunchConfiguration configuration) {
.setText(configuration.getAttribute(AbstractDebugDelegate.PROGRAM, defaultSelectedFile)); // $NON-NLS-1$
this.argumentsText.setText(configuration.getAttribute(AbstractDebugDelegate.ARGUMENTS, "")); //$NON-NLS-1$
this.workingDirectoryText.setText(
configuration.getAttribute(DebugPlugin.ATTR_WORKING_DIRECTORY, pathOrEmpty(getSelectedProject()))); // $NON-NLS-1$
configuration.getAttribute(AbstractDebugDelegate.CWD, pathOrEmpty(getSelectedProject()))); // $NON-NLS-1$
} catch (CoreException e) {
Activator.getDefault().getLog().log(e.getStatus());
}
Expand All @@ -159,7 +156,7 @@ public void initializeFrom(ILaunchConfiguration configuration) {
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
configuration.setAttribute(AbstractDebugDelegate.PROGRAM, this.programPathText.getText());
configuration.setAttribute(AbstractDebugDelegate.ARGUMENTS, this.argumentsText.getText());
configuration.setAttribute(DebugPlugin.ATTR_WORKING_DIRECTORY, this.workingDirectoryText.getText());
configuration.setAttribute(AbstractDebugDelegate.CWD, this.workingDirectoryText.getText());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,19 @@
*******************************************************************************/
package org.eclipse.wildwebdeveloper.debug.chrome;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.lsp4e.debug.DSPPlugin;
import org.eclipse.lsp4e.debug.launcher.DSPLaunchDelegate;
import org.eclipse.swt.widgets.Display;
import org.eclipse.wildwebdeveloper.Activator;
import org.eclipse.wildwebdeveloper.InitializeLaunchConfigurations;
import org.eclipse.wildwebdeveloper.debug.AbstractDebugDelegate;
import org.eclipse.wildwebdeveloper.debug.node.NodeAttachDebugDelegate;

public class ChromeAttachDebugDelegate extends DSPLaunchDelegate {

static final String ID = "org.eclipse.wildwebdeveloper.launchConfiguration.nodeAttach"; //$NON-NLS-1$
public class ChromeAttachDebugDelegate extends AbstractDebugDelegate {
static final String ID = "org.eclipse.wildwebdeveloper.launchConfiguration.chromeRunDebug"; //$NON-NLS-1$

// see https://github.com/Microsoft/vscode-node-debug/blob/master/src/node/nodeDebug.ts LaunchRequestArguments
static final String ADDRESS = "address"; //$NON-NLS-1$
Expand All @@ -54,25 +41,8 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
param.put("webRoot", "/home/aobuchow/Documents/Firefox Debugger Testing");
param.put("url", "https://www.google.ca/");
param.put("runtimeExecutable", "/usr/bin/chromium-browser");
try {
URL fileURL = FileLocator.toFileURL(
getClass().getResource("/language-servers/node_modules/node-debug2/out/src/nodeDebug.js"));
File file = new File("/home/aobuchow/.vscode/extensions/msjsdiag.debugger-for-chrome-4.11.7/out/src/chromeDebug.js");
List<String> debugCmdArgs = Collections.singletonList(file.getAbsolutePath());

DSPLaunchDelegateLaunchBuilder builder = new DSPLaunchDelegateLaunchBuilder(configuration, mode, launch,
monitor);
builder.setLaunchDebugAdapter(InitializeLaunchConfigurations.getNodeJsLocation(), debugCmdArgs);
builder.setMonitorDebugAdapter(configuration.getAttribute(DSPPlugin.ATTR_DSP_MONITOR_DEBUG_ADAPTER, false));
builder.setDspParameters(param);

super.launch(builder);
}
catch (IOException e) {
IStatus errorStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
//Activator.getDefault().getLog().log(errorStatus);
ErrorDialog.openError(Display.getDefault().getActiveShell(), "Debug error", e.getMessage(), errorStatus); //$NON-NLS-1$
}

super.launchWithParameters(configuration, mode, launch, monitor, param, ChromeRunDAPDebugDelegate.findDebugAdapter());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.core.runtime.CoreException;
Expand All @@ -30,17 +30,15 @@
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.lsp4e.debug.DSPPlugin;
import org.eclipse.lsp4e.debug.launcher.DSPLaunchDelegate;
import org.eclipse.swt.widgets.Display;
import org.eclipse.wildwebdeveloper.Activator;
import org.eclipse.wildwebdeveloper.InitializeLaunchConfigurations;
import org.eclipse.wildwebdeveloper.debug.AbstractDebugDelegate;

import com.google.gson.JsonObject;

public class ChromeRunDAPDebugDelegate extends DSPLaunchDelegate {

public class ChromeRunDAPDebugDelegate extends AbstractDebugDelegate {
static final String ID = "org.eclipse.wildwebdeveloper.launchConfiguration.chromeRunDebug"; //$NON-NLS-1$

// see
Expand All @@ -57,7 +55,7 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
Map<String, Object> param = new HashMap<>();

// File to debug
param.put("file", configuration.getAttribute(AbstractDebugDelegate.PROGRAM, "no program path defined"));
param.put("file", configuration.getAttribute(AbstractDebugDelegate.PROGRAM, "no program path defined")); //$NON-NLS-1$
// Chrome executable arguments
String argsString = configuration.getAttribute(AbstractDebugDelegate.ARGUMENTS, "").trim(); //$NON-NLS-1$
if (!argsString.isEmpty()) {
Expand Down Expand Up @@ -87,32 +85,35 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
// is released in VSCode
param.put(AbstractDebugDelegate.SOURCE_MAPS, false);

// TODO: Let user point to the location of their chrome executable
// TODO: Let user point to the location of their Chrome executable
param.put(RUNTIME_EXECUTABLE, findChromeLocation());

if (configuration.getAttribute(VERBOSE, false)) {
param.put(TRACE, VERBOSE);
}

super.launchWithParameters(configuration, mode, launch, monitor, param, findDebugAdapter());
}

static File findDebugAdapter() {
URL fileURL;
try {
URL fileURL = FileLocator.toFileURL(
getClass().getResource("/language-servers/chrome-debug-adapter/package/out/src/chromeDebug.js"));
// "/language-servers/node_modules/vscode-firefox-debug/out/adapter/firefoxDebugAdapter.js"
File file = new File(fileURL.getPath());
List<String> debugCmdArgs = Collections.singletonList(file.getAbsolutePath());

DSPLaunchDelegateLaunchBuilder builder = new DSPLaunchDelegateLaunchBuilder(configuration, mode, launch,
monitor);
builder.setLaunchDebugAdapter(InitializeLaunchConfigurations.getNodeJsLocation(), debugCmdArgs);
builder.setMonitorDebugAdapter(configuration.getAttribute(DSPPlugin.ATTR_DSP_MONITOR_DEBUG_ADAPTER, false));
builder.setDspParameters(param);

super.launch(builder);
} catch (IOException e) {
// TODO: Change location of Chrome Debug Adapter to node_modules folder
fileURL = FileLocator.toFileURL(
ChromeRunDAPDebugDelegate.class.getResource("/language-servers/chrome-debug-adapter/package/out/src/chromeDebug.js"));
return new File(fileURL.toURI());
} catch (IOException | URISyntaxException e) {
IStatus errorStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
Activator.getDefault().getLog().log(errorStatus);
ErrorDialog.openError(Display.getDefault().getActiveShell(), "Debug error", e.getMessage(), errorStatus); //$NON-NLS-1$
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
ErrorDialog.openError(Display.getDefault().getActiveShell(), "Debug error", e.getMessage(), errorStatus); //$NON-NLS-1$
}
});
}
return null;

}

private String findChromeLocation() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
/*******************************************************************************
* Copyright (c) 2019 Red Hat Inc. and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Andrew Obuchowicz (Red Hat Inc.)
*******************************************************************************/
package org.eclipse.wildwebdeveloper.debug.chrome;

import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.wildwebdeveloper.debug.RunHTMLDebugTab;

public class RunChromeDebugTab extends RunHTMLDebugTab {
private Button verboseConsoleOutput;

public RunChromeDebugTab() {
super();
super.shortcut = new ChromeRunDebugLaunchShortcut();
}

@Override
public void createControl(Composite parent) {
super.createControl(parent);


verboseConsoleOutput = new Button(resComposite, SWT.CHECK);
verboseConsoleOutput.setText("Verbose console output");
verboseConsoleOutput.addSelectionListener(SelectionListener.widgetSelectedAdapter((e) -> {
Expand All @@ -26,12 +37,6 @@ public void createControl(Composite parent) {
}));
}


@Override
public void initializeFrom(ILaunchConfiguration configuration) {
super.initializeFrom(configuration);
}

@Override
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
super.performApply(configuration);
Expand Down

0 comments on commit 1add0b5

Please sign in to comment.