Skip to content

Commit

Permalink
replaced Joda Time by Java Time (openhab#1342)
Browse files Browse the repository at this point in the history
* replaced Joda Time by Java Time

Signed-off-by: Kai Kreuzer <kai@openhab.org>

* removed joda from target platform feature

Signed-off-by: Kai Kreuzer <kai@openhab.org>

* updated tests

Signed-off-by: Kai Kreuzer <kai@openhab.org>

* fixed persistence extension tests

Signed-off-by: Kai Kreuzer <kai@openhab.org>
GitOrigin-RevId: 86899da
  • Loading branch information
kaikreuzer authored and splatch committed Jul 11, 2023
1 parent 71c576e commit 931b2e0
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 139 deletions.
8 changes: 0 additions & 8 deletions bom/compile/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,6 @@
<scope>compile</scope>
</dependency>

<!-- Joda Time -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.2</version>
<scope>compile</scope>
</dependency>

<!-- jUPnP -->
<dependency>
<groupId>org.jupnp</groupId>
Expand Down
8 changes: 0 additions & 8 deletions bom/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -885,14 +885,6 @@
<scope>compile</scope>
</dependency>

<!-- Joda Time -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.2</version>
<scope>compile</scope>
</dependency>

<!-- ... -->
<dependency>
<groupId>com.eclipsesource.jaxrs</groupId>
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.opensmarthouse.core.model.persistence/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<artifactId>org.openhab.core.reactor.bundles</artifactId>
<version>3.0.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.core.model.persistence</artifactId>

<name>openHAB Core :: Bundles :: Model Persistence</name>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@
import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;

import java.time.Instant;
import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.eclipse.xtext.xbase.XExpression;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure0;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.openhab.core.model.core.ModelRepository;
import org.openhab.core.model.script.ScriptServiceUtil;
import org.openhab.core.model.script.engine.Script;
import org.openhab.core.model.script.engine.ScriptEngine;
import org.openhab.core.model.script.engine.ScriptExecutionException;
import org.openhab.core.model.script.internal.actions.TimerExecutionJob;
import org.openhab.core.model.script.internal.actions.TimerImpl;
import org.eclipse.xtext.xbase.XExpression;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure0;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.joda.time.base.AbstractInstant;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobKey;
Expand Down Expand Up @@ -87,7 +89,7 @@ public static Object callScript(String scriptName) throws ScriptExecutionExcepti
* @return a handle to the created timer, so that it can be canceled or rescheduled
* @throws ScriptExecutionException if an error occurs during the execution
*/
public static Timer createTimer(AbstractInstant instant, Procedure0 closure) {
public static Timer createTimer(Instant instant, Procedure0 closure) {
JobDataMap dataMap = new JobDataMap();
dataMap.put("procedure", closure);
return makeTimer(instant, closure.toString(), dataMap);
Expand All @@ -103,7 +105,7 @@ public static Timer createTimer(AbstractInstant instant, Procedure0 closure) {
* @return a handle to the created timer, so that it can be canceled or rescheduled
* @throws ScriptExecutionException if an error occurs during the execution
*/
public static Timer createTimerWithArgument(AbstractInstant instant, Object arg1, Procedure1<Object> closure) {
public static Timer createTimerWithArgument(Instant instant, Object arg1, Procedure1<Object> closure) {
JobDataMap dataMap = new JobDataMap();
dataMap.put("procedure1", closure);
dataMap.put("argument1", arg1);
Expand All @@ -118,11 +120,11 @@ public static Timer createTimerWithArgument(AbstractInstant instant, Object arg1
* @param dataMap job data map, preconfigured with arguments
* @return
*/
private static Timer makeTimer(AbstractInstant instant, String closure, JobDataMap dataMap) {
private static Timer makeTimer(Instant instant, String closure, JobDataMap dataMap) {

Logger logger = LoggerFactory.getLogger(ScriptExecution.class);
JobKey jobKey = new JobKey(getTimerId() + " " + instant.toString() + ": " + closure.toString());
Trigger trigger = newTrigger().startAt(instant.toDate()).build();
Trigger trigger = newTrigger().startAt(Date.from(instant)).build();
Timer timer = new TimerImpl(jobKey, trigger.getKey(), dataMap, instant);
try {
JobDetail job = newJob(TimerExecutionJob.class).withIdentity(jobKey).usingJobData(dataMap).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
package org.openhab.core.model.script.actions;

import org.joda.time.base.AbstractInstant;
import java.time.Instant;

/**
* A timer is a handle for a block of code that is scheduled for future execution. A timer
Expand All @@ -25,21 +25,21 @@ public interface Timer {

/**
* Cancels the timer
*
*
* @return true, if cancellation was successful
*/
public boolean cancel();

/**
* Determines whether the scheduled code is currently executed.
*
*
* @return true, if the code is being executed, false otherwise
*/
public boolean isRunning();

/**
* Determines whether the scheduled execution has already terminated.
*
*
* @return true, if the scheduled execution has already terminated, false otherwise
*/
public boolean hasTerminated();
Expand All @@ -48,10 +48,10 @@ public interface Timer {
* Reschedules a timer to a new starting time.
* This can also be called after a timer has terminated, which will result in another
* execution of the same code.
*
*
* @param newTime the new time to execute the code
* @return true, if the rescheduling was done successful
*/
public boolean reschedule(AbstractInstant newTime);
public boolean reschedule(Instant newTime);

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;

import java.time.Instant;
import java.util.Date;

import org.openhab.core.model.script.actions.Timer;
import org.joda.time.DateTime;
import org.joda.time.base.AbstractInstant;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
Expand Down Expand Up @@ -56,12 +55,12 @@ public class TimerImpl implements Timer {
private final JobKey jobKey;
private TriggerKey triggerKey;
private final JobDataMap dataMap;
private final AbstractInstant startTime;
private final Instant startTime;

private boolean cancelled = false;
private boolean terminated = false;

public TimerImpl(JobKey jobKey, TriggerKey triggerKey, JobDataMap dataMap, AbstractInstant startTime) {
public TimerImpl(JobKey jobKey, TriggerKey triggerKey, JobDataMap dataMap, Instant startTime) {
this.jobKey = jobKey;
this.triggerKey = triggerKey;
this.dataMap = dataMap;
Expand All @@ -83,9 +82,9 @@ public boolean cancel() {
}

@Override
public boolean reschedule(AbstractInstant newTime) {
public boolean reschedule(Instant newTime) {
try {
Trigger trigger = newTrigger().startAt(newTime.toDate()).build();
Trigger trigger = newTrigger().startAt(Date.from(newTime)).build();
Date nextTriggerTime = scheduler.rescheduleJob(triggerKey, trigger);
if (nextTriggerTime == null) {
logger.debug("Scheduling a new job job '{}' because the original has already run", jobKey.toString());
Expand Down Expand Up @@ -114,7 +113,7 @@ public boolean isRunning() {
} catch (SchedulerException e) {
// fallback implementation
logger.debug("An error occurred getting currently running jobs: {}", e.getMessage());
return DateTime.now().isAfter(startTime) && !terminated;
return Instant.now().isAfter(startTime) && !terminated;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URLEncoder;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.eclipse.xtext.xbase.scoping.batch.ImplicitlyImportedFeatures;
import org.joda.time.DateTime;
import org.openhab.core.library.unit.BinaryPrefix;
import org.openhab.core.library.unit.ImperialUnits;
import org.openhab.core.library.unit.MetricPrefix;
Expand Down Expand Up @@ -108,8 +109,9 @@ protected List<Class<?>> getStaticImportClasses() {
result.add(SmartHomeUnits.class);
result.add(BinaryPrefix.class);

// jodatime static functions
result.add(DateTime.class);
// date time static functions
result.add(Instant.class);
result.add(ZonedDateTime.class);

result.addAll(getActionClasses());
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@

public class ScriptImportSectionNamespaceScopeProvider extends XImportSectionNamespaceScopeProvider {

public static final QualifiedName CORE_LIBRARY_TYPES_PACKAGE = QualifiedName.create("org", "openhab",
"core", "library", "types");
public static final QualifiedName CORE_LIBRARY_ITEMS_PACKAGE = QualifiedName.create("org", "openhab",
"core", "library", "items");
public static final QualifiedName CORE_ITEMS_PACKAGE = QualifiedName.create("org", "openhab", "core",
"items");
public static final QualifiedName CORE_PERSISTENCE_PACKAGE = QualifiedName.create("org", "openhab",
"core", "persistence");
public static final QualifiedName MODEL_SCRIPT_ACTIONS_PACKAGE = QualifiedName.create("org", "openhab",
"core", "model", "script", "actions");
public static final QualifiedName JODA_TIME_PACKAGE = QualifiedName.create("org", "joda", "time");
public static final QualifiedName CORE_LIBRARY_TYPES_PACKAGE = QualifiedName.create("org", "openhab", "core",
"library", "types");
public static final QualifiedName CORE_LIBRARY_ITEMS_PACKAGE = QualifiedName.create("org", "openhab", "core",
"library", "items");
public static final QualifiedName CORE_ITEMS_PACKAGE = QualifiedName.create("org", "openhab", "core", "items");
public static final QualifiedName CORE_PERSISTENCE_PACKAGE = QualifiedName.create("org", "openhab", "core",
"persistence");
public static final QualifiedName MODEL_SCRIPT_ACTIONS_PACKAGE = QualifiedName.create("org", "openhab", "core",
"model", "script", "actions");
public static final QualifiedName TIME_PACKAGE = QualifiedName.create("java", "time");

@Override
protected List<ImportNormalizer> getImplicitImports(boolean ignoreCase) {
Expand All @@ -40,7 +39,7 @@ protected List<ImportNormalizer> getImplicitImports(boolean ignoreCase) {
implicitImports.add(doCreateImportNormalizer(CORE_ITEMS_PACKAGE, true, false));
implicitImports.add(doCreateImportNormalizer(CORE_PERSISTENCE_PACKAGE, true, false));
implicitImports.add(doCreateImportNormalizer(MODEL_SCRIPT_ACTIONS_PACKAGE, true, false));
implicitImports.add(doCreateImportNormalizer(JODA_TIME_PACKAGE, true, false));
implicitImports.add(doCreateImportNormalizer(TIME_PACKAGE, true, false));
return implicitImports;
}

Expand Down
1 change: 0 additions & 1 deletion features/karaf/openhab-tp/src/main/feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

<!-- TODO: Unbundled libraries -->
<bundle dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.xstream/1.4.7_1</bundle>
<bundle dependency="true">mvn:joda-time/joda-time/2.9.2</bundle>
</feature>

<feature name="openhab.tp-coap" description="Californium CoAP library" version="${project.version}">
Expand Down
Loading

0 comments on commit 931b2e0

Please sign in to comment.