JAVA-18148 Create a new java-nashorn project from the existing langua… (#14268)
* JAVA-18148 Create a new java-nashorn project from the existing language-interop * JAVA-18148 Cleanup the project to contain just the python related language interop --------- Co-authored-by: timis1 <[email protected]>
This commit is contained in:
committed by
GitHub
co-authored by
timis1
parent
86932cba3d
commit
68f6c19109
+34
@@ -0,0 +1,34 @@
|
||||
package com.baeldung.language.interop.python;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.script.ScriptEngineFactory;
|
||||
import javax.script.ScriptEngineManager;
|
||||
|
||||
public class ScriptEngineManagerUtils {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ScriptEngineManagerUtils.class);
|
||||
|
||||
private ScriptEngineManagerUtils() {
|
||||
}
|
||||
|
||||
public static void listEngines() {
|
||||
ScriptEngineManager manager = new ScriptEngineManager();
|
||||
List<ScriptEngineFactory> engines = manager.getEngineFactories();
|
||||
|
||||
for (ScriptEngineFactory engine : engines) {
|
||||
LOGGER.info("Engine name: {}", engine.getEngineName());
|
||||
LOGGER.info("Version: {}", engine.getEngineVersion());
|
||||
LOGGER.info("Language: {}", engine.getLanguageName());
|
||||
|
||||
LOGGER.info("Short Names:");
|
||||
for (String names : engine.getNames()) {
|
||||
LOGGER.info(names);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
var first = {
|
||||
name: "Whiskey",
|
||||
age: 5
|
||||
};
|
||||
|
||||
var second = {
|
||||
volume: 100
|
||||
};
|
||||
|
||||
Object.bindProperties(first, second);
|
||||
|
||||
print(first.volume);
|
||||
|
||||
second.volume = 1000;
|
||||
print(first.volume);
|
||||
@@ -0,0 +1 @@
|
||||
print(__FILE__, __LINE__, __DIR__);
|
||||
@@ -0,0 +1,19 @@
|
||||
var math = {
|
||||
increment: function (num) {
|
||||
return ++num;
|
||||
},
|
||||
|
||||
failFunc: function () {
|
||||
try {
|
||||
throw "BOOM";
|
||||
} catch (e if typeof e === 'string') {
|
||||
print("String thrown: " + e);
|
||||
}
|
||||
catch (e) {
|
||||
print("this shouldn't happen!");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
math;
|
||||
@@ -0,0 +1,11 @@
|
||||
var demo = {
|
||||
__noSuchProperty__: function (propName) {
|
||||
print("Accessed non-existing property: " + propName);
|
||||
},
|
||||
|
||||
__noSuchMethod__: function (methodName) {
|
||||
print("Invoked non-existing method: " + methodName);
|
||||
}
|
||||
};
|
||||
|
||||
demo;
|
||||
@@ -0,0 +1 @@
|
||||
function increment(num) ++num;
|
||||
@@ -0,0 +1,2 @@
|
||||
print(" hello world".trimLeft());
|
||||
print("hello world ".trimRight());
|
||||
@@ -0,0 +1,9 @@
|
||||
function arrays(arr) {
|
||||
|
||||
var javaIntArray = Java.to(arr, "int[]");
|
||||
print(javaIntArray[0]);
|
||||
print(javaIntArray[1]);
|
||||
print(javaIntArray[2]);
|
||||
}
|
||||
|
||||
arrays([100, "1654", true]);
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user