Merge changes from topic "get-rid-of-joda-time"
* changes: Guard against null values for date during mail parsing Provide Joda time only for Elasticsearch Don't export Joda time for plugins anymore Remove joda-time from BUILD files for core Gerrit Switch to Java Date/Time API for TimeUtil Switch to Java Date/Time API for mail related code Switch to Java Date/Time API in ScheduleConfig Switch to Java Date/Time API in ResourceServletTest Switch to Java Date/Time API in ChangeBundleTest OutputStreamQueryTest: Remove test proving equivalence to Joda time Switch to Java Date/Time API in OutputStreamQuery
This commit is contained in:
@@ -16,16 +16,16 @@ package com.google.gerrit.server.config;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import java.text.MessageFormat;
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDateTime;
|
||||
import org.joda.time.LocalTime;
|
||||
import org.joda.time.MutableDateTime;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
import org.joda.time.format.ISODateTimeFormat;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -49,16 +49,16 @@ public class ScheduleConfig {
|
||||
}
|
||||
|
||||
public ScheduleConfig(Config rc, String section, String subsection) {
|
||||
this(rc, section, subsection, DateTime.now());
|
||||
this(rc, section, subsection, ZonedDateTime.now());
|
||||
}
|
||||
|
||||
public ScheduleConfig(
|
||||
Config rc, String section, String subsection, String keyInterval, String keyStartTime) {
|
||||
this(rc, section, subsection, keyInterval, keyStartTime, DateTime.now());
|
||||
this(rc, section, subsection, keyInterval, keyStartTime, ZonedDateTime.now());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
ScheduleConfig(Config rc, String section, String subsection, DateTime now) {
|
||||
ScheduleConfig(Config rc, String section, String subsection, ZonedDateTime now) {
|
||||
this(rc, section, subsection, KEY_INTERVAL, KEY_STARTTIME, now);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class ScheduleConfig {
|
||||
String subsection,
|
||||
String keyInterval,
|
||||
String keyStartTime,
|
||||
DateTime now) {
|
||||
ZonedDateTime now) {
|
||||
this.rc = rc;
|
||||
this.section = section;
|
||||
this.subsection = subsection;
|
||||
@@ -122,31 +122,24 @@ public class ScheduleConfig {
|
||||
String section,
|
||||
String subsection,
|
||||
String keyStartTime,
|
||||
DateTime now,
|
||||
ZonedDateTime now,
|
||||
long interval) {
|
||||
long delay = MISSING_CONFIG;
|
||||
String start = rc.getString(section, subsection, keyStartTime);
|
||||
try {
|
||||
if (start != null) {
|
||||
DateTimeFormatter formatter;
|
||||
MutableDateTime startTime = now.toMutableDateTime();
|
||||
DateTimeFormatter formatter =
|
||||
DateTimeFormatter.ofPattern("[E ]HH:mm").withLocale(Locale.US);
|
||||
LocalTime firstStartTime = LocalTime.parse(start, formatter);
|
||||
ZonedDateTime startTime = now.with(firstStartTime);
|
||||
try {
|
||||
formatter = ISODateTimeFormat.hourMinute();
|
||||
LocalTime firstStartTime = formatter.parseLocalTime(start);
|
||||
startTime.hourOfDay().set(firstStartTime.getHourOfDay());
|
||||
startTime.minuteOfHour().set(firstStartTime.getMinuteOfHour());
|
||||
} catch (IllegalArgumentException e1) {
|
||||
formatter = DateTimeFormat.forPattern("E HH:mm").withLocale(Locale.US);
|
||||
LocalDateTime firstStartDateTime = formatter.parseLocalDateTime(start);
|
||||
startTime.dayOfWeek().set(firstStartDateTime.getDayOfWeek());
|
||||
startTime.hourOfDay().set(firstStartDateTime.getHourOfDay());
|
||||
startTime.minuteOfHour().set(firstStartDateTime.getMinuteOfHour());
|
||||
DayOfWeek dayOfWeek = formatter.parse(start, DayOfWeek::from);
|
||||
startTime = startTime.with(dayOfWeek);
|
||||
} catch (DateTimeParseException ignored) {
|
||||
// Day of week is an optional parameter.
|
||||
}
|
||||
startTime.secondOfMinute().set(0);
|
||||
startTime.millisOfSecond().set(0);
|
||||
long s = startTime.getMillis();
|
||||
long n = now.getMillis();
|
||||
delay = (s - n) % interval;
|
||||
startTime = startTime.truncatedTo(ChronoUnit.MINUTES);
|
||||
delay = Duration.between(now, startTime).toMillis() % interval;
|
||||
if (delay <= 0) {
|
||||
delay += interval;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import com.google.auto.value.AutoValue;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.server.mail.Address;
|
||||
import org.joda.time.DateTime;
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* A simplified representation of an RFC 2045-2047 mime email message used for representing received
|
||||
@@ -40,7 +40,7 @@ public abstract class MailMessage {
|
||||
|
||||
public abstract ImmutableList<Address> cc();
|
||||
// Metadata
|
||||
public abstract DateTime dateReceived();
|
||||
public abstract Instant dateReceived();
|
||||
|
||||
public abstract ImmutableList<String> additionalHeaders();
|
||||
// Content
|
||||
@@ -84,7 +84,7 @@ public abstract class MailMessage {
|
||||
return this;
|
||||
}
|
||||
|
||||
public abstract Builder dateReceived(DateTime val);
|
||||
public abstract Builder dateReceived(Instant instant);
|
||||
|
||||
public abstract ImmutableList.Builder<String> additionalHeadersBuilder();
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ import org.apache.james.mime4j.dom.Multipart;
|
||||
import org.apache.james.mime4j.dom.TextBody;
|
||||
import org.apache.james.mime4j.dom.address.Mailbox;
|
||||
import org.apache.james.mime4j.message.DefaultMessageBuilder;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/** Parses raw email content received through POP3 or IMAP into an internal {@link MailMessage}. */
|
||||
public class RawMailParser {
|
||||
@@ -66,7 +65,9 @@ public class RawMailParser {
|
||||
if (mimeMessage.getSubject() != null) {
|
||||
messageBuilder.subject(mimeMessage.getSubject());
|
||||
}
|
||||
messageBuilder.dateReceived(new DateTime(mimeMessage.getDate()));
|
||||
if (mimeMessage.getDate() != null) {
|
||||
messageBuilder.dateReceived(mimeMessage.getDate().toInstant());
|
||||
}
|
||||
|
||||
// Add From, To and Cc
|
||||
if (mimeMessage.getFrom() != null && mimeMessage.getFrom().size() > 0) {
|
||||
|
||||
@@ -42,17 +42,19 @@ import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.eclipse.jgit.util.io.DisabledOutputStream;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -65,7 +67,10 @@ import org.slf4j.LoggerFactory;
|
||||
public class OutputStreamQuery {
|
||||
private static final Logger log = LoggerFactory.getLogger(OutputStreamQuery.class);
|
||||
|
||||
private static final DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss zzz");
|
||||
private static final DateTimeFormatter dtf =
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss zzz")
|
||||
.withLocale(Locale.US)
|
||||
.withZone(ZoneId.systemDefault());
|
||||
|
||||
public enum OutputFormat {
|
||||
TEXT,
|
||||
@@ -402,7 +407,7 @@ public class OutputStreamQuery {
|
||||
out.print('\n');
|
||||
} else if (value instanceof Long && isDateField(field)) {
|
||||
out.print(' ');
|
||||
out.print(dtf.print(((Long) value) * 1000L));
|
||||
out.print(dtf.format(Instant.ofEpochSecond((Long) value)));
|
||||
out.print('\n');
|
||||
} else if (isPrimitive(value)) {
|
||||
out.print(' ');
|
||||
|
||||
Reference in New Issue
Block a user