diff --git a/gerrit-gwtui-common/BUCK b/gerrit-gwtui-common/BUCK index 6ee0336bc2..3977487650 100644 --- a/gerrit-gwtui-common/BUCK +++ b/gerrit-gwtui-common/BUCK @@ -63,3 +63,16 @@ java_library( name = 'diffy_image_files', resources = DIFFY, ) + +java_test( + name = 'client_tests', + srcs = glob(['src/test/java/**/*.java']), + deps = [ + ':client', + '//lib:junit', + '//lib/jgit:jgit', + ], + source_under_test = [':client'], + vm_args = ['-Xmx512m'], + visibility = ['//tools/eclipse:classpath'], +) diff --git a/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/CommonConstants.java b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/CommonConstants.java new file mode 100644 index 0000000000..032c47ce9f --- /dev/null +++ b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/CommonConstants.java @@ -0,0 +1,36 @@ +// Copyright (C) 2015 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.client; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.Constants; + +public interface CommonConstants extends Constants { + public static final CommonConstants C = GWT.create(CommonConstants.class); + + String inTheFuture(); + String month(); + String months(); + String year(); + String years(); + + String oneSecondAgo(); + String oneMinuteAgo(); + String oneHourAgo(); + String oneDayAgo(); + String oneWeekAgo(); + String oneMonthAgo(); + String oneYearAgo(); +} diff --git a/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/CommonConstants.properties b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/CommonConstants.properties new file mode 100644 index 0000000000..3202bfce0c --- /dev/null +++ b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/CommonConstants.properties @@ -0,0 +1,13 @@ +inTheFuture = in the future +month = month +months = months +years = years +year = year + +oneSecondAgo = 1 second ago +oneMinuteAgo = 1 minute ago +oneHourAgo = 1 hour ago +oneDayAgo = 1 day ago +oneWeekAgo = 1 week ago +oneMonthAgo = 1 month ago +oneYearAgo = 1 year ago diff --git a/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/CommonMessages.java b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/CommonMessages.java new file mode 100644 index 0000000000..aa5e3cffb4 --- /dev/null +++ b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/CommonMessages.java @@ -0,0 +1,33 @@ +// Copyright (C) 2015 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.client; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.Messages; + +public interface CommonMessages extends Messages { + public static final CommonMessages M = GWT.create(CommonMessages.class); + + String secondsAgo(long seconds); + String minutesAgo(long minutes); + String hoursAgo(long hours); + String daysAgo(long days); + String weeksAgo(long weeks); + String monthsAgo(long months); + String yearsAgo(long years); + String years0MonthsAgo(long years, String yearLabel); + String yearsMonthsAgo(long years, String yearLabel, long months, + String monthLabel); +} diff --git a/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/CommonMessages.properties b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/CommonMessages.properties new file mode 100644 index 0000000000..738602effa --- /dev/null +++ b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/CommonMessages.properties @@ -0,0 +1,9 @@ +secondsAgo = {0} seconds ago +minutesAgo = {0} minutes ago +hoursAgo = {0} hours ago +daysAgo = {0} days ago +weeksAgo = {0} weeks ago +monthsAgo = {0} months ago +years0MonthsAgo = {0} {1} ago +yearsMonthsAgo = {0} {1}, {2} {3} ago +yearsAgo = {0} years ago diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/RelativeDateFormatter.java b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/RelativeDateFormatter.java similarity index 77% rename from gerrit-gwtui/src/main/java/com/google/gerrit/client/RelativeDateFormatter.java rename to gerrit-gwtui-common/src/main/java/com/google/gerrit/client/RelativeDateFormatter.java index 443a6a8aa2..eb4b0bac2e 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/RelativeDateFormatter.java +++ b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/RelativeDateFormatter.java @@ -14,7 +14,8 @@ package com.google.gerrit.client; -import com.google.gerrit.client.changes.Util; +import static com.google.gerrit.client.CommonConstants.C; +import static com.google.gerrit.client.CommonMessages.M; import java.util.Date; @@ -24,17 +25,11 @@ import java.util.Date; */ public class RelativeDateFormatter { static final long SECOND_IN_MILLIS = 1000; - static final long MINUTE_IN_MILLIS = 60 * SECOND_IN_MILLIS; - static final long HOUR_IN_MILLIS = 60 * MINUTE_IN_MILLIS; - static final long DAY_IN_MILLIS = 24 * HOUR_IN_MILLIS; - static final long WEEK_IN_MILLIS = 7 * DAY_IN_MILLIS; - static final long MONTH_IN_MILLIS = 30 * DAY_IN_MILLIS; - static final long YEAR_IN_MILLIS = 365 * DAY_IN_MILLIS; /** @@ -48,16 +43,16 @@ public class RelativeDateFormatter { // shouldn't happen in a perfect world if (ageMillis < 0) { - return Util.C.inTheFuture(); + return C.inTheFuture(); } // seconds if (ageMillis < upperLimit(MINUTE_IN_MILLIS)) { long seconds = round(ageMillis, SECOND_IN_MILLIS); if (seconds == 1) { - return Util.C.oneSecondAgo(); + return C.oneSecondAgo(); } else { - return Util.M.secondsAgo(seconds); + return M.secondsAgo(seconds); } } @@ -65,9 +60,9 @@ public class RelativeDateFormatter { if (ageMillis < upperLimit(HOUR_IN_MILLIS)) { long minutes = round(ageMillis, MINUTE_IN_MILLIS); if (minutes == 1) { - return Util.C.oneMinuteAgo(); + return C.oneMinuteAgo(); } else { - return Util.M.minutesAgo(minutes); + return M.minutesAgo(minutes); } } @@ -75,9 +70,9 @@ public class RelativeDateFormatter { if (ageMillis < upperLimit(DAY_IN_MILLIS)) { long hours = round(ageMillis, HOUR_IN_MILLIS); if (hours == 1) { - return Util.C.oneHourAgo(); + return C.oneHourAgo(); } else { - return Util.M.hoursAgo(hours); + return M.hoursAgo(hours); } } @@ -85,9 +80,9 @@ public class RelativeDateFormatter { if (ageMillis < 14 * DAY_IN_MILLIS) { long days = round(ageMillis, DAY_IN_MILLIS); if (days == 1) { - return Util.C.oneDayAgo(); + return C.oneDayAgo(); } else { - return Util.M.daysAgo(days); + return M.daysAgo(days); } } @@ -95,9 +90,9 @@ public class RelativeDateFormatter { if (ageMillis < 10 * WEEK_IN_MILLIS) { long weeks = round(ageMillis, WEEK_IN_MILLIS); if (weeks == 1) { - return Util.C.oneWeekAgo(); + return C.oneWeekAgo(); } else { - return Util.M.weeksAgo(weeks); + return M.weeksAgo(weeks); } } @@ -105,32 +100,31 @@ public class RelativeDateFormatter { if (ageMillis < YEAR_IN_MILLIS) { long months = round(ageMillis, MONTH_IN_MILLIS); if (months == 1) { - return Util.C.oneMonthAgo(); + return C.oneMonthAgo(); } else { - return Util.M.monthsAgo(months); + return M.monthsAgo(months); } } // up to 5 years use "year, months" rounded to months if (ageMillis < 5 * YEAR_IN_MILLIS) { long years = ageMillis / YEAR_IN_MILLIS; - String yearLabel = (years > 1) ? Util.C.years() : Util.C.year(); + String yearLabel = (years > 1) ? C.years() : C.year(); long months = round(ageMillis % YEAR_IN_MILLIS, MONTH_IN_MILLIS); - String monthLabel = - (months > 1) ? Util.C.months() : (months == 1 ? Util.C.month() : ""); + String monthLabel = (months > 1) ? C.months() : (months == 1 ? C.month() : ""); if (months == 0) { - return Util.M.years0MonthsAgo(years, yearLabel); + return M.years0MonthsAgo(years, yearLabel); } else { - return Util.M.yearsMonthsAgo(years, yearLabel, months, monthLabel); + return M.yearsMonthsAgo(years, yearLabel, months, monthLabel); } } // years long years = round(ageMillis, YEAR_IN_MILLIS); if (years == 1) { - return Util.C.oneYearAgo(); + return C.oneYearAgo(); } else { - return Util.M.yearsAgo(years); + return M.yearsAgo(years); } } diff --git a/gerrit-gwtui/src/test/java/com/google/gerrit/client/RelativeDateFormatterTest.java b/gerrit-gwtui-common/src/test/java/com/google/gerrit/client/RelativeDateFormatterTest.java similarity index 99% rename from gerrit-gwtui/src/test/java/com/google/gerrit/client/RelativeDateFormatterTest.java rename to gerrit-gwtui-common/src/test/java/com/google/gerrit/client/RelativeDateFormatterTest.java index 6705e51d3a..7c71921a66 100644 --- a/gerrit-gwtui/src/test/java/com/google/gerrit/client/RelativeDateFormatterTest.java +++ b/gerrit-gwtui-common/src/test/java/com/google/gerrit/client/RelativeDateFormatterTest.java @@ -19,6 +19,7 @@ import static com.google.gerrit.client.RelativeDateFormatter.HOUR_IN_MILLIS; import static com.google.gerrit.client.RelativeDateFormatter.MINUTE_IN_MILLIS; import static com.google.gerrit.client.RelativeDateFormatter.SECOND_IN_MILLIS; import static com.google.gerrit.client.RelativeDateFormatter.YEAR_IN_MILLIS; + import static org.junit.Assert.assertEquals; import org.eclipse.jgit.util.RelativeDateFormatter; diff --git a/gerrit-gwtui/BUCK b/gerrit-gwtui/BUCK index 5eed21a5e0..90fdcab36c 100644 --- a/gerrit-gwtui/BUCK +++ b/gerrit-gwtui/BUCK @@ -61,7 +61,6 @@ java_test( '//lib/gwt:dev', '//lib/gwt:user', '//lib/gwt:gwt-test-utils', - '//lib/jgit:jgit', ], source_under_test = [':ui_module'], vm_args = ['-Xmx512m'], diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeConstants.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeConstants.java index 759e7228c5..ca4c633e12 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeConstants.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeConstants.java @@ -201,19 +201,5 @@ public interface ChangeConstants extends Constants { String diffAllSideBySide(); String diffAllUnified(); - String inTheFuture(); - String month(); - String months(); - String year(); - String years(); - - String oneSecondAgo(); - String oneMinuteAgo(); - String oneHourAgo(); - String oneDayAgo(); - String oneWeekAgo(); - String oneMonthAgo(); - String oneYearAgo(); - String votable(); } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeConstants.properties b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeConstants.properties index ca29773fa2..e3481615a2 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeConstants.properties +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeConstants.properties @@ -183,18 +183,4 @@ buttonClose = Close diffAllSideBySide = All Side-by-Side diffAllUnified = All Unified -inTheFuture = in the future -month = month -months = months -years = years -year = year - -oneSecondAgo = 1 second ago -oneMinuteAgo = 1 minute ago -oneHourAgo = 1 hour ago -oneDayAgo = 1 day ago -oneWeekAgo = 1 week ago -oneMonthAgo = 1 month ago -oneYearAgo = 1 year ago - votable = Votable: diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeMessages.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeMessages.java index 76e321161f..2d3644e2bf 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeMessages.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeMessages.java @@ -60,16 +60,5 @@ public interface ChangeMessages extends Messages { String groupHasTooManyMembers(String group); String groupManyMembersConfirmation(String group, int memberCount); - String secondsAgo(long seconds); - String minutesAgo(long minutes); - String hoursAgo(long hours); - String daysAgo(long days); - String weeksAgo(long weeks); - String monthsAgo(long months); - String yearsAgo(long years); - String years0MonthsAgo(long years, String yearLabel); - String yearsMonthsAgo(long years, String yearLabel, long months, - String monthLabel); - String insertionsAndDeletions(int insertions, int deletions); } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeMessages.properties b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeMessages.properties index 7069c4a1fc..c10979408a 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeMessages.properties +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeMessages.properties @@ -43,14 +43,4 @@ groupIsNotAllowed = The group {0} cannot be added as reviewer. groupHasTooManyMembers = The group {0} has too many members to add them all as reviewers. groupManyMembersConfirmation = The group {0} has {1} members. Do you want to add them all as reviewers? -secondsAgo = {0} seconds ago -minutesAgo = {0} minutes ago -hoursAgo = {0} hours ago -daysAgo = {0} days ago -weeksAgo = {0} weeks ago -monthsAgo = {0} months ago -years0MonthsAgo = {0} {1} ago -yearsMonthsAgo = {0} {1}, {2} {3} ago -yearsAgo = {0} years ago - insertionsAndDeletions = +{0}, -{1} diff --git a/gerrit-plugin-gwtui/src/main/java/com/google/gerrit/plugin/client/FormatUtil.java b/gerrit-plugin-gwtui/src/main/java/com/google/gerrit/plugin/client/FormatUtil.java index ccad45dacd..f52bbefc62 100644 --- a/gerrit-plugin-gwtui/src/main/java/com/google/gerrit/plugin/client/FormatUtil.java +++ b/gerrit-plugin-gwtui/src/main/java/com/google/gerrit/plugin/client/FormatUtil.java @@ -16,6 +16,7 @@ package com.google.gerrit.plugin.client; import com.google.gerrit.client.AccountFormatter; import com.google.gerrit.client.DateFormatter; +import com.google.gerrit.client.RelativeDateFormatter; import com.google.gerrit.client.info.AccountInfo; import java.util.Date; @@ -44,6 +45,11 @@ public class FormatUtil { return new DateFormatter(Plugin.get().getUserPreferences()); } + /** Format a date using git log's relative date format. */ + public static String relativeFormat(Date dt) { + return RelativeDateFormatter.format(dt); + } + /** * Formats an account as a name and an email address. *