From 998ae3d5dec3dce3dad5f588baeb070dbc1704de Mon Sep 17 00:00:00 2001 From: JP Martin Date: Fri, 9 Dec 2016 15:05:12 -0800 Subject: [PATCH 1/3] Add a PathMatcher for CloudStorageFileSystem Add a test, as well. We reuse the default PathMatcher since it does a fine job of globbing files. --- .../contrib/nio/CloudStorageFileSystem.java | 7 ++----- .../nio/CloudStorageFileSystemTest.java | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystem.java b/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystem.java index 60a39fb5a817..4f031c92f740 100644 --- a/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystem.java +++ b/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystem.java @@ -27,6 +27,7 @@ import java.net.URISyntaxException; import java.nio.file.FileStore; import java.nio.file.FileSystem; +import java.nio.file.FileSystems; import java.nio.file.Path; import java.nio.file.PathMatcher; import java.nio.file.WatchService; @@ -210,13 +211,9 @@ public Set supportedFileAttributeViews() { return SUPPORTED_VIEWS; } - /** - * Throws {@link UnsupportedOperationException} because this feature hasn't been implemented yet. - */ @Override public PathMatcher getPathMatcher(String syntaxAndPattern) { - // TODO(#813): Implement me. - throw new UnsupportedOperationException(); + return FileSystems.getDefault().getPathMatcher(syntaxAndPattern); } /** diff --git a/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemTest.java b/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemTest.java index ec856447b96a..4d1dc866fa85 100644 --- a/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemTest.java +++ b/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemTest.java @@ -17,9 +17,11 @@ package com.google.cloud.storage.contrib.nio; import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; import static java.nio.charset.StandardCharsets.UTF_8; import com.google.cloud.storage.StorageOptions; +import com.google.common.collect.ImmutableList; import com.google.common.testing.EqualsTester; import com.google.common.testing.NullPointerTester; @@ -34,6 +36,7 @@ import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.PathMatcher; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; @@ -159,4 +162,22 @@ public void testListFiles() throws IOException { assertThat(got).containsExactlyElementsIn(goodPaths); } } + + @Test + public void testMatcher() throws IOException { + try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) { + List paths = ImmutableList.of("a.java", "a.text", "folder/c.java", "d"); + String pattern1 = "glob:*.java"; + PathMatcher matcher1 = fs.getPathMatcher(pattern1); + List matches1 = ImmutableList.of(true, false, true, false); + String pattern2 = "glob:*.{java,text}"; + PathMatcher matcher2 = fs.getPathMatcher(pattern2); + List matches2 = ImmutableList.of(true, true, true, false); + for (int i=0; i Date: Wed, 11 Jan 2017 17:19:18 -0800 Subject: [PATCH 2/3] Change testMatcher from data-centric to code-centric (it still does the same thing) --- .../nio/CloudStorageFileSystemTest.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemTest.java b/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemTest.java index 4d1dc866fa85..487ee80716aa 100644 --- a/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemTest.java +++ b/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemTest.java @@ -17,7 +17,6 @@ package com.google.cloud.storage.contrib.nio; import static com.google.common.truth.Truth.assertThat; -import static com.google.common.truth.Truth.assertWithMessage; import static java.nio.charset.StandardCharsets.UTF_8; import com.google.cloud.storage.StorageOptions; @@ -166,18 +165,23 @@ public void testListFiles() throws IOException { @Test public void testMatcher() throws IOException { try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) { - List paths = ImmutableList.of("a.java", "a.text", "folder/c.java", "d"); String pattern1 = "glob:*.java"; PathMatcher matcher1 = fs.getPathMatcher(pattern1); - List matches1 = ImmutableList.of(true, false, true, false); String pattern2 = "glob:*.{java,text}"; PathMatcher matcher2 = fs.getPathMatcher(pattern2); - List matches2 = ImmutableList.of(true, true, true, false); - for (int i=0; i Date: Fri, 13 Jan 2017 10:30:18 -0800 Subject: [PATCH 3/3] Remove unused import, rename variables, move test code around --- .../nio/CloudStorageFileSystemTest.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemTest.java b/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemTest.java index 487ee80716aa..d7d5b346c376 100644 --- a/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemTest.java +++ b/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemTest.java @@ -20,7 +20,6 @@ import static java.nio.charset.StandardCharsets.UTF_8; import com.google.cloud.storage.StorageOptions; -import com.google.common.collect.ImmutableList; import com.google.common.testing.EqualsTester; import com.google.common.testing.NullPointerTester; @@ -166,18 +165,18 @@ public void testListFiles() throws IOException { public void testMatcher() throws IOException { try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) { String pattern1 = "glob:*.java"; - PathMatcher matcher1 = fs.getPathMatcher(pattern1); + PathMatcher javaFileMatcher = fs.getPathMatcher(pattern1); + assertMatches(fs, javaFileMatcher, "a.java", true); + assertMatches(fs, javaFileMatcher, "a.text", false); + assertMatches(fs, javaFileMatcher, "folder/c.java", true); + assertMatches(fs, javaFileMatcher, "d", false); + String pattern2 = "glob:*.{java,text}"; - PathMatcher matcher2 = fs.getPathMatcher(pattern2); - - assertMatches(fs, matcher1, "a.java", true); - assertMatches(fs, matcher1, "a.text", false); - assertMatches(fs, matcher1, "folder/c.java", true); - assertMatches(fs, matcher1, "d", false); - assertMatches(fs, matcher2, "a.java", true); - assertMatches(fs, matcher2, "a.text", true); - assertMatches(fs, matcher2, "folder/c.java", true); - assertMatches(fs, matcher2, "d", false); + PathMatcher javaAndTextFileMatcher = fs.getPathMatcher(pattern2); + assertMatches(fs, javaAndTextFileMatcher, "a.java", true); + assertMatches(fs, javaAndTextFileMatcher, "a.text", true); + assertMatches(fs, javaAndTextFileMatcher, "folder/c.java", true); + assertMatches(fs, javaAndTextFileMatcher, "d", false); } }