diff --git a/CODEOWNERS b/CODEOWNERS index 94f3ed94d29..68a951f270d 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -5,6 +5,7 @@ * @openhab/add-ons-maintainers # Add-on maintainers: +/bundles/org.openhab.automation.groovyscripting/ @wborn /bundles/org.openhab.binding.adorne/ @theiding /bundles/org.openhab.binding.airquality/ @kubawolanin /bundles/org.openhab.binding.airvisualnode/ @3cky diff --git a/bom/openhab-addons/pom.xml b/bom/openhab-addons/pom.xml index e300dce9a2a..3d23653f938 100644 --- a/bom/openhab-addons/pom.xml +++ b/bom/openhab-addons/pom.xml @@ -16,6 +16,11 @@ openHAB Add-ons :: BOM :: openHAB Add-ons + + org.openhab.addons.bundles + org.openhab.automation.groovyscripting + ${project.version} + org.openhab.addons.bundles org.openhab.binding.adorne diff --git a/bundles/org.openhab.automation.groovyscripting/NOTICE b/bundles/org.openhab.automation.groovyscripting/NOTICE new file mode 100644 index 00000000000..38d625e3492 --- /dev/null +++ b/bundles/org.openhab.automation.groovyscripting/NOTICE @@ -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 diff --git a/bundles/org.openhab.automation.groovyscripting/README.md b/bundles/org.openhab.automation.groovyscripting/README.md new file mode 100644 index 00000000000..d23cb9ac123 --- /dev/null +++ b/bundles/org.openhab.automation.groovyscripting/README.md @@ -0,0 +1,3 @@ +# Groovy Scripting + +This add-on provides support for [Groovy](https://groovy-lang.org/) 3.x scripts in openHAB. diff --git a/bundles/org.openhab.automation.groovyscripting/pom.xml b/bundles/org.openhab.automation.groovyscripting/pom.xml new file mode 100644 index 00000000000..4bcb1691b50 --- /dev/null +++ b/bundles/org.openhab.automation.groovyscripting/pom.xml @@ -0,0 +1,43 @@ + + + + 4.0.0 + + + org.openhab.addons.bundles + org.openhab.addons.reactor.bundles + 3.0.0-SNAPSHOT + + + org.openhab.automation.groovyscripting + + openHAB Add-ons :: Automation :: Groovy Scripting + + + + 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 + 3.0.6 + + + + + org.codehaus.groovy + groovy + ${groovy.version} + compile + + + org.codehaus.groovy + groovy-jsr223 + ${groovy.version} + compile + + + + diff --git a/bundles/org.openhab.automation.groovyscripting/src/main/feature/feature.xml b/bundles/org.openhab.automation.groovyscripting/src/main/feature/feature.xml new file mode 100644 index 00000000000..ae04075dcc8 --- /dev/null +++ b/bundles/org.openhab.automation.groovyscripting/src/main/feature/feature.xml @@ -0,0 +1,9 @@ + + + mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features + + + openhab-runtime-base + mvn:org.openhab.addons.bundles/org.openhab.automation.groovyscripting/${project.version} + + diff --git a/bundles/org.openhab.automation.groovyscripting/src/main/java/org/openhab/automation/groovyscripting/internal/GroovyScriptEngineFactory.java b/bundles/org.openhab.automation.groovyscripting/src/main/java/org/openhab/automation/groovyscripting/internal/GroovyScriptEngineFactory.java new file mode 100644 index 00000000000..7dae3d657c1 --- /dev/null +++ b/bundles/org.openhab.automation.groovyscripting/src/main/java/org/openhab/automation/groovyscripting/internal/GroovyScriptEngineFactory.java @@ -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 scriptTypes = (List) Stream.of(factory.getExtensions(), factory.getMimeTypes()) + .flatMap(List::stream) // + .collect(Collectors.toUnmodifiableList()); + + @Override + public List getScriptTypes() { + return scriptTypes; + } + + @Override + public @Nullable ScriptEngine createScriptEngine(String scriptType) { + return scriptTypes.contains(scriptType) ? factory.getScriptEngine() : null; + } +} diff --git a/bundles/org.openhab.automation.groovyscripting/src/main/java/org/openhab/automation/groovyscripting/internal/package-info.java b/bundles/org.openhab.automation.groovyscripting/src/main/java/org/openhab/automation/groovyscripting/internal/package-info.java new file mode 100644 index 00000000000..6be4121b66e --- /dev/null +++ b/bundles/org.openhab.automation.groovyscripting/src/main/java/org/openhab/automation/groovyscripting/internal/package-info.java @@ -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 + */ diff --git a/bundles/pom.xml b/bundles/pom.xml index f7af5daa79b..e0c7e2eb72f 100644 --- a/bundles/pom.xml +++ b/bundles/pom.xml @@ -17,6 +17,8 @@ openHAB Add-ons :: Bundles + + org.openhab.automation.groovyscripting org.openhab.io.homekit org.openhab.io.hueemulation