Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1294: WebRoot folder can now be set when debugging a URL #1306

Merged
merged 4 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.jface.dialogs.ErrorDialog;
Expand All @@ -29,6 +30,7 @@

public class AbstractHTMLDebugDelegate extends DSPLaunchDelegate {
public static final String ARGUMENTS = "runtimeArgs"; //$NON-NLS-1$
public static final String WEBROOT = "webRoot";

public void launchWithParameters(ILaunchConfiguration configuration, String mode, ILaunch launch,
IProgressMonitor monitor, Map<String, Object> param, File debugAdapter) throws CoreException {
Expand All @@ -39,6 +41,12 @@ public void launchWithParameters(ILaunchConfiguration configuration, String mode
monitor);
builder.setLaunchDebugAdapter(NodeJSManager.getNodeJsLocation().getAbsolutePath(), debugCmdArgs);
builder.setMonitorDebugAdapter(configuration.getAttribute(DSPPlugin.ATTR_DSP_MONITOR_DEBUG_ADAPTER, false));

//If webRoot is set -> Inform DSPLaunchDelegate
if (!configuration.getAttribute(WEBROOT, "").isBlank()) {
param.put(WEBROOT, VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(configuration.getAttribute(WEBROOT,"")));
}

builder.setDspParameters(param);

super.launch(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.wildwebdeveloper.debug;

import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
import static org.eclipse.wildwebdeveloper.debug.SelectionUtils.getSelectedFile;
import static org.eclipse.wildwebdeveloper.debug.SelectionUtils.getSelectedProject;
import static org.eclipse.wildwebdeveloper.debug.SelectionUtils.pathOrEmpty;
Expand All @@ -21,13 +22,19 @@
import java.net.URL;
import java.text.MessageFormat;

import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.fieldassist.ControlDecoration;
import org.eclipse.jface.fieldassist.FieldDecoration;
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
Expand All @@ -41,20 +48,29 @@
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
import org.eclipse.ui.model.WorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider;
import org.eclipse.ui.views.navigator.ResourceComparator;
import org.eclipse.wildwebdeveloper.Activator;
import org.eclipse.wildwebdeveloper.debug.chrome.ChromeRunDAPDebugDelegate;
import org.eclipse.wildwebdeveloper.debug.chrome.ChromeRunDebugLaunchShortcut;

public abstract class AbstractRunHTMLDebugTab extends AbstractLaunchConfigurationTab {

private Text programPathText;
private Text argumentsText;
private Text workingDirectoryText;
protected Composite resComposite;
private Text urlText;
private ControlDecoration urlDecoration;
private Text webRootText;
private ControlDecoration webRootDecoration;
private Button webRootProjectSelectButton;
private Button webRootFilesystemSelectButton;
protected AbstractDebugAdapterLaunchShortcut shortcut = new ChromeRunDebugLaunchShortcut();
private Button filePath;
private ControlDecoration decoration;
private ControlDecoration fileDecoration;
private Button fileRadio;
private Button urlRadio;

Expand All @@ -64,29 +80,30 @@ public AbstractRunHTMLDebugTab() {
@Override
public void createControl(Composite parent) {
resComposite = new Composite(parent, SWT.NONE);
resComposite.setLayout(new GridLayout(3, false));
resComposite.setLayout(new GridLayout(4, false));

fileRadio = createRadioButton(resComposite, Messages.FirefoxDebugTab_File);
fileRadio.setToolTipText(Messages.AbstractRunHTMLDebugTab_fileRadioToolTip);
fileRadio.setLayoutData(new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false));
fileRadio.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
urlText.setEnabled(false);
webRootText.setEnabled(false);
webRootProjectSelectButton.setEnabled(false);
webRootFilesystemSelectButton.setEnabled(false);
programPathText.setEnabled(true);
filePath.setEnabled(true);
validateProgramPath();
setDirty(true);
validateProgramPathAndURL();
updateLaunchConfigurationDialog();
}));

this.programPathText = new Text(resComposite, SWT.BORDER);
this.programPathText.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
decoration = new ControlDecoration(programPathText, SWT.TOP | SWT.LEFT);
this.programPathText.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false, 2, 1));
fileDecoration = new ControlDecoration(programPathText, SWT.TOP | SWT.LEFT);
FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
.getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
decoration.setImage(fieldDecoration.getImage());
fileDecoration.setImage(fieldDecoration.getImage());
this.programPathText.addModifyListener(event -> {
setDirty(true);
validateProgramPath();
validateProgramPathAndURL();
updateLaunchConfigurationDialog();
});
filePath = new Button(resComposite, SWT.PUSH);
Expand All @@ -98,8 +115,6 @@ public void createControl(Composite parent) {
String path = filePathDialog.open();
if (path != null) {
programPathText.setText(path);
setDirty(true);
updateLaunchConfigurationDialog();
}
}));

Expand All @@ -110,32 +125,91 @@ public void createControl(Composite parent) {
programPathText.setEnabled(false);
filePath.setEnabled(false);
urlText.setEnabled(true);
decoration.hide();
setDirty(true);
webRootText.setEnabled(true);
webRootProjectSelectButton.setEnabled(true);
webRootFilesystemSelectButton.setEnabled(true);
validateProgramPathAndURL();
updateLaunchConfigurationDialog();
}));
urlText = new Text(resComposite, SWT.BORDER);
GridData urlTextGD = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
urlTextGD.horizontalSpan = 2;
urlTextGD.horizontalSpan = 3;
urlText.setLayoutData(urlTextGD);
urlDecoration = new ControlDecoration(urlText, SWT.TOP | SWT.LEFT);
urlDecoration.setImage(fieldDecoration.getImage());
urlText.addModifyListener(e -> {
setDirty(true);
validateProgramPath();
validateProgramPathAndURL();
updateLaunchConfigurationDialog();
});

new Label(resComposite, SWT.NONE).setText(Messages.AbstractRunHTMLDebugTab_webRoot_folder);
webRootText = new Text(resComposite, SWT.BORDER);
webRootText.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
webRootDecoration = new ControlDecoration(webRootText, SWT.TOP | SWT.LEFT);
webRootDecoration.setImage(fieldDecoration.getImage());
webRootText.addModifyListener(e -> {
validateProgramPathAndURL();
updateLaunchConfigurationDialog();
});
webRootProjectSelectButton = new Button(resComposite, SWT.PUSH);
webRootProjectSelectButton.setText(Messages.AbstractRunHTMLDebugTab_browse_workspace);
webRootProjectSelectButton.addSelectionListener(widgetSelectedAdapter(e -> {
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(),
new WorkbenchContentProvider());
dialog.setTitle(Messages.AbstractRunHTMLDebugTab_select_webroot);
dialog.setMessage(Messages.AbstractRunHTMLDebugTab_select_webroot);
dialog.setValidator(selection -> {
//Ok-button is only activated after the user has selected something
if (selection.length == 0) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0,
"", null);
}
for (Object f : selection) {
if (!(f instanceof IProject || f instanceof IFolder)) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0,
"Must select a project or a folder", null); //$NON-NLS-1$
}
}
return new Status(IStatus.OK, Activator.PLUGIN_ID, 0,
"", null);
});
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
if (dialog.open() == IDialogConstants.OK_ID) {
IResource resource = (IResource) dialog.getFirstResult();
if (resource != null) {
String arg = resource.getFullPath().toString();
String fileLoc = VariablesPlugin.getDefault().getStringVariableManager()
.generateVariableExpression("workspace_loc", arg); //$NON-NLS-1$
webRootText.setText(fileLoc);
}
}
}));
webRootFilesystemSelectButton = new Button(resComposite, SWT.PUSH);
webRootFilesystemSelectButton.setText(Messages.AbstractRunHTMLDebugTab_browse);
webRootFilesystemSelectButton.addSelectionListener(SelectionListener.widgetSelectedAdapter((e) -> {
DirectoryDialog directoryDialog = new DirectoryDialog(resComposite.getShell());
directoryDialog.setFilterPath(ResourcesPlugin.getWorkspace().getRoot().getLocation().toString());
directoryDialog.setText(Messages.AbstractRunHTMLDebugTab_select_webroot);
String path = directoryDialog.open();
if (path != null) {
webRootText.setText(path);
}
}));


new Label(resComposite, SWT.NONE).setText(Messages.RunProgramTab_argument);
this.argumentsText = new Text(resComposite, SWT.BORDER);
GridData argsGD = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
argsGD.horizontalSpan = 2;
argsGD.horizontalSpan = 3;
this.argumentsText.setLayoutData(argsGD);
this.argumentsText.addModifyListener(e -> {
setDirty(true);
updateLaunchConfigurationDialog();
});
new Label(resComposite, SWT.NONE).setText(Messages.RunProgramTab_workingDirectory);
this.workingDirectoryText = new Text(resComposite, SWT.BORDER);
this.workingDirectoryText.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
this.workingDirectoryText.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false, 2, 1));
this.workingDirectoryText.addModifyListener(e -> {
setDirty(true);
updateLaunchConfigurationDialog();
Expand All @@ -156,8 +230,13 @@ public void createControl(Composite parent) {
setControl(resComposite);
}

private void validateProgramPath() {
private void validateProgramPathAndURL() {
setDirty(true);

setErrorMessage(null);
fileDecoration.hide();
urlDecoration.hide();
webRootDecoration.hide();

String errorMessage = null;
if (fileRadio.getSelection()) {
Expand All @@ -175,6 +254,13 @@ private void validateProgramPath() {
} catch (CoreException ex) {
errorMessage = ex.getMessage();
}

if (errorMessage != null) {
setErrorMessage(errorMessage);
fileDecoration.setDescriptionText(errorMessage);
fileDecoration.show();
}

} else if (urlRadio.getSelection()) {
if (urlText.getText().length() > 0) {
try {
Expand All @@ -183,19 +269,21 @@ private void validateProgramPath() {
errorMessage = MessageFormat.format(
Messages.RunProgramTab_error_malformedUR,
ex.getMessage());
urlDecoration.setDescriptionText(errorMessage);
urlDecoration.show();
}
if(webRootText.getText().isBlank()) {
Si-So marked this conversation as resolved.
Show resolved Hide resolved
errorMessage = Messages.AbstractRunHTMLDebugTab_cannot_debug_without_webroot;
webRootDecoration.setDescriptionText(errorMessage);
webRootDecoration.show();
}

if (errorMessage != null) {
setErrorMessage(errorMessage);
}
}
}

if (errorMessage != null) {
setErrorMessage(errorMessage);
decoration.setDescriptionText(errorMessage);
decoration.show();
} else {
setErrorMessage(null);
decoration.hide();
}

updateLaunchConfigurationDialog();
}

Expand All @@ -214,15 +302,22 @@ public void initializeFrom(ILaunchConfiguration configuration) {
this.workingDirectoryText.setText(
configuration.getAttribute(DebugPlugin.ATTR_WORKING_DIRECTORY, pathOrEmpty(getSelectedProject())));
this.urlText.setText(configuration.getAttribute(ChromeRunDAPDebugDelegate.URL, "")); //$NON-NLS-1$
this.webRootText.setText(configuration.getAttribute(AbstractHTMLDebugDelegate.WEBROOT, ""));
if (urlText.getText().isEmpty()) {
fileRadio.setSelection(true);
urlText.setEnabled(false);
webRootText.setEnabled(false);
webRootProjectSelectButton.setEnabled(false);
webRootFilesystemSelectButton.setEnabled(false);
} else {
programPathText.setEnabled(false);
filePath.setEnabled(false);
urlText.setEnabled(true);
webRootText.setEnabled(true);
webRootProjectSelectButton.setEnabled(true);
webRootFilesystemSelectButton.setEnabled(true);
urlRadio.setSelection(true);
decoration.hide();
fileDecoration.hide();
}
} catch (CoreException e) {
Activator.getDefault().getLog().log(e.getStatus());
Expand All @@ -238,6 +333,7 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) {
} else if (urlText.isEnabled()) {
configuration.setAttribute(ChromeRunDAPDebugDelegate.URL, urlText.getText());
configuration.setAttribute(LaunchConstants.PROGRAM, "");
configuration.setAttribute(AbstractHTMLDebugDelegate.WEBROOT, this.webRootText.getText());
}

configuration.setAttribute(AbstractHTMLDebugDelegate.ARGUMENTS, this.argumentsText.getText());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.wildwebdeveloper.debug.messages"; //$NON-NLS-1$
public static String AbstractRunHTMLDebugTab_browse;
public static String AbstractRunHTMLDebugTab_fileRadioToolTip;
public static String AbstractRunHTMLDebugTab_webRoot_folder;
public static String AbstractRunHTMLDebugTab_browse_workspace;
public static String AbstractRunHTMLDebugTab_select_webroot;
public static String AbstractRunHTMLDebugTab_cannot_debug_without_webroot;
public static String AttachTab_address;
public static String AttachTab_port;
public static String AttachTab_title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
String url = configuration.getAttribute(ChromeRunDAPDebugDelegate.URL, "");
if (!url.isEmpty()) {
param.put(ChromeRunDAPDebugDelegate.URL, url);
File projectDirectory = new File(VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(configuration.getAttribute(DebugPlugin.ATTR_WORKING_DIRECTORY, "")));
param.put("webRoot", projectDirectory.getAbsolutePath());
} else {
param.put(FILE, VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(configuration.getAttribute(LaunchConstants.PROGRAM, "No program path set").trim())); //$NON-NLS-1$
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
################################################################
AbstractRunHTMLDebugTab_browse=\ud83d\udcc2 Browse...
AbstractRunHTMLDebugTab_fileRadioToolTip=The local .html file to debug.
AbstractRunHTMLDebugTab_webRoot_folder=WebRoot Folder
AbstractRunHTMLDebugTab_browse_workspace=\ud83d\udcc2 Browse workspace...
AbstractRunHTMLDebugTab_select_webroot=Select the root folder of your web application
AbstractRunHTMLDebugTab_cannot_debug_without_webroot=Without specifying the webRoot folder, no breakpoints will be triggered.
AttachTab_address=Address:
AttachTab_port=Port:
AttachTab_title=\ud83d\udd17 Attach
Expand Down