<name>openHAB Add-ons :: Bundles :: 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>4.0.7</groovy.version>
+ <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.fusesource.jansi.*;resolution:=optional,org.stringtemplate.v4.*;resolution:=optional</bnd.importpackage>
+ <groovy.version>4.0.9</groovy.version>
</properties>
<dependencies>
<version>${groovy.version}</version>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.groovy</groupId>
+ <artifactId>groovy-json</artifactId>
+ <version>${groovy.version}</version>
+ <scope>compile</scope>
+ </dependency>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy-xml</artifactId>
<version>${groovy.version}</version>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.groovy</groupId>
+ <artifactId>groovy-yaml</artifactId>
+ <version>${groovy.version}</version>
+ <scope>compile</scope>
+ </dependency>
</dependencies>
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>biz.aQute.bnd</groupId>
+ <artifactId>bnd-maven-plugin</artifactId>
+ <configuration>
+ <bnd><![CDATA[${oh.bndDefaults}
+Require-Capability:
+ osgi.extender:=
+ filter:="(osgi.extender=osgi.serviceloader.processor)",
+ osgi.serviceloader:=
+ filter:="(osgi.serviceloader=org.apache.groovy.json.FastStringServiceFactory)";
+ cardinality:=multiple
+SPI-Provider: *
+SPI-Consumer: *
+]]>
+ </bnd>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
</project>
--- /dev/null
+-include: ../itest-common.bndrun
+
+Bundle-SymbolicName: ${project.artifactId}
+Fragment-Host: org.openhab.automation.groovyscripting
+
+-runrequires: \
+ bnd.identity;id='org.openhab.automation.groovyscripting.tests',\
+ bnd.identity;id='org.openhab.core',\
+ bnd.identity;id='org.openhab.automation.groovyscripting'
+
+# We would like to use the "volatile" storage only
+-runblacklist: \
+ bnd.identity;id='org.openhab.core.storage.json'
+
+#
+# done
+#
+-runbundles: \
+ biz.aQute.tester.junit-platform;version='[6.4.0,6.4.1)',\
+ ch.qos.logback.classic;version='[1.2.11,1.2.12)',\
+ ch.qos.logback.core;version='[1.2.11,1.2.12)',\
+ com.fasterxml.jackson.core.jackson-annotations;version='[2.14.1,2.14.2)',\
+ com.fasterxml.jackson.core.jackson-core;version='[2.14.2,2.14.3)',\
+ com.fasterxml.jackson.core.jackson-databind;version='[2.14.2,2.14.3)',\
+ com.fasterxml.jackson.dataformat.jackson-dataformat-yaml;version='[2.14.2,2.14.3)',\
+ com.google.gson;version='[2.9.1,2.9.2)',\
+ com.sun.jna;version='[5.12.1,5.12.2)',\
+ com.sun.xml.bind.jaxb-osgi;version='[2.3.3,2.3.4)',\
+ io.methvin.directory-watcher;version='[0.17.1,0.17.2)',\
+ jakarta.annotation-api;version='[1.3.5,1.3.6)',\
+ jakarta.annotation-api;version='[2.0.0,2.0.1)',\
+ jakarta.inject.jakarta.inject-api;version='[2.0.0,2.0.1)',\
+ jakarta.xml.bind-api;version='[2.3.3,2.3.4)',\
+ javax.measure.unit-api;version='[2.1.2,2.1.3)',\
+ jollyday;version='[0.5.10,0.5.11)',\
+ junit-jupiter-api;version='[5.8.1,5.8.2)',\
+ junit-jupiter-engine;version='[5.8.1,5.8.2)',\
+ junit-platform-commons;version='[1.8.1,1.8.2)',\
+ junit-platform-engine;version='[1.8.1,1.8.2)',\
+ junit-platform-launcher;version='[1.8.1,1.8.2)',\
+ org.apache.servicemix.specs.activation-api-1.2.1;version='[1.2.1,1.2.2)',\
+ org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\
+ org.glassfish.hk2.external.javax.inject;version='[2.4.0,2.4.1)',\
+ org.glassfish.hk2.osgi-resource-locator;version='[1.0.3,1.0.4)',\
+ org.hamcrest;version='[2.2.0,2.2.1)',\
+ org.jsr-305;version='[3.0.2,3.0.3)',\
+ org.openhab.automation.groovyscripting;version='[4.0.0,4.0.1)',\
+ org.openhab.automation.groovyscripting.tests;version='[4.0.0,4.0.1)',\
+ org.openhab.core;version='[4.0.0,4.0.1)',\
+ org.openhab.core.automation;version='[4.0.0,4.0.1)',\
+ org.openhab.core.automation.module.script;version='[4.0.0,4.0.1)',\
+ org.openhab.core.config.core;version='[4.0.0,4.0.1)',\
+ org.openhab.core.ephemeris;version='[4.0.0,4.0.1)',\
+ org.openhab.core.io.console;version='[4.0.0,4.0.1)',\
+ org.openhab.core.test;version='[4.0.0,4.0.1)',\
+ org.openhab.core.thing;version='[4.0.0,4.0.1)',\
+ org.openhab.core.transform;version='[4.0.0,4.0.1)',\
+ org.opentest4j;version='[1.2.0,1.2.1)',\
+ org.osgi.service.event;version='[1.4.0,1.4.1)',\
+ org.osgi.util.function;version='[1.2.0,1.2.1)',\
+ org.osgi.util.promise;version='[1.2.0,1.2.1)',\
+ org.threeten.extra;version='[1.5.0,1.5.1)',\
+ org.yaml.snakeyaml;version='[1.33.0,1.33.1)',\
+ si-units;version='[2.1.0,2.1.1)',\
+ si.uom.si-quantity;version='[2.1.0,2.1.1)',\
+ tech.units.indriya;version='[2.1.2,2.1.3)',\
+ uom-lib-common;version='[2.1.0,2.1.1)',\
+ xstream;version='[1.4.19,1.4.20)',\
+ org.apache.felix.configadmin;version='[1.9.26,1.9.27)',\
+ org.apache.felix.http.servlet-api;version='[1.2.0,1.2.1)',\
+ org.apache.felix.scr;version='[2.2.4,2.2.5)',\
+ org.eclipse.jetty.http;version='[9.4.50,9.4.51)',\
+ org.eclipse.jetty.io;version='[9.4.50,9.4.51)',\
+ org.eclipse.jetty.security;version='[9.4.50,9.4.51)',\
+ org.eclipse.jetty.server;version='[9.4.50,9.4.51)',\
+ org.eclipse.jetty.servlet;version='[9.4.50,9.4.51)',\
+ org.eclipse.jetty.util;version='[9.4.50,9.4.51)',\
+ org.eclipse.jetty.util.ajax;version='[9.4.50,9.4.51)',\
+ org.ops4j.pax.logging.pax-logging-api;version='[2.2.0,2.2.1)',\
+ org.osgi.service.component;version='[1.5.0,1.5.1)'
--- /dev/null
+/**
+ * Copyright (c) 2010-2023 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;
+
+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 JSON, XML and YAML slurpers using the Groovy scripting engine.
+ *
+ * @author Wouter Born - Initial contribution
+ */
+@NonNullByDefault
+public class SlurperOSGiTest extends JavaOSGiTest {
+
+ private @NonNullByDefault({}) ScriptEngine engine;
+
+ private final String path = "OH-INF/automation/jsr223/";
+
+ @BeforeEach
+ public void init() {
+ ScriptEngineManager scriptManager = getService(ScriptEngineManager.class);
+ ScriptEngineContainer container = scriptManager.createScriptEngine("groovy", "myGroovyEngine");
+ engine = container.getScriptEngine();
+ }
+
+ private void evalScript(String fileName) throws ScriptException, IOException {
+ URL url = bundleContext.getBundle().getResource(path + fileName);
+ engine.eval(new InputStreamReader(url.openStream()));
+ }
+
+ @Test
+ public void jsonSlurper() throws ScriptException, IOException {
+ evalScript("json-slurper.groovy");
+ }
+
+ @Test
+ public void xmlSlurper() throws ScriptException, IOException {
+ evalScript("xml-slurper.groovy");
+ }
+
+ @Test
+ public void yamlSlurper() throws ScriptException, IOException {
+ evalScript("yaml-slurper.groovy");
+ }
+}