Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a PathMatcher for CloudStorageFileSystem #1469

Merged
merged 3 commits into from
Jan 13, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -20,6 +20,7 @@
import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.cloud.storage.StorageOptions;
import com.google.common.collect.ImmutableList;

This comment was marked as spam.

This comment was marked as spam.

import com.google.common.testing.EqualsTester;
import com.google.common.testing.NullPointerTester;

Expand All @@ -34,6 +35,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 +161,27 @@ public void testListFiles() throws IOException {
assertThat(got).containsExactlyElementsIn(goodPaths);
}
}

@Test
public void testMatcher() throws IOException {
try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) {
String pattern1 = "glob:*.java";
PathMatcher matcher1 = fs.getPathMatcher(pattern1);

This comment was marked as spam.

This comment was marked as spam.

String pattern2 = "glob:*.{java,text}";
PathMatcher matcher2 = fs.getPathMatcher(pattern2);

This comment was marked as spam.

This comment was marked as spam.


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);
}
}

private void assertMatches(FileSystem fs, PathMatcher matcher, String toMatch, boolean expected) {
assertThat(matcher.matches(fs.getPath(toMatch).getFileName())).isEqualTo(expected);
}
}