Skip to content

Commit 05a882f

Browse files
committed
refs #26 run/debug coffee,litcoffee; #57 running app.js with node-dev,
forever, supervisor, nodemon etc
1 parent 10040cc commit 05a882f

13 files changed

Lines changed: 205 additions & 39 deletions

File tree

org.nodeclipse.debug/README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11

2-
##
2+
## org.nodeclipse.debug
3+
4+
Running and debugging node applications
5+
6+
### Developing
7+
8+
Open `plugin.xml`, in "Testing" section click "Launch an Eclipse application"
9+
10+
#### New Run/debug definition
11+
12+
1. in `plugin.xml` add `LaunchShortcut`
13+
14+
<extension
15+
point= "org.eclipse.debug.ui.launchShortcuts" >
16+
17+
2. create new `public class LaunchShortcutName implements ILaunchShortcut`
18+
319

420
## TODO notes
521

org.nodeclipse.debug/plugin.xml

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
id="org.nodeclipse.debug.launch.LaunchConfigurationType"
2222
modes="run, debug"
2323
name="Node Application">
24+
</launchConfigurationType>
25+
<!-- node run/debug with monitor (not yet used)-->
26+
<launchConfigurationType
27+
delegate="org.nodeclipse.debug.launch.LaunchConfigurationDelegate"
28+
id="org.nodeclipse.debug.launch.LaunchTypeWithMonitor"
29+
modes="run, debug"
30+
name="Node with monitor">
2431
</launchConfigurationType>
2532
<launchConfigurationType
2633
id="org.nodeclipse.debug.launch.LaunchType$StandaloneV8"
@@ -45,7 +52,8 @@
4552
icon= "icons/node.png"
4653
id= "org.nodeclipse.debug.launch.LaunchConfigurationTypeImage" >
4754
</launchConfigurationTypeImage>
48-
</extension>
55+
</extension>
56+
<!-- node run/debug -->
4957
<extension
5058
point= "org.eclipse.debug.ui.launchShortcuts" >
5159
<shortcut
@@ -71,21 +79,57 @@
7179
value= "*.js" >
7280
</test>
7381
</or>
74-
</iterate>
75-
82+
</iterate>
7683
</with>
7784
</enablement>
7885
</contextualLaunch>
7986
</shortcut>
8087
</extension>
88+
<!-- node run/debug with monitor-->
89+
<extension
90+
point= "org.eclipse.debug.ui.launchShortcuts" >
91+
<shortcut
92+
class= "org.nodeclipse.debug.launch.LaunchShortcutWithMonitor"
93+
icon= "icons/node.png"
94+
id= "org.nodeclipse.debug.launch.LaunchShortcutWithMonitor"
95+
label= "Node with monitor"
96+
modes= "run, debug" >
97+
<configurationType
98+
id= "org.nodeclipse.debug.launch.LaunchConfigurationType" >
99+
</configurationType>
100+
<contextualLaunch>
101+
<enablement>
102+
<with
103+
variable= "selection" >
104+
<count
105+
value= "1" >
106+
</count>
107+
<iterate>
108+
<or>
109+
<test
110+
property= "org.eclipse.debug.ui.matchesPattern"
111+
value= "*.js" >
112+
</test>
113+
<test
114+
property= "org.eclipse.debug.ui.matchesPattern"
115+
value= "*.coffee" >
116+
</test>
117+
</or>
118+
</iterate>
119+
</with>
120+
</enablement>
121+
</contextualLaunch>
122+
</shortcut>
123+
</extension>
124+
<!-- coffee run/debug -->
81125
<extension
82126
point= "org.eclipse.debug.ui.launchShortcuts" >
83127
<shortcut
84128
class= "org.nodeclipse.debug.launch.LaunchShortcut"
85129
icon= "icons/coffee.png"
86130
id= "org.nodeclipse.debug.launch.LaunchShortcut"
87131
label= "coffee"
88-
modes= "run" >
132+
modes= "run, debug" >
89133
<configurationType
90134
id= "org.nodeclipse.debug.launch.LaunchConfigurationType" >
91135
</configurationType>
@@ -96,27 +140,22 @@
96140
<count
97141
value= "1" >
98142
</count>
99-
<iterate>
143+
<iterate> <!-- TODO how to? 3 filenameext -->
100144
<or>
101145
<test
102146
property= "org.eclipse.debug.ui.matchesPattern"
103147
value= "*.coffee" >
104148
</test>
105-
</or>
106-
<!-- TODO how to?
107-
<or>
108149
<test
109150
property= "org.eclipse.debug.ui.matchesPattern"
110151
value= "*.litcoffee" >
111152
</test>
112-
</or>
113-
<or>
114153
<test
115154
property= "org.eclipse.debug.ui.matchesPattern"
116155
value= "*.coffee.md" >
117156
</test>
118157
</or>
119-
-->
158+
120159
</iterate>
121160
</with>
122161
</enablement>

org.nodeclipse.debug/src/org/nodeclipse/debug/launch/LaunchConfigurationDelegate.java

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
import org.nodeclipse.ui.Activator;
3232
import org.nodeclipse.ui.preferences.PreferenceConstants;
3333

34+
/**
35+
* launch() implements starting Node and passing all parameters
36+
*
37+
* @author Lamb, Tomoyuki, Pushkar, Paul Vverest
38+
*/
3439
public class LaunchConfigurationDelegate implements
3540
ILaunchConfigurationDelegate {
3641
private static RuntimeProcess nodeProcess = null;
@@ -58,15 +63,21 @@ public void launch(ILaunchConfiguration configuration, String mode,
5863
File nodeFile = new File(nodePath);
5964
if(!nodeFile.exists()){
6065
// If the location is not valid than show a dialog which prompts the user to goto the preferences page
61-
showPreferencesDialog();
66+
showPreferencesDialog("Node.js runtime is not correctly configured.\n\n"
67+
+ "Please goto Window -> Prefrences -> Nodeclipse and configure the correct location");
6268
return;
6369
}
6470

6571
List<String> cmdLine = new ArrayList<String>();
6672
// Application path should be stored in preference.
6773
cmdLine.add(nodePath);
6874
if (mode.equals(ILaunchManager.DEBUG_MODE)) {
69-
cmdLine.add("--debug-brk=5858");
75+
// -brk says to Node runtime wait until Chromium Debugger starts and connects
76+
// that is causing "stop on first line" behavior,
77+
// otherwise small apps or first line can be undebuggable.
78+
// TODO flexible debugging port, instead of hard-coded 5858
79+
// #61 https://github.com/Nodeclipse/nodeclipse-1/issues/61
80+
cmdLine.add("--debug-brk=5858");
7081
}
7182

7283
String nodeArgs = configuration.getAttribute(Constants.ATTR_NODE_ARGUMENTS, "");
@@ -77,17 +88,38 @@ public void launch(ILaunchConfiguration configuration, String mode,
7788
}
7889
}
7990

80-
String file =
81-
configuration.getAttribute(Constants.KEY_FILE_PATH, Constants.BLANK_STRING);
91+
String file = configuration.getAttribute(Constants.KEY_FILE_PATH, Constants.BLANK_STRING);
8292
String extension = null;
8393
int i = file.lastIndexOf('.');
8494
if(i > 0) {
8595
extension = file.substring(i+1);
8696
} else {
87-
throw new CoreException(new Status(IStatus.OK, ChromiumDebugPlugin.PLUGIN_ID, "Target file does not have extension: " + file, null));
97+
throw new CoreException(new Status(IStatus.OK, ChromiumDebugPlugin.PLUGIN_ID,
98+
"Target file does not have extension: " + file, null));
8899
}
89-
if("coffee".equals(extension)) {
90-
cmdLine.add(Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.COFFEE_PATH));
100+
101+
// #57 running app.js with node-dev, forever, supervisor, nodemon etc
102+
// https://github.com/Nodeclipse/nodeclipse-1/issues/57
103+
String nodeMonitor = configuration.getAttribute(Constants.ATTR_NODE_MONITOR, "");
104+
if(!nodeMonitor.equals("")) { // any value
105+
//TODO support selection, now only one
106+
107+
String nodeMonitorPath= Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.NODE_MONITOR_PATH);
108+
109+
// Check if the node monitor location is correctly configured
110+
File nodeMonitorFile = new File(nodeMonitorPath);
111+
if(!nodeMonitorFile.exists()){
112+
// If the location is not valid than show a dialog which prompts the user to goto the preferences page
113+
showPreferencesDialog("Node.js monitor is not correctly configured.\n"
114+
+ "Select path to installed util: forever, node-dev, nodemon or superviser.\n\n"
115+
+ "Please goto Window -> Prefrences -> Nodeclipse and configure the correct location");
116+
return;
117+
}
118+
cmdLine.add(nodeMonitorPath);
119+
} else {
120+
if("coffee".equals(extension)) {
121+
cmdLine.add(Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.COFFEE_PATH));
122+
}
91123
}
92124

93125
String filePath =
@@ -138,16 +170,17 @@ public void launch(ILaunchConfiguration configuration, String mode,
138170
nodeProcess = process;
139171
}
140172

141-
private void showPreferencesDialog() {
173+
private void showPreferencesDialog(final String message) {
142174
Display.getDefault().syncExec(new Runnable() {
143175
public void run() {
144176
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
145177

146-
MessageDialog dialog = new MessageDialog(shell, "Nodeclipse", null, "Node.js runtime is not correctly configured.\n\n"
147-
+ "Please goto Window -> Prefrences -> Nodeclipse and configure the correct location", MessageDialog.ERROR, new String[] { "Open Prefrences ...", "Cancel" }, 0);
178+
MessageDialog dialog = new MessageDialog(shell, "Nodeclipse", null, message,
179+
MessageDialog.ERROR, new String[] { "Open Prefrences ...", "Cancel" }, 0);
148180
int result = dialog.open();
149181
if (result == 0) {
150-
PreferenceDialog pref = PreferencesUtil.createPreferenceDialogOn(shell, PreferenceConstants.PREFERENCES_PAGE, null, null);
182+
PreferenceDialog pref = PreferencesUtil.createPreferenceDialogOn(shell,
183+
PreferenceConstants.PREFERENCES_PAGE, null, null);
151184
if (pref != null)
152185
pref.open();
153186
}

org.nodeclipse.debug/src/org/nodeclipse/debug/launch/LaunchShortcut.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import org.eclipse.debug.core.ILaunchConfigurationType;
88
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
99
import org.eclipse.debug.core.ILaunchManager;
10-
import org.eclipse.debug.internal.ui.DebugUIPlugin;
1110
import org.eclipse.debug.ui.DebugUITools;
1211
import org.eclipse.debug.ui.ILaunchShortcut;
1312
import org.eclipse.jface.dialogs.MessageDialog;
@@ -76,6 +75,7 @@ private void launchFile(IFile file, String mode) throws CoreException {
7675
ILaunchConfigurationType type = launchManager.getLaunchConfigurationType(Constants.LAUNCH_CONFIGURATION_TYPE_ID);
7776
ILaunchConfiguration configuration = createLaunchConfiguration(type, path, file);
7877
DebugUITools.launch(configuration, mode);
78+
// then execution goes in LaunchConfigurationDelegate.java launch() method
7979
}
8080

8181
/**
@@ -103,6 +103,11 @@ private ILaunchConfiguration createLaunchConfiguration(ILaunchConfigurationType
103103
// create a new configuration for the file
104104
ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, configname);
105105
workingCopy.setAttribute(Constants.KEY_FILE_PATH, path);
106+
setMoreAttributes(workingCopy);
106107
return workingCopy.doSave();
107108
}
109+
110+
protected void setMoreAttributes(ILaunchConfigurationWorkingCopy workingCopy) {
111+
// stub for extension
112+
}
108113
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.nodeclipse.debug.launch;
2+
3+
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
4+
import org.nodeclipse.debug.util.Constants;
5+
6+
/**
7+
* Using "Run As" --> "Node with monitor" will lead here
8+
*
9+
* @author Paul Verest
10+
* @since 0.6
11+
**/
12+
public class LaunchShortcutWithMonitor extends LaunchShortcut{
13+
14+
@Override
15+
protected void setMoreAttributes(ILaunchConfigurationWorkingCopy workingCopy) {
16+
workingCopy.setAttribute(Constants.ATTR_NODE_MONITOR, "e.g. node_dev"); // any value
17+
}
18+
}

org.nodeclipse.debug/src/org/nodeclipse/debug/util/Constants.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
/*******************************************************************************
22
* Copyright (c) 2012 Lamb. All rights reserved.
3-
*
3+
* Copyright (c) 2013 Nodeclipse organization
44
*******************************************************************************/
55
package org.nodeclipse.debug.util;
66

7-
import org.eclipse.debug.core.DebugPlugin;
8-
97
public class Constants {
108

119
public static final String LAUNCH_CONFIGURATION_TYPE_ID = "org.nodeclipse.debug.launch.LaunchConfigurationType";
@@ -35,4 +33,6 @@ public class Constants {
3533

3634
public static final String ATTR_ENVIRONMENT_VARIABLES = "attr_environment_variables";
3735
public static final String ATTR_APPEND_ENVIRONMENT_VARIABLES = "attr_append_environment_variables";
36+
37+
public static final String ATTR_NODE_MONITOR = "attr_node_monitor";
3838
}

org.nodeclipse.help/HelpToc.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<topic label="Configuration" href="contents/.configuration.md.html"/>
66
<topic label="Run" href="contents/.run.md.html"/>
77
<topic label="Debug" href="contents/.debug.md.html"/>
8+
<topic label="Monitor" href="contents/.monitor.md.html"/>
89
<topic label="Markdown" href="contents/.markdown.md.html"/>
910
<topic label="Github Flavored Markdown (GFM)" href="contents/.github-flavored-markdown.md.html"/>
1011
<topic label="JavaScript" href="contents/.javascript.md.html"/>

org.nodeclipse.help/contents/coffeescript.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Title: Nodeclipse Online Help - CoffeeScript
33

44
## CoffeeSctipt Editor
55

6-
Included in [Enide](nodeclipse.org/enide) since 0.4.20
6+
Included in [Enide](www.nodeclipse.org/enide) since 0.4.20
77

88
It has XText dependency, that can usually be automatically resolved by Eclipse (that was downloaded from eclipse.org)
99

@@ -19,4 +19,12 @@ for other Eclipse distributions use Enide or install prior from <http://download
1919
.listen 1337, '127.0.0.1'
2020
2121
console.log 'Server running at http://127.0.0.1:1337/'
22-
22+
23+
### Running/debugging
24+
25+
Nodeclipse since version 0.6 allows to run and debug .coffee file directly.
26+
Node.js command line tool 'coffee' is used.
27+
Note that when debugging, source map are not implemeted, and execution start from this coffee tool
28+
that compiles your module.
29+
Stay in Node perspective until compilation to see your modules appear in V8 virtual project.
30+
Then open those files and set breakpoints.

org.nodeclipse.help/contents/configuration.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ Team -> Git -> History : Check "Follow renames"
1414

1515
Switch to Node perspective (e.g. Window -> Open Perspective -> Other ... -> Node)
1616

17-
Window -> Show View -> Other... -> GFM Support -> GFM View
18-
(Very useful when exploring <code>node_modules</code> folders)
19-
2017
Window -> Show View -> Other... -> REST Client -> REST Client Tool
2118

19+
REST Client Tool is also nice to use in Debug perspective.
20+
2221
### Before 0.6
2322

23+
Window -> Show View -> Other... -> GFM Support -> GFM View
24+
(Very useful when exploring <code>node_modules</code> folders)
25+
2426
#### File associations
2527

2628
Window -> Preferences -> General -> Editors -> File Associations <kbd>Add...</kbd>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Title: Nodeclipse Help - Run/Debug with Monitor
2+
3+
4+
## Run/Debug with Monitor
5+
6+
https://github.com/Nodeclipse/nodeclipse-1/issues/57
7+
running app.js with node-dev, forever, supervisor, nodemon etc
8+
9+
Configure your source file monitor of your choice:
10+
11+
`forever [action] [options] SCRIPT [script-options]`
12+
`nodemon [your node app]`
13+
`node-dev foo.js`
14+
`supervisor [options] <program>`
15+
16+
[forever](https://github.com/nodejitsu/forever) - 2700 stars
17+
node-dev https://github.com/fgnass/node-dev - 380 stars (doesn't require any configuration)
18+
[nodemon](https://github.com/remy/nodemon) 1500 stars - support running .coffee
19+
[supervisor](https://github.com/isaacs/node-supervisor) 1100 stars
20+
21+

0 commit comments

Comments
 (0)