Skip to content

Commit c4705d4

Browse files
authored
Merge pull request #435 from sosahvictor/master
Extension of the install provider to accept a class
2 parents 67bc0b5 + e32c87f commit c4705d4

File tree

3 files changed

+95
-30
lines changed

3 files changed

+95
-30
lines changed

eclipse/tern.eclipse.ide.server.nodejs.core/schema/nodeJSInstalls.exsd

Lines changed: 24 additions & 7 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>
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 <sosah.victor@gmail.com>- initial API and implementation
10+
*/
11+
package tern.eclipse.ide.server.nodejs.core;
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:sosah.victor@gmail.com">sosah.victor@gmail.com</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+
}

eclipse/tern.eclipse.ide.server.nodejs.core/src/tern/eclipse/ide/server/nodejs/internal/core/NodejsInstall.java

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
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 <angelo.zerr@gmail.com> - initial API and implementation
10+
* Victor Sosa <sosah.victor@gmail.com> - Extension to allow locations computed programmatically
1011
*/
1112
package tern.eclipse.ide.server.nodejs.internal.core;
1213

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

17+
import org.eclipse.core.runtime.CoreException;
1618
import org.eclipse.core.runtime.FileLocator;
1719
import org.eclipse.core.runtime.IConfigurationElement;
1820
import org.eclipse.core.runtime.Platform;
1921

2022
import tern.eclipse.ide.server.nodejs.core.INodejsInstall;
23+
import tern.eclipse.ide.server.nodejs.core.INodejsInstallProvider;
2124
import tern.utils.ZipUtils;
2225

2326
public class NodejsInstall implements INodejsInstall {
2427

25-
private final String id;
26-
private final String name;
28+
private String id;
29+
private String name;
2730
private File path;
2831

2932
/**
@@ -34,28 +37,43 @@ public class NodejsInstall implements INodejsInstall {
3437
* @throws IOException
3538
*/
3639
public NodejsInstall(IConfigurationElement element) throws IOException {
40+
createClass(element);
41+
}
42+
43+
private void createClass(IConfigurationElement element) throws IOException {
3744
this.id = element.getAttribute("id");
3845
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
43-
.getBundle(pluginId));
44-
this.path = new File(baseDir, path);
45-
46-
// check if path exists, if it doesn't look for zip
47-
if (!this.path.exists()) {
48-
String zip = element.getAttribute("zip");
49-
50-
File zipFile = new File(baseDir, zip);
51-
52-
if (zipFile.exists()) {
53-
if (zipFile.getName().toLowerCase().endsWith(".zip")) {
54-
ZipUtils.extract(zipFile, baseDir);
55-
}
56-
57-
if(this.path.exists()) {
58-
this.path.setExecutable(true);
46+
47+
String clazz = element.getAttribute("class");
48+
if (clazz != null && !clazz.isEmpty()) {
49+
try {
50+
INodejsInstallProvider provider = (INodejsInstallProvider) element.createExecutableExtension("class");
51+
this.path = provider.getPath();
52+
} catch (CoreException e) {
53+
Trace.trace(Trace.SEVERE, "Problems at creating install provider", e);
54+
}
55+
} else {
56+
String pluginId = element.getNamespaceIdentifier();
57+
String path = element.getAttribute("path");
58+
if (path != null && path.length() > 0) {
59+
File baseDir = FileLocator.getBundleFile(Platform
60+
.getBundle(pluginId));
61+
this.path = new File(baseDir, path);
62+
63+
// check if path exists, if it doesn't look for zip
64+
if (!this.path.exists()) {
65+
String zip = element.getAttribute("zip");
66+
67+
File zipFile = new File(baseDir, zip);
68+
69+
if (zipFile.exists()) {
70+
if (zipFile.getName().toLowerCase().endsWith(".zip")) {
71+
ZipUtils.extract(zipFile, baseDir);
72+
}
73+
74+
if(this.path.exists()) {
75+
this.path.setExecutable(true);
76+
}
5977
}
6078
}
6179
}

0 commit comments

Comments
 (0)