[jsscriptingnashorn] JavaScript Scripting Nashorn Automation (#14013)
* [jsscriptingnashorn] JavaScript Scripting Nashorn Automation This add-on allows you to use your older JavaScript (ECMAScript 5.1) rules on newer Java versions until they are migrated to JavaScript (ECMAScript 2021+). The add-on uses a standalone [Nashorn Engine](https://github.com/openjdk/nashorn) which was part of Java until it was removed in Java 15. * Update parent to 3.4.0-SNAPSHOT and nashorn-core to 15.4 For the Nashorn changelog, see: https://github.com/openjdk/nashorn/blob/main/CHANGELOG.md * Update parent to 4.0.0-SNAPSHOT * Remove removeUnsupportedNashornArgs * Update scriptTypes * Add CODEOWNERS entry * Recycle ScriptScopeOSGiTest.java It got removed in openhab/openhab-core#2994 * Remove redundant new line from pom.xml Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2022 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.openhab.automation.jsscriptingnashorn;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openhab.core.automation.module.script.ScriptEngineContainer;
|
||||
import org.openhab.core.automation.module.script.ScriptEngineManager;
|
||||
import org.openhab.core.test.java.JavaOSGiTest;
|
||||
|
||||
/**
|
||||
* This tests the script modules using the Nashorn scripting engine.
|
||||
*
|
||||
* @author Kai Kreuzer - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ScriptScopeOSGiTest extends JavaOSGiTest {
|
||||
|
||||
private @NonNullByDefault({}) ScriptEngine engine;
|
||||
|
||||
private final String path = "OH-INF/automation/jsr223/";
|
||||
private final String workingFile = "scopeWorking.nashornjs";
|
||||
private final String failureFile = "scopeFailure.nashornjs";
|
||||
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
ScriptEngineManager scriptManager = getService(ScriptEngineManager.class);
|
||||
ScriptEngineContainer container = scriptManager.createScriptEngine("nashornjs", "myJSEngine");
|
||||
engine = container.getScriptEngine();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScopeDefinesItemTypes() throws ScriptException, IOException {
|
||||
URL url = bundleContext.getBundle().getResource(path + workingFile);
|
||||
engine.eval(new InputStreamReader(url.openStream()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScopeDoesNotDefineFoobar() throws ScriptException, IOException {
|
||||
URL url = bundleContext.getBundle().getResource(path + failureFile);
|
||||
assertThrows(ScriptException.class, () -> engine.eval(new InputStreamReader(url.openStream())));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
if(FOOBAR === undefined && UnDefType.FOOBAR === undefined) {
|
||||
throw "FOOBAR and UnDefType.FOOBAR not defined";
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
'use strict';
|
||||
|
||||
if(State === undefined) {
|
||||
throw "State not defined";
|
||||
}
|
||||
|
||||
if(Command === undefined) {
|
||||
throw "Command not defined";
|
||||
}
|
||||
|
||||
if(URLEncoder === undefined) {
|
||||
throw "URLEncoder not defined";
|
||||
}
|
||||
|
||||
if(File === undefined) {
|
||||
throw "File not defined";
|
||||
}
|
||||
|
||||
if(Files === undefined) {
|
||||
throw "Files not defined";
|
||||
}
|
||||
|
||||
if(Path === undefined) {
|
||||
throw "Path not defined";
|
||||
}
|
||||
|
||||
if(Paths === undefined) {
|
||||
throw "Paths not defined";
|
||||
}
|
||||
|
||||
//types
|
||||
if(IncreaseDecreaseType === undefined) {
|
||||
throw "IncreaseDecreaseType not defined";
|
||||
}
|
||||
|
||||
if(DECREASE === undefined) {
|
||||
throw "DECREASE not defined";
|
||||
}
|
||||
|
||||
if(INCREASE === undefined) {
|
||||
throw "INCREASE not defined";
|
||||
}
|
||||
|
||||
if(OnOffType === undefined) {
|
||||
throw "OnOffType not defined";
|
||||
}
|
||||
|
||||
if(ON === undefined) {
|
||||
throw "OFF not defined";
|
||||
}
|
||||
|
||||
if(OpenClosedType === undefined) {
|
||||
throw "OpenClosedType not defined";
|
||||
}
|
||||
|
||||
if(CLOSED === undefined) {
|
||||
throw "CLOSED not defined";
|
||||
}
|
||||
|
||||
if(OPEN === undefined) {
|
||||
throw "OPEN not defined";
|
||||
}
|
||||
|
||||
if(StopMoveType === undefined) {
|
||||
throw "StopMoveType not defined";
|
||||
}
|
||||
|
||||
if(MOVE === undefined) {
|
||||
throw "MOVE not defined";
|
||||
}
|
||||
|
||||
if(STOP === undefined) {
|
||||
throw "STOP not defined";
|
||||
}
|
||||
|
||||
if(UpDownType === undefined) {
|
||||
throw "UpDownType not defined";
|
||||
}
|
||||
|
||||
if(DOWN === undefined) {
|
||||
throw "DOWN not defined";
|
||||
}
|
||||
|
||||
if(UP === undefined) {
|
||||
throw "UP not defined";
|
||||
}
|
||||
|
||||
if(UnDefType === undefined) {
|
||||
throw "UnDefType not defined";
|
||||
}
|
||||
|
||||
if(NULL === undefined) {
|
||||
throw "NULL not defined";
|
||||
}
|
||||
|
||||
if(NextPreviousType === undefined) {
|
||||
throw "NextPreviousType not defined";
|
||||
}
|
||||
|
||||
if(NEXT === undefined) {
|
||||
throw "NEXT not defined";
|
||||
}
|
||||
|
||||
if(PREVIOUS === undefined) {
|
||||
throw "PREVIOUS not defined";
|
||||
}
|
||||
|
||||
if(PlayPauseType === undefined) {
|
||||
throw "PlayPauseType not defined";
|
||||
}
|
||||
|
||||
if(PLAY === undefined) {
|
||||
throw "PLAY not defined";
|
||||
}
|
||||
|
||||
if(PAUSE === undefined) {
|
||||
throw "PAUSE not defined";
|
||||
}
|
||||
|
||||
if(RewindFastforwardType === undefined) {
|
||||
throw "RewindFastforwardType not defined";
|
||||
}
|
||||
|
||||
if(REWIND === undefined) {
|
||||
throw "REWIND not defined";
|
||||
}
|
||||
|
||||
if(FASTFORWARD === undefined) {
|
||||
throw "FASTFORWARD not defined";
|
||||
}
|
||||
|
||||
if(QuantityType === undefined) {
|
||||
throw "QuantityType not defined";
|
||||
}
|
||||
|
||||
if(StringListType === undefined) {
|
||||
throw "StringListType not defined";
|
||||
}
|
||||
|
||||
if(RawType === undefined) {
|
||||
throw "RawType not defined";
|
||||
}
|
||||
|
||||
if(DateTimeType === undefined) {
|
||||
throw "DateTimeType not defined";
|
||||
}
|
||||
|
||||
if(DecimalType === undefined) {
|
||||
throw "DecimalType not defined";
|
||||
}
|
||||
|
||||
if(DateTimeType === undefined) {
|
||||
throw "DateTimeType not defined";
|
||||
}
|
||||
|
||||
if(HSBType === undefined) {
|
||||
throw "HSBType not defined";
|
||||
}
|
||||
|
||||
if(PercentType === undefined) {
|
||||
throw "PercentType not defined";
|
||||
}
|
||||
|
||||
if(PointType === undefined) {
|
||||
throw "PointType not defined";
|
||||
}
|
||||
|
||||
if(StringType === undefined) {
|
||||
throw "StringType not defined";
|
||||
}
|
||||
|
||||
if(items === undefined) {
|
||||
throw "items not defined";
|
||||
}
|
||||
|
||||
if(ir === undefined) {
|
||||
throw "ir not defined";
|
||||
}
|
||||
|
||||
if(itemRegistry === undefined) {
|
||||
throw "itemRegistry not defined";
|
||||
}
|
||||
|
||||
if(things === undefined) {
|
||||
throw "things not defined";
|
||||
}
|
||||
|
||||
if(events === undefined) {
|
||||
throw "events not defined";
|
||||
}
|
||||
|
||||
if(rules === undefined) {
|
||||
throw "rules not defined";
|
||||
}
|
||||
Reference in New Issue
Block a user