Skip to content

Commit

Permalink
Merge branch 'angelozerr/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
demonfiddler committed Nov 10, 2015
2 parents 4505fc3 + b86cc38 commit 57a774c
Show file tree
Hide file tree
Showing 251 changed files with 35,774 additions and 737 deletions.
20 changes: 7 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ tern.java
[tern.js](https://github.com/marijnh/tern) is a stand-alone code-analysis engine for JavaScript written in Javascript.

[tern.java](https://github.com/angelozerr/tern.java) provides the capability to use
[tern.js](https://github.com/marijnh/tern) with Java context. It provides several implementation :
[tern.js](https://github.com/marijnh/tern) with Java context. It provides several tern server implementation :

* wraps tern.js with Java code by using [Rhino](https://developer.mozilla.org/en-US/docs/Rhino) to create a Tern Server with Java code.
* wraps tern.js with Java code by using [node.js](http://nodejs.org/) to create a Tern Server with Java code.
* an other idea is to use [javv8](https://code.google.com/p/jav8/) but it seems the project is dead and [I need win32 implementation](https://code.google.com/p/jav8/issues/detail?id=26).
* one more idea is to explorer [Java 8 Nashorn JavaScript engine](https://blogs.oracle.com/nashorn/), possibly with [avatar.js](https://avatar-js.java.net/), see [#33](https://github.com/angelozerr/tern.java/issues/33)

As Tern is *very* CPU and memory intensive, the implementation with Rhino is very slow when JavaScript document is big. So it's better to use
node.js or javv8.
* [tern.server.j2v8](https://github.com/angelozerr/tern.java/tree/master/core/tern.server.j2v8) wraps tern.js with Java code by using [J2V8](https://github.com/eclipsesource/J2V8) to create a Tern Server with Java code.
* [tern.server.rhino](https://github.com/angelozerr/tern.java/tree/master/core/tern.server.rhino) wraps tern.js with Java code by using [Rhino](https://developer.mozilla.org/en-US/docs/Rhino) to create a Tern Server with Java code.
* [tern.server.nashorn](https://github.com/angelozerr/tern.java/tree/master/core/tern.server.nashorn) wraps tern.js with Java code by using [Java 8 Nashorn JavaScript engine](https://blogs.oracle.com/nashorn/) to create a Tern Server with Java code.
* [tern.server.nodejs](https://github.com/angelozerr/tern.java/tree/master/core/tern.server.nodejs) wraps tern.js with Java code by using [node.js](http://nodejs.org/) to create a Tern Server with Java code.

As Tern is *very* CPU and memory intensive, the implementation with Rhino is very slow when JavaScript document is big. So it's better to use node.js or javv8. Nashorn is a little slow compare to J2V8 or node.js

## Core Features

Expand Down Expand Up @@ -72,8 +71,3 @@ See https://www.genuitec.com/tag/tern/ for more informations.
## Build

See cloudbees job: https://opensagres.ci.cloudbees.com/job/tern.java/

## Rhino version

As [tern.js](https://github.com/marijnh/tern) uses [ECMAScript5](http://fr.wikipedia.org/wiki/ECMAScript), the Rhino version should support it. The [org.mozilla.javascript](https://github.com/angelozerr/tern.java/tree/master/org.mozilla.javascript) is an OSGi bundle which wraps the JAR
**Rhino 1.7R4** which supports ECMAScript5.
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>fr.opensagres.js</groupId>
<artifactId>tern.java</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
</parent>
<artifactId>core</artifactId>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion core/tern.core.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Tests2
Bundle-SymbolicName: tern.core.tests
Bundle-Version: 1.1.0.qualifier
Bundle-Version: 1.2.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: tern.core,
tern.server.nodejs,
Expand Down
2 changes: 1 addition & 1 deletion core/tern.core.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>fr.opensagres.js</groupId>
<artifactId>core</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
</parent>
<artifactId>tern.core.tests</artifactId>
</project>
4 changes: 2 additions & 2 deletions core/tern.core.tests/src/tern/TernRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class TernRepositoryTest {

@Test
public void defaultRepository() throws TernException {
File ternFile = PathHelper.getNodejsTernBaseDir();
TernRepository repository = new TernRepository("default", ternFile);
File ternBaseDir = PathHelper.getTernRepositoryDir();
TernRepository repository = new TernRepository("default", ternBaseDir);
ITernModule[] modules = repository.getModules();
for (int i = 0; i < modules.length; i++) {
System.err.println(modules[i].getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,15 @@ private static void unZipIfNecessary(String os, String ws, String arch) {
* @return
*/
public static File getNodejsTernBaseDir() {

return new File("../ternjs/node_modules/tern");
return new File(getTernRepositoryDir(), "node_modules/tern");
}

/**
* Return tern base dir.
*
* @return
*/
public static File getTernRepositoryDir() {
return new File("../ternjs");
}
}
2 changes: 1 addition & 1 deletion core/tern.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-SymbolicName: tern.core
Bundle-Version: 1.1.0.qualifier
Bundle-Version: 1.2.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: tern,
tern.angular,
Expand Down
2 changes: 1 addition & 1 deletion core/tern.core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<parent>
<groupId>fr.opensagres.js</groupId>
<artifactId>core</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
</parent>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class TernModuleMetadataManager {
private final File baseDir;

public TernModuleMetadataManager(ITernRepository repository) {
this(repository.getTernBaseDir().getParentFile().getParentFile());
this(repository.getBaseDir());
}

public TernModuleMetadataManager(File baseDir) {
Expand Down
54 changes: 35 additions & 19 deletions core/tern.core/src/tern/repository/ITernRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@
* Tern repository is a local base dir which contains the tern.js JS files :
*
* <ul>
* <li>bin folder</li>
* <li>defs folder</li>
* <li>plugin folder</li>
* <li>node_modules folder</li>
* <li>metadata</li>
* <li>node_modules
* <ul>
* <li>tern
* <ul>
* <li>bin</li>
* <li>defs</li>
* <li>plugin</li>
* </ul>
* </li>
* </ul>
* </li>
* </ul>
*
*/
Expand All @@ -39,9 +47,30 @@ public interface ITernRepository {
String getName();

/**
* Returns the tern base dir which contains ternjs and their custom plugins.
* Returns the base directory of the tern repository.
*
* @return the tern base dir which contains ternjs and their custom plugins.
* @return the base directory of the tern repository.
*/
File getBaseDir();

/**
* Update the tbase directory of the tern repository.
*
* @param baseDir
*/
void setBaseDir(File baseDir);

/**
* Returns the node_modules directory.
*
* @return the node_modules directory.
*/
File getNodeModulesDir();

/**
* Returns the tern base dir (node_modules/tern) which contains ternjs and their custom plugins.
*
* @return the tern base dir (node_modules/tern) which contains ternjs and their custom plugins.
*/
File getTernBaseDir();

Expand All @@ -54,13 +83,6 @@ public interface ITernRepository {
*/
String getTernBaseDirAsString();

/**
* Update the tern base dir which contains ternjs and their custom plugins.
*
* @param ternFile
*/
void setTernBaseDir(File ternFile);

/**
* Returns true if the repository is a default repository and false
* otherwise (custom repository).
Expand Down Expand Up @@ -135,10 +157,4 @@ public interface ITernRepository {
*/
TernModuleMetadata getDefaultMetadata(String moduleName);

/**
* Returns the node_modules directory.
*
* @return the node_modules directory.
*/
File getNodeModulesDir();
}
39 changes: 24 additions & 15 deletions core/tern.core/src/tern/repository/TernRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,22 @@ public class TernRepository implements ITernRepository {
.asList(new String[] { "commonjs", "modules", "node_resolve" });

private final String name;
private File baseDir;
private File nodeModulesDir;
private File ternBaseDir;
private final boolean defaultRepository;
private Map<String, ITernModule> modules;
private Map<String, ITernModule> modulesByOrigin;
private ITernPlugin[] linters;
private final TernModuleMetadataManager metadataManager;

public TernRepository(String name, File ternBaseDir) {
this(name, ternBaseDir, false);
public TernRepository(String name, File baseDir) {
this(name, baseDir, false);
}

public TernRepository(String name, File ternFile, boolean defaultRepository) {
public TernRepository(String name, File baseDir, boolean defaultRepository) {
this.name = name;
this.ternBaseDir = ternFile;
this.setBaseDir(baseDir);
this.defaultRepository = defaultRepository;
this.metadataManager = new TernModuleMetadataManager(this);
}
Expand Down Expand Up @@ -123,11 +125,6 @@ private void loadModules(Map<String, ITernModule> modules, Map<String, ITernModu
loadModules(modules, modulesByOrigin, getNodeModulesDir(), null);
}

@Override
public File getNodeModulesDir() {
return getTernBaseDir().getParentFile();
}

private void loadModules(Map<String, ITernModule> modules, Map<String, ITernModule> modulesByOrigin, File baseDir,
List<String> ignoreModules) throws TernException {
if (baseDir.exists()) {
Expand Down Expand Up @@ -156,7 +153,24 @@ private boolean isIgnoreModule(ITernModule module, List<String> ignoreModules) {
public void refresh() {
this.modules = null;
}


@Override
public File getBaseDir() {
return baseDir;
}

@Override
public void setBaseDir(File baseDir) {
this.baseDir = baseDir;
this.nodeModulesDir = new File(baseDir, "node_modules");
this.ternBaseDir = new File(nodeModulesDir, "tern");
}

@Override
public File getNodeModulesDir() {
return nodeModulesDir;
}

@Override
public File getTernBaseDir() {
return ternBaseDir;
Expand All @@ -167,11 +181,6 @@ public String getTernBaseDirAsString() {
return TernModuleHelper.getPath(getTernBaseDir());
}

@Override
public void setTernBaseDir(File ternBaseDir) {
this.ternBaseDir = ternBaseDir;
}

@Override
public boolean isDefault() {
return defaultRepository;
Expand Down
2 changes: 1 addition & 1 deletion core/tern.server.j2v8/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-SymbolicName: tern.server.j2v8;singleton:=true
Bundle-Version: 1.1.0.qualifier
Bundle-Version: 1.2.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: tern.core
Bundle-ClassPath: .
Expand Down
20 changes: 3 additions & 17 deletions core/tern.server.j2v8/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ tern.server.j2v8

## Sample with SWT

[tern.eclipse.swt.samples](https://github.com/angelozerr/tern.java/tree/master/eclipse/tern.eclipse.swt.samples) provides a sample with a simple SWT Text & the J2V8 tern server implementation. To use it :
[tern.eclipse.swt.samples](https://github.com/angelozerr/tern.java/tree/master/samples/tern.eclipse.swt.samples) provides a sample with a simple SWT Text & the J2V8 tern server implementation. To use it :

* import the following projects in your workspace :

Expand All @@ -37,7 +37,7 @@ tern.server.j2v8
* tern.server.j2v8
* ternjs

* Run the main https://github.com/angelozerr/tern.java/blob/master/eclipse/tern.eclipse.swt.samples/src/tern/eclipse/swt/samples/j2v8/J2V8TernEditor.java
* Run the main https://github.com/angelozerr/tern.java/blob/master/samples/tern.eclipse.swt.samples/src/tern/eclipse/swt/samples/j2v8/J2V8TernEditor.java

You can play with Ctrl+Space to open tern completion :

Expand All @@ -53,20 +53,6 @@ You can play with Ctrl+Space to open tern completion :
* implement basic console.log. I think J2V8 should provide that.

# Limitation

* cannot be used with Eclipse IDE, because of async tern completion (with thread) and https://github.com/eclipsesource/J2V8/issues/33 , it throws error :

```
java.lang.Error: Invalid V8 thread access.
at com.eclipsesource.v8.V8.checkThread(V8.java:246)
at com.eclipsesource.v8.V8.executeStringScript(V8.java:187)
at com.eclipsesource.v8.V8.executeStringScript(V8.java:183)
at tern.server.j2v8.J2V8TernServer.request(J2V8TernServer.java:79)
at tern.server.j2v8.J2V8TernServer.request(J2V8TernServer.java:69)
at tern.server.protocol.TernResultsProcessorsFactory.makeRequestAndProcess(TernResultsProcessorsFactory.java:36)
at tern.eclipse.ide.internal.core.resources.IDETernServerAsyncReqProcessor.run(IDETernServerAsyncReqProcessor.java:104)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
```

* not tested, but is it working if there are several J2V8 tern server (several v8 instances)? Because in Eclipse IDE, there are a tern server per Eclipse project.
* some tern plugin requires **require** node function to support their features like :
Expand All @@ -78,4 +64,4 @@ java.lang.Error: Invalid V8 thread access.
# TODO

* clean code!
* integrate the thern server J2v8 inside Eclipse IDE
* integrate the thern server J2V8 inside Eclipse IDE
2 changes: 1 addition & 1 deletion core/tern.server.j2v8/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
# Contributors:
# Angelo Zerr <angelo.zerr@gmail.com> - Initial API and implementation
###############################################################################
pluginName=Tern - Server - Nodejs
pluginName=Tern - Server - J2V8
providerName=Angelo ZERR
7 changes: 7 additions & 0 deletions core/tern.server.nashorn/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
File renamed without changes.
34 changes: 34 additions & 0 deletions core/tern.server.nashorn/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>tern.server.nashorn</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
17 changes: 17 additions & 0 deletions core/tern.server.nashorn/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-SymbolicName: tern.server.nashorn;singleton:=true
Bundle-Version: 1.2.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: tern.core
Bundle-ClassPath: .
Import-Package: com.eclipsesource.json;version="[0.9.4,0.9.5)",
com.eclipsesource.v8,
com.eclipsesource.v8.utils,
org.osgi.framework
Bundle-ActivationPolicy: lazy
Bundle-Activator: tern.server.nashorn.Activator
Export-Package: tern.server.nashorn
Loading

0 comments on commit 57a774c

Please sign in to comment.