Skip to content

Commit

Permalink
Add a PathMatcher for CloudStorageFileSystem
Browse files Browse the repository at this point in the history
Add a test, as well.
We reuse the default PathMatcher since it does a fine job of globbing files.
  • Loading branch information
jean-philippe-martin committed Dec 9, 2016
1 parent 27962a3 commit 998ae3d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -210,13 +211,9 @@ public Set<String> 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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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<String> paths = ImmutableList.of("a.java", "a.text", "folder/c.java", "d");
String pattern1 = "glob:*.java";
PathMatcher matcher1 = fs.getPathMatcher(pattern1);
List<Boolean> matches1 = ImmutableList.of(true, false, true, false);
String pattern2 = "glob:*.{java,text}";
PathMatcher matcher2 = fs.getPathMatcher(pattern2);
List<Boolean> matches2 = ImmutableList.of(true, true, true, false);
for (int i=0; i<paths.size(); i++) {
Path input = fs.getPath(paths.get(i)).getFileName();
assertWithMessage(pattern1 + " on " + paths.get(i)).that(matcher1.matches(input)).isEqualTo(matches1.get(i));
assertWithMessage(pattern2 + " on " + paths.get(i)).that(matcher2.matches(input)).isEqualTo(matches2.get(i));
}
}
}
}

0 comments on commit 998ae3d

Please sign in to comment.