Skip to content

Commit d0f3d87

Browse files
committed
Added feature to pass arguments to nodejs and to program itself
1 parent b59b54e commit d0f3d87

7 files changed

Lines changed: 254 additions & 26 deletions

File tree

org.nodeclipse.debug/plugin.xml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<?eclipse version="3.4"?>
33
<plugin>
4-
<extension point="org.eclipse.core.runtime.adapters">
5-
<factory
6-
class="org.nodeclipse.debug.model.BreakpointAdapterFactory"
7-
adaptableType="org.eclipse.ui.texteditor.ITextEditor">
8-
<adapter type="org.eclipse.debug.ui.actions.IToggleBreakpointsTarget" />
9-
</factory>
10-
</extension>
4+
<extension point="org.eclipse.core.runtime.adapters">
5+
<factory
6+
class="org.nodeclipse.debug.model.BreakpointAdapterFactory"
7+
adaptableType="org.eclipse.ui.texteditor.ITextEditor">
8+
<adapter type="org.eclipse.debug.ui.actions.IToggleBreakpointsTarget" />
9+
</factory>
10+
</extension>
1111

1212
<extension
1313
point="org.eclipse.debug.core.launchConfigurationTypes">
14-
<launchConfigurationType
14+
<launchConfigurationType
1515
delegate="org.nodeclipse.debug.launch.LaunchConfigurationDelegate"
1616
id="org.nodeclipse.debug.launch.LaunchConfigurationType"
1717
modes="run, debug"
1818
name="Node Application">
19-
</launchConfigurationType>
19+
</launchConfigurationType>
2020
<launchConfigurationType
2121
id="org.nodeclipse.debug.launch.LaunchType$StandaloneV8"
2222
delegate="org.nodeclipse.debug.launch.StandaloneV8LaunchTypeWrapper"
@@ -74,12 +74,12 @@
7474
</shortcut>
7575
</extension>
7676
<extension
77-
point="org.eclipse.debug.ui.launchConfigurationTabGroups">
78-
<launchConfigurationTabGroup
77+
point="org.eclipse.debug.ui.launchConfigurationTabGroups">
78+
<launchConfigurationTabGroup
7979
class= "org.nodeclipse.debug.launch.LaunchConfigurationTabGroup"
8080
id= "org.nodeclipse.debug.launch.LaunchConfigurationTabGroup"
8181
type= "org.nodeclipse.debug.launch.LaunchConfigurationType" >
82-
</launchConfigurationTabGroup>
82+
</launchConfigurationTabGroup>
8383
<launchConfigurationTabGroup
8484
type="org.nodeclipse.debug.launch.LaunchType$StandaloneV8"
8585
class="org.chromium.debug.ui.launcher.LaunchTabGroup$StandaloneV8"

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

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,36 @@ public void launch(ILaunchConfiguration configuration, String mode,
5050
if (mode.equals(ILaunchManager.DEBUG_MODE)) {
5151
cmdLine.add("--debug-brk=5858");
5252
}
53-
String file = configuration.getAttribute(Constants.KEY_FILE_PATH,
54-
Constants.BLANK_STRING);
55-
String filePath = ResourcesPlugin.getWorkspace().getRoot()
56-
.findMember(file).getLocation().toOSString();
53+
54+
String nodeArgs = configuration.getAttribute(Constants.ATTR_NODE_ARGUMENTS, "");
55+
if(!nodeArgs.equals("")) {
56+
String[] sa = nodeArgs.split(" ");
57+
for(String s : sa) {
58+
cmdLine.add(s);
59+
}
60+
}
61+
62+
String file =
63+
configuration.getAttribute(Constants.KEY_FILE_PATH, Constants.BLANK_STRING);
64+
String filePath =
65+
ResourcesPlugin.getWorkspace().getRoot().findMember(file).getLocation().toOSString();
5766
// path is relative, so can not found it.
5867
cmdLine.add(filePath);
68+
69+
String programArgs = configuration.getAttribute(Constants.ATTR_PROGRAM_ARGUMENTS, "");
70+
if(!programArgs.equals("")) {
71+
String[] sa = programArgs.split(" ");
72+
for(String s : sa) {
73+
cmdLine.add(s);
74+
}
75+
}
76+
5977
String[] cmds = {};
6078
cmds = cmdLine.toArray(cmds);
6179
// Launch a process to debug.eg,
6280
Process p = DebugPlugin
6381
.exec(cmds, (new File(filePath)).getParentFile());
6482
RuntimeProcess process = (RuntimeProcess)DebugPlugin.newProcess(launch, p, Constants.PROCESS_MESSAGE);
65-
// if (mode.equals(ILaunchManager.DEBUG_MODE)) {
66-
// DebugTarget target = new DebugTarget(launch, process, p);
67-
// launch.addDebugTarget(target);
68-
// }
6983
if (mode.equals(ILaunchManager.DEBUG_MODE)) {
7084
if(!process.isTerminated()) {
7185
NodeDebugUtil.launch(mode, launch, monitor);
@@ -81,7 +95,6 @@ public static void terminateNodeProcess() {
8195
} catch (DebugException e) {
8296
e.printStackTrace();
8397
}
84-
// nodeProcess.destroy();
8598
nodeProcess = null;
8699
}
87100
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import org.eclipse.core.runtime.Path;
1010
import org.eclipse.debug.core.ILaunchConfiguration;
1111
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
12+
import org.eclipse.debug.internal.ui.stringsubstitution.SelectedResourceManager;
1213
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
14+
import org.eclipse.jface.viewers.IStructuredSelection;
1315
import org.eclipse.jface.window.Window;
1416
import org.eclipse.swt.SWT;
1517
import org.eclipse.swt.events.ModifyEvent;

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
66
import org.eclipse.debug.ui.ILaunchConfigurationTab;
77

8+
89
/**
910
* Using "Run"-->"Run Configurations"--> "New Configuration"-- > "Run" willlead
1011
* here.
@@ -13,7 +14,11 @@ public class LaunchConfigurationTabGroup extends AbstractLaunchConfigurationTabG
1314

1415
@Override
1516
public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
16-
ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] { new LaunchConfigurationMainTab(), new CommonTab() };
17+
ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
18+
new LaunchConfigurationMainTab(),
19+
new NodeArgumentsTab(),
20+
new CommonTab()
21+
};
1722
setTabs(tabs);
1823
}
1924
}

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
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;
1011
import org.eclipse.debug.ui.DebugUITools;
1112
import org.eclipse.debug.ui.ILaunchShortcut;
1213
import org.eclipse.jface.dialogs.MessageDialog;
@@ -75,7 +76,6 @@ private void launchFile(IFile file, String mode) throws CoreException {
7576
ILaunchConfigurationType type = launchManager.getLaunchConfigurationType(Constants.LAUNCH_CONFIGURATION_TYPE_ID);
7677
ILaunchConfiguration configuration = createLaunchConfiguration(type, path, file);
7778
DebugUITools.launch(configuration, mode);
78-
7979
}
8080

8181
/**
@@ -88,8 +88,17 @@ private void launchFile(IFile file, String mode) throws CoreException {
8888
* @throws CoreException
8989
*/
9090
private ILaunchConfiguration createLaunchConfiguration(ILaunchConfigurationType type, String path, IFile file) throws CoreException {
91-
// create a new configuration for the file
92-
ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, file.getName());
91+
String configname = file.getName();
92+
93+
ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(type);
94+
for(ILaunchConfiguration config : configs) {
95+
if(configname.equals(config.getName())) {
96+
return config;
97+
}
98+
}
99+
100+
// create a new configuration for the file
101+
ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, configname);
93102
workingCopy.setAttribute(Constants.KEY_FILE_PATH, path);
94103
return workingCopy.doSave();
95104
}
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
package org.nodeclipse.debug.launch;
2+
3+
import org.eclipse.core.runtime.CoreException;
4+
import org.eclipse.debug.core.ILaunchConfiguration;
5+
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
6+
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
7+
import org.eclipse.debug.ui.StringVariableSelectionDialog;
8+
import org.eclipse.swt.SWT;
9+
import org.eclipse.swt.events.ModifyEvent;
10+
import org.eclipse.swt.events.ModifyListener;
11+
import org.eclipse.swt.events.SelectionAdapter;
12+
import org.eclipse.swt.events.SelectionEvent;
13+
import org.eclipse.swt.events.TraverseEvent;
14+
import org.eclipse.swt.events.TraverseListener;
15+
import org.eclipse.swt.graphics.Font;
16+
import org.eclipse.swt.layout.GridData;
17+
import org.eclipse.swt.layout.GridLayout;
18+
import org.eclipse.swt.widgets.Button;
19+
import org.eclipse.swt.widgets.Composite;
20+
import org.eclipse.swt.widgets.Group;
21+
import org.eclipse.swt.widgets.Label;
22+
import org.eclipse.swt.widgets.Text;
23+
import org.nodeclipse.debug.util.Constants;
24+
25+
public class NodeArgumentsTab extends AbstractLaunchConfigurationTab {
26+
protected Label fPrgmArgumentsLabel;
27+
protected Text fPrgmArgumentsText;
28+
29+
// Node arguments widgets
30+
protected Label fNodeArgumentsLabel;
31+
protected Text fNodeArgumentsText;
32+
33+
@Override
34+
public void createControl(Composite parent) {
35+
Font font = parent.getFont();
36+
Composite comp = new Composite(parent, SWT.NONE);
37+
GridLayout layout = new GridLayout(1, true);
38+
comp.setLayout(layout);
39+
comp.setFont(font);
40+
41+
GridData gd = new GridData(GridData.FILL_BOTH);
42+
comp.setLayoutData(gd);
43+
setControl(comp);
44+
//setHelpContextId();
45+
46+
Group group = new Group(comp, SWT.NONE);
47+
group.setFont(font);
48+
layout = new GridLayout();
49+
group.setLayout(layout);
50+
group.setLayoutData(new GridData(GridData.FILL_BOTH));
51+
52+
group.setText("Program Arguments");
53+
54+
fPrgmArgumentsText = new Text(group, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL);
55+
fPrgmArgumentsText.addTraverseListener(new TraverseListener() {
56+
public void keyTraversed(TraverseEvent e) {
57+
switch (e.detail) {
58+
case SWT.TRAVERSE_ESCAPE:
59+
case SWT.TRAVERSE_PAGE_NEXT:
60+
case SWT.TRAVERSE_PAGE_PREVIOUS:
61+
e.doit = true;
62+
break;
63+
case SWT.TRAVERSE_RETURN:
64+
case SWT.TRAVERSE_TAB_NEXT:
65+
case SWT.TRAVERSE_TAB_PREVIOUS:
66+
if ((fPrgmArgumentsText.getStyle() & SWT.SINGLE) != 0) {
67+
e.doit = true;
68+
} else {
69+
if (!fPrgmArgumentsText.isEnabled() || (e.stateMask & SWT.MODIFIER_MASK) != 0) {
70+
e.doit = true;
71+
}
72+
}
73+
break;
74+
}
75+
}
76+
});
77+
gd = new GridData(GridData.FILL_BOTH);
78+
gd.heightHint = 40;
79+
gd.widthHint = 100;
80+
fPrgmArgumentsText.setLayoutData(gd);
81+
fPrgmArgumentsText.setFont(font);
82+
fPrgmArgumentsText.addModifyListener(new ModifyListener() {
83+
public void modifyText(ModifyEvent evt) {
84+
scheduleUpdateJob();
85+
}
86+
});
87+
//ControlAccessibleListener.addListener(fPrgmArgumentsText, group.getText());
88+
89+
String buttonLabel = "Variables...";
90+
Button pgrmArgVariableButton = createPushButton(group, buttonLabel, null);
91+
pgrmArgVariableButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
92+
pgrmArgVariableButton.addSelectionListener(new SelectionAdapter() {
93+
public void widgetSelected(SelectionEvent e) {
94+
StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell());
95+
dialog.open();
96+
String variable = dialog.getVariableExpression();
97+
if (variable != null) {
98+
fPrgmArgumentsText.insert(variable);
99+
}
100+
}
101+
});
102+
103+
Group groupNode = new Group(comp, SWT.NONE);
104+
groupNode.setFont(font);
105+
groupNode.setLayout(new GridLayout());
106+
groupNode.setLayoutData(new GridData(GridData.FILL_BOTH));
107+
108+
groupNode.setText("Node Arguments");
109+
110+
fNodeArgumentsText = new Text(groupNode, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL);
111+
fNodeArgumentsText.addTraverseListener(new TraverseListener() {
112+
public void keyTraversed(TraverseEvent e) {
113+
switch (e.detail) {
114+
case SWT.TRAVERSE_ESCAPE:
115+
case SWT.TRAVERSE_PAGE_NEXT:
116+
case SWT.TRAVERSE_PAGE_PREVIOUS:
117+
e.doit = true;
118+
break;
119+
case SWT.TRAVERSE_RETURN:
120+
case SWT.TRAVERSE_TAB_NEXT:
121+
case SWT.TRAVERSE_TAB_PREVIOUS:
122+
if ((fPrgmArgumentsText.getStyle() & SWT.SINGLE) != 0) {
123+
e.doit = true;
124+
} else {
125+
if (!fPrgmArgumentsText.isEnabled() || (e.stateMask & SWT.MODIFIER_MASK) != 0) {
126+
e.doit = true;
127+
}
128+
}
129+
break;
130+
}
131+
}
132+
});
133+
GridData gd2 = new GridData(GridData.FILL_BOTH);
134+
gd2.heightHint = 40;
135+
gd2.widthHint = 100;
136+
fNodeArgumentsText.setLayoutData(gd2);
137+
fNodeArgumentsText.setFont(font);
138+
fNodeArgumentsText.addModifyListener(new ModifyListener() {
139+
public void modifyText(ModifyEvent evt) {
140+
scheduleUpdateJob();
141+
}
142+
});
143+
//ControlAccessibleListener.addListener(fPrgmArgumentsText, group.getText());
144+
145+
String buttonLabel2 = "Variables...";
146+
Button pgrmArgVariableButton2 = createPushButton(groupNode, buttonLabel2, null);
147+
pgrmArgVariableButton2.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
148+
pgrmArgVariableButton2.addSelectionListener(new SelectionAdapter() {
149+
public void widgetSelected(SelectionEvent e) {
150+
StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell());
151+
dialog.open();
152+
String variable = dialog.getVariableExpression();
153+
if (variable != null) {
154+
fNodeArgumentsText.insert(variable);
155+
}
156+
}
157+
});
158+
}
159+
160+
@Override
161+
public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
162+
}
163+
164+
@Override
165+
public void initializeFrom(ILaunchConfiguration configuration) {
166+
try {
167+
fPrgmArgumentsText.setText((String)configuration.getAttribute(Constants.ATTR_PROGRAM_ARGUMENTS, ""));
168+
fNodeArgumentsText.setText((String)configuration.getAttribute(Constants.ATTR_NODE_ARGUMENTS, ""));
169+
} catch (CoreException e) {
170+
e.printStackTrace();
171+
}
172+
}
173+
174+
@Override
175+
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
176+
configuration.setAttribute(Constants.ATTR_PROGRAM_ARGUMENTS, getAttributeValueFrom(fPrgmArgumentsText));
177+
configuration.setAttribute(Constants.ATTR_NODE_ARGUMENTS, getAttributeValueFrom(fNodeArgumentsText));
178+
}
179+
180+
@Override
181+
public String getName() {
182+
return "Arguments";
183+
}
184+
185+
/**
186+
* Returns the string in the text widget, or <code>null</code> if empty.
187+
*
188+
* @return text or <code>null</code>
189+
*/
190+
protected String getAttributeValueFrom(Text text) {
191+
String content = text.getText().trim();
192+
if (content.length() > 0) {
193+
return content;
194+
}
195+
return null;
196+
}
197+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ public class Constants {
2626
public static final String FILE_LABEL = "File";
2727
public static final String SEARCH_LABEL = "Search...";
2828
public static final String SEARCH_TITLE = "Search File";
29-
29+
30+
public static final String ATTR_PROGRAM_ARGUMENTS = "attr_program_arguments";
31+
public static final String ATTR_NODE_ARGUMENTS = "attr_node_arguments";
3032
}

0 commit comments

Comments
 (0)