Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralopezvenegas2016-04-28 17:04:56 +0000
committerIlya Buziuk2016-04-28 22:21:03 +0000
commitee10cb689ad7c100f079b5cf34c7c7be09c0fee7 (patch)
treebffdb9291e7e2ecbb5783891fa4029ddf7c2d3cb
parenta143359a3c4557671aaee50b1c382bbba3c82a3e (diff)
downloadwebtools.jsdt-ee10cb689ad7c100f079b5cf34c7c7be09c0fee7.tar.gz
webtools.jsdt-ee10cb689ad7c100f079b5cf34c7c7be09c0fee7.tar.xz
webtools.jsdt-ee10cb689ad7c100f079b5cf34c7c7be09c0fee7.zip
Bug 492478 - Node.js launch available for closed/deleted projects
Added a Project field in Node.js main tab, included some validations for the new project field and also set mapped resources. Change-Id: I438a4df7c37ed78f25a4601df3a73582b5d9cdde Signed-off-by: alopezvenegas <adalbert@mx1.ibm.com>
-rw-r--r--bundles/org.eclipse.wst.jsdt.chromium.debug.core/src/org/eclipse/wst/jsdt/chromium/debug/core/ChromiumSourceComputer.java21
-rw-r--r--bundles/org.eclipse.wst.jsdt.chromium.debug.core/src/org/eclipse/wst/jsdt/chromium/debug/core/model/LaunchParams.java2
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/Messages.java7
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/NodeLaunchConfigurationDelegate.java10
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/shortcut/NodeLaunch.java16
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeLaunchArgumentsTab.java51
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeLaunchMainTab.java221
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeWorkingDirectoryBlock.java21
-rw-r--r--nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/messages.properties9
9 files changed, 243 insertions, 115 deletions
diff --git a/bundles/org.eclipse.wst.jsdt.chromium.debug.core/src/org/eclipse/wst/jsdt/chromium/debug/core/ChromiumSourceComputer.java b/bundles/org.eclipse.wst.jsdt.chromium.debug.core/src/org/eclipse/wst/jsdt/chromium/debug/core/ChromiumSourceComputer.java
index 5d64f3344..16c0c2c6b 100644
--- a/bundles/org.eclipse.wst.jsdt.chromium.debug.core/src/org/eclipse/wst/jsdt/chromium/debug/core/ChromiumSourceComputer.java
+++ b/bundles/org.eclipse.wst.jsdt.chromium.debug.core/src/org/eclipse/wst/jsdt/chromium/debug/core/ChromiumSourceComputer.java
@@ -33,12 +33,13 @@ public class ChromiumSourceComputer implements ISourcePathComputerDelegate {
throws CoreException {
List<ISourceContainer> containers = new ArrayList<ISourceContainer>();
- String projectPath = configuration.getAttribute(LaunchParams.ATTR_APP_PROJECT, (String) null);
- if (projectPath != null) {
- IProject project = getProject(projectPath);
+ String projectName = configuration.getAttribute(LaunchParams.ATTR_APP_PROJECT, (String) null);
+ if (projectName != null) {
+ IProject project = getProject(projectName);
if (project != null && project.isAccessible()) {
+ String path = project.getLocation().toOSString();
// {@link SourceNameMapperContainer} for projects available in the workspace
- SourceNameMapperContainer workspaceConatiner = createWorkspaceSourceContainer(project, projectPath);
+ SourceNameMapperContainer workspaceConatiner = createWorkspaceSourceContainer(project, path);
containers.add(workspaceConatiner);
}
}
@@ -50,19 +51,13 @@ public class ChromiumSourceComputer implements ISourcePathComputerDelegate {
return containers.toArray(new ISourceContainer[containers.size()]);
}
- private IProject getProject(String path) {
- IProject project = null;
- File file = new File(path);
- if (file.exists()) {
- String projectName = file.getName();
- project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
- }
- return project;
+ private IProject getProject(String name) {
+ return ResourcesPlugin.getWorkspace().getRoot().getProject(name);
}
private SourceNameMapperContainer createWorkspaceSourceContainer(IProject project, String path) {
// Using absolute path as a mapping prefix for project
- return new SourceNameMapperContainer(path + System.getProperty("file.separator"),
+ return new SourceNameMapperContainer(path + System.getProperty("file.separator"), //$NON-NLS-1$
new ProjectSourceContainer(project, true));
}
diff --git a/bundles/org.eclipse.wst.jsdt.chromium.debug.core/src/org/eclipse/wst/jsdt/chromium/debug/core/model/LaunchParams.java b/bundles/org.eclipse.wst.jsdt.chromium.debug.core/src/org/eclipse/wst/jsdt/chromium/debug/core/model/LaunchParams.java
index 15621a85c..1339cab42 100644
--- a/bundles/org.eclipse.wst.jsdt.chromium.debug.core/src/org/eclipse/wst/jsdt/chromium/debug/core/model/LaunchParams.java
+++ b/bundles/org.eclipse.wst.jsdt.chromium.debug.core/src/org/eclipse/wst/jsdt/chromium/debug/core/model/LaunchParams.java
@@ -39,7 +39,7 @@ public class LaunchParams {
public static final String WIP_BACKEND_ID = "wip_backend_id"; //$NON-NLS-1$
// project attribute from {@link NodeConstants} required for debugging via JSDT editor
- public static final String ATTR_APP_PROJECT = "attr_app_project";
+ public static final String ATTR_APP_PROJECT = "attr_app_project"; //$NON-NLS-1$
// PREDEFINED_SOURCE_WRAPPER_IDS see below.
diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/Messages.java b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/Messages.java
index c5b928deb..b2d911b98 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/Messages.java
+++ b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/Messages.java
@@ -24,17 +24,24 @@ public class Messages extends NLS {
public static String LAUNCH_CONFIGURATION_ARGUMENTS_TAB_NODE_ARGUMENTS_TEXT;
public static String LAUNCH_CONFIGURATION_ARGUMENTS_TAB_APP_ARGUMENTS_TEXT;
public static String LAUNCH_CONFIGURATION_ARGUMENTS_TAB_VARIABLES_TEXT;
+ public static String LAUNCH_CONFIGURATION_MAIN_TAB_PROJECT_TEXT;
public static String LAUNCH_CONFIGURATION_MAIN_TAB_MAIN_FILE_TEXT;
public static String LAUNCH_CONFIGURATION_MAIN_TAB_CONNECTION_TEXT;
public static String LAUNCH_CONFIGURATION_MAIN_TAB_HOST_TEXT;
public static String LAUNCH_CONFIGURATION_MAIN_TAB_PORT_TEXT;
public static String LAUNCH_CONFIGURATION_MAIN_TAB_DEBUGGER_NETWORK_CONSOLE_TEXT;
public static String LAUNCH_CONFIGURATION_MAIN_TAB_BREAK_TEXT;
+ public static String LAUNCH_CONFIGURATION_MAIN_TAB_BROWSE_BUTTON;
public static String LAUNCH_CONFIGURATION_MAIN_TAB_WORKSPACE_BUTTON;
+ public static String LAUNCH_CONFIGURATION_MAIN_TAB_SELECT_PROJECT_TITLE;
+ public static String LAUNCH_CONFIGURATION_MAIN_TAB_SELECT_PROJECT_DESCRIPTION;
public static String LAUNCH_CONFIGURATION_MAIN_TAB_SELECT_MAIN_FILE_TITLE;
public static String LAUNCH_CONFIGURATION_MAIN_TAB_SELECT_MAIN_FILE_DESCRIPTION;
+ public static String LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_PROJECT_DOES_NOT_EXIST;
+ public static String LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_SPECIFY_PROJECT;
public static String LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_MAIN_FILE_DOES_NOT_EXIST;
public static String LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_SPECIFY_MAIN_FILE;
+ public static String LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_MAIN_FILE_NOT_IN_PROJECT;
public static String LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_SPECIFY_HOST;
public static String LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_INVALID_PORT;
public static String LAUNCH_CONFIGURATION_DELEGATE_CHROMIUM_DEBUGGER_DELAY_TASK;
diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/NodeLaunchConfigurationDelegate.java b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/NodeLaunchConfigurationDelegate.java
index 928848a30..21d03642a 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/NodeLaunchConfigurationDelegate.java
+++ b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/NodeLaunchConfigurationDelegate.java
@@ -13,6 +13,7 @@ package org.eclipse.wst.jsdt.js.node.internal.launch;
import java.io.File;
import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -69,7 +70,6 @@ public class NodeLaunchConfigurationDelegate extends LaunchConfigurationDelegate
}
try {
- String project = configuration.getAttribute(NodeConstants.ATTR_APP_PROJECT, NodeConstants.EMPTY);
String mainTypeName = configuration.getAttribute(NodeConstants.ATTR_APP_PATH, NodeConstants.EMPTY);
// Resolve possible ${workspace_loc} variable
mainTypeName = LaunchConfigurationUtil.resolveValue(mainTypeName);
@@ -126,6 +126,7 @@ public class NodeLaunchConfigurationDelegate extends LaunchConfigurationDelegate
// Launch Chromium V8
if(mode.equals(ILaunchManager.DEBUG_MODE)){
+ String projectName = configuration.getAttribute(NodeConstants.ATTR_APP_PROJECT, NodeConstants.EMPTY);
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfigurationType type = launchManager.getLaunchConfigurationType(NodeConstants.CHROMIUM_LAUNCH_CONFIGURATION_TYPE_ID);
IContainer container = null;
@@ -144,7 +145,7 @@ public class NodeLaunchConfigurationDelegate extends LaunchConfigurationDelegate
chromiumLaunch.setAttribute(NodeConstants.SOURCE_LOOKUP_MODE, NodeConstants.EXACT_MATCH);
- chromiumLaunch.setAttribute(NodeConstants.ATTR_APP_PROJECT, project);
+ chromiumLaunch.setAttribute(NodeConstants.ATTR_APP_PROJECT, projectName);
Display.getDefault().asyncExec(new Runnable() {
@@ -189,7 +190,10 @@ public class NodeLaunchConfigurationDelegate extends LaunchConfigurationDelegate
File workingPath = null;
String workingDirectory = configuration.getAttribute(NodeConstants.ATTR_WORKING_DIRECTORY, NodeConstants.EMPTY);
if (workingDirectory.equals(NodeConstants.EMPTY)) {
- workingDirectory = configuration.getAttribute(NodeConstants.ATTR_APP_PROJECT, NodeConstants.EMPTY);
+ String projectName = configuration.getAttribute(NodeConstants.ATTR_APP_PROJECT, NodeConstants.EMPTY);
+ if (!projectName.equals(NodeConstants.EMPTY)) {
+ workingDirectory = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName).getLocation().toOSString();
+ }
}
if (workingDirectory.length() > 0){
workingDirectory = LaunchConfigurationUtil.resolveValue(workingDirectory);
diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/shortcut/NodeLaunch.java b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/shortcut/NodeLaunch.java
index 7cb8f9c59..d72e22d51 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/shortcut/NodeLaunch.java
+++ b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/shortcut/NodeLaunch.java
@@ -16,7 +16,7 @@ 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.IPath;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
@@ -142,7 +142,19 @@ public class NodeLaunch implements ILaunchShortcut{
IContainer container = null;
ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(container, configName);
workingCopy.setAttribute(NodeConstants.ATTR_APP_PATH, path);
- workingCopy.setAttribute(NodeConstants.ATTR_APP_PROJECT, file.getProject().getLocation().toOSString());
+ workingCopy.setAttribute(NodeConstants.ATTR_APP_PROJECT, file.getProject().getName());
+ workingCopy.setMappedResources(getResource(file.getProject().getName()));
return workingCopy.doSave();
}
+
+ private IResource[] getResource(String projectName){
+ if (projectName.length() > 0) {
+ IStatus status = ResourcesPlugin.getWorkspace().validateName(projectName, IResource.PROJECT);
+ if(status.isOK()){
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ return new IResource[] {project};
+ }
+ }
+ return null;
+ }
}
diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeLaunchArgumentsTab.java b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeLaunchArgumentsTab.java
index ee23e7658..0054af384 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeLaunchArgumentsTab.java
+++ b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeLaunchArgumentsTab.java
@@ -22,7 +22,6 @@ import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
@@ -42,21 +41,23 @@ import org.eclipse.wst.jsdt.js.node.internal.Messages;
*/
public class NodeLaunchArgumentsTab extends AbstractLaunchConfigurationTab {
- protected Text nodeArgumentsText;
- protected Text appArgumentsText;
- protected Button nodeVariablesButton;
- protected Button appVariablesButton;
+ private Text nodeArgumentsText;
+ private Text appArgumentsText;
+ private Button nodeVariablesButton;
+ private Button appVariablesButton;
NodeWorkingDirectoryBlock workingDirectoryBlock = new NodeWorkingDirectoryBlock(NodeConstants.ATTR_WORKING_DIRECTORY);
private ModifyListener modifyListener = new ModifyListener() {
- public void modifyText(ModifyEvent e) {
+ @Override
+ public void modifyText(ModifyEvent e) {
updateLaunchConfigurationDialog();
}
};
private SelectionListener nodeArgsSelectionListener = new SelectionListener() {
- public void widgetSelected(SelectionEvent e) {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell());
dialog.open();
String variable = dialog.getVariableExpression();
@@ -71,7 +72,8 @@ public class NodeLaunchArgumentsTab extends AbstractLaunchConfigurationTab {
};
private SelectionListener appArgsSelectionListener = new SelectionListener() {
- public void widgetSelected(SelectionEvent e) {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell());
dialog.open();
String variable = dialog.getVariableExpression();
@@ -163,11 +165,13 @@ public class NodeLaunchArgumentsTab extends AbstractLaunchConfigurationTab {
workingDirectoryBlock.createControl(parent);
}
- public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
+ @Override
+ public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
workingDirectoryBlock.setDefaults(configuration);
}
- public void initializeFrom(ILaunchConfiguration configuration) {
+ @Override
+ public void initializeFrom(ILaunchConfiguration configuration) {
try {
nodeArgumentsText.setText(configuration.getAttribute(NodeConstants.ATTR_NODE_ARGUMENTS, NodeConstants.EMPTY));
appArgumentsText.setText(configuration.getAttribute(NodeConstants.ATTR_APP_ARGUMENTS, NodeConstants.EMPTY));
@@ -178,24 +182,29 @@ public class NodeLaunchArgumentsTab extends AbstractLaunchConfigurationTab {
}
}
- public void performApply(ILaunchConfigurationWorkingCopy configuration) {
+ @Override
+ public void performApply(ILaunchConfigurationWorkingCopy configuration) {
configuration.setAttribute(NodeConstants.ATTR_NODE_ARGUMENTS, nodeArgumentsText.getText().trim());
configuration.setAttribute(NodeConstants.ATTR_APP_ARGUMENTS, appArgumentsText.getText().trim());
workingDirectoryBlock.performApply(configuration);
}
- public boolean isValid(ILaunchConfiguration launchConfig) {
+
+ @Override
+ public boolean isValid(ILaunchConfiguration launchConfig) {
setErrorMessage(null);
setMessage(null);
return workingDirectoryBlock.isValid(launchConfig);
}
+ @Override
public void setLaunchConfigurationDialog(ILaunchConfigurationDialog dialog){
super.setLaunchConfigurationDialog(dialog);
workingDirectoryBlock.setLaunchConfigurationDialog(dialog);
}
- public String getErrorMessage() {
+ @Override
+ public String getErrorMessage() {
String m = super.getErrorMessage();
if (m == null) {
return workingDirectoryBlock.getErrorMessage();
@@ -203,7 +212,8 @@ public class NodeLaunchArgumentsTab extends AbstractLaunchConfigurationTab {
return m;
}
- public String getMessage() {
+ @Override
+ public String getMessage() {
String m = super.getMessage();
if (m == null) {
return workingDirectoryBlock.getMessage();
@@ -211,22 +221,13 @@ public class NodeLaunchArgumentsTab extends AbstractLaunchConfigurationTab {
return m;
}
- public Composite createComposite(Composite parent, Font font, int columns, int hspan, int fill) {
- Composite composite = new Composite(parent, SWT.NONE);
- composite.setLayout(new GridLayout(columns, false));
- composite.setFont(font);
- GridData gridData = new GridData(fill);
- gridData.horizontalSpan = hspan;
- composite.setLayoutData(gridData);
- return composite;
- }
-
@Override
public Image getImage() {
return ImageResource.getImage(ImageResource.IMG_ARGUMENTS);
}
- public String getName() {
+ @Override
+ public String getName() {
return Messages.LAUNCH_CONFIGURATION_ARGUMENTS_TAB;
}
diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeLaunchMainTab.java b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeLaunchMainTab.java
index ebd9c38de..46e4979ab 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeLaunchMainTab.java
+++ b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeLaunchMainTab.java
@@ -15,8 +15,11 @@ import java.io.File;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
@@ -28,6 +31,7 @@ import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.window.Window;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.ModifyEvent;
@@ -36,7 +40,6 @@ import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
-import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
@@ -64,8 +67,9 @@ import org.eclipse.wst.jsdt.js.node.internal.util.LaunchConfigurationUtil;
public class NodeLaunchMainTab extends AbstractLaunchConfigurationTab {
private Text scriptText;
- private Button searchButton;
- private boolean mainTabEntriesValid;
+ private Button workspaceButton;
+ private Text projectText;
+ private Button browseButton;
// Debug variables
private Label debugPortLabel;
@@ -91,7 +95,6 @@ public class NodeLaunchMainTab extends AbstractLaunchConfigurationTab {
}
};
- //
private VerifyListener onlyDigitsListener = new VerifyListener() {
@Override
public void verifyText(VerifyEvent e) {
@@ -131,7 +134,8 @@ public class NodeLaunchMainTab extends AbstractLaunchConfigurationTab {
layout.numColumns = 1;
composite.setLayout(layout);
- createProgramGroup(composite);
+ createProjectGroup(composite);
+ createMainFileGroup(composite);
if (mode.equals(ILaunchManager.DEBUG_MODE)) {
createDebugSpecificsGroup(composite);
}
@@ -147,7 +151,6 @@ public class NodeLaunchMainTab extends AbstractLaunchConfigurationTab {
connectionGroup.setLayout(new GridLayout(1, false));
connectionGroup.setFont(parent.getFont());
- // Create
debugHostLabel = new Label(connectionGroup, SWT.NONE);
debugHostLabel.setText(Messages.LAUNCH_CONFIGURATION_MAIN_TAB_HOST_TEXT);
debugHostText = new Text(connectionGroup, SWT.SINGLE | SWT.BORDER);
@@ -171,48 +174,120 @@ public class NodeLaunchMainTab extends AbstractLaunchConfigurationTab {
Messages.LAUNCH_CONFIGURATION_MAIN_TAB_DEBUGGER_NETWORK_CONSOLE_TEXT);
debugAddNetworkConsoleButton.addSelectionListener(selectionListener);
}
+
+ private void createProjectGroup(Composite parent) {
+ Group projectGroup = new Group(parent, SWT.NONE);
+ projectGroup.setText(Messages.LAUNCH_CONFIGURATION_MAIN_TAB_PROJECT_TEXT);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ projectGroup.setLayoutData(gd);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ projectGroup.setLayout(layout);
+ projectGroup.setFont(parent.getFont());
+
+ projectText = new Text(projectGroup, SWT.SINGLE | SWT.BORDER);
+ projectText.setLayoutData(gd);
+ projectText.setFont(parent.getFont());
+ projectText.addModifyListener(modifyListener);
+ browseButton = createPushButton(projectGroup, Messages.LAUNCH_CONFIGURATION_MAIN_TAB_BROWSE_BUTTON, null);
+ browseButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ String project = browseProjects(Messages.LAUNCH_CONFIGURATION_MAIN_TAB_SELECT_PROJECT_DESCRIPTION);
+ if (project != null && !project.equals(NodeConstants.EMPTY)) {
+ projectText.setText(project);
+ updateLaunchConfigurationDialog();
+ }
+ }
+ });
+ }
- private void createProgramGroup(Composite parent) {
- Group programGroup = new Group(parent, SWT.NONE);
- programGroup.setText(Messages.LAUNCH_CONFIGURATION_MAIN_TAB_MAIN_FILE_TEXT);
+ private void createMainFileGroup(Composite parent) {
+ Group mainFileGroup = new Group(parent, SWT.NONE);
+ mainFileGroup.setText(Messages.LAUNCH_CONFIGURATION_MAIN_TAB_MAIN_FILE_TEXT);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
- programGroup.setLayoutData(gd);
+ mainFileGroup.setLayoutData(gd);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
- programGroup.setLayout(layout);
- programGroup.setFont(parent.getFont());
+ mainFileGroup.setLayout(layout);
+ mainFileGroup.setFont(parent.getFont());
- //Script part
- scriptText = new Text(programGroup, SWT.SINGLE | SWT.BORDER);
+ scriptText = new Text(mainFileGroup, SWT.SINGLE | SWT.BORDER);
scriptText.setLayoutData(gd);
scriptText.setFont(parent.getFont());
scriptText.addModifyListener(modifyListener);
- searchButton = createPushButton(programGroup, Messages.LAUNCH_CONFIGURATION_MAIN_TAB_WORKSPACE_BUTTON, null);
- searchButton.addSelectionListener(new SelectionAdapter() {
+ workspaceButton = createPushButton(mainFileGroup, Messages.LAUNCH_CONFIGURATION_MAIN_TAB_WORKSPACE_BUTTON, null);
+ workspaceButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- String scriptFile = browseWorkspace(Messages.LAUNCH_CONFIGURATION_MAIN_TAB_SELECT_MAIN_FILE_DESCRIPTION);
- if (scriptFile != null && !scriptFile.equals(NodeConstants.EMPTY)) {
- scriptText.setText(scriptFile);
- updateLaunchConfigurationDialog();
+ String script = browseWorkspace(Messages.LAUNCH_CONFIGURATION_MAIN_TAB_SELECT_MAIN_FILE_DESCRIPTION);
+ if (script != null && !script.equals(NodeConstants.EMPTY)) {
+ scriptText.setText(script);
+ // Set project to be the same as the main file
+ String scriptLocation = null;
+ try {
+ scriptLocation = LaunchConfigurationUtil.resolveValue(script);
+ } catch (CoreException ex) { // Do nothing
+ }
+
+ if(scriptLocation != null){
+ IPath location= Path.fromOSString(scriptLocation);
+ IFile iFile= ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(location);
+ projectText.setText(iFile.getProject().getName());
+ }
}
+ updateLaunchConfigurationDialog();
}
});
}
+
+ private String browseProjects(String description) {
+ ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getControl().getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
+ dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
+ dialog.setAllowMultiple(false);
+ dialog.addFilter(new ViewerFilter() {
+ @Override
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ if (element instanceof IProject) {
+ IProject project = (IProject) element;
+ if (project != null && project.exists() && project.isOpen()){
+ return true;
+ }
+ }
+ return false;
+ }
+ });
+ dialog.setTitle(Messages.LAUNCH_CONFIGURATION_MAIN_TAB_SELECT_PROJECT_TITLE);
+ dialog.setMessage(description);
+ dialog.setValidator(new ISelectionStatusValidator() {
+ @Override
+ public IStatus validate(Object[] selection) {
+ if (selection != null && selection.length > 0 && selection[0] instanceof IProject){
+ return new Status(IStatus.OK, NodePlugin.PLUGIN_ID, IStatus.OK, NodeConstants.EMPTY, null);
+ }
+ return new Status(IStatus.ERROR, NodePlugin.PLUGIN_ID, IStatus.ERROR, NodeConstants.EMPTY, null);
+ }
+ });
+
+ if (dialog.open() == Window.OK) {
+ IProject project = (IProject) dialog.getFirstResult();
+ if (project != null) {
+ return project.getName();
+ }
+ }
+ return null;
+ }
- protected String browseWorkspace(String description) {
+ private String browseWorkspace(String description) {
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getControl().getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
dialog.setAllowMultiple(false);
dialog.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
- if (element instanceof IProject || element instanceof IFolder) {
+ if (element instanceof IProject || element instanceof IFolder || element instanceof IFile) {
return true;
}
- if(element instanceof IFile) {
- return true;
- }
return false;
}
});
@@ -231,8 +306,7 @@ public class NodeLaunchMainTab extends AbstractLaunchConfigurationTab {
if (dialog.open() == Window.OK) {
IFile file = (IFile) dialog.getFirstResult();
if (file != null) {
- return VariablesPlugin.getDefault().getStringVariableManager().generateVariableExpression(
- "workspace_loc", //$NON-NLS-1$
+ return VariablesPlugin.getDefault().getStringVariableManager().generateVariableExpression("workspace_loc", //$NON-NLS-1$
file.getFullPath().toString());
}
}
@@ -246,6 +320,7 @@ public class NodeLaunchMainTab extends AbstractLaunchConfigurationTab {
@Override
public void initializeFrom(ILaunchConfiguration configuration) {
try {
+ projectText.setText(configuration.getAttribute(NodeConstants.ATTR_APP_PROJECT, NodeConstants.EMPTY));
scriptText.setText(configuration.getAttribute(NodeConstants.ATTR_APP_PATH, NodeConstants.EMPTY));
if (getLaunchConfigurationDialog().getMode().equals(ILaunchManager.DEBUG_MODE)) {
debugHostText
@@ -263,6 +338,7 @@ public class NodeLaunchMainTab extends AbstractLaunchConfigurationTab {
@Override
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
+ configuration.setAttribute(NodeConstants.ATTR_APP_PROJECT, projectText.getText().trim());
configuration.setAttribute(NodeConstants.ATTR_APP_PATH, scriptText.getText().trim());
if (getLaunchConfigurationDialog().getMode().equals(ILaunchManager.DEBUG_MODE)) {
configuration.setAttribute(NodeConstants.ATTR_HOST_FIELD, debugHostText.getText().trim());
@@ -271,31 +347,53 @@ public class NodeLaunchMainTab extends AbstractLaunchConfigurationTab {
debugAddNetworkConsoleButton.getSelection());
configuration.setAttribute(NodeConstants.ATTR_BREAK_FIELD, debugBreakButton.getSelection());
}
-
- //Set default working directory
- if(!scriptText.getText().trim().equals(NodeConstants.EMPTY)) {
- File file = new File(scriptText.getText().trim());
- IFile iFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(Path.fromOSString(file.getAbsolutePath()));
- if(iFile != null && iFile.exists()) {
- String project = iFile.getProject().getLocation().toOSString();
- configuration.setAttribute(NodeConstants.ATTR_APP_PROJECT, project);
+
+ //Set mapped resources
+ String projectName = projectText.getText().trim();
+ configuration.setMappedResources(getResource(projectName));
+ }
+
+ private IResource[] getResource(String projectName){
+ if (projectName.length() > 0) {
+ IStatus status = ResourcesPlugin.getWorkspace().validateName(projectName, IResource.PROJECT);
+ if(status.isOK()){
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ return new IResource[] {project};
}
- }
+ }
+ return null;
}
@Override
public boolean isValid(ILaunchConfiguration launchConfig) {
- validateEntries();
- return mainTabEntriesValid;
+ return validateEntries();
}
- protected void validateEntries(){
+ private boolean validateEntries(){
setErrorMessage(null);
- mainTabEntriesValid = true;
-
- String scriptFile = scriptText.getText();
- if (mainTabEntriesValid && scriptFile.length() > 0) {
+ // Validate project
+ String projectName = projectText.getText().trim();
+ if (projectName.length() > 0) {
+ IStatus status = ResourcesPlugin.getWorkspace().validateName(projectName, IResource.PROJECT);
+ if(status.isOK()){
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ if (project == null || !project.exists() || !project.isOpen()){
+ setErrorMessage(Messages.LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_PROJECT_DOES_NOT_EXIST);
+ return false;
+ }
+ } else {
+ setErrorMessage(status.getMessage());
+ return false;
+ }
+ } else {
+ setErrorMessage(Messages.LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_SPECIFY_PROJECT);
+ return false;
+ }
+
+ // Validate main file
+ String scriptFile = scriptText.getText().trim();
+ if (scriptFile.length() > 0) {
// Resolve possible eclipse variables
try {
scriptFile = LaunchConfigurationUtil.resolveValue(scriptFile);
@@ -309,19 +407,29 @@ public class NodeLaunchMainTab extends AbstractLaunchConfigurationTab {
if (file == null || !file.exists() || file.isDirectory()) {
setErrorMessage(Messages.LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_MAIN_FILE_DOES_NOT_EXIST);
- mainTabEntriesValid = false;
+ return false;
+ }
+
+ // Validate main file is contained in selected project
+ IWorkspace workspace= ResourcesPlugin.getWorkspace();
+ IPath location= Path.fromOSString(file.getAbsolutePath());
+ IFile ifile= workspace.getRoot().getFileForLocation(location);
+ if(!ifile.getProject().getName().equals(projectName)){
+ setErrorMessage(NLS.bind(Messages.LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_MAIN_FILE_NOT_IN_PROJECT, projectName));
+ return false;
}
- } else if(mainTabEntriesValid && scriptFile.length() <= 0){
+ } else {
setErrorMessage(Messages.LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_SPECIFY_MAIN_FILE);
- mainTabEntriesValid = false;
+ return false;
}
+ // Debug mode validations
if(getLaunchConfigurationDialog().getMode().equals(ILaunchManager.DEBUG_MODE)){
+ //Validate host
String host = debugHostText.getText();
-
- if (mainTabEntriesValid && host.length() <= 0) {
+ if (host.length() <= 0) {
setErrorMessage(Messages.LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_SPECIFY_HOST);
- mainTabEntriesValid = false;
+ return false;
}
// Validate port range
@@ -331,23 +439,14 @@ public class NodeLaunchMainTab extends AbstractLaunchConfigurationTab {
portNumber = Integer.valueOf(port);
}
- if (mainTabEntriesValid && (port.length() <= 0 || portNumber < 1024 || portNumber > 65535)) {
+ if (port.length() <= 0 || portNumber < 1024 || portNumber > 65535) {
setErrorMessage(Messages.LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_INVALID_PORT);
- mainTabEntriesValid = false;
+ return false;
}
}
+ return true;
}
- public Composite createComposite(Composite parent, Font font, int columns, int hspan, int fill) {
- Composite g = new Composite(parent, SWT.NONE);
- g.setLayout(new GridLayout(columns, false));
- g.setFont(font);
- GridData gd = new GridData(fill);
- gd.horizontalSpan = hspan;
- g.setLayoutData(gd);
- return g;
- }
-
@Override
public Image getImage() {
return ImageResource.getImage(ImageResource.IMG_NODEJS);
diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeWorkingDirectoryBlock.java b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeWorkingDirectoryBlock.java
index 58f517073..cc7cbedd8 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeWorkingDirectoryBlock.java
+++ b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/launch/ui/NodeWorkingDirectoryBlock.java
@@ -10,11 +10,11 @@
*******************************************************************************/
package org.eclipse.wst.jsdt.js.node.internal.launch.ui;
-import java.io.File;
-
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.debug.core.ILaunchConfiguration;
import org.eclipse.debug.ui.WorkingDirectoryBlock;
import org.eclipse.wst.jsdt.js.node.NodePlugin;
@@ -34,18 +34,21 @@ public class NodeWorkingDirectoryBlock extends WorkingDirectoryBlock {
@Override
protected IProject getProject(ILaunchConfiguration launchConfiguration) throws CoreException {
- String projectLocation = NodeConstants.EMPTY;
+ String projectName = NodeConstants.EMPTY;
try {
- projectLocation = launchConfiguration.getAttribute(NodeConstants.ATTR_APP_PROJECT,
+ projectName = launchConfiguration.getAttribute(NodeConstants.ATTR_APP_PROJECT,
NodeConstants.EMPTY);
} catch (CoreException e) {
NodePlugin.logError(e, e.getLocalizedMessage());
}
- if (!projectLocation.equals(NodeConstants.EMPTY)) {
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(new File(projectLocation).getName());
- if (project != null && project.isAccessible()) {
- return project;
- }
+ if (!projectName.equals(NodeConstants.EMPTY)) {
+ IStatus status = ResourcesPlugin.getWorkspace().validateName(projectName, IResource.PROJECT);
+ if(status.isOK()){
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ if (project != null && project.isAccessible()) {
+ return project;
+ }
+ }
}
return null;
}
diff --git a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/messages.properties b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/messages.properties
index 385683d46..ae4ca9bbe 100644
--- a/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/messages.properties
+++ b/nodejs/org.eclipse.wst.jsdt.js.node/src/org/eclipse/wst/jsdt/js/node/internal/messages.properties
@@ -14,17 +14,24 @@ LAUNCH_CONFIGURATION_MAIN_TAB=Main
LAUNCH_CONFIGURATION_ARGUMENTS_TAB_NODE_ARGUMENTS_TEXT=Node arguments
LAUNCH_CONFIGURATION_ARGUMENTS_TAB_APP_ARGUMENTS_TEXT=Application arguments
LAUNCH_CONFIGURATION_ARGUMENTS_TAB_VARIABLES_TEXT=Variables
-LAUNCH_CONFIGURATION_MAIN_TAB_MAIN_FILE_TEXT=Main file
+LAUNCH_CONFIGURATION_MAIN_TAB_PROJECT_TEXT=Project:
+LAUNCH_CONFIGURATION_MAIN_TAB_MAIN_FILE_TEXT=Main file:
LAUNCH_CONFIGURATION_MAIN_TAB_CONNECTION_TEXT=Connection
LAUNCH_CONFIGURATION_MAIN_TAB_HOST_TEXT=Host:
LAUNCH_CONFIGURATION_MAIN_TAB_PORT_TEXT=Port:
LAUNCH_CONFIGURATION_MAIN_TAB_DEBUGGER_NETWORK_CONSOLE_TEXT=Show debugger network communication console
LAUNCH_CONFIGURATION_MAIN_TAB_BREAK_TEXT=Break on the first line
+LAUNCH_CONFIGURATION_MAIN_TAB_BROWSE_BUTTON=Browse...
LAUNCH_CONFIGURATION_MAIN_TAB_WORKSPACE_BUTTON=Workspace...
+LAUNCH_CONFIGURATION_MAIN_TAB_SELECT_PROJECT_TITLE=Select project
+LAUNCH_CONFIGURATION_MAIN_TAB_SELECT_PROJECT_DESCRIPTION=Select a project
LAUNCH_CONFIGURATION_MAIN_TAB_SELECT_MAIN_FILE_TITLE=Select Main file
LAUNCH_CONFIGURATION_MAIN_TAB_SELECT_MAIN_FILE_DESCRIPTION=Select a Javascript Main file
+LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_PROJECT_DOES_NOT_EXIST=Specified project does not exist or is close
+LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_SPECIFY_PROJECT=Specify a project
LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_MAIN_FILE_DOES_NOT_EXIST=Specified file does not exist or is a directory
LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_SPECIFY_MAIN_FILE=Specify a main file
+LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_MAIN_FILE_NOT_IN_PROJECT=Main file not contained in "{0}" project
LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_SPECIFY_HOST=Specify a host
LAUNCH_CONFIGURATION_MAIN_TAB_ERROR_INVALID_PORT=Debug port must be in range 1024 to 65535
LAUNCH_CONFIGURATION_DELEGATE_CHROMIUM_DEBUGGER_DELAY_TASK=Delaying Chromium debugger launch by 5 seconds

Back to the top