diff --git a/gerrit-cache-h2/src/main/java/com/google/gerrit/server/cache/h2/H2CacheImpl.java b/gerrit-cache-h2/src/main/java/com/google/gerrit/server/cache/h2/H2CacheImpl.java index 41474dab7b..0c56bf6bdd 100644 --- a/gerrit-cache-h2/src/main/java/com/google/gerrit/server/cache/h2/H2CacheImpl.java +++ b/gerrit-cache-h2/src/main/java/com/google/gerrit/server/cache/h2/H2CacheImpl.java @@ -11,6 +11,7 @@ import com.google.common.hash.BloomFilter; import com.google.common.hash.Funnel; import com.google.common.hash.Funnels; import com.google.common.hash.PrimitiveSink; +import com.google.gerrit.server.util.TimeUtil; import com.google.inject.TypeLiteral; import org.h2.jdbc.JdbcSQLException; @@ -114,7 +115,7 @@ public class H2CacheImpl extends AbstractLoadingCache { @Override public void put(final K key, V val) { final ValueHolder h = new ValueHolder(val); - h.created = System.currentTimeMillis(); + h.created = TimeUtil.nowMs(); mem.put(key, h); executor.execute(new Runnable() { @Override @@ -182,7 +183,7 @@ public class H2CacheImpl extends AbstractLoadingCache { cal.set(Calendar.MILLISECOND, 0); cal.add(Calendar.DAY_OF_MONTH, 1); - long delay = cal.getTimeInMillis() - System.currentTimeMillis(); + long delay = cal.getTimeInMillis() - TimeUtil.nowMs(); service.schedule(new Runnable() { @Override public void run() { @@ -245,7 +246,7 @@ public class H2CacheImpl extends AbstractLoadingCache { } final ValueHolder h = new ValueHolder(loader.load(key)); - h.created = System.currentTimeMillis(); + h.created = TimeUtil.nowMs(); executor.execute(new Runnable() { @Override public void run() { @@ -461,7 +462,7 @@ public class H2CacheImpl extends AbstractLoadingCache { c.touch =c.conn.prepareStatement("UPDATE data SET accessed=? WHERE k=?"); } try { - c.touch.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + c.touch.setTimestamp(1, new Timestamp(TimeUtil.nowMs())); keyType.set(c.touch, 2, key); c.touch.executeUpdate(); } finally { @@ -490,7 +491,7 @@ public class H2CacheImpl extends AbstractLoadingCache { keyType.set(c.put, 1, key); c.put.setObject(2, holder.value); c.put.setTimestamp(3, new Timestamp(holder.created)); - c.put.setTimestamp(4, new Timestamp(System.currentTimeMillis())); + c.put.setTimestamp(4, new Timestamp(TimeUtil.nowMs())); c.put.executeUpdate(); holder.clean = true; } finally { diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/HttpLogoutServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/HttpLogoutServlet.java index c3639cebe8..ddbba3b503 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/HttpLogoutServlet.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/HttpLogoutServlet.java @@ -14,14 +14,15 @@ package com.google.gerrit.httpd; +import com.google.common.base.Strings; import com.google.gerrit.audit.AuditEvent; import com.google.gerrit.audit.AuditService; -import com.google.common.base.Strings; import com.google.gerrit.common.Nullable; import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.account.AccountManager; import com.google.gerrit.server.config.AuthConfig; import com.google.gerrit.server.config.CanonicalWebUrl; +import com.google.gerrit.server.util.TimeUtil; import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.Singleton; @@ -80,7 +81,7 @@ class HttpLogoutServlet extends HttpServlet { final String sid = webSession.get().getSessionId(); final CurrentUser currentUser = webSession.get().getCurrentUser(); final String what = "sign out"; - final long when = System.currentTimeMillis(); + final long when = TimeUtil.nowMs(); try { doLogout(req, rsp); diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/WebSessionManager.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/WebSessionManager.java index a5338f809d..03eca9fcbe 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/WebSessionManager.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/WebSessionManager.java @@ -22,6 +22,7 @@ import static com.google.gerrit.server.ioutil.BasicSerialization.writeBytes; import static com.google.gerrit.server.ioutil.BasicSerialization.writeFixInt64; import static com.google.gerrit.server.ioutil.BasicSerialization.writeString; import static com.google.gerrit.server.ioutil.BasicSerialization.writeVarInt32; +import static com.google.gerrit.server.util.TimeUtil.nowMs; import static java.util.concurrent.TimeUnit.HOURS; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.MINUTES; @@ -53,10 +54,6 @@ class WebSessionManager { private static final Logger log = LoggerFactory.getLogger(WebSessionManager.class); static final String CACHE_NAME = "web_sessions"; - static long now() { - return System.currentTimeMillis(); - } - private final long sessionMaxAgeMillis; private final SecureRandom prng; private final Cache self; @@ -117,7 +114,7 @@ class WebSessionManager { final long halfAgeRefresh = sessionMaxAgeMillis >>> 1; final long minRefresh = MILLISECONDS.convert(1, HOURS); final long refresh = Math.min(halfAgeRefresh, minRefresh); - final long now = now(); + final long now = nowMs(); final long refreshCookieAt = now + refresh; final long expiresAt = now + sessionMaxAgeMillis; if (sid == null) { @@ -150,7 +147,7 @@ class WebSessionManager { Val get(final Key key) { Val val = self.getIfPresent(key.token); - if (val != null && val.expiresAt <= now()) { + if (val != null && val.expiresAt <= nowMs()) { self.invalidate(key.token); return null; } @@ -223,7 +220,7 @@ class WebSessionManager { } boolean needsCookieRefresh() { - return refreshCookieAt <= now(); + return refreshCookieAt <= nowMs(); } boolean isPersistentCookie() { diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/CatServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/CatServlet.java index 1ecd929a40..47a9263209 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/CatServlet.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/CatServlet.java @@ -24,6 +24,7 @@ import com.google.gerrit.server.FileTypeRegistry; import com.google.gerrit.server.git.GitRepositoryManager; import com.google.gerrit.server.project.ChangeControl; import com.google.gerrit.server.project.NoSuchChangeException; +import com.google.gerrit.server.util.TimeUtil; import com.google.gwtexpui.server.CacheHeaders; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; @@ -333,7 +334,7 @@ public class CatServlet extends HttpServlet { md.update(req.getRemoteAddr().getBytes("UTF-8")); md.update(buf, 0, 4); - NB.encodeInt64(buf, 0, System.currentTimeMillis()); + NB.encodeInt64(buf, 0, TimeUtil.nowMs()); md.update(buf, 0, 8); rng.nextBytes(buf); diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java index becacf194d..517b0174c6 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java @@ -16,7 +16,9 @@ package com.google.gerrit.httpd.restapi; import static com.google.common.base.Charsets.UTF_8; import static com.google.common.base.Preconditions.checkNotNull; + import static java.math.RoundingMode.CEILING; + import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST; import static javax.servlet.http.HttpServletResponse.SC_CONFLICT; import static javax.servlet.http.HttpServletResponse.SC_CREATED; @@ -76,6 +78,7 @@ import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.OptionUtil; import com.google.gerrit.server.OutputFormat; import com.google.gerrit.server.account.CapabilityUtils; +import com.google.gerrit.server.util.TimeUtil; import com.google.gson.ExclusionStrategy; import com.google.gson.FieldAttributes; import com.google.gson.FieldNamingPolicy; @@ -185,7 +188,7 @@ public class RestApiServlet extends HttpServlet { @Override protected final void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { - long auditStartTs = System.currentTimeMillis(); + long auditStartTs = TimeUtil.nowMs(); res.setHeader("Content-Disposition", "attachment"); res.setHeader("X-Content-Type-Options", "nosniff"); int status = SC_OK; diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/GerritJsonServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/GerritJsonServlet.java index 55ecb01d2e..5a0d328405 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/GerritJsonServlet.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/GerritJsonServlet.java @@ -24,6 +24,7 @@ import com.google.gerrit.common.errors.NotSignedInException; import com.google.gerrit.httpd.WebSession; import com.google.gerrit.server.AccessPath; import com.google.gerrit.server.CurrentUser; +import com.google.gerrit.server.util.TimeUtil; import com.google.gson.GsonBuilder; import com.google.gwtjsonrpc.common.RemoteJsonService; import com.google.gwtjsonrpc.server.ActiveCall; @@ -238,7 +239,7 @@ final class GerritJsonServlet extends JsonServlet final HttpServletResponse o) { super(i, o); this.session = session; - this.when = System.currentTimeMillis(); + this.when = TimeUtil.nowMs(); } @Override @@ -290,7 +291,7 @@ final class GerritJsonServlet extends JsonServlet } public long getElapsed() { - return System.currentTimeMillis() - when; + return TimeUtil.nowMs() - when; } } diff --git a/gerrit-launcher/BUCK b/gerrit-launcher/BUCK index e5ff3d0f3b..344e53d90d 100644 --- a/gerrit-launcher/BUCK +++ b/gerrit-launcher/BUCK @@ -1,6 +1,7 @@ java_library( name = 'launcher', srcs = glob(['src/main/java/**/*.java']), + deps = ['//lib/joda:joda-time'], visibility = [ '//gerrit-acceptance-tests/...', '//gerrit-main:main_lib', diff --git a/gerrit-launcher/src/main/java/com/google/gerrit/launcher/GerritLauncher.java b/gerrit-launcher/src/main/java/com/google/gerrit/launcher/GerritLauncher.java index afe61d2cf3..2dd20a2e22 100644 --- a/gerrit-launcher/src/main/java/com/google/gerrit/launcher/GerritLauncher.java +++ b/gerrit-launcher/src/main/java/com/google/gerrit/launcher/GerritLauncher.java @@ -17,6 +17,8 @@ package com.google.gerrit.launcher; import static java.util.concurrent.TimeUnit.DAYS; import static java.util.concurrent.TimeUnit.MILLISECONDS; +import org.joda.time.DateTimeUtils; + import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -506,7 +508,7 @@ public final class GerritLauncher { // final File[] tmpEntries = tmp.listFiles(); if (tmpEntries != null) { - final long now = System.currentTimeMillis(); + final long now = DateTimeUtils.currentTimeMillis(); final long expired = now - MILLISECONDS.convert(7, DAYS); for (final File tmpEntry : tmpEntries) { if (tmpEntry.isDirectory() && tmpEntry.lastModified() < expired) { diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/HttpLog.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/HttpLog.java index 5ee335d111..6aef5099c0 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/HttpLog.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/HttpLog.java @@ -17,6 +17,7 @@ package com.google.gerrit.pgm.http.jetty; import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.config.SitePaths; +import com.google.gerrit.server.util.TimeUtil; import org.apache.log4j.Appender; import org.apache.log4j.AsyncAppender; @@ -95,7 +96,7 @@ class HttpLog extends AbstractLifeCycle implements RequestLog { final LoggingEvent event = new LoggingEvent( // Logger.class.getName(), // fqnOfCategoryClass log, // logger - System.currentTimeMillis(), // when + TimeUtil.nowMs(), // when Level.INFO, // level "", // message text "HTTPD", // thread name @@ -162,7 +163,7 @@ class HttpLog extends AbstractLifeCycle implements RequestLog { dateFormat = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss Z"); dateFormat.setTimeZone(tz); - lastTimeMillis = System.currentTimeMillis(); + lastTimeMillis = TimeUtil.nowMs(); lastTimeString = dateFormat.format(new Date(lastTimeMillis)); } diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/JettyServer.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/JettyServer.java index 35df8d9a7d..aa0f3f9c8d 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/JettyServer.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/JettyServer.java @@ -25,6 +25,7 @@ import com.google.gerrit.reviewdb.client.AuthType; import com.google.gerrit.server.config.ConfigUtil; import com.google.gerrit.server.config.GerritServerConfig; import com.google.gerrit.server.config.SitePaths; +import com.google.gerrit.server.util.TimeUtil; import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Singleton; @@ -596,7 +597,7 @@ public class JettyServer { if (properties.contains("PATH")) { proc.environment().put("PATH", properties.getProperty("PATH")); } - long start = System.currentTimeMillis(); + long start = TimeUtil.nowMs(); Process rebuild = proc.start(); byte[] out; InputStream in = rebuild.getInputStream(); @@ -619,7 +620,7 @@ public class JettyServer { System.exit(status); } - long time = System.currentTimeMillis() - start; + long time = TimeUtil.nowMs() - start; log.info(String.format("UPDATED %s in %.3fs", target, time / 1000.0)); } diff --git a/gerrit-server/BUCK b/gerrit-server/BUCK index b5799aa303..66929cbd9a 100644 --- a/gerrit-server/BUCK +++ b/gerrit-server/BUCK @@ -45,6 +45,7 @@ java_library2( '//lib/guice:guice-assistedinject', '//lib/guice:guice-servlet', '//lib/jgit:jgit', + '//lib/joda:joda-time', '//lib/log:api', '//lib/prolog:prolog-cafe', ], diff --git a/gerrit-server/src/main/java/com/google/gerrit/audit/AuditEvent.java b/gerrit-server/src/main/java/com/google/gerrit/audit/AuditEvent.java index 173ced622e..cdb24e76b0 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/audit/AuditEvent.java +++ b/gerrit-server/src/main/java/com/google/gerrit/audit/AuditEvent.java @@ -19,6 +19,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import com.google.gerrit.server.CurrentUser; +import com.google.gerrit.server.util.TimeUtil; public class AuditEvent { @@ -94,7 +95,7 @@ public class AuditEvent { this.params = Objects.firstNonNull(params, EMPTY_PARAMS); this.uuid = new UUID(); this.result = result; - this.elapsed = System.currentTimeMillis() - timeAtStart; + this.elapsed = TimeUtil.nowMs() - timeAtStart; } @Override diff --git a/gerrit-server/src/main/java/com/google/gerrit/rules/PrologCompiler.java b/gerrit-server/src/main/java/com/google/gerrit/rules/PrologCompiler.java index f9aac596f9..a0196fdf05 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/rules/PrologCompiler.java +++ b/gerrit-server/src/main/java/com/google/gerrit/rules/PrologCompiler.java @@ -18,6 +18,7 @@ import com.google.gerrit.common.Version; import com.google.gerrit.server.config.GerritServerConfig; import com.google.gerrit.server.config.SitePaths; import com.google.gerrit.server.git.GitRepositoryManager; +import com.google.gerrit.server.util.TimeUtil; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; @@ -222,7 +223,7 @@ public class PrologCompiler implements Callable { /** Takes compiled prolog .class files, puts them into the jar file. */ private void createJar(File archiveFile, List toBeJared, File tempDir, ObjectId metaConfig, ObjectId rulesId) throws IOException { - long now = System.currentTimeMillis(); + long now = TimeUtil.nowMs(); File tmpjar = File.createTempFile(".rulec_", ".jar", archiveFile.getParentFile()); try { Manifest mf = new Manifest(); @@ -315,4 +316,4 @@ public class PrologCompiler implements Callable { } dir.delete(); } -} \ No newline at end of file +} diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/ChangeUtil.java b/gerrit-server/src/main/java/com/google/gerrit/server/ChangeUtil.java index 3c460b8480..2caa81acd3 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/ChangeUtil.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/ChangeUtil.java @@ -50,6 +50,7 @@ import com.google.gerrit.server.project.NoSuchChangeException; import com.google.gerrit.server.project.RefControl; import com.google.gerrit.server.util.IdGenerator; import com.google.gerrit.server.util.MagicBranch; +import com.google.gerrit.server.util.TimeUtil; import com.google.gwtorm.server.OrmConcurrencyException; import com.google.gwtorm.server.OrmException; @@ -144,7 +145,7 @@ public class ChangeUtil { } public static void updated(final Change c) { - c.resetLastUpdatedOn(); + c.setLastUpdatedOn(new Timestamp(TimeUtil.nowMs())); computeSortKey(c); } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/PatchSetInserter.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/PatchSetInserter.java index c64db76581..b153ce3c39 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/PatchSetInserter.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/PatchSetInserter.java @@ -18,7 +18,6 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.collect.Sets; - import com.google.common.util.concurrent.CheckedFuture; import com.google.gerrit.common.ChangeHooks; import com.google.gerrit.reviewdb.client.Account; @@ -46,6 +45,7 @@ import com.google.gerrit.server.project.ProjectState; import com.google.gerrit.server.project.RefControl; import com.google.gerrit.server.ssh.NoSshInfo; import com.google.gerrit.server.ssh.SshInfo; +import com.google.gerrit.server.util.TimeUtil; import com.google.gwtorm.server.AtomicUpdate; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; @@ -332,7 +332,7 @@ public class PatchSetInserter { if (patchSet == null) { patchSet = new PatchSet( ChangeUtil.nextPatchSetId(git, change.currentPatchSetId())); - patchSet.setCreatedOn(new Timestamp(System.currentTimeMillis())); + patchSet.setCreatedOn(new Timestamp(TimeUtil.nowMs())); patchSet.setUploader(change.getOwner()); patchSet.setRevision(new RevId(commit.name())); } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/Submit.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/Submit.java index f446bc5d5e..2362f54a09 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/Submit.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/Submit.java @@ -39,6 +39,7 @@ import com.google.gerrit.server.git.GitRepositoryManager; import com.google.gerrit.server.git.MergeQueue; import com.google.gerrit.server.index.ChangeIndexer; import com.google.gerrit.server.project.ChangeControl; +import com.google.gerrit.server.util.TimeUtil; import com.google.gwtorm.server.AtomicUpdate; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; @@ -178,7 +179,7 @@ public class Submit implements RestModifyView, public Change submit(RevisionResource rsrc, IdentifiedUser caller) throws OrmException, IOException { - final Timestamp timestamp = new Timestamp(System.currentTimeMillis()); + final Timestamp timestamp = new Timestamp(TimeUtil.nowMs()); Change change = rsrc.getChange(); ReviewDb db = dbProvider.get(); db.changes().beginTransaction(change.getId()); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/contact/EncryptedContactStore.java b/gerrit-server/src/main/java/com/google/gerrit/server/contact/EncryptedContactStore.java index bd1c0d7c6f..ce3e2f6079 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/contact/EncryptedContactStore.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/contact/EncryptedContactStore.java @@ -20,6 +20,7 @@ import com.google.gerrit.reviewdb.client.AccountExternalId; import com.google.gerrit.reviewdb.client.ContactInformation; import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.UrlEncoded; +import com.google.gerrit.server.util.TimeUtil; import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.SchemaFactory; import com.google.inject.ProvisionException; @@ -213,7 +214,7 @@ class EncryptedContactStore implements ContactStore { throws ContactInformationStoreException { Timestamp on = account.getContactFiledOn(); if (on == null) { - on = new Timestamp(System.currentTimeMillis()); + on = new Timestamp(TimeUtil.nowMs()); } final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/ChangeMergeQueue.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/ChangeMergeQueue.java index 12219e23cf..a6b0a12e6e 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/git/ChangeMergeQueue.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/ChangeMergeQueue.java @@ -27,6 +27,7 @@ import com.google.gerrit.server.config.RequestScopedReviewDbProvider; import com.google.gerrit.server.ssh.SshInfo; import com.google.gerrit.server.util.RequestContext; import com.google.gerrit.server.util.RequestScopePropagator; +import com.google.gerrit.server.util.TimeUtil; import com.google.inject.AbstractModule; import com.google.inject.Inject; import com.google.inject.Injector; @@ -155,7 +156,7 @@ public class ChangeMergeQueue implements MergeQueue { @Override public synchronized void recheckAfter(final Branch.NameKey branch, final long delay, final TimeUnit delayUnit) { - final long now = System.currentTimeMillis(); + final long now = TimeUtil.nowMs(); final long at = now + MILLISECONDS.convert(delay, delayUnit); RecheckJob e = recheck.get(branch); if (e == null) { @@ -216,7 +217,7 @@ public class ChangeMergeQueue implements MergeQueue { } private synchronized void recheck(final RecheckJob e) { - final long remainingDelay = e.recheckAt - System.currentTimeMillis(); + final long remainingDelay = e.recheckAt - TimeUtil.nowMs(); if (MILLISECONDS.convert(10, SECONDS) < remainingDelay) { // Woke up too early, the job deadline was pushed back. // Reschedule for the new deadline. We allow for a small diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/CherryPick.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/CherryPick.java index f4ed7cdb91..f95ec94ed5 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/git/CherryPick.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/CherryPick.java @@ -24,6 +24,7 @@ import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.ChangeUtil; import com.google.gerrit.server.extensions.events.GitReferenceUpdated; import com.google.gerrit.server.patch.PatchSetInfoFactory; +import com.google.gerrit.server.util.TimeUtil; import com.google.gwtorm.server.OrmException; import org.eclipse.jgit.lib.ObjectId; @@ -159,7 +160,7 @@ public class CherryPick extends SubmitStrategy { PatchSet.Id id = ChangeUtil.nextPatchSetId(args.repo, n.change.currentPatchSetId()); final PatchSet ps = new PatchSet(id); - ps.setCreatedOn(new Timestamp(System.currentTimeMillis())); + ps.setCreatedOn(new Timestamp(TimeUtil.nowMs())); ps.setUploader(submitAudit.getAccountId()); ps.setRevision(new RevId(newCommit.getId().getName())); insertAncestors(args.db, ps.getId(), newCommit); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/MergeOp.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/MergeOp.java index f20de2dbe6..7d62acb874 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/git/MergeOp.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/MergeOp.java @@ -15,10 +15,12 @@ package com.google.gerrit.server.git; import static com.google.gerrit.server.git.MergeUtil.getSubmitter; + import static java.util.concurrent.TimeUnit.HOURS; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.MINUTES; import static java.util.concurrent.TimeUnit.SECONDS; + import static org.eclipse.jgit.lib.RefDatabase.ALL; import com.google.common.base.Objects; @@ -59,6 +61,7 @@ import com.google.gerrit.server.project.NoSuchProjectException; import com.google.gerrit.server.project.ProjectCache; import com.google.gerrit.server.project.ProjectState; import com.google.gerrit.server.util.RequestScopePropagator; +import com.google.gerrit.server.util.TimeUtil; import com.google.gwtorm.server.AtomicUpdate; import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.SchemaFactory; @@ -705,7 +708,7 @@ public class MergeOp { final Capable capable; final Change c = commit.change; final boolean submitStillPossible = isSubmitForMissingCommitsStillPossible(commit); - final long now = System.currentTimeMillis(); + final long now = TimeUtil.nowMs(); final long waitUntil = c.getLastUpdatedOn().getTime() + DEPENDENCY_DELAY; if (submitStillPossible && now < waitUntil) { // If we waited a short while we might still be able to get @@ -956,7 +959,7 @@ public class MergeOp { @Nullable PatchSetApproval submitter, ChangeMessage msg) { if (submitter != null - && System.currentTimeMillis() - submitter.getGranted().getTime() + && TimeUtil.nowMs() - submitter.getGranted().getTime() > MAX_SUBMIT_WINDOW) { return RetryStatus.UNSUBMIT; } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/ReceiveCommits.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/ReceiveCommits.java index 594b4e44bf..680ddec2aa 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/git/ReceiveCommits.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/ReceiveCommits.java @@ -17,6 +17,7 @@ package com.google.gerrit.server.git; import static com.google.gerrit.server.git.MultiProgressMonitor.UNKNOWN; import static com.google.gerrit.server.mail.MailUtil.getRecipientsFromApprovals; import static com.google.gerrit.server.mail.MailUtil.getRecipientsFromFooters; + import static org.eclipse.jgit.lib.Constants.R_HEADS; import static org.eclipse.jgit.lib.RefDatabase.ALL; import static org.eclipse.jgit.transport.ReceiveCommand.Result.NOT_ATTEMPTED; @@ -94,6 +95,7 @@ import com.google.gerrit.server.project.RefControl; import com.google.gerrit.server.ssh.SshInfo; import com.google.gerrit.server.util.MagicBranch; import com.google.gerrit.server.util.RequestScopePropagator; +import com.google.gerrit.server.util.TimeUtil; import com.google.gerrit.util.cli.CmdLineParser; import com.google.gwtorm.server.AtomicUpdate; import com.google.gwtorm.server.OrmException; @@ -124,9 +126,9 @@ import org.eclipse.jgit.transport.AdvertiseRefsHook; import org.eclipse.jgit.transport.AdvertiseRefsHookChain; import org.eclipse.jgit.transport.BaseReceivePack; import org.eclipse.jgit.transport.ReceiveCommand; -import org.eclipse.jgit.transport.ServiceMayNotContinueException; import org.eclipse.jgit.transport.ReceiveCommand.Result; import org.eclipse.jgit.transport.ReceivePack; +import org.eclipse.jgit.transport.ServiceMayNotContinueException; import org.eclipse.jgit.transport.UploadPack; import org.kohsuke.args4j.CmdLineException; import org.kohsuke.args4j.Option; @@ -1740,7 +1742,7 @@ public class ReceiveCommits { PatchSet.Id id = ChangeUtil.nextPatchSetId(allRefs, change.currentPatchSetId()); newPatchSet = new PatchSet(id); - newPatchSet.setCreatedOn(new Timestamp(System.currentTimeMillis())); + newPatchSet.setCreatedOn(new Timestamp(TimeUtil.nowMs())); newPatchSet.setUploader(currentUser.getAccountId()); newPatchSet.setRevision(toRevId(newCommit)); if (magicBranch != null && magicBranch.isDraft()) { diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/mail/SmtpEmailSender.java b/gerrit-server/src/main/java/com/google/gerrit/server/mail/SmtpEmailSender.java index 9f9a3a25b8..89fc6b98cd 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/mail/SmtpEmailSender.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/mail/SmtpEmailSender.java @@ -18,6 +18,7 @@ import com.google.gerrit.common.Version; import com.google.gerrit.common.errors.EmailException; import com.google.gerrit.server.config.ConfigUtil; import com.google.gerrit.server.config.GerritServerConfig; +import com.google.gerrit.server.util.TimeUtil; import com.google.inject.AbstractModule; import com.google.inject.Inject; import com.google.inject.Singleton; @@ -151,7 +152,7 @@ public class SmtpEmailSender implements EmailSender { setMissingHeader(hdrs, "Importance", importance); } if(expiryDays > 0) { - Date expiry = new Date(System.currentTimeMillis() + + Date expiry = new Date(TimeUtil.nowMs() + expiryDays * 24 * 60 * 60 * 1000L ); setMissingHeader(hdrs, "Expiry-Date", new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z").format(expiry)); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/plugins/PluginCleanerTask.java b/gerrit-server/src/main/java/com/google/gerrit/server/plugins/PluginCleanerTask.java index 7081d706d7..606d5daa7e 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/plugins/PluginCleanerTask.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/plugins/PluginCleanerTask.java @@ -15,6 +15,7 @@ package com.google.gerrit.server.plugins; import com.google.gerrit.server.git.WorkQueue; +import com.google.gerrit.server.util.TimeUtil; import com.google.inject.Inject; import com.google.inject.Singleton; @@ -52,7 +53,7 @@ class PluginCleanerTask implements Runnable { self = null; if (0 < left) { - long waiting = System.currentTimeMillis() - start; + long waiting = TimeUtil.nowMs() - start; PluginLoader.log.warn(String.format( "%d plugins still waiting to be reclaimed after %d minutes", pending, @@ -76,7 +77,7 @@ class PluginCleanerTask implements Runnable { synchronized void clean(int expect) { if (self == null && pending == 0) { - start = System.currentTimeMillis(); + start = TimeUtil.nowMs(); } pending = expect; ensureScheduled(); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/query/change/AgePredicate.java b/gerrit-server/src/main/java/com/google/gerrit/server/query/change/AgePredicate.java index 5f457c3cf2..9a867d4dc4 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/query/change/AgePredicate.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/query/change/AgePredicate.java @@ -22,6 +22,7 @@ import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.config.ConfigUtil; import com.google.gerrit.server.index.ChangeField; import com.google.gerrit.server.index.TimestampRangePredicate; +import com.google.gerrit.server.util.TimeUtil; import com.google.gwtorm.server.OrmException; import com.google.inject.Provider; @@ -37,7 +38,7 @@ public class AgePredicate extends TimestampRangePredicate { long s = ConfigUtil.getTimeUnit(getValue(), 0, SECONDS); long ms = MILLISECONDS.convert(s, SECONDS); - this.cut = System.currentTimeMillis() - ms; + this.cut = TimeUtil.nowMs() - ms; } public Timestamp getMinTimestamp() { diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/query/change/QueryProcessor.java b/gerrit-server/src/main/java/com/google/gerrit/server/query/change/QueryProcessor.java index bdce7f4b34..5624f458ee 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/query/change/QueryProcessor.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/query/change/QueryProcessor.java @@ -31,6 +31,7 @@ import com.google.gerrit.server.project.ChangeControl; import com.google.gerrit.server.project.NoSuchChangeException; import com.google.gerrit.server.query.Predicate; import com.google.gerrit.server.query.QueryParseException; +import com.google.gerrit.server.util.TimeUtil; import com.google.gson.Gson; import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.ResultSet; @@ -292,7 +293,7 @@ public class QueryProcessor { try { final QueryStatsAttribute stats = new QueryStatsAttribute(); - stats.runTimeMilliseconds = System.currentTimeMillis(); + stats.runTimeMilliseconds = TimeUtil.nowMs(); List results = queryChanges(queryString); ChangeAttribute c = null; @@ -362,7 +363,7 @@ public class QueryProcessor { stats.resumeSortKey = c.sortKey; } stats.runTimeMilliseconds = - System.currentTimeMillis() - stats.runTimeMilliseconds; + TimeUtil.nowMs() - stats.runTimeMilliseconds; show(stats); } catch (OrmException err) { log.error("Cannot execute query: " + queryString, err); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/schema/Schema_65.java b/gerrit-server/src/main/java/com/google/gerrit/server/schema/Schema_65.java index 1cdf25cdea..624a51b95f 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/schema/Schema_65.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/schema/Schema_65.java @@ -39,6 +39,7 @@ import com.google.gerrit.server.git.GitRepositoryManager; import com.google.gerrit.server.git.MetaDataUpdate; import com.google.gerrit.server.git.ProjectConfig; import com.google.gerrit.server.git.VersionedMetaData.BatchMetaDataUpdate; +import com.google.gerrit.server.util.TimeUtil; import com.google.gwtorm.jdbc.JdbcSchema; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; @@ -348,7 +349,7 @@ public class Schema_65 extends SchemaVersion { " reviewed_on, review_comments " + "FROM account_agreements WHERE status = 'V'"); try { - long minTime = System.currentTimeMillis(); + long minTime = TimeUtil.nowMs(); while (rs.next()) { Account.Id accountId = new Account.Id(rs.getInt(1)); Account.Id reviewerId = new Account.Id(rs.getInt(4)); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/util/TimeUtil.java b/gerrit-server/src/main/java/com/google/gerrit/server/util/TimeUtil.java new file mode 100644 index 0000000000..f614b8921a --- /dev/null +++ b/gerrit-server/src/main/java/com/google/gerrit/server/util/TimeUtil.java @@ -0,0 +1,27 @@ +// Copyright (C) 2013 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.server.util; + +import org.joda.time.DateTimeUtils; + +/** Static utility methods for dealing with dates and times. */ +public class TimeUtil { + public static long nowMs() { + return DateTimeUtils.currentTimeMillis(); + } + + private TimeUtil() { + } +} diff --git a/gerrit-server/src/test/java/com/google/gerrit/rules/PrologTestCase.java b/gerrit-server/src/test/java/com/google/gerrit/rules/PrologTestCase.java index 4d86596af2..df39003344 100644 --- a/gerrit-server/src/test/java/com/google/gerrit/rules/PrologTestCase.java +++ b/gerrit-server/src/test/java/com/google/gerrit/rules/PrologTestCase.java @@ -14,6 +14,7 @@ package com.google.gerrit.rules; +import com.google.gerrit.server.util.TimeUtil; import com.google.inject.Guice; import com.google.inject.Module; @@ -116,7 +117,7 @@ public abstract class PrologTestCase extends TestCase { public void runPrologBasedTests() { int errors = 0; - long start = System.currentTimeMillis(); + long start = TimeUtil.nowMs(); for (Term test : tests) { PrologEnvironment env = envFactory.create(machine); @@ -159,7 +160,7 @@ public abstract class PrologTestCase extends TestCase { } } - long end = System.currentTimeMillis(); + long end = TimeUtil.nowMs(); System.out.println("-------------------------------"); System.out.format("Prolog tests: %d, Failures: %d, Time elapsed %.3f sec", tests.size(), errors, (end - start) / 1000.0); diff --git a/gerrit-server/src/test/java/com/google/gerrit/server/change/CommentsTest.java b/gerrit-server/src/test/java/com/google/gerrit/server/change/CommentsTest.java index f1d986d776..42df126e69 100644 --- a/gerrit-server/src/test/java/com/google/gerrit/server/change/CommentsTest.java +++ b/gerrit-server/src/test/java/com/google/gerrit/server/change/CommentsTest.java @@ -30,14 +30,15 @@ import com.google.gerrit.extensions.restapi.RestReadView; import com.google.gerrit.extensions.restapi.RestView; import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Change; +import com.google.gerrit.reviewdb.client.CommentRange; import com.google.gerrit.reviewdb.client.Patch; import com.google.gerrit.reviewdb.client.PatchLineComment; import com.google.gerrit.reviewdb.client.PatchLineComment.Status; import com.google.gerrit.reviewdb.client.PatchSet; -import com.google.gerrit.reviewdb.client.CommentRange; import com.google.gerrit.reviewdb.server.PatchLineCommentAccess; import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.account.AccountInfo; +import com.google.gerrit.server.util.TimeUtil; import com.google.gwtorm.server.ListResultSet; import com.google.gwtorm.server.ResultSet; import com.google.inject.AbstractModule; @@ -109,7 +110,7 @@ public class CommentsTest extends TestCase { PatchSet ps2 = new PatchSet(psId2); expect(revRes2.getPatchSet()).andReturn(ps2); - long timeBase = System.currentTimeMillis(); + long timeBase = TimeUtil.nowMs(); plc1 = newPatchLineComment(psId1, "Comment1", null, "FileOne.txt", Side.REVISION, 1, account1, timeBase, "First Comment", new CommentRange(1, 2, 3, 4)); diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/BaseCommand.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/BaseCommand.java index 8673b28f30..c8b24f727e 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/BaseCommand.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/BaseCommand.java @@ -27,6 +27,7 @@ import com.google.gerrit.server.git.WorkQueue; import com.google.gerrit.server.git.WorkQueue.CancelableRunnable; import com.google.gerrit.server.project.NoSuchChangeException; import com.google.gerrit.server.project.NoSuchProjectException; +import com.google.gerrit.server.util.TimeUtil; import com.google.gerrit.sshd.SshScope.Context; import com.google.gerrit.util.cli.CmdLineParser; import com.google.gerrit.util.cli.EndOfOptionsHandler; @@ -429,7 +430,7 @@ public abstract class BaseCommand implements Command { int rc = 0; final Context old = sshScope.set(context); try { - context.started = System.currentTimeMillis(); + context.started = TimeUtil.nowMs(); thisThread.setName("SSH " + taskName); if (thunk instanceof ProjectCommandRunnable) { diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshLog.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshLog.java index 8c1740741d..b3b6815a5c 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshLog.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshLog.java @@ -25,6 +25,7 @@ import com.google.gerrit.server.PeerDaemonUser; import com.google.gerrit.server.config.GerritServerConfig; import com.google.gerrit.server.config.SitePaths; import com.google.gerrit.server.util.IdGenerator; +import com.google.gerrit.server.util.TimeUtil; import com.google.gerrit.sshd.SshScope.Context; import com.google.inject.Inject; import com.google.inject.Provider; @@ -109,7 +110,7 @@ class SshLog implements LifecycleListener { final LoggingEvent event = new LoggingEvent( // Logger.class.getName(), // fqnOfCategoryClass log, // logger - System.currentTimeMillis(), // when + TimeUtil.nowMs(), // when Level.INFO, // level "AUTH FAILURE FROM " + sd.getRemoteAddressAsString(), // message text "SSHD", // thread name @@ -133,7 +134,7 @@ class SshLog implements LifecycleListener { void onExecute(DispatchCommand dcmd, int exitValue) { final Context ctx = context.get(); - ctx.finished = System.currentTimeMillis(); + ctx.finished = TimeUtil.nowMs(); String cmd = extractWhat(dcmd); @@ -219,7 +220,7 @@ class SshLog implements LifecycleListener { final LoggingEvent event = new LoggingEvent( // Logger.class.getName(), // fqnOfCategoryClass log, // logger - System.currentTimeMillis(), // when + TimeUtil.nowMs(), // when Level.INFO, // level msg, // message text "SSHD", // thread name @@ -473,7 +474,7 @@ class SshLog implements LifecycleListener { } private long extractCreated(final Context ctx) { - return (ctx != null) ? ctx.created : System.currentTimeMillis(); + return (ctx != null) ? ctx.created : TimeUtil.nowMs(); } private CurrentUser extractCurrentUser(final Context ctx) { diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshScope.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshScope.java index 9b19e02454..440f236c7f 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshScope.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/SshScope.java @@ -23,6 +23,7 @@ import com.google.gerrit.server.config.RequestScopedReviewDbProvider; import com.google.gerrit.server.util.RequestContext; import com.google.gerrit.server.util.ThreadLocalRequestContext; import com.google.gerrit.server.util.ThreadLocalRequestScopePropagator; +import com.google.gerrit.server.util.TimeUtil; import com.google.gwtorm.server.SchemaFactory; import com.google.inject.Inject; import com.google.inject.Key; @@ -165,7 +166,7 @@ class SshScope { } Context newContext(SchemaFactory sf, SshSession s, String cmd) { - return new Context(sf, s, cmd, System.currentTimeMillis()); + return new Context(sf, s, cmd, TimeUtil.nowMs()); } private Context newContinuingContext(Context ctx) { diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/QueryShell.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/QueryShell.java index 3f0bc4c6fe..56498438da 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/QueryShell.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/QueryShell.java @@ -16,6 +16,7 @@ package com.google.gerrit.sshd.commands; import com.google.gerrit.common.Version; import com.google.gerrit.reviewdb.server.ReviewDb; +import com.google.gerrit.server.util.TimeUtil; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gwtorm.jdbc.JdbcSchema; @@ -354,7 +355,7 @@ public class QueryShell { } private void executeStatement(final String sql) { - final long start = System.currentTimeMillis(); + final long start = TimeUtil.nowMs(); final boolean hasResultSet; try { hasResultSet = statement.execute(sql); @@ -374,7 +375,7 @@ public class QueryShell { } else { final int updateCount = statement.getUpdateCount(); - final long ms = System.currentTimeMillis() - start; + final long ms = TimeUtil.nowMs() - start; switch (outputFormat) { case JSON_SINGLE: case JSON: { @@ -490,7 +491,7 @@ public class QueryShell { tail = new JsonObject(); tail.addProperty("type", "query-stats"); tail.addProperty("rowCount", rowCnt); - final long ms = System.currentTimeMillis() - start; + final long ms = TimeUtil.nowMs() - start; tail.addProperty("runTimeMilliseconds", ms); } @@ -629,7 +630,7 @@ public class QueryShell { if (start != 0) { final int rowCount = rows.size(); - final long ms = System.currentTimeMillis() - start; + final long ms = TimeUtil.nowMs() - start; println("(" + rowCount + (rowCount == 1 ? " row" : " rows") + "; " + ms + " ms)"); } diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ShowCaches.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ShowCaches.java index b02d9c8574..89ba6ba59a 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ShowCaches.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ShowCaches.java @@ -26,6 +26,7 @@ import com.google.gerrit.server.cache.h2.H2CacheImpl; import com.google.gerrit.server.config.SitePath; import com.google.gerrit.server.git.WorkQueue; import com.google.gerrit.server.git.WorkQueue.Task; +import com.google.gerrit.server.util.TimeUtil; import com.google.gerrit.sshd.CommandMetaData; import com.google.gerrit.sshd.SshDaemon; import com.google.inject.Inject; @@ -59,7 +60,7 @@ final class ShowCaches extends CacheCommand { static class StartupListener implements LifecycleListener { @Override public void start() { - serverStarted = System.currentTimeMillis(); + serverStarted = TimeUtil.nowMs(); } @Override @@ -270,7 +271,7 @@ final class ShowCaches extends CacheCommand { return; } - long now = System.currentTimeMillis(); + long now = TimeUtil.nowMs(); Collection list = acceptor.getManagedSessions().values(); long oldest = now; for (IoSession s : list) { diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ShowConnections.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ShowConnections.java index c0e5d6e779..f8531ed55a 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ShowConnections.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ShowConnections.java @@ -19,6 +19,7 @@ import com.google.gerrit.extensions.annotations.RequiresCapability; import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.util.IdGenerator; +import com.google.gerrit.server.util.TimeUtil; import com.google.gerrit.sshd.CommandMetaData; import com.google.gerrit.sshd.SshCommand; import com.google.gerrit.sshd.SshDaemon; @@ -94,7 +95,7 @@ final class ShowConnections extends SshCommand { hostNameWidth = wide ? Integer.MAX_VALUE : columns - 9 - 9 - 10 - 32; - final long now = System.currentTimeMillis(); + final long now = TimeUtil.nowMs(); stdout.print(String.format("%-8s %8s %8s %-15s %s\n", // "Session", "Start", "Idle", "User", "Remote Host")); stdout.print("--------------------------------------------------------------\n"); diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ShowQueue.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ShowQueue.java index 2f1d0bfa40..7759c9441d 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ShowQueue.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ShowQueue.java @@ -22,6 +22,7 @@ import com.google.gerrit.server.git.WorkQueue.Task; import com.google.gerrit.server.project.ProjectCache; import com.google.gerrit.server.project.ProjectState; import com.google.gerrit.server.util.IdGenerator; +import com.google.gerrit.server.util.TimeUtil; import com.google.gerrit.sshd.AdminHighPriorityCommand; import com.google.gerrit.sshd.CommandMetaData; import com.google.gerrit.sshd.SshCommand; @@ -102,7 +103,7 @@ final class ShowQueue extends SshCommand { + "--------------------------------\n"); int numberOfPendingTasks = 0; - final long now = System.currentTimeMillis(); + final long now = TimeUtil.nowMs(); final boolean viewAll = currentUser.getCapabilities().canViewQueue(); for (final Task task : pending) { @@ -186,7 +187,7 @@ final class ShowQueue extends SshCommand { } private static String startTime(final Date when) { - return format(when, System.currentTimeMillis() - when.getTime()); + return format(when, TimeUtil.nowMs() - when.getTime()); } private static String format(final Date when, final long timeFromNow) { diff --git a/lib/joda/BUCK b/lib/joda/BUCK new file mode 100644 index 0000000000..d45ce78d18 --- /dev/null +++ b/lib/joda/BUCK @@ -0,0 +1,25 @@ +include_defs('//lib/maven.defs') + +EXCLUDE = [ + 'META-INF/LICENSE.txt', + 'META-INF/NOTICE.txt', +] + +maven_jar( + name = 'joda-time', + id = 'joda-time:joda-time:2.3', + sha1 = '56498efd17752898cfcc3868c1b6211a07b12b8f', + deps = [':joda-convert'], + license = 'Apache2.0', + exclude = EXCLUDE, + visibility = ['PUBLIC'], +) + +maven_jar( + name = 'joda-convert', + id = 'org.joda:joda-convert:1.2', + bin_sha1 = '35ec554f0cd00c956cc69051514d9488b1374dec', + license = 'Apache2.0', + exclude = EXCLUDE, + visibility = ['//lib/joda:joda-time'], +)