Skip to content

Commit f283895

Browse files
authored
Rename setters/getters/builders for Storage classes to meet proto conventions (#1308)
* Rename setters/getters/builders for Storage classes to meet proto conventions * Favor renaming over deprecation for package-private methods * Update TESTING.md to catch RemoteStorageHelper renaming * Update ITBigQueryTest to match Storage renaming * Update google-cloud-nio to match Storage renaming * Fix RemoteStorageHelper class javadoc * Make deprecated methods call renamed ones
1 parent 307f9f0 commit f283895

49 files changed

Lines changed: 3238 additions & 1392 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ import com.google.cloud.storage.StorageOptions;
548548
549549
Storage storage = StorageOptions.defaultInstance().service();
550550
BlobId blobId = BlobId.of("bucket", "blob_name");
551-
BlobInfo blobInfo = BlobInfo.builder(blobId).contentType("text/plain").build();
551+
BlobInfo blobInfo = BlobInfo.newBuiler(blobId).setContentType("text/plain").build();
552552
Blob blob = storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
553553
```
554554
The second snippet shows how to update a Storage blob if it exists. Complete source code can be
@@ -569,7 +569,7 @@ Storage storage = StorageOptions.defaultInstance().service();
569569
BlobId blobId = BlobId.of("bucket", "blob_name");
570570
Blob blob = storage.get(blobId);
571571
if (blob != null) {
572-
byte[] prevContent = blob.content();
572+
byte[] prevContent = blob.getContent();
573573
System.out.println(new String(prevContent, UTF_8));
574574
WritableByteChannel channel = blob.writer();
575575
channel.write(ByteBuffer.wrap("Updated content".getBytes(UTF_8)));

TESTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ Here is an example that uses the `RemoteStorageHelper` to create a bucket.
258258
```java
259259
RemoteStorageHelper helper =
260260
RemoteStorageHelper.create(PROJECT_ID, new FileInputStream("/path/to/my/JSON/key.json"));
261-
Storage storage = helper.options().service();
261+
Storage storage = helper.getOptions().service();
262262
String bucket = RemoteStorageHelper.generateBucketName();
263263
storage.create(BucketInfo.of(bucket));
264264
```

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,13 @@ public static void beforeClass() throws InterruptedException, TimeoutException {
194194
RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create();
195195
RemoteStorageHelper storageHelper = RemoteStorageHelper.create();
196196
bigquery = bigqueryHelper.options().service();
197-
storage = storageHelper.options().service();
197+
storage = storageHelper.getOptions().service();
198198
storage.create(BucketInfo.of(BUCKET));
199-
storage.create(BlobInfo.builder(BUCKET, LOAD_FILE).contentType("text/plain").build(),
199+
storage.create(BlobInfo.newBuilder(BUCKET, LOAD_FILE).setContentType("text/plain").build(),
200200
CSV_CONTENT.getBytes(StandardCharsets.UTF_8));
201-
storage.create(BlobInfo.builder(BUCKET, JSON_LOAD_FILE).contentType("application/json").build(),
201+
storage.create(BlobInfo.newBuilder(BUCKET, JSON_LOAD_FILE)
202+
.setContentType("application/json")
203+
.build(),
202204
JSON_CONTENT.getBytes(StandardCharsets.UTF_8));
203205
DatasetInfo info = DatasetInfo.builder(DATASET).description(DESCRIPTION).build();
204206
bigquery.create(info);

google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemProvider.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private static class LazyPathIterator extends AbstractIterator<Path> {
106106
@Override
107107
protected Path computeNext() {
108108
while (blobIterator.hasNext()) {
109-
Path path = fileSystem.getPath(blobIterator.next().name());
109+
Path path = fileSystem.getPath(blobIterator.next().getName());
110110
try {
111111
if (filter.accept(path)) {
112112
return path;
@@ -266,20 +266,20 @@ private SeekableByteChannel newWriteChannel(Path path, Set<? extends OpenOption>
266266
throw new CloudStoragePseudoDirectoryException(cloudPath);
267267
}
268268
BlobId file = cloudPath.getBlobId();
269-
BlobInfo.Builder infoBuilder = BlobInfo.builder(file);
269+
BlobInfo.Builder infoBuilder = BlobInfo.newBuilder(file);
270270
List<Storage.BlobWriteOption> writeOptions = new ArrayList<>();
271271
List<Acl> acls = new ArrayList<>();
272272

273273
HashMap<String, String> metas = new HashMap<>();
274274
for (OpenOption option : options) {
275275
if (option instanceof OptionMimeType) {
276-
infoBuilder.contentType(((OptionMimeType) option).mimeType());
276+
infoBuilder.setContentType(((OptionMimeType) option).mimeType());
277277
} else if (option instanceof OptionCacheControl) {
278-
infoBuilder.cacheControl(((OptionCacheControl) option).cacheControl());
278+
infoBuilder.setCacheControl(((OptionCacheControl) option).cacheControl());
279279
} else if (option instanceof OptionContentDisposition) {
280-
infoBuilder.contentDisposition(((OptionContentDisposition) option).contentDisposition());
280+
infoBuilder.setContentDisposition(((OptionContentDisposition) option).contentDisposition());
281281
} else if (option instanceof OptionContentEncoding) {
282-
infoBuilder.contentEncoding(((OptionContentEncoding) option).contentEncoding());
282+
infoBuilder.setContentEncoding(((OptionContentEncoding) option).contentEncoding());
283283
} else if (option instanceof OptionUserMetadata) {
284284
OptionUserMetadata opMeta = (OptionUserMetadata) option;
285285
metas.put(opMeta.key(), opMeta.value());
@@ -317,10 +317,10 @@ private SeekableByteChannel newWriteChannel(Path path, Set<? extends OpenOption>
317317
}
318318

319319
if (!metas.isEmpty()) {
320-
infoBuilder.metadata(metas);
320+
infoBuilder.setMetadata(metas);
321321
}
322322
if (!acls.isEmpty()) {
323-
infoBuilder.acl(acls);
323+
infoBuilder.setAcl(acls);
324324
}
325325

326326
try {
@@ -391,7 +391,7 @@ public void copy(Path source, Path target, CopyOption... options) throws IOExcep
391391
boolean setContentDisposition = false;
392392

393393
CloudStoragePath toPath = CloudStorageUtil.checkPath(target);
394-
BlobInfo.Builder tgtInfoBuilder = BlobInfo.builder(toPath.getBlobId()).contentType("");
394+
BlobInfo.Builder tgtInfoBuilder = BlobInfo.newBuilder(toPath.getBlobId()).setContentType("");
395395

396396
int blockSize = -1;
397397
for (CopyOption option : options) {
@@ -411,16 +411,16 @@ public void copy(Path source, Path target, CopyOption... options) throws IOExcep
411411
if (option instanceof OptionBlockSize) {
412412
blockSize = ((OptionBlockSize) option).size();
413413
} else if (option instanceof OptionMimeType) {
414-
tgtInfoBuilder.contentType(((OptionMimeType) option).mimeType());
414+
tgtInfoBuilder.setContentType(((OptionMimeType) option).mimeType());
415415
setContentType = true;
416416
} else if (option instanceof OptionCacheControl) {
417-
tgtInfoBuilder.cacheControl(((OptionCacheControl) option).cacheControl());
417+
tgtInfoBuilder.setCacheControl(((OptionCacheControl) option).cacheControl());
418418
setCacheControl = true;
419419
} else if (option instanceof OptionContentEncoding) {
420-
tgtInfoBuilder.contentEncoding(((OptionContentEncoding) option).contentEncoding());
420+
tgtInfoBuilder.setContentEncoding(((OptionContentEncoding) option).contentEncoding());
421421
setContentEncoding = true;
422422
} else if (option instanceof OptionContentDisposition) {
423-
tgtInfoBuilder.contentDisposition(
423+
tgtInfoBuilder.setContentDisposition(
424424
((OptionContentDisposition) option).contentDisposition());
425425
setContentDisposition = true;
426426
} else {
@@ -467,31 +467,31 @@ public void copy(Path source, Path target, CopyOption... options) throws IOExcep
467467
throw new NoSuchFileException(fromPath.toString());
468468
}
469469
if (!setCacheControl) {
470-
tgtInfoBuilder.cacheControl(blobInfo.cacheControl());
470+
tgtInfoBuilder.setCacheControl(blobInfo.getCacheControl());
471471
}
472472
if (!setContentType) {
473-
tgtInfoBuilder.contentType(blobInfo.contentType());
473+
tgtInfoBuilder.setContentType(blobInfo.getContentType());
474474
}
475475
if (!setContentEncoding) {
476-
tgtInfoBuilder.contentEncoding(blobInfo.contentEncoding());
476+
tgtInfoBuilder.setContentEncoding(blobInfo.getContentEncoding());
477477
}
478478
if (!setContentDisposition) {
479-
tgtInfoBuilder.contentDisposition(blobInfo.contentDisposition());
479+
tgtInfoBuilder.setContentDisposition(blobInfo.getContentDisposition());
480480
}
481-
tgtInfoBuilder.acl(blobInfo.acl());
482-
tgtInfoBuilder.metadata(blobInfo.metadata());
481+
tgtInfoBuilder.setAcl(blobInfo.getAcl());
482+
tgtInfoBuilder.setMetadata(blobInfo.getMetadata());
483483
}
484484

485485
BlobInfo tgtInfo = tgtInfoBuilder.build();
486486
Storage.CopyRequest.Builder copyReqBuilder =
487-
Storage.CopyRequest.builder().source(fromPath.getBlobId());
487+
Storage.CopyRequest.newBuilder().setSource(fromPath.getBlobId());
488488
if (wantReplaceExisting) {
489-
copyReqBuilder = copyReqBuilder.target(tgtInfo);
489+
copyReqBuilder = copyReqBuilder.setTarget(tgtInfo);
490490
} else {
491-
copyReqBuilder = copyReqBuilder.target(tgtInfo, Storage.BlobTargetOption.doesNotExist());
491+
copyReqBuilder = copyReqBuilder.setTarget(tgtInfo, Storage.BlobTargetOption.doesNotExist());
492492
}
493493
CopyWriter copyWriter = storage.copy(copyReqBuilder.build());
494-
copyWriter.result();
494+
copyWriter.getResult();
495495
} catch (StorageException oops) {
496496
throw asIoException(oops);
497497
}
@@ -551,9 +551,9 @@ public <A extends BasicFileAttributes> A readAttributes(
551551
}
552552
BlobInfo blobInfo = storage.get(cloudPath.getBlobId());
553553
// null size indicate a file that we haven't closed yet, so GCS treats it as not there yet.
554-
if (null == blobInfo || blobInfo.size() == null) {
554+
if (null == blobInfo || blobInfo.getSize() == null) {
555555
throw new NoSuchFileException(
556-
cloudPath.getBlobId().bucket() + "/" + cloudPath.getBlobId().name());
556+
cloudPath.getBlobId().getBucket() + "/" + cloudPath.getBlobId().getName());
557557
}
558558
CloudStorageObjectAttributes ret;
559559
ret = new CloudStorageObjectAttributes(blobInfo);

google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageObjectAttributes.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ final class CloudStorageObjectAttributes implements CloudStorageFileAttributes {
4545

4646
@Override
4747
public long size() {
48-
return info.size();
48+
return info.getSize();
4949
}
5050

5151
@Override
5252
public FileTime creationTime() {
53-
if (info.updateTime() == null) {
53+
if (info.getUpdateTime() == null) {
5454
return CloudStorageFileSystem.FILE_TIME_UNKNOWN;
5555
}
56-
return FileTime.fromMillis(info.updateTime());
56+
return FileTime.fromMillis(info.getUpdateTime());
5757
}
5858

5959
@Override
@@ -63,40 +63,40 @@ public FileTime lastModifiedTime() {
6363

6464
@Override
6565
public Optional<String> etag() {
66-
return Optional.fromNullable(info.etag());
66+
return Optional.fromNullable(info.getEtag());
6767
}
6868

6969
@Override
7070
public Optional<String> mimeType() {
71-
return Optional.fromNullable(info.contentType());
71+
return Optional.fromNullable(info.getContentType());
7272
}
7373

7474
@Override
7575
public Optional<List<Acl>> acl() {
76-
return Optional.fromNullable(info.acl());
76+
return Optional.fromNullable(info.getAcl());
7777
}
7878

7979
@Override
8080
public Optional<String> cacheControl() {
81-
return Optional.fromNullable(info.cacheControl());
81+
return Optional.fromNullable(info.getCacheControl());
8282
}
8383

8484
@Override
8585
public Optional<String> contentEncoding() {
86-
return Optional.fromNullable(info.contentEncoding());
86+
return Optional.fromNullable(info.getContentEncoding());
8787
}
8888

8989
@Override
9090
public Optional<String> contentDisposition() {
91-
return Optional.fromNullable(info.contentDisposition());
91+
return Optional.fromNullable(info.getContentDisposition());
9292
}
9393

9494
@Override
9595
public ImmutableMap<String, String> userMetadata() {
96-
if (null == info.metadata()) {
96+
if (null == info.getMetadata()) {
9797
return ImmutableMap.of();
9898
}
99-
return ImmutableMap.copyOf(info.metadata());
99+
return ImmutableMap.copyOf(info.getMetadata());
100100
}
101101

102102
@Override
@@ -126,7 +126,9 @@ public FileTime lastAccessTime() {
126126

127127
@Override
128128
public Object fileKey() {
129-
return info.blobId().bucket() + info.blobId().name() + info.blobId().generation();
129+
return info.getBlobId().getBucket()
130+
+ info.getBlobId().getName()
131+
+ info.getBlobId().getGeneration();
130132
}
131133

132134
@Override

google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageReadChannel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ private void checkOpen() throws ClosedChannelException {
143143
private static long fetchSize(Storage gcsStorage, BlobId file) throws IOException {
144144
BlobInfo blobInfo = gcsStorage.get(file);
145145
if (blobInfo == null) {
146-
throw new NoSuchFileException(String.format("gs://%s/%s", file.bucket(), file.name()));
146+
throw new NoSuchFileException(String.format("gs://%s/%s", file.getBucket(), file.getName()));
147147
}
148-
return blobInfo.size();
148+
return blobInfo.getSize();
149149
}
150150
}

google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStoragePathTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,37 +76,37 @@ public void testGetGcsFilename_empty_notAllowed() throws IOException {
7676
@Test
7777
public void testGetGcsFilename_stripsPrefixSlash() throws IOException {
7878
try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) {
79-
assertThat(fs.getPath("/hi").getBlobId().name()).isEqualTo("hi");
79+
assertThat(fs.getPath("/hi").getBlobId().getName()).isEqualTo("hi");
8080
}
8181
}
8282

8383
@Test
8484
public void testGetGcsFilename_overrideStripPrefixSlash_doesntStripPrefixSlash() throws IOException {
8585
try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle", stripPrefixSlash(false))) {
86-
assertThat(fs.getPath("/hi").getBlobId().name()).isEqualTo("/hi");
86+
assertThat(fs.getPath("/hi").getBlobId().getName()).isEqualTo("/hi");
8787
}
8888
}
8989

9090
@Test
9191
public void testGetGcsFilename_extraSlashes_throwsIae() throws IOException {
9292
try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) {
9393
thrown.expect(IllegalArgumentException.class);
94-
fs.getPath("a//b").getBlobId().name();
94+
fs.getPath("a//b").getBlobId().getName();
9595
}
9696
}
9797

9898
@Test
9999
public void testGetGcsFilename_overridepermitEmptyPathComponents() throws IOException {
100100
try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle", permitEmptyPathComponents(true))) {
101-
assertThat(fs.getPath("a//b").getBlobId().name()).isEqualTo("a//b");
101+
assertThat(fs.getPath("a//b").getBlobId().getName()).isEqualTo("a//b");
102102
}
103103
}
104104

105105
@Test
106106
public void testGetGcsFilename_freaksOutOnExtraSlashesAndDotDirs() throws IOException {
107107
try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) {
108108
thrown.expect(IllegalArgumentException.class);
109-
fs.getPath("a//b/..").getBlobId().name();
109+
fs.getPath("a//b/..").getBlobId().getName();
110110
}
111111
}
112112

google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageReadChannelTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class CloudStorageReadChannelTest {
5959

6060
@Before
6161
public void before() throws IOException {
62-
when(metadata.size()).thenReturn(42L);
62+
when(metadata.getSize()).thenReturn(42L);
6363
when(gcsStorage.get(file)).thenReturn(metadata);
6464
when(gcsStorage.reader(eq(file))).thenReturn(gcsChannel);
6565
when(gcsChannel.isOpen()).thenReturn(true);

google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/it/ITGcsNio.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public class ITGcsNio {
9898
public static void beforeClass() throws IOException {
9999
// loads the credentials from local disk as par README
100100
RemoteStorageHelper gcsHelper = RemoteStorageHelper.create();
101-
storageOptions = gcsHelper.options();
101+
storageOptions = gcsHelper.getOptions();
102102
storage = storageOptions.service();
103103
// create and populate test bucket
104104
storage.create(BucketInfo.of(BUCKET));
@@ -121,7 +121,7 @@ private static byte[] randomContents(int size) {
121121
}
122122

123123
private static void fillFile(Storage storage, String fname, int size) throws IOException {
124-
storage.create(BlobInfo.builder(BUCKET, fname).build(), randomContents(size));
124+
storage.create(BlobInfo.newBuilder(BUCKET, fname).build(), randomContents(size));
125125
}
126126

127127
@Test

0 commit comments

Comments
 (0)