Skip to content

Commit 4efd495

Browse files
author
Paul Verest 伟保罗
committed
PhantomJS set working dir, use EnvironmentTab from .debug module;
1 parent 5480397 commit 4efd495

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
lines changed

org.nodeclipse.debug/src/org/nodeclipse/debug/launch/NodeEnvironmentTab.java renamed to org.nodeclipse.debug/src/org/nodeclipse/debug/launch/LaunchConfigurationEnvironmentTab.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
import org.eclipse.ui.PlatformUI;
7474
import org.nodeclipse.debug.util.Constants;
7575

76-
@SuppressWarnings("restriction")
7776
/**
7877
* Launch configuration tab for configuring the environment passed
7978
* into Runtime.exec(...) when a config is launched.
@@ -87,7 +86,8 @@
8786
* @since 3.0
8887
* @noextend This class is not intended to be subclassed by clients.
8988
*/
90-
public class NodeEnvironmentTab extends AbstractLaunchConfigurationTab {
89+
@SuppressWarnings("restriction")
90+
public class LaunchConfigurationEnvironmentTab extends AbstractLaunchConfigurationTab {
9191

9292
protected TableViewer environmentTable;
9393
protected String[] envTableColumnHeaders = {
@@ -185,7 +185,7 @@ public Image getColumnImage(Object element, int columnIndex) {
185185
/**
186186
* Constructs a new tab with default context help.
187187
*/
188-
public NodeEnvironmentTab() {
188+
public LaunchConfigurationEnvironmentTab() {
189189
setHelpContextId(IDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_ENVIRONMENT_TAB);
190190
}
191191

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
1717
ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
1818
new LaunchConfigurationMainTab(),
1919
new NodeArgumentsTab(),
20-
new NodeEnvironmentTab(),
20+
new LaunchConfigurationEnvironmentTab(),
2121
new CommonTab()
2222
};
2323
setTabs(tabs);

org.nodeclipse.phantomjs/src/org/nodeclipse/phantomjs/launch/Constants.java renamed to org.nodeclipse.phantomjs/src/org/nodeclipse/phantomjs/launch/ConstantsPhantomJS.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.nodeclipse.phantomjs.launch;
22

3-
public class Constants {
3+
public class ConstantsPhantomJS {
44

55
public static final String PROCESS_MESSAGE = "PhantomJS Process";
66

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

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import java.io.File;
44
import java.util.ArrayList;
5+
import java.util.HashMap;
56
import java.util.List;
7+
import java.util.Map;
68

79
import org.eclipse.core.resources.ResourcesPlugin;
810
import org.eclipse.core.runtime.CoreException;
@@ -14,7 +16,9 @@
1416
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
1517
import org.eclipse.debug.core.model.RuntimeProcess;
1618
import org.eclipse.jface.preference.IPreferenceStore;
19+
import org.nodeclipse.debug.util.Constants;
1720
import org.nodeclipse.debug.util.NodeDebugUtil;
21+
import org.nodeclipse.debug.util.VariablesUtil;
1822
import org.nodeclipse.ui.Activator;
1923
import org.nodeclipse.ui.preferences.Dialogs;
2024
import org.nodeclipse.ui.preferences.PreferenceConstants;
@@ -36,6 +40,7 @@ public class LaunchConfigurationDelegate
3640
//extends org.nodeclipse.debug.launch.LaunchConfigurationDelegate
3741
implements ILaunchConfigurationDelegate {
3842

43+
//@SuppressWarnings("unchecked")
3944
@Override
4045
public void launch(ILaunchConfiguration configuration, String mode,
4146
ILaunch launch, IProgressMonitor monitor) throws CoreException {
@@ -72,16 +77,37 @@ public void launch(ILaunchConfiguration configuration, String mode,
7277
// path is relative, so cannot find it, unless get absolute path
7378
cmdLine.add(filePath);
7479

80+
String workingDirectory = configuration.getAttribute(Constants.ATTR_WORKING_DIRECTORY, "");
81+
File workingPath = null;
82+
if(workingDirectory.length() == 0) {
83+
workingPath = (new File(filePath)).getParentFile();
84+
} else {
85+
workingDirectory = VariablesUtil.resolveValue(workingDirectory);
86+
if(workingDirectory == null) {
87+
workingPath = (new File(filePath)).getParentFile();
88+
} else {
89+
workingPath = new File(workingDirectory);
90+
}
91+
}
92+
93+
Map<String, String> envm = new HashMap<String, String>();
94+
envm = configuration.getAttribute(Constants.ATTR_ENVIRONMENT_VARIABLES, envm);
95+
String[] envp = new String[envm.size()];
96+
int idx = 0;
97+
for(String key : envm.keySet()) {
98+
String value = envm.get(key);
99+
envp[idx++] = key + "=" + value;
100+
}
101+
75102

76103
for(String s : cmdLine) NodeclipseConsole.write(s+" ");
77104
NodeclipseConsole.write("\n");
78105

79106
String[] cmds = {};
80107
cmds = cmdLine.toArray(cmds);
81-
// Launch a process to debug.eg,
82-
//TODO Process p = DebugPlugin.exec(cmds, workingPath, envp);
83-
Process p = DebugPlugin.exec(cmds, null, null);
84-
RuntimeProcess process = (RuntimeProcess)DebugPlugin.newProcess(launch, p, Constants.PROCESS_MESSAGE);
108+
// Launch a process to run or debug
109+
Process p = DebugPlugin.exec(cmds, workingPath, envp);
110+
RuntimeProcess process = (RuntimeProcess)DebugPlugin.newProcess(launch, p, ConstantsPhantomJS.PROCESS_MESSAGE);
85111
if (isDebugMode) {
86112
int phantomjsDebugPort = preferenceStore.getInt(PreferenceConstants.PHANTOMJS_DEBUG_PORT);
87113
NodeDebugUtil.launch(mode, launch, monitor, phantomjsDebugPort);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.eclipse.debug.ui.CommonTab;
55
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
66
import org.eclipse.debug.ui.ILaunchConfigurationTab;
7+
import org.nodeclipse.debug.launch.LaunchConfigurationEnvironmentTab;
78

89

910
/**
@@ -18,7 +19,7 @@ public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
1819
ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
1920
// new LaunchConfigurationMainTab(),
2021
// new NodeArgumentsTab(),
21-
// new NodeEnvironmentTab(),
22+
new LaunchConfigurationEnvironmentTab(),
2223
new CommonTab()
2324
};
2425
setTabs(tabs);

0 commit comments

Comments
 (0)