From 3f10e81080e190bc5b66f5585c0377ac8de8badc Mon Sep 17 00:00:00 2001 From: Lubomir Litchev Date: Fri, 26 Oct 2018 15:19:53 -0700 Subject: [PATCH] Rename LocalCache to LocalCacheStorage Summary: Renamed LocalCache to LocalCacheStorage. Reviewed By: bobyangyf fbshipit-source-id: 677265dec0 --- .../parser/cache/ParserCacheException.java | 5 ++- ...rserCache.java => ParserCacheStorage.java} | 4 +- ...LocalCache.java => LocalCacheStorage.java} | 20 +++++----- ...heTest.java => LocalCacheStorageTest.java} | 38 ++++++++++--------- 4 files changed, 36 insertions(+), 31 deletions(-) rename src/com/facebook/buck/parser/cache/{ParserCache.java => ParserCacheStorage.java} (95%) rename src/com/facebook/buck/parser/cache/impl/{LocalCache.java => LocalCacheStorage.java} (91%) rename test/com/facebook/buck/parser/cache/impl/{LocalCacheTest.java => LocalCacheStorageTest.java} (91%) diff --git a/src/com/facebook/buck/parser/cache/ParserCacheException.java b/src/com/facebook/buck/parser/cache/ParserCacheException.java index ac6e40f4ef8..9da19757f5f 100644 --- a/src/com/facebook/buck/parser/cache/ParserCacheException.java +++ b/src/com/facebook/buck/parser/cache/ParserCacheException.java @@ -16,7 +16,10 @@ package com.facebook.buck.parser.cache; -/** This exception is thrown when there are failures while doing {@link ParserCache} operations. */ +/** + * This exception is thrown when there are failures while doing {@link ParserCacheStorage} + * operations. + */ public class ParserCacheException extends Exception { /** diff --git a/src/com/facebook/buck/parser/cache/ParserCache.java b/src/com/facebook/buck/parser/cache/ParserCacheStorage.java similarity index 95% rename from src/com/facebook/buck/parser/cache/ParserCache.java rename to src/com/facebook/buck/parser/cache/ParserCacheStorage.java index cab743939f2..8e391f190b5 100644 --- a/src/com/facebook/buck/parser/cache/ParserCache.java +++ b/src/com/facebook/buck/parser/cache/ParserCacheStorage.java @@ -20,7 +20,7 @@ import com.google.common.hash.HashCode; /** This is the main interface for interacting with the cache. */ -public interface ParserCache { +public interface ParserCacheStorage { /** * Stores a {@link BuildFileManifest} object to the cache. @@ -43,7 +43,7 @@ void storeBuildFileManifest( * @return an {@link BuildFileManifest} object status operation if the operation is successful. In * case of failure an appropriate exception is thrown. * @throws ParserCacheException thrown when there is an error constructing the {@link - * BuildFileManifest} from the {@link ParserCache}. + * BuildFileManifest} from the {@link ParserCacheStorage}. */ BuildFileManifest getBuildFileManifest(HashCode weakFingerprint, HashCode strongFingerprint) throws ParserCacheException; diff --git a/src/com/facebook/buck/parser/cache/impl/LocalCache.java b/src/com/facebook/buck/parser/cache/impl/LocalCacheStorage.java similarity index 91% rename from src/com/facebook/buck/parser/cache/impl/LocalCache.java rename to src/com/facebook/buck/parser/cache/impl/LocalCacheStorage.java index 466733f040b..7820edeee99 100644 --- a/src/com/facebook/buck/parser/cache/impl/LocalCache.java +++ b/src/com/facebook/buck/parser/cache/impl/LocalCacheStorage.java @@ -19,8 +19,8 @@ import com.facebook.buck.core.util.log.Logger; import com.facebook.buck.io.filesystem.ProjectFilesystem; import com.facebook.buck.parser.api.BuildFileManifest; -import com.facebook.buck.parser.cache.ParserCache; import com.facebook.buck.parser.cache.ParserCacheException; +import com.facebook.buck.parser.cache.ParserCacheStorage; import com.facebook.buck.parser.cache.json.BuildFileManifestSerializer; import com.google.common.base.Preconditions; import com.google.common.base.Stopwatch; @@ -31,14 +31,14 @@ import java.nio.file.Path; import java.util.concurrent.TimeUnit; -/** A local filesystem backed implementation for the {@link ParserCache} interface. */ -public class LocalCache implements ParserCache { - private static final Logger LOG = Logger.get(LocalCache.class); +/** An local filesystem backed implementation for the {@link ParserCacheStorage} interface. */ +public class LocalCacheStorage implements ParserCacheStorage { + private static final Logger LOG = Logger.get(LocalCacheStorage.class); private final Path localCachePath; private final ProjectFilesystem filesystem; - private LocalCache(Path localCachePath, ProjectFilesystem filesystem) { + private LocalCacheStorage(Path localCachePath, ProjectFilesystem filesystem) { this.filesystem = filesystem; this.localCachePath = localCachePath; } @@ -64,20 +64,20 @@ private static Path createLocalCachePathFromConfig( } /** - * Static factory for creating {@link LocalCache} objects. + * Static factory for creating {@link LocalCacheStorage} objects. * * @param parserCacheConfig the {@code parserCacheConfig} object to be used for this parsing. * @return a new instance of fully instantiated local cache object. - * @throws ParserCacheException when the {@link LocalCache} object cannot be constructed. + * @throws ParserCacheException when the {@link LocalCacheStorage} object cannot be constructed. */ - public static LocalCache newInstance( + public static LocalCacheStorage newInstance( AbstractParserCacheConfig parserCacheConfig, ProjectFilesystem filesystem) throws ParserCacheException { Preconditions.checkState( parserCacheConfig.isDirParserCacheEnabled(), - "Invalid state: LocalCache should not be instantiated if the cache is disabled."); + "Invalid state: LocalCacheStorage should not be instantiated if the cache is disabled."); Path localCachePath = createLocalCachePathFromConfig(parserCacheConfig, filesystem); - return new LocalCache(localCachePath, filesystem); + return new LocalCacheStorage(localCachePath, filesystem); } @Override diff --git a/test/com/facebook/buck/parser/cache/impl/LocalCacheTest.java b/test/com/facebook/buck/parser/cache/impl/LocalCacheStorageTest.java similarity index 91% rename from test/com/facebook/buck/parser/cache/impl/LocalCacheTest.java rename to test/com/facebook/buck/parser/cache/impl/LocalCacheStorageTest.java index c6283ed1e44..ab419a73963 100644 --- a/test/com/facebook/buck/parser/cache/impl/LocalCacheTest.java +++ b/test/com/facebook/buck/parser/cache/impl/LocalCacheStorageTest.java @@ -56,7 +56,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; -public class LocalCacheTest { +public class LocalCacheStorageTest { @Rule public ExpectedException expectedException = ExpectedException.none(); @Rule public TemporaryPaths tempDir = new TemporaryPaths(); @@ -113,7 +113,7 @@ public void setUp() { assumeThat(Platform.detect(), not(Platform.WINDOWS)); filesystem = FakeProjectFilesystem.createJavaOnlyFilesystem("/"); localHandler = new LocalHandler(); - Logger.get(LocalCache.class).addHandler(localHandler); + Logger.get(LocalCacheStorage.class).addHandler(localHandler); } @Test @@ -122,13 +122,14 @@ public void createLocalCacheWithAbsolutePathAndException() expectedException.expect(ParserCacheException.class); expectedException.expectMessage("Failed to create local cache directory - /foo/bar"); filesystem.createNewFile(Paths.get("/foo")); - LocalCache.newInstance(getParserCacheConfig(true, filesystem.getPath("/foo/bar")), filesystem); + LocalCacheStorage.newInstance( + getParserCacheConfig(true, filesystem.getPath("/foo/bar")), filesystem); } @Test public void createLocalCacheWithAbsolutePath() throws ParserCacheException { Path absPath = filesystem.getBuckPaths().getBuckOut().resolve("/foo/bar").toAbsolutePath(); - LocalCache.newInstance(getParserCacheConfig(true, absPath), filesystem); + LocalCacheStorage.newInstance(getParserCacheConfig(true, absPath), filesystem); List events = localHandler.messages; assertEquals(1, events.size()); LogRecord event = events.get(0); @@ -139,7 +140,7 @@ public void createLocalCacheWithAbsolutePath() throws ParserCacheException { @Test public void createLocalCacheWithRelativePath() throws ParserCacheException { Path path = filesystem.getPath("foo/bar"); - LocalCache.newInstance(getParserCacheConfig(true, path), filesystem); + LocalCacheStorage.newInstance(getParserCacheConfig(true, path), filesystem); List events = localHandler.messages; assertEquals(1, events.size()); LogRecord event = events.get(0); @@ -153,15 +154,15 @@ public void createLocalCacheWithRelativePath() throws ParserCacheException { public void createLocalCacheWhenCachingDisabled() throws ParserCacheException { expectedException.expect(IllegalStateException.class); expectedException.expectMessage( - "Invalid state: LocalCache should not be instantiated if the cache is disabled."); - LocalCache.newInstance( + "Invalid state: LocalCacheStorage should not be instantiated if the cache is disabled."); + LocalCacheStorage.newInstance( getParserCacheConfig(false, filesystem.getPath(tempDir.getRoot().toString())), filesystem); } @Test public void createLocalCacheWhenCacheDefaultDirectory() throws ParserCacheException { Path emptyPathForDefaultCacheLocation = filesystem.getPath("\"\""); - LocalCache.newInstance( + LocalCacheStorage.newInstance( getParserCacheConfig(true, emptyPathForDefaultCacheLocation), filesystem); List events = localHandler.messages; assertEquals(1, events.size()); @@ -172,8 +173,8 @@ public void createLocalCacheWhenCacheDefaultDirectory() throws ParserCacheExcept @Test public void createLocalCacheWFPDirectoryNonExisting() throws IOException, ParserCacheException { - LocalCache localCache = - LocalCache.newInstance( + LocalCacheStorage localCacheStorage = + LocalCacheStorage.newInstance( getParserCacheConfig( true, filesystem.getPath(tempDir.getRoot().toString() + File.separator + FOO_BAR_PATH)), @@ -181,7 +182,7 @@ public void createLocalCacheWFPDirectoryNonExisting() throws IOException, Parser Path buildPath = filesystem.getPath(FOO_BAR_PATH); HashCode weakFingerprint = Fingerprinter.getWeakFingerprint(buildPath, getConfig().getConfig()); HashCode strongFingerprint = Fingerprinter.getStrongFingerprint(filesystem, ImmutableList.of()); - localCache.storeBuildFileManifest(weakFingerprint, strongFingerprint, null); + localCacheStorage.storeBuildFileManifest(weakFingerprint, strongFingerprint, null); Path localCachePath = tempDir.getRoot().resolve(FOO_BAR_PATH); assertNotNull(localCachePath); Path weakFingerprintPath = @@ -193,8 +194,8 @@ public void createLocalCacheWFPDirectoryNonExisting() throws IOException, Parser @Test public void createLocalCacheWFPDirectoryExistingAndKeepIt() throws IOException, ParserCacheException { - LocalCache localCache = - LocalCache.newInstance( + LocalCacheStorage localCacheStorage = + LocalCacheStorage.newInstance( getParserCacheConfig( true, filesystem.getPath(tempDir.getRoot().toString() + File.separator + FOO_BAR_PATH)), @@ -211,7 +212,7 @@ public void createLocalCacheWFPDirectoryExistingAndKeepIt() assertTrue(filesystem.exists(newFilePath)); HashCode weakFingerprint = Fingerprinter.getWeakFingerprint(buildPath, getConfig().getConfig()); HashCode strongFingerprint = Fingerprinter.getStrongFingerprint(filesystem, ImmutableList.of()); - localCache.storeBuildFileManifest(weakFingerprint, strongFingerprint, null); + localCacheStorage.storeBuildFileManifest(weakFingerprint, strongFingerprint, null); assertNotNull(localCachePath); assertTrue(filesystem.exists(wfpPath)); assertTrue(filesystem.exists(newFilePath)); @@ -220,8 +221,8 @@ public void createLocalCacheWFPDirectoryExistingAndKeepIt() @Test public void stroreInLocalCacheAndGetFromLocalCacheAndVerifyMatch() throws IOException, ParserCacheException { - LocalCache localCache = - LocalCache.newInstance( + LocalCacheStorage localCacheStorage = + LocalCacheStorage.newInstance( getParserCacheConfig( true, filesystem.getPath(tempDir.getRoot().toString() + File.separator + FOO_BAR_PATH)), @@ -295,7 +296,8 @@ public void stroreInLocalCacheAndGetFromLocalCacheAndVerifyMatch() HashCode strongFingerprinter = Fingerprinter.getStrongFingerprint(filesystem, includes); // Store in local cache - localCache.storeBuildFileManifest(weakFingerprinter, strongFingerprinter, buildFileManifest); + localCacheStorage.storeBuildFileManifest( + weakFingerprinter, strongFingerprinter, buildFileManifest); Path serializedDataFile = localCachePath @@ -305,7 +307,7 @@ public void stroreInLocalCacheAndGetFromLocalCacheAndVerifyMatch() // Get from local cache BuildFileManifest buildFileManifestResult = - localCache.getBuildFileManifest(weakFingerprinter, strongFingerprinter); + localCacheStorage.getBuildFileManifest(weakFingerprinter, strongFingerprinter); assertEquals(buildFileManifest, buildFileManifestResult); }