Permalink
Browse files

prototype executing (parallel and inheriting in JS) Java (tests) and …

…JavaScript by JavaScript during runtime without restart
  • Loading branch information...
1 parent 8ed4849 commit bd2b2264aaf0c576a9423785f187c16625a8c3aa @Tibor17 committed Feb 17, 2014
Showing with 1,350 additions and 382 deletions.
  1. +108 −236 plugins/itest/itest.iws
  2. +7 −0 plugins/itest/src/main/java/org/apache/maven/plugin/itest/JScriptMojo.java
  3. +127 −0 plugins/itest/src/main/java/org/apache/maven/plugin/itest/Result.java
  4. +50 −0 plugins/itest/src/main/java/org/apache/maven/plugin/itest/RunnerUtil.java
  5. +39 −0 plugins/itest/src/main/java/org/apache/maven/plugin/itest/Script.java
  6. +1 −0 plugins/prototypes/callJavaMethod.bat
  7. +2 −0 plugins/prototypes/callJavaMethod.js
  8. +1 −0 plugins/prototypes/extendSameMethods.bat
  9. +4 −0 plugins/prototypes/extendSameMethods.js
  10. BIN plugins/prototypes/lib/FunctionOverride.class
  11. BIN plugins/prototypes/lib/JavaMethod.class
  12. BIN plugins/prototypes/lib/SameMethods.class
  13. BIN plugins/prototypes/lib/callJavaMethod.class
  14. BIN plugins/prototypes/lib/callJavaMethod1.class
  15. BIN plugins/prototypes/lib/extendSameMethods.class
  16. BIN plugins/prototypes/lib/extendSameMethods1.class
  17. BIN plugins/prototypes/lib/sharingContext.class
  18. BIN plugins/prototypes/lib/sharingContext1.class
  19. BIN plugins/prototypes/lib/sharingContext2.class
  20. BIN plugins/prototypes/lib/sharingContext3.class
  21. BIN plugins/prototypes/lib/sharingContext4.class
  22. BIN plugins/prototypes/lib/sharingContext41.class
  23. BIN plugins/prototypes/lib/test101.class
  24. +7 −1 plugins/prototypes/prototypes.ipr
  25. +605 −145 plugins/prototypes/prototypes.iws
  26. +10 −0 plugins/prototypes/sameFunctions.js
  27. +20 −0 plugins/prototypes/src/JavaMethod.java
  28. +235 −0 plugins/prototypes/src/RunnerMozillaExtendsFunctionOverride2.java
  29. +32 −0 plugins/prototypes/src/RunnerMozillaExtendsSameMethods.java
  30. +45 −0 plugins/prototypes/src/RunnerMozillaJavaMethod.java
  31. +29 −0 plugins/prototypes/src/RunnerMozillaSameFunctions.java
  32. +27 −0 plugins/prototypes/src/SameMethods.java
  33. +1 −0 plugins/prototypes/test10.js
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -79,6 +79,13 @@
boolean useConsole;
/**
+ * As of plugin version 1.0-alpha-04, sets whether the plugin uses a default console in an interactive mode.
+ * @parameter expression="${jscript.useDefaultConsole}" default-value="false"
+ * @since 1.0-alpha-04
+ */
+ boolean useDefaultConsole;
+
+ /**
* As of plugin version 1.0-alpha-01, sets whether the plugin uses a verbose mode.
* The script is printed.
* @parameter expression="${jscript.useConsole}" default-value="false"
@@ -0,0 +1,127 @@
+/*
+ * The copyright holders of this work license this file to You under
+ * the Apache License, Version 2.0 (the "License"); you may not use this
+ * file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.maven.plugin.itest;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.mozilla.javascript.Function;
+import org.mozilla.javascript.NativeFunction;
+import org.mozilla.javascript.Scriptable;
+import org.mozilla.javascript.Undefined;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+abstract class Result {
+ private final Object result;
+
+ protected Result(Object result) {
+ this.result = result;
+ }
+
+ protected final boolean isResultUndefined() {
+ return result == Undefined.instance;
+ }
+
+ protected abstract Map<String, Function> getFunctions();
+
+ protected static LinkedHashMap<String, Function> getFunctions(NativeFunction compiledScript)
+ throws MojoExecutionException, MojoFailureException {
+ int count = getParamAndVarCount(compiledScript);
+ final LinkedHashMap<String, Function> functions
+ = new LinkedHashMap<String, Function>(count);
+ for (int id = 0; id < count; ++id) {
+ String fname = getParamOrVarName(compiledScript, id);
+ compiledScript.
+ }
+ }
+
+ private static int getParamAndVarCount(NativeFunction compiledScript)
+ throws MojoExecutionException, MojoFailureException {
+ try {
+ Method count = compiledScript.getClass().getMethod("getParamAndVarCount");
+ if (!Modifier.isPublic(count.getModifiers()))
+ throw new MojoExecutionException("implemented method NativeFunction#getParamAndVarCount() " +
+ "must not be protected in " + compiledScript.getClass().getName());
+ return (Integer) count.invoke(compiledScript);
+ } catch (NoSuchMethodException e) {
+ throw new MojoExecutionException("broken backward compatibility NativeFunction#getParamAndVarCount() in "
+ + compiledScript.getClass().getName(), e);
+ } catch (SecurityException e) {
+ String shortMsg = "java.lang.SecurityManager#checkMemberAccess for public methods ";
+ String longMsg = shortMsg.concat(compiledScript.getClass().getName());
+ throw new MojoFailureException(e, shortMsg, longMsg);
+ } catch (InvocationTargetException e) {
+ throw new MojoExecutionException("implemented method NativeFunction#getParamAndVarCount() " +
+ " in " + compiledScript.getClass().getName() + " throws an exception ", e);
+ } catch (IllegalAccessException e) {
+ throw new MojoExecutionException("implemented method NativeFunction#getParamAndVarCount() " +
+ "must not be protected in " + compiledScript.getClass().getName(), e);
+ } catch (IllegalArgumentException e) {
+ throw new MojoExecutionException("broken backward compatibility NativeFunction#getParamAndVarCount() of arguments in "
+ + compiledScript.getClass().getName(), e);
+ } catch (ExceptionInInitializerError e) {
+ throw new MojoExecutionException("static initializer failure while calling NativeFunction#getParamAndVarCount() in "
+ + compiledScript.getClass().getName(), e);
+ }
+ }
+
+ private static String getParamOrVarName(NativeFunction compiledScript, int id)
+ throws MojoExecutionException, MojoFailureException {
+ try {
+ Method count = compiledScript.getClass().getMethod("getParamOrVarName", int.class);
+ if (!Modifier.isPublic(count.getModifiers()))
+ throw new MojoExecutionException("implemented method NativeFunction#getParamOrVarName(int) " +
+ "must not be protected in " + compiledScript.getClass().getName());
+ return (String) count.invoke(compiledScript, id);
+ } catch (NoSuchMethodException e) {
+ throw new MojoExecutionException("broken backward compatibility NativeFunction#getParamOrVarName(int) in "
+ + compiledScript.getClass().getName(), e);
+ } catch (SecurityException e) {
+ String shortMsg = "java.lang.SecurityManager#checkMemberAccess for public methods ";
+ String longMsg = shortMsg.concat(compiledScript.getClass().getName());
+ throw new MojoFailureException(e, shortMsg, longMsg);
+ } catch (InvocationTargetException e) {
+ throw new MojoExecutionException("implemented method NativeFunction#getParamOrVarName(int) " +
+ " in " + compiledScript.getClass().getName() + " throws an exception ", e);
+ } catch (IllegalAccessException e) {
+ throw new MojoExecutionException("implemented method NativeFunction#getParamOrVarName(int) " +
+ "must not be protected in " + compiledScript.getClass().getName(), e);
+ } catch (IllegalArgumentException e) {
+ throw new MojoExecutionException("broken backward compatibility NativeFunction#getParamOrVarName(int) of arguments in "
+ + compiledScript.getClass().getName(), e);
+ } catch (ExceptionInInitializerError e) {
+ throw new MojoExecutionException("static initializer failure while calling NativeFunction#getParamOrVarName(int) in "
+ + compiledScript.getClass().getName(), e);
+ }
+ }
+
+ protected static LinkedHashMap<String, Function> getAllFunctions(Scriptable scope) {
+ final Object[] ids = scope.getIds();
+ final LinkedHashMap<String, Function> functions
+ = new LinkedHashMap<String, Function>(ids.length);
+ for (final Object id : ids) {
+ if (!(id instanceof String)) continue;
+ final String fname = (String) id;
+ final Object fObj = scope.get(fname, scope);
+ if (!functions.containsKey(fname) && fObj instanceof Function)
+ functions.put(fname, (Function) fObj);
+ }
+ return functions;
+ }
+}
@@ -0,0 +1,50 @@
+/*
+ * The copyright holders of this work license this file to You under
+ * the Apache License, Version 2.0 (the "License"); you may not use this
+ * file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.maven.plugin.itest;
+
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.Scriptable;
+
+final class RunnerUtil {
+ public static Result run(Context ctx, Scriptable scope, Script<String> script) {
+ if (ctx == null) throw new NullPointerException("null context " + Context.class.getName());
+ if (scope == null) throw new NullPointerException("null scope " + Scriptable.class.getName());
+ if (script == null) throw new NullPointerException("null script " + Script.class.getName());
+ if (script.getScript() == null) throw new NullPointerException("null script");
+ if (script.getScript().length() == 0) throw new IllegalArgumentException("empty script");
+ if (script.getScriptName() == null) throw new NullPointerException("null script name");
+ if (script.getStartByLine() < 0) throw new IllegalArgumentException("negative start by line " + script.getStartByLine());
+ Object r = ctx.evaluateString(scope, script.getScript(), script.getScriptName(), script.getStartByLine(), null);
+
+ return new Result(r) {};
+ }
+
+ public static Result run(Scriptable scope, Script<String> script) {
+ try {
+ return run(Context.enter(), scope, script);
+ } finally {
+ Context.exit();
+ }
+ }
+
+ public static Result run(Script<String> script) {
+ try {
+ Context ctx = Context.enter();
+ return run(ctx, ctx.initStandardObjects(), script);
+ } finally {
+ Context.exit();
+ }
+ }
+}
@@ -0,0 +1,39 @@
+/*
+ * The copyright holders of this work license this file to You under
+ * the Apache License, Version 2.0 (the "License"); you may not use this
+ * file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.maven.plugin.itest;
+
+final class Script<T> {
+ private final T script;
+ private final String scriptName;
+ private final int startByLine;
+
+ public Script(T script, String scriptName, int startByLine) {
+ this.script = script;
+ this.scriptName = scriptName;
+ this.startByLine = startByLine;
+ }
+
+ public T getScript() {
+ return script;
+ }
+
+ public String getScriptName() {
+ return scriptName;
+ }
+
+ public int getStartByLine() {
+ return startByLine;
+ }
+}
@@ -0,0 +1 @@
+java -classpath "lib/js-1.7R1.jar;lib/." org.mozilla.javascript.tools.jsc.Main -d lib -extends JavaMethod callJavaMethod.js
@@ -0,0 +1,2 @@
+'hello';
+f();
@@ -0,0 +1 @@
+java -classpath "lib/js-1.7R1.jar;lib/." org.mozilla.javascript.tools.jsc.Main -d lib -extends SameMethods extendSameMethods.js
@@ -0,0 +1,4 @@
+f();
+f(5);
+g(10);
+g();
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -44,6 +44,9 @@
<entry_points version="2.0" />
</component>
<component name="IdProvider" IDEtalkID="417C6E34DE47E8EA08584633A5646B11" />
+ <component name="JavacSettings">
+ <option name="ADDITIONAL_OPTIONS_STRING" value="-target 1.5" />
+ </component>
<component name="JavadocGenerationManager">
<option name="OUTPUT_DIRECTORY" />
<option name="OPTION_SCOPE" value="protected" />
@@ -187,7 +190,10 @@
<module fileurl="file://$PROJECT_DIR$/prototypes.iml" filepath="$PROJECT_DIR$/prototypes.iml" />
</modules>
</component>
- <component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" assert-keyword="true" jdk-15="true" project-jdk-name="openjdk version &quot;1.8.0-ea&quot;" project-jdk-type="JavaSDK">
+ <component name="ProjectResources">
+ <default-html-doctype>http://www.w3.org/1999/xhtml</default-html-doctype>
+ </component>
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="VcsDirectoryMappings">
Oops, something went wrong.

0 comments on commit bd2b226

Please sign in to comment.