Reformat code with google-java-format 1.7 The newer Gerrit branches are following the google-java-format 1.7 rules for code formatting by now. The websession-flatfile plugin was not yet adhering to these rules. This change applies the format changes done by the google-java-format 1.7 tool. Change-Id: I9e7e6ba9614431bb101fdd743fb8858a2df2b362
diff --git a/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/CleanupInterval.java b/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/CleanupInterval.java index 9874881..56c64fd 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/CleanupInterval.java +++ b/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/CleanupInterval.java
@@ -17,10 +17,8 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; import com.google.inject.BindingAnnotation; - import java.lang.annotation.Retention; @Retention(RUNTIME) @BindingAnnotation -public @interface CleanupInterval { -} +public @interface CleanupInterval {}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSession.java b/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSession.java index e9a2b70..dac8be6 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSession.java +++ b/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSession.java
@@ -27,7 +27,6 @@ import com.google.inject.Provider; import com.google.inject.servlet.RequestScoped; import com.google.inject.servlet.ServletScopes; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -39,18 +38,26 @@ protected void configure() { bindScope(RequestScoped.class, ServletScopes.REQUEST); DynamicItem.bind(binder(), WebSession.class) - .to(FlatFileWebSession.class).in(RequestScoped.class); + .to(FlatFileWebSession.class) + .in(RequestScoped.class); } } @Inject - FlatFileWebSession(@RootRelative final Provider<HttpServletRequest> request, + FlatFileWebSession( + @RootRelative final Provider<HttpServletRequest> request, @RootRelative final Provider<HttpServletResponse> response, final WebSessionManagerFactory managerFactory, - final FlatFileWebSessionCache cache, final AuthConfig authConfig, + final FlatFileWebSessionCache cache, + final AuthConfig authConfig, final Provider<AnonymousUser> anonymousProvider, final RequestFactory identified) { - super(request.get(), response.get(), managerFactory.create(cache), - authConfig, anonymousProvider, identified); + super( + request.get(), + response.get(), + managerFactory.create(cache), + authConfig, + anonymousProvider, + identified); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSessionCache.java b/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSessionCache.java index a240aee..f6726ed 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSessionCache.java +++ b/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSessionCache.java
@@ -22,10 +22,6 @@ import com.google.gerrit.httpd.WebSessionManager.Val; import com.google.inject.Inject; import com.google.inject.Singleton; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; @@ -44,12 +40,12 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ExecutionException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Singleton -public class FlatFileWebSessionCache implements - Cache<String, WebSessionManager.Val> { - private static final Logger log = LoggerFactory - .getLogger(FlatFileWebSessionCache.class); +public class FlatFileWebSessionCache implements Cache<String, WebSessionManager.Val> { + private static final Logger log = LoggerFactory.getLogger(FlatFileWebSessionCache.class); private final Path dir; @@ -90,8 +86,7 @@ } @Override - public Val get(String key, Callable<? extends Val> valueLoader) - throws ExecutionException { + public Val get(String key, Callable<? extends Val> valueLoader) throws ExecutionException { Val value = getIfPresent(key); if (value == null) { try { @@ -149,12 +144,13 @@ @Override public void put(String key, Val value) { try { - Path tempFile = - Files.createTempFile(dir, UUID.randomUUID().toString(), null); + Path tempFile = Files.createTempFile(dir, UUID.randomUUID().toString(), null); try (OutputStream fileStream = Files.newOutputStream(tempFile); ObjectOutputStream objStream = new ObjectOutputStream(fileStream)) { objStream.writeObject(value); - Files.move(tempFile, tempFile.resolveSibling(key), + Files.move( + tempFile, + tempFile.resolveSibling(key), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE); } @@ -187,8 +183,13 @@ ObjectInputStream objStream = new ObjectInputStream(fileStream)) { return (Val) objStream.readObject(); } catch (ClassNotFoundException e) { - log.warn("Entry " + path + " in cache " + dir + " has an incompatible " - + "class and can't be deserialized. Invalidating entry."); + log.warn( + "Entry " + + path + + " in cache " + + dir + + " has an incompatible " + + "class and can't be deserialized. Invalidating entry."); invalidate(path.getFileName().toString()); } catch (IOException e) { log.warn("Cannot read cache " + dir, e);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSessionCacheCleaner.java b/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSessionCacheCleaner.java index c6c89a6..d5842a0 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSessionCacheCleaner.java +++ b/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSessionCacheCleaner.java
@@ -40,13 +40,13 @@ @Override public void start() { - queue.getDefaultQueue().scheduleAtFixedRate(cleaner, INITIAL_DELAY_MS, - cleanupInterval, MILLISECONDS); + queue + .getDefaultQueue() + .scheduleAtFixedRate(cleaner, INITIAL_DELAY_MS, cleanupInterval, MILLISECONDS); } @Override - public void stop() { - } + public void stop() {} } private FlatFileWebSessionCache flatFileWebSessionCache;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/Module.java b/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/Module.java index a5ea0c3..c98d0e9 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/Module.java +++ b/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/Module.java
@@ -24,9 +24,7 @@ import com.google.gerrit.server.config.SitePaths; import com.google.inject.Provides; import com.google.inject.Singleton; - import com.googlesource.gerrit.plugins.websession.flatfile.FlatFileWebSessionCacheCleaner.CleanerLifecycle; - import java.nio.file.Path; import java.nio.file.Paths; @@ -42,10 +40,10 @@ @Provides @Singleton @WebSessionDir - Path getWebSessionDir(SitePaths site, PluginConfigFactory cfg, - @PluginName String pluginName) { - return Paths.get(cfg.getFromGerritConfig(pluginName).getString("directory", - site.site_path + "/websessions")); + Path getWebSessionDir(SitePaths site, PluginConfigFactory cfg, @PluginName String pluginName) { + return Paths.get( + cfg.getFromGerritConfig(pluginName) + .getString("directory", site.site_path + "/websessions")); } @Provides @@ -53,9 +51,7 @@ @CleanupInterval Long getCleanupInterval(PluginConfigFactory cfg, @PluginName String pluginName) { String fromConfig = - Strings.nullToEmpty(cfg.getFromGerritConfig(pluginName).getString( - "cleanupInterval")); - return HOURS.toMillis(ConfigUtil.getTimeUnit(fromConfig, - DEFAULT_CLEANUP_INTERVAL, HOURS)); + Strings.nullToEmpty(cfg.getFromGerritConfig(pluginName).getString("cleanupInterval")); + return HOURS.toMillis(ConfigUtil.getTimeUnit(fromConfig, DEFAULT_CLEANUP_INTERVAL, HOURS)); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/WebSessionDir.java b/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/WebSessionDir.java index 02288bf..eb01bb1 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/WebSessionDir.java +++ b/src/main/java/com/googlesource/gerrit/plugins/websession/flatfile/WebSessionDir.java
@@ -17,10 +17,8 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; import com.google.inject.BindingAnnotation; - import java.lang.annotation.Retention; @Retention(RUNTIME) @BindingAnnotation -@interface WebSessionDir { -} +@interface WebSessionDir {}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSessionCacheTest.java b/src/test/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSessionCacheTest.java index 905d6bf..7a24bd4 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSessionCacheTest.java +++ b/src/test/java/com/googlesource/gerrit/plugins/websession/flatfile/FlatFileWebSessionCacheTest.java
@@ -18,11 +18,6 @@ import com.google.common.collect.ImmutableMap; import com.google.gerrit.httpd.WebSessionManager.Val; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - import java.io.IOException; import java.io.InputStream; import java.nio.file.DirectoryStream; @@ -39,6 +34,9 @@ import java.util.Map; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; public class FlatFileWebSessionCacheTest { @@ -95,8 +93,7 @@ Files.createFile(dir.resolve(key)); loadExistingKeyToCacheDir(); List<String> keys = Arrays.asList(new String[] {key, existingKey}); - assertThat(flatFileWebSessionCache.getAllPresent(keys)) - .containsKey(existingKey); + assertThat(flatFileWebSessionCache.getAllPresent(keys)).containsKey(existingKey); } @Test @@ -123,12 +120,10 @@ return null; } } - assertThat(flatFileWebSessionCache.get(existingKey, new ValueLoader())) - .isNull(); + assertThat(flatFileWebSessionCache.get(existingKey, new ValueLoader())).isNull(); loadExistingKeyToCacheDir(); - assertThat(flatFileWebSessionCache.get(existingKey, new ValueLoader())) - .isNotNull(); + assertThat(flatFileWebSessionCache.get(existingKey, new ValueLoader())).isNotNull(); } @Test(expected = ExecutionException.class) @@ -139,8 +134,7 @@ throw new Exception(); } } - assertThat(flatFileWebSessionCache.get(existingKey, new ValueLoader())) - .isNull(); + assertThat(flatFileWebSessionCache.get(existingKey, new ValueLoader())).isNull(); } @Test @@ -213,21 +207,22 @@ } private void emptyAndDelete(Path dir) throws IOException { - Files.walkFileTree(dir, new SimpleFileVisitor<Path>() { - @Override - public FileVisitResult postVisitDirectory(Path dir, IOException exc) - throws IOException { - Files.delete(dir); - return FileVisitResult.CONTINUE; - } + Files.walkFileTree( + dir, + new SimpleFileVisitor<Path>() { + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + Files.delete(dir); + return FileVisitResult.CONTINUE; + } - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) - throws IOException { - Files.delete(file); - return FileVisitResult.CONTINUE; - } - }); + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) + throws IOException { + Files.delete(file); + return FileVisitResult.CONTINUE; + } + }); } private boolean isDirEmpty(final Path dir) throws IOException {