-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathPreferenceInitializer.java
192 lines (169 loc) · 7.04 KB
/
PreferenceInitializer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package org.nodeclipse.ui.preferences;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.IPreferenceStore;
import org.nodeclipse.ui.Activator;
import org.nodeclipse.ui.util.Constants;
import org.nodeclipse.ui.util.LogUtil;
import org.nodeclipse.ui.util.NodeclipseConsole;
import org.nodeclipse.ui.util.OSUtils;
import org.nodeclipse.ui.util.ProcessUtils;
/**
*
* @author oncereply, Paul Verest
*
*/
public class PreferenceInitializer extends AbstractPreferenceInitializer {
public PreferenceInitializer() {
}
@Override
public void initializeDefaultPreferences() {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
store.setDefault(PreferenceConstants.NODECLIPSE_CONSOLE_ENABLED, true);
//store.setDefault(PreferenceConstants.NODE_OPTIONS, "--harmony");
//store.setDefault(PreferenceConstants.NODE_APPLICATION_ARGUMENTS, "--tea-pot-mode");
store.setDefault(PreferenceConstants.NODE_ALLOW_MANY, true);
store.setDefault(PreferenceConstants.ADD_JSDT_NATURE, false);
store.setDefault(PreferenceConstants.ADD_TERN_NATURE, true);
store.setDefault(PreferenceConstants.USE_NODEJS_BASE_MODULE_DEFINITIONS, true);
store.setDefault(PreferenceConstants.USE_ORION_INDEX_FILES, true);
store.setDefault(PreferenceConstants.USE_COMPLETIONS_JSON, true);
//store.setDefault(PreferenceConstants.NODE_DEBUG_NO_BREAK, ""); //default is empty,null,no
store.setDefault(PreferenceConstants.NODE_DEBUG_PORT, "5858");
String node_path = "/usr/local/bin/node";
String node_monitor_path = "/usr/local/lib/node_modules/node-dev/bin/node-dev";
String express_path = "/usr/local/lib/node_modules/express/bin/express";
String express_generator_path = "/usr/local/lib/node_modules/express-generator/bin/express";
String coffee_path = "/usr/local/bin/coffee";
String typescript_compiler_path = "/usr/local/lib/node_modules/typescript/bin/tsc";
File file;
if (OSUtils.isWindows()) {
store.setDefault(PreferenceConstants.NODE_JUST_NODE, true);
node_path = "C:/Program Files/nodejs/node.exe".replace('/', File.separatorChar);
file = new File(node_path);
if (!file.exists()) {
node_path = "C:/Program Files (x86)/nodejs/node.exe".replace('/', File.separatorChar);
}
String windowsNodeModulesPath = System.getProperty("user.home")
+ "/AppData/Roaming/npm/node_modules/";
node_monitor_path = (windowsNodeModulesPath+"node-dev/bin/node-dev").replace('/', File.separatorChar);
express_path = (windowsNodeModulesPath+"express/bin/express").replace('/', File.separatorChar);
express_generator_path = (windowsNodeModulesPath+"express-generator/bin/express").replace('/', File.separatorChar);
coffee_path = (windowsNodeModulesPath+"coffee-script/bin/coffee").replace('/', File.separatorChar);
typescript_compiler_path = (windowsNodeModulesPath+"typescript/bin/tsc").replace('/', File.separatorChar);
} else if (OSUtils.isMacOS()) {
file = new File(node_path);
if (!file.exists()) {
node_path = "/opt/local/bin/node";
}
file = new File(node_monitor_path);
if (!file.exists()) {
node_monitor_path = "/opt/local/lib/node_modules/node-dev/bin/node-dev";
}
file = new File(express_path);
if (!file.exists()) {
express_path = "/opt/local/lib/node_modules/express/bin/express";
}
file = new File(express_generator_path);
if (!file.exists()) {
express_generator_path = "/opt/local/lib/node_modules/express-generator/bin/express";
}
file = new File(coffee_path);
if (!file.exists()) {
coffee_path = "/opt/local/lib/node_modules/coffee-script/bin/coffee";
}
file = new File(typescript_compiler_path);
if (!file.exists()) {
typescript_compiler_path = "/opt/local/lib/node_modules/typescript/bin/tsc";
}
}
// Check & set Preferences
file = new File(node_path);
if (file.exists()) {
store.setDefault(PreferenceConstants.NODE_PATH, node_path);
} else {
file = findNode();
if (file != null && file.exists()) {
store.setDefault(PreferenceConstants.NODE_PATH, file.getAbsolutePath());
}
}
file = new File(node_monitor_path);
if (file.exists()) {
store.setDefault(PreferenceConstants.NODE_MONITOR_PATH, node_monitor_path);
}
// using bundles Node.js modules for Express & CoffeeScript {
// Express: try to use express-generator (for Express 4.x)
file = new File(express_generator_path);
if (file.exists()) {
store.setDefault(PreferenceConstants.EXPRESS_PATH, express_generator_path);
store.setDefault(PreferenceConstants.EXPRESS_VERSION,
ProcessUtils.getCurrentVersionOf(express_generator_path));
} else {
file = new File(express_path);
if (file.exists()) {
store.setDefault(PreferenceConstants.EXPRESS_PATH, express_path);
store.setDefault(PreferenceConstants.EXPRESS_VERSION,
ProcessUtils.getCurrentVersionOf(express_path));
} else {
express_path = ProcessUtils.getBundledExpressPath();
file = new File(express_path);
if (file.exists()) {
store.setDefault(PreferenceConstants.EXPRESS_PATH, express_path);
store.setDefault(PreferenceConstants.EXPRESS_VERSION,
ProcessUtils.getCurrentVersionOf(express_path));
}
}
}
//coffee
file = new File(coffee_path);
if (file.exists()) {
store.setDefault(PreferenceConstants.COFFEE_PATH, coffee_path);
} else {
coffee_path = ProcessUtils.getBundledCoffeePath();
file = new File(coffee_path);
if (file.exists()) {
store.setDefault(PreferenceConstants.COFFEE_PATH, coffee_path);
}
}
//}
store.setDefault(PreferenceConstants.COFFEE_COMPILE_OPTIONS, "--watch");
file = new File(typescript_compiler_path);
if (file.exists()) {
store.setDefault(PreferenceConstants.TYPESCRIPT_COMPILER_PATH, typescript_compiler_path);
}
store.setDefault(PreferenceConstants.MONGODB_SHELL_OPTIONS, "--shell");
}
private static String getNodeFileName() {
if (OSUtils.isWindows()) {
return "node.exe";
}
return "node";
}
private static File findNode() {
String nodeFileName = getNodeFileName();
String path = System.getenv("PATH");
String[] paths = path.split("" + File.pathSeparatorChar, 0);
List<String> directories = new ArrayList<String>();
for(String p : paths) {
directories.add(p);
}
// ensure /usr/local/bin is included for OS X
if (OSUtils.isMacOS()) {
directories.add("/usr/local/bin");
}
// search for Node.js in the PATH directories
for (String directory : directories) {
File nodeFile = new File(directory, nodeFileName);
if (nodeFile.exists()) {
return nodeFile;
}
}
// #158 do not throw Exception for not standard Node path or name, let Node path be empty in Preferences
//throw new IllegalStateException("Could not find Node.js.");
LogUtil.error("Node.js executable can't be found!");
return null;
}
}