Skip to content

Commit 21e68cc

Browse files
committed
Add a versions option to BlobListOption
1 parent bbe7b50 commit 21e68cc

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,16 @@ public static BlobListOption recursive(boolean recursive) {
700700
return new BlobListOption(StorageRpc.Option.DELIMITER, recursive);
701701
}
702702

703+
/**
704+
* If set to {@code true}, lists all versions of a blob.
705+
* The default is {@code false}.
706+
*
707+
* @see <a href ="https://cloud.google.com/storage/docs/object-versioning">Object Versioning</a>
708+
*/
709+
public static BlobListOption versions(boolean versions) {
710+
return new BlobListOption(StorageRpc.Option.VERSIONS, versions);
711+
}
712+
703713
/**
704714
* Returns an option to specify the blob's fields to be returned by the RPC call. If this option
705715
* is not provided all blob's fields are returned. {@code BlobListOption.fields}) can be used to

gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,14 @@ public class StorageImplTest {
200200
Storage.BlobListOption.prefix("prefix");
201201
private static final Storage.BlobListOption BLOB_LIST_FIELDS =
202202
Storage.BlobListOption.fields(Storage.BlobField.CONTENT_TYPE, Storage.BlobField.MD5HASH);
203+
private static final Storage.BlobListOption BLOB_LIST_VERSIONS =
204+
Storage.BlobListOption.versions(false);
203205
private static final Storage.BlobListOption BLOB_LIST_EMPTY_FIELDS =
204206
Storage.BlobListOption.fields();
205207
private static final Map<StorageRpc.Option, ?> BLOB_LIST_OPTIONS = ImmutableMap.of(
206208
StorageRpc.Option.MAX_RESULTS, BLOB_LIST_MAX_RESULT.value(),
207-
StorageRpc.Option.PREFIX, BLOB_LIST_PREFIX.value());
209+
StorageRpc.Option.PREFIX, BLOB_LIST_PREFIX.value(),
210+
StorageRpc.Option.VERSIONS, BLOB_LIST_VERSIONS.value());
208211

209212
private static final String PRIVATE_KEY_STRING = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoG"
210213
+ "BAL2xolH1zrISQ8+GzOV29BNjjzq4/HIP8Psd1+cZb81vDklSF+95wB250MSE0BDc81pvIMwj5OmIfLg1NY6uB"
@@ -650,7 +653,8 @@ public void testListBlobsWithOptions() {
650653
EasyMock.replay(storageRpcMock);
651654
initializeService();
652655
ImmutableList<Blob> blobList = ImmutableList.of(expectedBlob1, expectedBlob2);
653-
Page<Blob> page = storage.list(BUCKET_NAME1, BLOB_LIST_MAX_RESULT, BLOB_LIST_PREFIX);
656+
Page<Blob> page =
657+
storage.list(BUCKET_NAME1, BLOB_LIST_MAX_RESULT, BLOB_LIST_PREFIX, BLOB_LIST_VERSIONS);
654658
assertEquals(cursor, page.nextPageCursor());
655659
assertArrayEquals(blobList.toArray(), Iterables.toArray(page.values(), Blob.class));
656660
}

0 commit comments

Comments
 (0)