[groovyscripting] Add Groovy scripting support (#8772)
* Add Groovy scripting support This makes it really easy to start using Groovy 3.x scripts with openHAB! Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
* @openhab/add-ons-maintainers
|
* @openhab/add-ons-maintainers
|
||||||
|
|
||||||
# Add-on maintainers:
|
# Add-on maintainers:
|
||||||
|
/bundles/org.openhab.automation.groovyscripting/ @wborn
|
||||||
/bundles/org.openhab.binding.adorne/ @theiding
|
/bundles/org.openhab.binding.adorne/ @theiding
|
||||||
/bundles/org.openhab.binding.airquality/ @kubawolanin
|
/bundles/org.openhab.binding.airquality/ @kubawolanin
|
||||||
/bundles/org.openhab.binding.airvisualnode/ @3cky
|
/bundles/org.openhab.binding.airvisualnode/ @3cky
|
||||||
|
|||||||
@@ -16,6 +16,11 @@
|
|||||||
<name>openHAB Add-ons :: BOM :: openHAB Add-ons</name>
|
<name>openHAB Add-ons :: BOM :: openHAB Add-ons</name>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openhab.addons.bundles</groupId>
|
||||||
|
<artifactId>org.openhab.automation.groovyscripting</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.openhab.addons.bundles</groupId>
|
<groupId>org.openhab.addons.bundles</groupId>
|
||||||
<artifactId>org.openhab.binding.adorne</artifactId>
|
<artifactId>org.openhab.binding.adorne</artifactId>
|
||||||
|
|||||||
13
bundles/org.openhab.automation.groovyscripting/NOTICE
Normal file
13
bundles/org.openhab.automation.groovyscripting/NOTICE
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
This content is produced and maintained by the openHAB project.
|
||||||
|
|
||||||
|
* Project home: https://www.openhab.org
|
||||||
|
|
||||||
|
== Declared Project Licenses
|
||||||
|
|
||||||
|
This program and the accompanying materials are made available under the terms
|
||||||
|
of the Eclipse Public License 2.0 which is available at
|
||||||
|
https://www.eclipse.org/legal/epl-2.0/.
|
||||||
|
|
||||||
|
== Source Code
|
||||||
|
|
||||||
|
https://github.com/openhab/openhab-addons
|
||||||
3
bundles/org.openhab.automation.groovyscripting/README.md
Normal file
3
bundles/org.openhab.automation.groovyscripting/README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Groovy Scripting
|
||||||
|
|
||||||
|
This add-on provides support for [Groovy](https://groovy-lang.org/) 3.x scripts in openHAB.
|
||||||
43
bundles/org.openhab.automation.groovyscripting/pom.xml
Normal file
43
bundles/org.openhab.automation.groovyscripting/pom.xml
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.openhab.addons.bundles</groupId>
|
||||||
|
<artifactId>org.openhab.addons.reactor.bundles</artifactId>
|
||||||
|
<version>3.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>org.openhab.automation.groovyscripting</artifactId>
|
||||||
|
|
||||||
|
<name>openHAB Add-ons :: Automation :: Groovy Scripting</name>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<bnd.importpackage>
|
||||||
|
com.ibm.icu.*;resolution:=optional,
|
||||||
|
groovy.runtime.metaclass;resolution:=optional,
|
||||||
|
groovyjarjarantlr4.stringtemplate;resolution:=optional,
|
||||||
|
org.abego.treelayout.*;resolution:=optional,
|
||||||
|
org.apache.ivy.*;resolution:=optional,
|
||||||
|
org.stringtemplate.v4.*;resolution:=optional</bnd.importpackage>
|
||||||
|
<groovy.version>3.0.6</groovy.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.groovy</groupId>
|
||||||
|
<artifactId>groovy</artifactId>
|
||||||
|
<version>${groovy.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.groovy</groupId>
|
||||||
|
<artifactId>groovy-jsr223</artifactId>
|
||||||
|
<version>${groovy.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<features name="org.openhab.automation.groovyscripting-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
|
||||||
|
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features</repository>
|
||||||
|
|
||||||
|
<feature name="openhab-automation-groovyscripting" description="Groovy Scripting" version="${project.version}">
|
||||||
|
<feature>openhab-runtime-base</feature>
|
||||||
|
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.automation.groovyscripting/${project.version}</bundle>
|
||||||
|
</feature>
|
||||||
|
</features>
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2010-2020 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.groovyscripting.internal;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import javax.script.ScriptEngine;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
import org.openhab.core.automation.module.script.AbstractScriptEngineFactory;
|
||||||
|
import org.openhab.core.automation.module.script.ScriptEngineFactory;
|
||||||
|
import org.osgi.service.component.annotations.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is an implementation of a {@link ScriptEngineFactory} for Groovy.
|
||||||
|
*
|
||||||
|
* @author Wouter Born - Initial contribution
|
||||||
|
*/
|
||||||
|
@Component(service = ScriptEngineFactory.class)
|
||||||
|
@NonNullByDefault
|
||||||
|
public class GroovyScriptEngineFactory extends AbstractScriptEngineFactory {
|
||||||
|
|
||||||
|
private final org.codehaus.groovy.jsr223.GroovyScriptEngineFactory factory = new org.codehaus.groovy.jsr223.GroovyScriptEngineFactory();
|
||||||
|
|
||||||
|
private final List<String> scriptTypes = (List<String>) Stream.of(factory.getExtensions(), factory.getMimeTypes())
|
||||||
|
.flatMap(List::stream) //
|
||||||
|
.collect(Collectors.toUnmodifiableList());
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getScriptTypes() {
|
||||||
|
return scriptTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable ScriptEngine createScriptEngine(String scriptType) {
|
||||||
|
return scriptTypes.contains(scriptType) ? factory.getScriptEngine() : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2010-2020 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
@org.osgi.annotation.bundle.Header(name = org.osgi.framework.Constants.DYNAMICIMPORT_PACKAGE, value = "*")
|
||||||
|
package org.openhab.automation.groovyscripting.internal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Additional information for the Groovy Scripting package
|
||||||
|
*
|
||||||
|
* @author Wouter Born - Initial contribution
|
||||||
|
*/
|
||||||
@@ -17,6 +17,8 @@
|
|||||||
<name>openHAB Add-ons :: Bundles</name>
|
<name>openHAB Add-ons :: Bundles</name>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
|
<!-- automation -->
|
||||||
|
<module>org.openhab.automation.groovyscripting</module>
|
||||||
<!-- io -->
|
<!-- io -->
|
||||||
<module>org.openhab.io.homekit</module>
|
<module>org.openhab.io.homekit</module>
|
||||||
<module>org.openhab.io.hueemulation</module>
|
<module>org.openhab.io.hueemulation</module>
|
||||||
|
|||||||
Reference in New Issue
Block a user