From 7e2ed343d2a6a03938c3f074417464c63d31fd59 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 17 Sep 2018 15:50:19 +1200 Subject: Remove joda time library --- pom.xml | 5 ----- src/org/traccar/database/StatisticsManager.java | 4 ++-- src/org/traccar/helper/DateUtil.java | 10 ++++------ src/org/traccar/protocol/H02ProtocolEncoder.java | 14 +++++++------- src/org/traccar/protocol/OsmAndProtocolDecoder.java | 7 ++++--- src/org/traccar/protocol/SmokeyProtocolDecoder.java | 9 ++++----- src/org/traccar/web/CsvBuilder.java | 8 +++----- src/org/traccar/web/GpxBuilder.java | 9 ++------- src/org/traccar/web/WebServer.java | 1 - test/org/traccar/protocol/H02ProtocolEncoderTest.java | 10 ++++++++-- 10 files changed, 34 insertions(+), 43 deletions(-) diff --git a/pom.xml b/pom.xml index cf811e817..32d597309 100644 --- a/pom.xml +++ b/pom.xml @@ -23,11 +23,6 @@ 4.12 test - - joda-time - joda-time - 2.10 - commons-codec commons-codec diff --git a/src/org/traccar/database/StatisticsManager.java b/src/org/traccar/database/StatisticsManager.java index dcf15bb04..c2011a878 100644 --- a/src/org/traccar/database/StatisticsManager.java +++ b/src/org/traccar/database/StatisticsManager.java @@ -15,7 +15,6 @@ */ package org.traccar.database; -import org.joda.time.format.ISODateTimeFormat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.traccar.Context; @@ -24,6 +23,7 @@ import org.traccar.model.Statistics; import javax.ws.rs.client.Entity; import javax.ws.rs.core.Form; import java.sql.SQLException; +import java.time.format.DateTimeFormatter; import java.util.Calendar; import java.util.Date; import java.util.HashSet; @@ -72,7 +72,7 @@ public class StatisticsManager { String url = Context.getConfig().getString("server.statistics"); if (url != null) { - String time = ISODateTimeFormat.dateTime().print(statistics.getCaptureTime().getTime()); + String time = DateTimeFormatter.ISO_DATE_TIME.format(statistics.getCaptureTime().toInstant()); Form form = new Form(); form.param("version", Context.getAppVersion()); diff --git a/src/org/traccar/helper/DateUtil.java b/src/org/traccar/helper/DateUtil.java index 30bb1b2fa..458c74609 100644 --- a/src/org/traccar/helper/DateUtil.java +++ b/src/org/traccar/helper/DateUtil.java @@ -15,16 +15,13 @@ */ package org.traccar.helper; +import java.time.Instant; +import java.time.format.DateTimeFormatter; import java.util.Calendar; import java.util.Date; -import org.joda.time.format.DateTimeFormatter; -import org.joda.time.format.ISODateTimeFormat; - public final class DateUtil { - private static final DateTimeFormatter DATE_FORMAT = ISODateTimeFormat.dateTimeParser(); - private DateUtil() { } @@ -61,6 +58,7 @@ public final class DateUtil { } public static Date parseDate(String value) { - return DATE_FORMAT.parseDateTime(value).toDate(); + return Date.from(Instant.from(DateTimeFormatter.ISO_DATE_TIME.parse(value))); } + } diff --git a/src/org/traccar/protocol/H02ProtocolEncoder.java b/src/org/traccar/protocol/H02ProtocolEncoder.java index 87fad6016..6d5cfb298 100644 --- a/src/org/traccar/protocol/H02ProtocolEncoder.java +++ b/src/org/traccar/protocol/H02ProtocolEncoder.java @@ -16,19 +16,19 @@ */ package org.traccar.protocol; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; import org.traccar.StringProtocolEncoder; import org.traccar.model.Command; +import java.util.Date; + public class H02ProtocolEncoder extends StringProtocolEncoder { private static final String MARKER = "HQ"; - private Object formatCommand(DateTime time, String uniqueId, String type, String... params) { + private Object formatCommand(Date time, String uniqueId, String type, String... params) { - StringBuilder result = new StringBuilder(String.format("*%s,%s,%s,%02d%02d%02d", - MARKER, uniqueId, type, time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute())); + StringBuilder result = new StringBuilder( + String.format("*%s,%s,%s,%4$tH%4$tM%4$tS", MARKER, uniqueId, type, time)); for (String param : params) { result.append(",").append(param); @@ -39,7 +39,7 @@ public class H02ProtocolEncoder extends StringProtocolEncoder { return result.toString(); } - protected Object encodeCommand(Command command, DateTime time) { + protected Object encodeCommand(Command command, Date time) { String uniqueId = getUniqueId(command.getDeviceId()); switch (command.getType()) { @@ -62,7 +62,7 @@ public class H02ProtocolEncoder extends StringProtocolEncoder { @Override protected Object encodeCommand(Command command) { - return encodeCommand(command, new DateTime(DateTimeZone.UTC)); + return encodeCommand(command, new Date()); } } diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java index b270b6071..4d6a0d259 100644 --- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java +++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java @@ -19,7 +19,6 @@ import io.netty.channel.Channel; import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.QueryStringDecoder; -import org.joda.time.format.ISODateTimeFormat; import org.traccar.BaseHttpProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.model.CellTower; @@ -31,6 +30,8 @@ import java.net.SocketAddress; import java.nio.charset.StandardCharsets; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.time.Instant; +import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.List; import java.util.Map; @@ -81,8 +82,8 @@ public class OsmAndProtocolDecoder extends BaseHttpProtocolDecoder { position.setTime(new Date(timestamp)); } catch (NumberFormatException error) { if (value.contains("T")) { - position.setTime(new Date( - ISODateTimeFormat.dateTimeParser().parseMillis(value))); + position.setTime( + Date.from(Instant.from(DateTimeFormatter.ISO_DATE_TIME.parse(value)))); } else { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); position.setTime(dateFormat.parse(value)); diff --git a/src/org/traccar/protocol/SmokeyProtocolDecoder.java b/src/org/traccar/protocol/SmokeyProtocolDecoder.java index 825108ed2..b9cef5ad4 100644 --- a/src/org/traccar/protocol/SmokeyProtocolDecoder.java +++ b/src/org/traccar/protocol/SmokeyProtocolDecoder.java @@ -19,9 +19,6 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Seconds; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.NetworkMessage; @@ -33,6 +30,8 @@ import org.traccar.model.WifiAccessPoint; import java.net.SocketAddress; import java.nio.charset.StandardCharsets; +import java.time.Instant; +import java.time.temporal.ChronoUnit; public class SmokeyProtocolDecoder extends BaseProtocolDecoder { @@ -52,8 +51,8 @@ public class SmokeyProtocolDecoder extends BaseProtocolDecoder { response.writeByte(3); // protocol version response.writeByte(MSG_DATE_RECORD_ACK); response.writeBytes(id); - response.writeInt(Seconds.secondsBetween( - new DateTime(2000, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(DateTimeZone.UTC)).getSeconds()); + response.writeInt( + (int) ChronoUnit.SECONDS.between(Instant.parse("2000-01-01T00:00:00.00Z"), Instant.now())); response.writeByte(index); response.writeByte(report - 0x200); diff --git a/src/org/traccar/web/CsvBuilder.java b/src/org/traccar/web/CsvBuilder.java index 29e2ccfbc..f7455b528 100644 --- a/src/org/traccar/web/CsvBuilder.java +++ b/src/org/traccar/web/CsvBuilder.java @@ -19,6 +19,7 @@ package org.traccar.web; import java.beans.Introspector; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.Collection; import java.util.Comparator; @@ -28,9 +29,6 @@ import java.util.SortedSet; import java.util.TreeSet; import com.fasterxml.jackson.core.JsonProcessingException; -import org.joda.time.DateTime; -import org.joda.time.format.DateTimeFormatter; -import org.joda.time.format.ISODateTimeFormat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.traccar.Context; @@ -41,7 +39,6 @@ public class CsvBuilder { private static final String LINE_ENDING = "\r\n"; private static final String SEPARATOR = ";"; - private static final DateTimeFormatter DATE_FORMAT = ISODateTimeFormat.dateTime(); private StringBuilder builder = new StringBuilder(); @@ -94,7 +91,7 @@ public class CsvBuilder { addSeparator(); } else if (method.getReturnType().equals(Date.class)) { Date value = (Date) method.invoke(object); - builder.append(DATE_FORMAT.print(new DateTime(value))); + builder.append(DateTimeFormatter.ISO_DATE_TIME.format(value.toInstant())); addSeparator(); } else if (method.getReturnType().equals(Map.class)) { Map value = (Map) method.invoke(object); @@ -163,4 +160,5 @@ public class CsvBuilder { public String build() { return builder.toString(); } + } diff --git a/src/org/traccar/web/GpxBuilder.java b/src/org/traccar/web/GpxBuilder.java index bac7182dc..a4daf154e 100644 --- a/src/org/traccar/web/GpxBuilder.java +++ b/src/org/traccar/web/GpxBuilder.java @@ -16,11 +16,8 @@ */ package org.traccar.web; +import java.time.format.DateTimeFormatter; import java.util.Collection; - -import org.joda.time.DateTime; -import org.joda.time.format.DateTimeFormatter; -import org.joda.time.format.ISODateTimeFormat; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; @@ -41,8 +38,6 @@ public class GpxBuilder { + "%n"; private static final String FOOTER = ""; - private static final DateTimeFormatter DATE_FORMAT = ISODateTimeFormat.dateTime(); - public GpxBuilder() { builder.append(HEADER); builder.append("\n"); @@ -55,7 +50,7 @@ public class GpxBuilder { public void addPosition(Position position) { builder.append(String.format(POINT, position.getLatitude(), position.getLongitude(), - DATE_FORMAT.print(new DateTime(position.getFixTime())), position.getAltitude(), + DateTimeFormatter.ISO_DATE_TIME.format(position.getFixTime().toInstant()), position.getAltitude(), position.getCourse(), UnitsConverter.mpsFromKnots(position.getSpeed()))); } diff --git a/src/org/traccar/web/WebServer.java b/src/org/traccar/web/WebServer.java index 4bb88578f..90ea74a3b 100644 --- a/src/org/traccar/web/WebServer.java +++ b/src/org/traccar/web/WebServer.java @@ -130,7 +130,6 @@ public class WebServer { resourceHandler.setResourceBase(config.getString("web.path")); if (config.getBoolean("web.debug")) { resourceHandler.setWelcomeFiles(new String[] {"debug.html", "index.html"}); - resourceHandler.setMinMemoryMappedContentLength(-1); // avoid locking files on Windows } else { String cache = config.getString("web.cacheControl"); if (cache != null && !cache.isEmpty()) { diff --git a/test/org/traccar/protocol/H02ProtocolEncoderTest.java b/test/org/traccar/protocol/H02ProtocolEncoderTest.java index e7b409a88..e022a7b7e 100644 --- a/test/org/traccar/protocol/H02ProtocolEncoderTest.java +++ b/test/org/traccar/protocol/H02ProtocolEncoderTest.java @@ -1,16 +1,22 @@ package org.traccar.protocol; -import org.joda.time.DateTime; import org.junit.Test; import org.traccar.ProtocolTest; import org.traccar.model.Command; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneOffset; +import java.util.Date; + import static org.junit.Assert.assertEquals; public class H02ProtocolEncoderTest extends ProtocolTest { private H02ProtocolEncoder encoder = new H02ProtocolEncoder(); - private DateTime time = new DateTime().withHourOfDay(1).withMinuteOfHour(2).withSecondOfMinute(3); + private Date time = Date.from( + LocalDateTime.of(LocalDate.now(), LocalTime.of(1, 2, 3)).atZone(ZoneOffset.systemDefault()).toInstant()); @Test public void testAlarmArmEncode() throws Exception { -- cgit v1.2.3