Skip to content

Commit 35fc1a2

Browse files
committed
Deploy embed node.js in workspace.
1 parent 55332d0 commit 35fc1a2

File tree

3 files changed

+110
-31
lines changed

3 files changed

+110
-31
lines changed

eclipse/ts.eclipse.ide.core/schema/nodeJSInstalls.exsd

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,34 +45,51 @@
4545
</element>
4646

4747
<element name="install">
48+
<annotation>
49+
<documentation>
50+
This extension point allows developers to specify their own Node.js install location. This can be done in two ways:
51+
&lt;ol&gt;
52+
&lt;li&gt;A developer can implement &lt;i&gt;INodejsInstallProvider&lt;/i&gt; interface to programmatically tell Tern.java where Node.js is installed. This is useful for situations where you need to do some computations before specifying the location path.
53+
&lt;li&gt;Bundle Node.js in the extending bundle and specify the location of the Node program relative to the bundle. If you ship Node.js in your bundle in the form of a ZIP archive, make sure you specify the ZIP location withing the bundle using the &lt;i&gt;zip&lt;/i&gt; attribute.
54+
&lt;/ol&gt;
55+
</documentation>
56+
</annotation>
4857
<complexType>
49-
<sequence>
50-
</sequence>
5158
<attribute name="id" type="string" use="required">
5259
<annotation>
5360
<documentation>
54-
61+
The id of this Nodejs install. Each known Nodejs install has a distinct id. Ids are intended to be used internally as keys; they are not intended to be shown to end users.
5562
</documentation>
5663
</annotation>
5764
</attribute>
5865
<attribute name="name" type="string" use="required">
5966
<annotation>
6067
<documentation>
61-
68+
The displayable name for this Nodejs install.
69+
</documentation>
70+
</annotation>
71+
</attribute>
72+
<attribute name="class" type="string">
73+
<annotation>
74+
<documentation>
75+
Provides a way to programmatically specify the install location of a Node.js within the system. This allows extenders to compute install locations that are not in the extending bundle. Extenders must implement &lt;i&gt;tern.eclipse.ide.server.nodejs.core.INodejsInstallProvider&lt;/i&gt; interface.
6276
</documentation>
77+
<appinfo>
78+
<meta.attribute kind="java" basedOn=":tern.eclipse.ide.server.nodejs.core.INodejsInstallProvider"/>
79+
</appinfo>
6380
</annotation>
6481
</attribute>
65-
<attribute name="path" type="string" use="required">
82+
<attribute name="path" type="string">
6683
<annotation>
6784
<documentation>
68-
85+
The file path for this Nodejs install.
6986
</documentation>
7087
</annotation>
7188
</attribute>
7289
<attribute name="zip" type="string">
7390
<annotation>
7491
<documentation>
75-
92+
If path doesn&apos;t exist, specify a ZIP archive within the bundle that contains the node program. This extension will unzip it and look for the node path.
7693
</documentation>
7794
</annotation>
7895
</attribute>
@@ -100,4 +117,4 @@
100117
</annotation>
101118

102119

103-
</schema>
120+
</schema>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (c) 2016 Angelo ZERR, IBM
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Victor Sosa <[email protected]>- initial API and implementation
10+
*/
11+
package ts.eclipse.ide.core.nodejs;
12+
13+
import java.io.File;
14+
15+
/**
16+
* Provides a way to programmatically specify the install location of a Node.js
17+
* within the system.
18+
*
19+
* @author <a href="mailto:[email protected]">[email protected]</a>
20+
*
21+
*/
22+
public interface INodejsInstallProvider {
23+
24+
/**
25+
* Location where this Node.js is installed
26+
*
27+
* @return Node.js install location
28+
*/
29+
File getPath();
30+
}
Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
11
/**
2-
* Copyright (c) 2013-2016 Angelo ZERR.
2+
* Copyright (c) 2013-2016 Angelo ZERR, IBM.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
66
* http://www.eclipse.org/legal/epl-v10.html
77
*
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
10+
* Victor Sosa <[email protected]> - Extension to allow locations computed programmatically
1011
*/
1112
package ts.eclipse.ide.internal.core.nodejs;
1213

1314
import java.io.File;
1415
import java.io.IOException;
1516

17+
import org.eclipse.core.internal.runtime.InternalPlatform;
18+
import org.eclipse.core.runtime.CoreException;
1619
import org.eclipse.core.runtime.FileLocator;
1720
import org.eclipse.core.runtime.IConfigurationElement;
21+
import org.eclipse.core.runtime.IPath;
1822
import org.eclipse.core.runtime.Platform;
1923

2024
import ts.eclipse.ide.core.nodejs.IEmbeddedNodejs;
25+
import ts.eclipse.ide.core.nodejs.INodejsInstallProvider;
26+
import ts.eclipse.ide.internal.core.Trace;
2127
import ts.utils.ZipUtils;
2228

29+
30+
@SuppressWarnings("restriction")
2331
public class NodejsInstall implements IEmbeddedNodejs {
2432

25-
private final String id;
26-
private final String name;
33+
private String id;
34+
private String name;
2735
private File path;
2836

2937
/**
@@ -34,27 +42,51 @@ public class NodejsInstall implements IEmbeddedNodejs {
3442
* @throws IOException
3543
*/
3644
public NodejsInstall(IConfigurationElement element) throws IOException {
45+
createClass(element);
46+
}
47+
48+
private void createClass(IConfigurationElement element) throws IOException {
3749
this.id = element.getAttribute("id");
3850
this.name = element.getAttribute("name");
39-
String pluginId = element.getNamespaceIdentifier();
40-
String path = element.getAttribute("path");
41-
if (path != null && path.length() > 0) {
42-
File baseDir = FileLocator.getBundleFile(Platform.getBundle(pluginId));
43-
this.path = new File(baseDir, path);
44-
45-
// check if path exists, if it doesn't look for zip
46-
if (!this.path.exists()) {
47-
String zip = element.getAttribute("zip");
48-
49-
File zipFile = new File(baseDir, zip);
50-
51-
if (zipFile.exists()) {
52-
if (zipFile.getName().toLowerCase().endsWith(".zip")) {
53-
ZipUtils.extract(zipFile, baseDir);
54-
}
55-
56-
if (this.path.exists()) {
57-
this.path.setExecutable(true);
51+
52+
String clazz = element.getAttribute("class");
53+
if (clazz != null && !clazz.isEmpty()) {
54+
try {
55+
INodejsInstallProvider provider = (INodejsInstallProvider) element.createExecutableExtension("class");
56+
this.path = provider.getPath();
57+
} catch (CoreException e) {
58+
Trace.trace(Trace.SEVERE, "Problems at creating install provider", e);
59+
}
60+
} else {
61+
String pluginId = element.getNamespaceIdentifier();
62+
String path = element.getAttribute("path");
63+
if (path != null && path.length() > 0) {
64+
File bundleDir = FileLocator.getBundleFile(Platform
65+
.getBundle(pluginId));
66+
67+
IPath stateLocationPath = InternalPlatform.getDefault().getStateLocation(Platform
68+
.getBundle(pluginId));
69+
70+
if (stateLocationPath != null) {
71+
File baseDir = stateLocationPath.toFile();
72+
73+
this.path = new File(baseDir, path);
74+
75+
// check if path exists, if it doesn't look for zip
76+
if (!this.path.exists()) {
77+
String zip = element.getAttribute("zip");
78+
79+
File zipFile = new File(bundleDir, zip);
80+
81+
if (zipFile.exists()) {
82+
if (zipFile.getName().toLowerCase().endsWith(".zip")) {
83+
ZipUtils.extract(zipFile, baseDir);
84+
}
85+
86+
if(this.path.exists()) {
87+
this.path.setExecutable(true);
88+
}
89+
}
5890
}
5991
}
6092
}
@@ -80,4 +112,4 @@ public void dispose() {
80112

81113
}
82114

83-
}
115+
}

0 commit comments

Comments
 (0)