Skip to content

Commit

Permalink
Merge branch 'openhab:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
holgerfriedrich authored Aug 9, 2024
2 parents 9a9f67d + 716045a commit 6c3a1be
Show file tree
Hide file tree
Showing 274 changed files with 3,975 additions and 770 deletions.
2 changes: 1 addition & 1 deletion bom/compile-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openhab.core.bom</groupId>
<artifactId>org.openhab.core.reactor.bom</artifactId>
<version>4.2.0-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.core.bom.compile-model</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bom/compile/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openhab.core.bom</groupId>
<artifactId>org.openhab.core.reactor.bom</artifactId>
<version>4.2.0-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.core.bom.compile</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bom/openhab-core-index/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openhab.core.bom</groupId>
<artifactId>org.openhab.core.reactor.bom</artifactId>
<version>4.2.0-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.core.bom.openhab-core-index</artifactId>
Expand Down
14 changes: 13 additions & 1 deletion bom/openhab-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openhab.core.bom</groupId>
<artifactId>org.openhab.core.reactor.bom</artifactId>
<version>4.2.0-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.core.bom.openhab-core</artifactId>
Expand Down Expand Up @@ -328,6 +328,12 @@
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.openhab.core.bundles</groupId>
<artifactId>org.openhab.core.config.discovery.addon.sddp</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.openhab.core.bundles</groupId>
<artifactId>org.openhab.core.config.discovery.addon.upnp</artifactId>
Expand All @@ -346,6 +352,12 @@
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.openhab.core.bundles</groupId>
<artifactId>org.openhab.core.config.discovery.sddp</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.openhab.core.bundles</groupId>
<artifactId>org.openhab.core.config.discovery.usbserial</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openhab.core</groupId>
<artifactId>org.openhab.core.reactor</artifactId>
<version>4.2.0-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
</parent>

<groupId>org.openhab.core.bom</groupId>
Expand Down
2 changes: 1 addition & 1 deletion bom/runtime-index/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openhab.core.bom</groupId>
<artifactId>org.openhab.core.reactor.bom</artifactId>
<version>4.2.0-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.core.bom.runtime-index</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions bom/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openhab.core.bom</groupId>
<artifactId>org.openhab.core.reactor.bom</artifactId>
<version>4.2.0-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.core.bom.runtime</artifactId>
Expand Down Expand Up @@ -794,7 +794,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.1.0-jre</version>
<version>33.2.0-jre</version>
<scope>compile</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion bom/test-index/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openhab.core.bom</groupId>
<artifactId>org.openhab.core.reactor.bom</artifactId>
<version>4.2.0-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.core.bom.test-index</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bom/test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openhab.core.bom</groupId>
<artifactId>org.openhab.core.reactor.bom</artifactId>
<version>4.2.0-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.core.bom.test</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.openhab.core.addon.eclipse/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openhab.core.bundles</groupId>
<artifactId>org.openhab.core.reactor.bundles</artifactId>
<version>4.2.0-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.core.addon.eclipse</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.openhab.core.addon.marketplace.karaf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openhab.core.bundles</groupId>
<artifactId>org.openhab.core.reactor.bundles</artifactId>
<version>4.2.0-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.core.addon.marketplace.karaf</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.openhab.core.addon.marketplace/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openhab.core.bundles</groupId>
<artifactId>org.openhab.core.reactor.bundles</artifactId>
<version>4.2.0-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.core.addon.marketplace</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ system.config.jsonaddonservice.urls.description = Liste d'URLs séparées par un
system.config.marketplace.apiKey.label = Clé API pour community.openhab.org
system.config.marketplace.apiKey.description = Spécifiez la clé API à utiliser sur le forum de la communauté (pour les administrateurs - cela permet par exemple de voir le contenu qui n'a pas encore fait l'objet de revue ou autrement caché au grand public). Laissez vide si vous n'en avez pas.
system.config.marketplace.enable.label = Activer le marketplace de la communauté
system.config.marketplace.enable.description = Si désactivé, aucune extension du marketplace de la communautaire ne sera affichée. Les extensions déjà installées seront toujours disponibles.
system.config.marketplace.enable.description = Si désactivé, aucune extension du marketplace de la communauté ne sera affichée. Les extensions déjà installées seront toujours disponibles.
system.config.marketplace.showUnpublished.label = Afficher les entrées non publiées
system.config.marketplace.showUnpublished.description = Inclure les entrées qui n'ont pas été taguées comme publiées. Attention \: ceci peut inclure des entrées qui ne sont pas prêtes et qui pourraient ne pas fonctionner ou nuire à votre installation. Activez à vos risques et périls, uniquement pour les tests.

Expand Down
2 changes: 1 addition & 1 deletion bundles/org.openhab.core.addon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openhab.core.bundles</groupId>
<artifactId>org.openhab.core.reactor.bundles</artifactId>
<version>4.2.0-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.core.addon</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public void removeAddonInfoProvider(AddonInfoProvider addonInfoProvider) {
builder.withName(b.getName());
builder.withDescription(b.getDescription());
}
if (!(a.isMasterAddonInfo() || b.isMasterAddonInfo())) {
builder.isMasterAddonInfo(false);
if (!a.isMasterAddonInfo() && b.isMasterAddonInfo()) {
builder.isMasterAddonInfo(true);
}
if (a.getConnection() == null && b.getConnection() != null) {
builder.withConnection(b.getConnection());
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.openhab.core.audio/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openhab.core.bundles</groupId>
<artifactId>org.openhab.core.reactor.bundles</artifactId>
<version>4.2.0-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.core.audio</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.openhab.core.auth.jaas/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openhab.core.bundles</groupId>
<artifactId>org.openhab.core.reactor.bundles</artifactId>
<version>4.2.0-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.core.auth.jaas</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.openhab.core.auth.oauth2client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openhab.core.bundles</groupId>
<artifactId>org.openhab.core.reactor.bundles</artifactId>
<version>4.2.0-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.core.auth.oauth2client</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.openhab.core.automation.module.media/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openhab.core.bundles</groupId>
<artifactId>org.openhab.core.reactor.bundles</artifactId>
<version>4.2.0-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.core.automation.module.media</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openhab.core.bundles</groupId>
<artifactId>org.openhab.core.reactor.bundles</artifactId>
<version>4.2.0-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.core.automation.module.script.rulesupport</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# jsr223.ScriptedAction

module-type.jsr223.ScriptedAction.label = Actie script
module-type.jsr223.ScriptedAction.description = maakt het uitvoeren van een method die is gedefinieerd door een script mogelijk
module-type.jsr223.ScriptedAction.config.privId.description = de identifier van de private method
module-type.jsr223.ScriptedAction.output.result.label = resultaat
module-type.jsr223.ScriptedAction.output.result.description = het resultaat van het script.

# jsr223.ScriptedCondition

module-type.jsr223.ScriptedCondition.label = Voorwaarde script
module-type.jsr223.ScriptedCondition.description = maakt de definitie van een voorwaarde met een script mogelijk
module-type.jsr223.ScriptedCondition.config.privId.description = de identifier van de private method

# jsr223.ScriptedTrigger

module-type.jsr223.ScriptedTrigger.label = Trigger script
module-type.jsr223.ScriptedTrigger.description = maakt het uitvoeren van een method die is gedefinieerd door een script mogelijk
module-type.jsr223.ScriptedTrigger.config.privId.description = de identifier van de private method
module-type.jsr223.ScriptedTrigger.output.triggerOutput.label = TriggerOutput label
module-type.jsr223.ScriptedTrigger.output.triggerOutput.description = Tekst van de trigger
2 changes: 1 addition & 1 deletion bundles/org.openhab.core.automation.module.script/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openhab.core.bundles</groupId>
<artifactId>org.openhab.core.reactor.bundles</artifactId>
<version>4.2.0-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.core.automation.module.script</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
public class TimerImpl implements Timer {

private final Scheduler scheduler;
private final ZonedDateTime startTime;
private final SchedulerRunnable runnable;
private final @Nullable String identifier;
private ScheduledCompletableFuture<?> future;
Expand All @@ -42,7 +41,6 @@ public TimerImpl(Scheduler scheduler, ZonedDateTime startTime, SchedulerRunnable
public TimerImpl(Scheduler scheduler, ZonedDateTime startTime, SchedulerRunnable runnable,
@Nullable String identifier) {
this.scheduler = scheduler;
this.startTime = startTime;
this.runnable = runnable;
this.identifier = identifier;

Expand Down Expand Up @@ -78,7 +76,7 @@ public boolean isCancelled() {

@Override
public boolean isRunning() {
return isActive() && ZonedDateTime.now().isAfter(startTime);
return isActive() && ZonedDateTime.now().isAfter(future.getScheduledTime());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@
import java.util.Optional;
import java.util.UUID;

import javax.script.Compilable;
import javax.script.CompiledScript;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptException;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.automation.Module;
import org.openhab.core.automation.handler.BaseModuleHandler;
import org.openhab.core.automation.module.script.ScriptEngineContainer;
Expand All @@ -35,6 +39,7 @@
*
* @author Kai Kreuzer - Initial contribution
* @author Simon Merschjohann - Initial contribution
* @author Florian Hotze - Add support for script pre-compilation
*
* @param <T> the type of module the concrete handler can handle
*/
Expand All @@ -54,6 +59,7 @@ public abstract class AbstractScriptModuleHandler<T extends Module> extends Base
private final String engineIdentifier;

private Optional<ScriptEngine> scriptEngine = Optional.empty();
private Optional<CompiledScript> compiledScript = Optional.empty();
private final String type;
protected final String script;

Expand All @@ -80,6 +86,30 @@ private static String getValidConfigParameter(String parameter, Configuration co
}
}

/**
* Creates the {@link ScriptEngine} and compiles the script if the {@link ScriptEngine} implements
* {@link Compilable}.
*/
protected void compileScript() throws ScriptException {
if (compiledScript.isPresent()) {
return;
}
if (!scriptEngineManager.isSupported(this.type)) {
logger.debug(
"ScriptEngine for language '{}' could not be found, skipping compilation of script for identifier: {}",
type, engineIdentifier);
return;
}
Optional<ScriptEngine> engine = getScriptEngine();
if (engine.isPresent()) {
ScriptEngine scriptEngine = engine.get();
if (scriptEngine instanceof Compilable) {
logger.debug("Pre-compiling script of rule with UID '{}'", ruleUID);
compiledScript = Optional.ofNullable(((Compilable) scriptEngine).compile(script));
}
}
}

@Override
public void dispose() {
scriptEngineManager.removeEngine(engineIdentifier);
Expand Down Expand Up @@ -169,4 +199,26 @@ protected void resetExecutionContext(ScriptEngine engine, Map<String, ?> context
executionContext.removeAttribute(key, ScriptContext.ENGINE_SCOPE);
}
}

/**
* Evaluates the passed script with the ScriptEngine.
*
* @param engine the script engine that is used
* @param script the script to evaluate
* @return the value returned from the execution of the script
*/
protected @Nullable Object eval(ScriptEngine engine, String script) {
try {
if (compiledScript.isPresent()) {
logger.debug("Executing pre-compiled script of rule with UID '{}'", ruleUID);
return compiledScript.get().eval(engine.getContext());
}
logger.debug("Executing script of rule with UID '{}'", ruleUID);
return engine.eval(script);
} catch (ScriptException e) {
logger.error("Script execution of rule with UID '{}' failed: {}", ruleUID, e.getMessage(),
logger.isDebugEnabled() ? e : null);
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*
* @author Kai Kreuzer - Initial contribution
* @author Simon Merschjohann - Initial contribution
* @author Florian Hotze - Add support for script pre-compilation
*/
@NonNullByDefault
public class ScriptActionHandler extends AbstractScriptModuleHandler<Action> implements ActionHandler {
Expand Down Expand Up @@ -61,6 +62,11 @@ public void dispose() {
super.dispose();
}

@Override
public void compile() throws ScriptException {
super.compileScript();
}

@Override
public @Nullable Map<String, Object> execute(final Map<String, Object> context) {
Map<String, Object> resultMap = new HashMap<>();
Expand All @@ -71,13 +77,8 @@ public void dispose() {

getScriptEngine().ifPresent(scriptEngine -> {
setExecutionContext(scriptEngine, context);
try {
Object result = scriptEngine.eval(script);
resultMap.put("result", result);
} catch (ScriptException e) {
logger.error("Script execution of rule with UID '{}' failed: {}", ruleUID, e.getMessage(),
logger.isDebugEnabled() ? e : null);
}
Object result = eval(scriptEngine, script);
resultMap.put("result", result);
resetExecutionContext(scriptEngine, context);
});

Expand Down
Loading

0 comments on commit 6c3a1be

Please sign in to comment.