Skip to content

Commit

Permalink
org.nodeclipse.java.avatarjs idea/code
Browse files Browse the repository at this point in the history
  • Loading branch information
paulvi committed Apr 18, 2014
1 parent bf47dc8 commit 512b47f
Show file tree
Hide file tree
Showing 20 changed files with 590 additions and 0 deletions.
7 changes: 7 additions & 0 deletions org.nodeclipse.java.avatarjs/.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.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
28 changes: 28 additions & 0 deletions org.nodeclipse.java.avatarjs/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.nodeclipse.java.avatarjs</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>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
21 changes: 21 additions & 0 deletions org.nodeclipse.java.avatarjs/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Nodeclipse Java Avatar.js
Bundle-SymbolicName: org.nodeclipse.java.avatarjs;singleton:=true
Bundle-Version: 0.12.0.qualifier
Bundle-Activator: org.nodeclipse.java.avatarjs.Activator
Bundle-Vendor: Nodeclipse/Enide
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.ui.ide,
org.eclipse.ui.editors,
org.eclipse.debug.ui,
org.nodeclipse.ui,
org.nodeclipse.debug,
org.eclipse.wst.jsdt.core;bundle-version="1.1.102",
org.eclipse.wst.jsdt.ui,
org.nodeclipse.common
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Import-Package: org.nodeclipse.debug.launch,
org.nodeclipse.debug.util
35 changes: 35 additions & 0 deletions org.nodeclipse.java.avatarjs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

# org.nodeclipse.java.avatarjs

Quick and dirty idea/code to launch .js with java 8 and Avatar.js lib
Not yet finished, reason:
running with Java/Avatar.js is launching like `java -Djava.library.path=lib -jar lib/avatar-js.jar helloWorld.js`
- libs maybe missing or in other folder,
- embedding not released binaries in Eclipse plugin seems bad idea (also there are native lib for every OS)
- would require searching for project root (Node can actually run from any folder)


## Usage

Read at <>

Read also built-in <kbd>F1</kbd>
and [Online Help](https://github.com/Nodeclipse/nodeclipse-1/tree/master/org.nodeclipse.help/contents#intro)

### Links

- http://www.infoq.com/articles/nashorn
- https://blogs.oracle.com/theaquarium/entry/project_avatar_is_open_source
- https://avatar.java.net/
- http://blog.jonasbandi.net/2014/03/running-nodejs-applications-on-jvm-with.html
- http://strongloop.com/strongblog/how-to-run-node-js-on-the-jvm-with-avatar-js-and-loopback/

## Developing

Depends on `.ui` and `.common`

`Import-Package: org.nodeclipse.debug.launch` in MANIFEST.MF is for `org.nodeclipse.debug.launch.LaunchConfigurationEnvironmentTab`

org.nodeclipse.debug.util is for in org.nodeclipse.phantomjs.launch.LaunchConfigurationDelegate

TODO copy that Class or make .debug module general (not Node.js related)
6 changes: 6 additions & 0 deletions org.nodeclipse.java.avatarjs/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source.. = src/
output.. = bin/
bin.includes = plugin.xml,\
META-INF/,\
.,\
icons/
Binary file added org.nodeclipse.java.avatarjs/icons/java_16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added org.nodeclipse.java.avatarjs/icons/nashorn_16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 92 additions & 0 deletions org.nodeclipse.java.avatarjs/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

<extension
point="org.eclipse.ui.editors">
<editor
class="org.nodeclipse.ui.editors.NodeEditor"
contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor"
default="true"
extensions="ajs"
icon="icons/java_16x16.png"
id="org.nodeclipse.java.avatarjs.editors.JJSEditor"
name="Avatar.js Editor">
</editor>
</extension>

<extension
point="org.eclipse.debug.core.launchConfigurationTypes">
<launchConfigurationType
delegate="org.nodeclipse.java.avatarjs.launch.LaunchConfigurationDelegate"
id="org.nodeclipse.java.avatarjs.launch.LaunchConfigurationType"
modes="run, debug"
name="Avatar.js Application">
</launchConfigurationType>
</extension>
<extension
point= "org.eclipse.debug.ui.launchConfigurationTypeImages" >
<launchConfigurationTypeImage
configTypeID= "org.nodeclipse.java.avatarjs.launch.LaunchConfigurationType"
icon= "icons/java_16x16_bottom_right_corner_run_half_size.png"
id= "org.nodeclipse.java.avatarjs.launch.LaunchConfigurationTypeImage" >
</launchConfigurationTypeImage>
</extension>
<!-- avatar.js run/debug -->
<extension
point= "org.eclipse.debug.ui.launchShortcuts" >
<shortcut
class= "org.nodeclipse.java.avatarjs.launch.LaunchShortcut"
icon= "icons/nashorn_16x16_bottom_right_corner_run_half_size.png"
id= "org.nodeclipse.debug.launch.LaunchShortcut"
label= "Avatar.js Application"
modes= "run, debug" >
<configurationType
id= "org.nodeclipse.java.avatarjs.launch.LaunchConfigurationType" >
</configurationType>
<contextualLaunch>
<enablement>
<with
variable= "selection" >
<count
value= "1" >
</count>
<iterate>
<or>
<test
property= "org.eclipse.debug.ui.matchesPattern"
value= "*.js" >
</test>
<test
property= "org.eclipse.debug.ui.matchesPattern"
value= "*.jjs" >
</test>
</or>
</iterate>
</with>
</enablement>
</contextualLaunch>
</shortcut>
</extension>


<extension
point="org.eclipse.debug.ui.launchConfigurationTabGroups">
<launchConfigurationTabGroup
class= "org.nodeclipse.java.avatarjs.launch.LaunchConfigurationTabGroup"
id= "org.nodeclipse.java.avatarjs.launch.LaunchConfigurationTabGroup"
type= "org.nodeclipse.java.avatarjs.launch.LaunchConfigurationType" >
</launchConfigurationTabGroup>
</extension>

<extension
point="org.eclipse.ui.preferencePages">
<page
category="org.nodeclipse.ui.preferences.NodePreferencePage"
class="org.nodeclipse.java.avatarjs.preferences.AvatarjsPreferencePage"
id="org.nodeclipse.java.avatarjs.preferences.AvatarjsPreferencePage"
name="Avatar.js">
</page>
</extension>

</plugin>
19 changes: 19 additions & 0 deletions org.nodeclipse.java.avatarjs/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.nodeclipse.nodeclipse-1</groupId>
<artifactId>parent</artifactId>
<version>0.12.0-SNAPSHOT</version>
</parent>

<artifactId>org.nodeclipse.java.avatarjs</artifactId>
<packaging>eclipse-plugin</packaging>

<name>org.nodeclipse.java.avatarjs</name>
<description>org.nodeclipse.java.avatarjs</description>
</project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.nodeclipse.java.avatarjs;

import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.nodeclipse.java.avatarjs.preferences.AvatarjsConstants;
import org.osgi.framework.BundleContext;

/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {

// The plug-in ID
public static final String PLUGIN_ID = AvatarjsConstants.PLUGIN_ID;

// The shared instance
private static Activator plugin;

/**
* The constructor
*/
public Activator() {
}

/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}

/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}

/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package org.nodeclipse.java.avatarjs.launch;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
import org.eclipse.debug.core.model.RuntimeProcess;
import org.eclipse.jface.preference.IPreferenceStore;
import org.nodeclipse.common.preferences.CommonDialogs;
import org.nodeclipse.debug.util.Constants;
import org.nodeclipse.debug.util.VariablesUtil;
import org.nodeclipse.java.avatarjs.preferences.AvatarjsConstants;
import org.nodeclipse.ui.Activator;
//import org.nodeclipse.ui.preferences.PreferenceConstants;
import org.nodeclipse.ui.util.NodeclipseConsole;

/**
* Launching `jjs` from Java 8.<br>
* see LaunchConfigurationDelegate in .debug and .phantomjs module for comparison.
*
* @since 0.7
* @author Paul Verest
*/
public class LaunchConfigurationDelegate implements ILaunchConfigurationDelegate {

@Override
public void launch(ILaunchConfiguration configuration, String mode,
ILaunch launch, IProgressMonitor monitor) throws CoreException {

//NodeclipseConsole.write("launch jjs\n");

IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
boolean isDebugMode = mode.equals(ILaunchManager.DEBUG_MODE);

// Using configuration to build command line
List<String> cmdLine = new ArrayList<String>();

String jjsPath= preferenceStore.getString(AvatarjsConstants.JAVA_PATH);
// Check if the node location is correctly configured
File jjsFile = new File(jjsPath);
if(!jjsFile.exists()){
// If the location is not valid than show a dialog which prompts the user to goto the preferences page
// Dialogs.showPreferencesDialog("path to jjs util from Java 8 runtime is not correctly configured.\n\n"
// + "Please goto Window -> Prefrences -> Nodeclipse and configure the correct location under 'JJS path:'");
CommonDialogs.showPreferencesDialog(AvatarjsConstants.PREFERENCES_PAGE,
"Java 8 Nashorn jjs location is not correctly configured.\n\n"
+ "Please goto Window -> Preferences -> "+AvatarjsConstants.PREFERENCE_PAGE_NAME
+" and configure the correct location");
return;
}
cmdLine.add(jjsPath);

if (isDebugMode) {
//TODO research how to debug
}

String file = configuration.getAttribute("KEY_FILE_PATH", "");
String filePath = ResourcesPlugin.getWorkspace().getRoot().findMember(file).getLocation().toOSString();
// path is relative, so cannot find it, unless get absolute path
cmdLine.add(filePath);

File workingPath = null;
String workingDirectory = configuration.getAttribute(Constants.ATTR_WORKING_DIRECTORY, "");
if(workingDirectory.length() > 0) {
workingDirectory = VariablesUtil.resolveValue(workingDirectory);
if(workingDirectory != null) {
workingPath = new File(workingDirectory);
}
}
if (workingPath == null){
workingPath = (new File(filePath)).getParentFile();
}

Map<String, String> envm = new HashMap<String, String>();
envm = configuration.getAttribute(Constants.ATTR_ENVIRONMENT_VARIABLES, envm);
String[] envp = new String[envm.size()];
int idx = 0;
for(String key : envm.keySet()) {
String value = envm.get(key);
envp[idx++] = key + "=" + value;
}


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

String[] cmds = {};
cmds = cmdLine.toArray(cmds);
// Launch a process to debug.eg,
Process p = DebugPlugin.exec(cmds, workingPath, envp);
RuntimeProcess process = (RuntimeProcess)DebugPlugin.newProcess(launch, p, AvatarjsConstants.PROCESS_MESSAGE);
if (isDebugMode) {
//TODO research how to debug
}

}

}
Loading

0 comments on commit 512b47f

Please sign in to comment.