Skip to content

Commit 482954f

Browse files
committed
Merge pull request #277 from ajkannan/pull-updates
Pull updates from master branch
2 parents b54c501 + bba6925 commit 482954f

File tree

80 files changed

+7207
-1248
lines changed

Some content is hidden

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

80 files changed

+7207
-1248
lines changed

.travis.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ before_install:
88
- git clone -b travis `git config --get remote.origin.url` target/travis
99
- cp target/travis/settings.xml ~/.m2/settings.xml
1010
install: mvn install -DskipTests=true -Dgpg.skip=true
11-
script: mvn verify
11+
script:
12+
- utilities/verify.sh
1213
branches:
1314
only:
1415
- master
@@ -20,3 +21,5 @@ env:
2021
- secure: "CUM2l73KFm7U4eDsUKkh1WyEUzF3v94Ltvs7MnKU9olE1dNp3YmRBL9Lqhx3hSDqm/xv0ETQsPy29Fs2+VFkhQQxSley6iS/4trr2fioTB680txfXo/zDdmGSP1q1/U40fv1S+jvuBRAhDV5W+8dhWOGtzMH0tJp/TszeDGlmCY="
2122
- secure: "YBbdzseg5yDFpQIiMoc3P2BTmqef4o+KAvrLMEbobXjIkiglUQ7UHCoRWClX74fTKAwuC7JvK7o5xJGLnaY43jJADXrGtE8/d44HNJaieE67mNosDYtOiA0iI2uIRFCAnXJCZ8f/iHx2xVMHMNWlwyoil4IUcjj+D7FRcsT5alE="
2223
- secure: "Od7BwllgFXVfzFe8ooTNm05TR+Xd5QjHW0oqhU8vclaQs2oX4e0eNIsebXQfLi3xDgd1pz5uUQC/Z4S0NqACwyUuUvPdGYYmRPTR7Dh8HgGJ4ojSdN3RwaHsxUqG7Ajts9rIHOtRpY28xOChVRNX0Z7eAPlvxYU4Ed2ZEo356r0="
24+
- secure: "ROxa8HHuba+Dfixljq6poW1+Uwv8EaZUtTTTB7KEtAHJRN8rwoNS4TC0U0PEHcYAL+ivxP3zIfWOCoWreJGoa+V8y9BtLSuamUj/SSsuoHRdJjq5BmcHI/77P11HAzCH6Ul/GxsRB52/IRHwJyfKkh8XUMVSsCl7AG4CKUgt63Y="
25+
- secure: "MKZ3y6IYp3Z67T+BO4Brw+my8sRMSMdWWgvUcyBpwQZ64w7ccHJCce4W8WHCPNko/eczHHCJELPG28VNyPTWIV/Jt2ZJ6L9qLCjsQpDPOdJdDaAKc9Df4sm8fB0FBiPVDwMYPQF1/Sy2gK7FZf0YR3LOeoyzswRgmj5bQMdVEeU="

README.md

+79-26
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ Java idiomatic client for [Google Cloud Platform][cloud-platform] services.
99

1010
- [Homepage] (https://googlecloudplatform.github.io/gcloud-java/)
1111
- [API Documentation] (http://googlecloudplatform.github.io/gcloud-java/apidocs)
12-
- [Examples] (http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/examples/package-summary.html)
1312

1413
This client supports the following Google Cloud Platform services:
1514

1615
- [Google Cloud Datastore] (#google-cloud-datastore)
17-
18-
<!---
19-
- [Google Cloud Storage] (https://cloud.google.com/storage/)
20-
--->
16+
- [Google Cloud Storage] (#google-cloud-storage)
2117

2218
> Note: This client is a work-in-progress, and may occasionally
2319
> make backwards-incompatible changes.
@@ -29,32 +25,39 @@ Add this to your pom.xml file
2925
<dependency>
3026
<groupId>com.google.gcloud</groupId>
3127
<artifactId>gcloud-java</artifactId>
32-
<version>0.0.7</version>
28+
<version>0.0.10</version>
3329
</dependency>
3430
```
3531

36-
<!---
3732
Example Applications
3833
--------------------
3934

40-
- `java-datastore-sample`_ - A sample using Cloud Datastore
41-
.. _java-datastore-sample: https://github.com/GoogleCloudPlatform/java-datastore-sample
42-
--->
35+
- [`DatastoreExample`](https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/DatastoreExample.java) - A simple command line interface for the Cloud Datastore
36+
- Read more about using this application on the [`gcloud-java-examples` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/DatastoreExample.html).
37+
- [`StorageExample`](https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java) - A simple command line interface providing some of Cloud Storage's functionality
38+
- Read more about using this application on the [`gcloud-java-examples` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/StorageExample.html).
39+
40+
Authentication
41+
--------------
42+
43+
There are multiple ways to authenticate to use Google Cloud services.
44+
45+
1. When using `gcloud-java` libraries from within Compute/App Engine, no additional authentication steps are necessary.
46+
2. When using `gcloud-java` libraries elsewhere, there are two options:
47+
* [Generate a JSON service account key](https://cloud.google.com/storage/docs/authentication?hl=en#service_accounts). Supply a path to the downloaded JSON credentials file when building the options supplied to datastore/storage constructor.
48+
* If running locally for development/testing, you can use use [Google Cloud SDK](https://cloud.google.com/sdk/?hl=en). To use the SDK authentication, [download the SDK](https://cloud.google.com/sdk/?hl=en) if you haven't already. Then login using the SDK (`gcloud auth login` in command line), and set your current project using `gcloud config set project PROJECT_ID`.
4349

4450
Google Cloud Datastore
4551
----------------------
4652

47-
Google [Cloud Datastore][cloud-datastore] is a fully managed, schemaless database for
48-
storing non-relational data. Cloud Datastore automatically scales with
49-
your users and supports ACID transactions, high availability of reads and
50-
writes, strong consistency for reads and ancestor queries, and eventual
51-
consistency for all other queries.
53+
- [API Documentation][datastore-api]
54+
- [Official Documentation][cloud-datastore-docs]
5255

53-
See the [Google Cloud Datastore docs][cloud-datastore-activation] for more details on how to activate
54-
Cloud Datastore for your project.
56+
*Follow the [activation instructions][cloud-datastore-activation] to use the Google Cloud Datastore API with your project.*
5557

56-
See the ``gcloud-java`` API [datastore documentation][datastore-api] to learn how to interact
57-
with the Cloud Datastore using this Client Library.
58+
#### Preview
59+
60+
Here is a code snippet showing a simple usage example from within Compute/App Engine. Note that you must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
5861

5962
```java
6063
import com.google.gcloud.datastore.Datastore;
@@ -65,8 +68,7 @@ import com.google.gcloud.datastore.Entity;
6568
import com.google.gcloud.datastore.Key;
6669
import com.google.gcloud.datastore.KeyFactory;
6770

68-
DatastoreOptions options = DatastoreOptions.builder().projectId(PROJECT_ID).build();
69-
Datastore datastore = DatastoreFactory.instance().get(options);
71+
Datastore datastore = DatastoreFactory.instance().get(DatastoreOptions.getDefaultInstance());
7072
KeyFactory keyFactory = datastore.newKeyFactory().kind(KIND);
7173
Key key = keyFactory.newKey(keyName);
7274
Entity entity = datastore.get(key);
@@ -86,20 +88,59 @@ if (entity == null) {
8688
}
8789
```
8890

89-
Contributing
90-
------------
91+
Google Cloud Storage
92+
----------------------
9193

92-
Contributions to this library are always welcome and highly encouraged.
94+
- [API Documentation][storage-api]
95+
- [Official Documentation][cloud-storage-docs]
9396

94-
See [CONTRIBUTING] for more information on how to get started.
97+
*Follow the [activation instructions][cloud-storage-activation] to use the Google Cloud Storage API with your project.*
9598

96-
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct][code-of-conduct] for more information.
99+
#### Preview
100+
101+
Here is a code snippet showing a simple usage example from within Compute/App Engine. Note that you must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
102+
103+
```java
104+
import static java.nio.charset.StandardCharsets.UTF_8;
105+
106+
import com.google.gcloud.storage.Blob;
107+
import com.google.gcloud.storage.BlobId;
108+
import com.google.gcloud.storage.Storage;
109+
import com.google.gcloud.storage.StorageFactory;
110+
import com.google.gcloud.storage.StorageOptions;
111+
112+
import java.nio.ByteBuffer;
113+
import java.nio.channels.WritableByteChannel;
114+
115+
StorageOptions options = StorageOptions.builder().projectId("project").build();
116+
Storage storage = StorageFactory.instance().get(options);
117+
BlobId blobId = BlobId.of("bucket", "blob_name");
118+
Blob blob = Blob.load(storage, blobId);
119+
if (blob == null) {
120+
BlobInfo blobInfo = BlobInfo.builder(blobId).contentType("text/plain").build();
121+
storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
122+
} else {
123+
System.out.println("Updating content for " + blobId.name());
124+
byte[] prevContent = blob.content();
125+
System.out.println(new String(prevContent, UTF_8));
126+
WritableByteChannel channel = blob.writer();
127+
channel.write(ByteBuffer.wrap("Updated content".getBytes(UTF_8)));
128+
channel.close();
129+
}
130+
```
97131

98132
Java Versions
99133
-------------
100134

101135
Java 7 or above is required for using this client.
102136

137+
Testing
138+
-------
139+
140+
This library provides tools to help write tests for code that uses gcloud-java services.
141+
142+
See [TESTING] to read more about using our testing helpers.
143+
103144
Versioning
104145
----------
105146

@@ -109,6 +150,15 @@ It is currently in major version zero (``0.y.z``), which means that anything
109150
may change at any time and the public API should not be considered
110151
stable.
111152

153+
Contributing
154+
------------
155+
156+
Contributions to this library are always welcome and highly encouraged.
157+
158+
See [CONTRIBUTING] for more information on how to get started.
159+
160+
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct][code-of-conduct] for more information.
161+
112162
License
113163
-------
114164

@@ -118,6 +168,7 @@ Apache 2.0 - See [LICENSE] for more information.
118168
[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CONTRIBUTING.md
119169
[code-of-conduct]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CODE_OF_CONDUCT.md
120170
[LICENSE]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/LICENSE
171+
[TESTING]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/TESTING.md
121172
[cloud-platform]: https://cloud.google.com/
122173
[cloud-datastore]: https://cloud.google.com/datastore/docs
123174
[cloud-datastore-docs]: https://cloud.google.com/datastore/docs
@@ -130,3 +181,5 @@ Apache 2.0 - See [LICENSE] for more information.
130181
[cloud-storage]: https://cloud.google.com/storage/
131182
[cloud-storage-docs]: https://cloud.google.com/storage/docs/overview
132183
[cloud-storage-create-bucket]: https://cloud.google.com/storage/docs/cloud-console#_creatingbuckets
184+
[cloud-storage-activation]: https://cloud.google.com/storage/docs/signup
185+
[storage-api]: http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/storage/package-summary.html

RELEASING.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
### Overview
2+
3+
Most of the release process is handled by the `after_success.sh` script, triggered after Travis CI successfully completes a non-PR build. A new artifact will be released to Maven Central Repository via Travis CI when "-SNAPSHOT" is not included in the version (as listed in the base directory's `pom.xml`). The website and README files will also be updated automatically in this case. When "-SNAPSHOT" is included in the version, Travis only updates the artifact in the snapshot repository.
4+
5+
### To push a release version
6+
7+
1. Run `utilities/update_pom_version.sh` from the repository's base directory.
8+
This script takes an optional argument denoting the new version. By default, if the current version is X.Y.Z-SNAPSHOT, the script will update the version in all the pom.xml files to X.Y.Z. If desired, another version can be supplied via command line argument instead.
9+
10+
2. Create a PR to update the pom.xml version.
11+
The PR should look something like [#225](https://github.com/GoogleCloudPlatform/gcloud-java/pull/225). After this PR is merged into GoogleCloudPlatform/gcloud-java, Travis CI will push a new website to GoogleCloudPlatform/gh-pages, push a new artifact to the Maven Central Repository, and update versions in the README files.
12+
13+
3. Create a release on Github manually.
14+
Go to the [releases page](https://github.com/GoogleCloudPlatform/gcloud-java/releases) and click "Draft a new release." Use `vX.Y.Z` as the "Tag Version" and `X.Y.Z` as the "Release Title", where `X.Y.Z` is the release version as listed in the `pom.xml` files.
15+
16+
4. Run `utilities/update_pom_version.sh` again (to include "-SNAPSHOT" in the project version).
17+
As mentioned before, there is an optional version argument. By default, the script will update the version from "X.Y.Z" to "X.Y.Z+1-SNAPSHOT". Suppose a different version is desired, for example X+1.0.0-SNAPSHOT. Then the appropriate command to run would be `utilities/update_pom_version.sh X+1.0.0-SNAPSHOT`.
18+
19+
5. Create and merge in another PR to reflect the updated project version. For an example of what this PR should look like, see [#227](https://github.com/GoogleCloudPlatform/gcloud-java/pull/227).
20+
21+
### To push a snapshot version
22+
23+
Pushing a snapshot is completely automated. If "-SNAPSHOT" is included in the version denoted by the base directory's pom.xml, then an updated artifact will be pushed to the snapshot repository when Travis CI successfully completes a non-PR build.
24+
25+
### Improvements
26+
27+
Automatic tagging is not currently implemented, though it was discussed in [#119](https://github.com/GoogleCloudPlatform/gcloud-java/pull/119). If the version updates continue to be manual, a one-line git tag command can be added to `after_success.sh` to correctly tag releases. However, automatically creating useful annotations for this tag will be difficult. Also, if the release process becomes fully automated, tagging becomes a harder problem, as mentioned in that issue.

TESTING.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
## gcloud-java tools for testing
2+
3+
This library provides tools to help write tests for code that uses gcloud-java services.
4+
5+
### Testing code that uses Datastore
6+
7+
#### On your machine
8+
9+
You can test against a temporary local datastore by following these steps:
10+
11+
1. Start the local datastore emulator using `LocalGcdHelper`. This can be done in two ways:
12+
- Run `LocalGcdHelper.java`'s `main` method with arguments `START` and (optionally) `--port=<port number>`. This will create a temporary folder on your computer and bind `localhost:<port number>` for communication with the local datastore. The port number is an optional argument. If no port number is specified, port 8080 will be used.
13+
- Call `LocalGcdHelper.start(<project ID>, <port number>)` before running your tests. Save the `LocalGcdHelper` object returned so that you can stop the emulator later.
14+
15+
2. In your program, create and use a datastore whose host is set host to `localhost:<port number>`. For example,
16+
```java
17+
DatastoreOptions options = DatastoreOptions.builder()
18+
.projectId(PROJECT_ID)
19+
.host("http://localhost:8080")
20+
.build();
21+
Datastore localDatastore = DatastoreFactory.instance().get(options);
22+
```
23+
3. Run your tests.
24+
25+
4. Stop the local datastore emulator.
26+
- If you ran `LocalGcdHelper.java`'s `main` function to start the emulator, run `LocalGcdHelper.java`'s `main` method with arguments `STOP` and (optionally) `--port=<port number>`. If the port is not supplied, the program will attempt to close the last port started.
27+
- If you ran `LocalGcdHelper.start()` to start the emulator, call the `stop()` method on the `LocalGcdHelper` object returned by `LocalGcdHelper.start()`.
28+
29+
#### On a remote machine
30+
31+
You can test against a remote datastore emulator as well. To do this, set the `DatastoreOptions` project endpoint to the hostname of the remote machine, like the example below.
32+
33+
```java
34+
DatastoreOptions options = DatastoreOptions.builder()
35+
.projectId(PROJECT_ID)
36+
.host("http://<hostname of machine>:<port>")
37+
.build();
38+
Datastore localDatastore = DatastoreFactory.instance().get(options);
39+
```
40+
41+
Note that the remote datastore must be running before your tests are run.
42+
43+
### Testing code that uses Storage
44+
45+
Currently, there isn't an emulator for Google Cloud Storage, so an alternative is to create a test project. `RemoteGcsHelper` contains convenience methods to make setting up and cleaning up the test project easier. To use this class, follow the steps below:
46+
47+
1. Create a test Google Cloud project.
48+
49+
2. Download a JSON service account credentials file from the Google Developer's Console. See more about this on the [Google Cloud Platform Storage Authentication page][cloud-platform-storage-authentication].
50+
51+
3. Create a `RemoteGcsHelper` object using your project ID and JSON key.
52+
Here is an example that uses the `RemoteGcsHelper` to create a bucket.
53+
```java
54+
RemoteGcsHelper gcsHelper = RemoteGcsHelper.create(PROJECT_ID, "/path/to/my/JSON/key.json");
55+
Storage storage = StorageFactory.instance().get(gcsHelper.options());
56+
String bucket = RemoteGcsHelper.generateBucketName();
57+
storage.create(BucketInfo.of(bucket));
58+
```
59+
60+
4. Run your tests.
61+
62+
5. Clean up the test project by using `forceDelete` to clear any buckets used.
63+
Here is an example that clears the bucket created in Step 3 with a timeout of 5 seconds.
64+
```java
65+
RemoteGcsHelper.forceDelete(storage, bucket, 5, TimeUnit.SECONDS);
66+
```
67+
68+
69+
[cloud-platform-storage-authentication]:https://cloud.google.com/storage/docs/authentication?hl=en#service_accounts

gcloud-java-core/README.md

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
Google Cloud Java Client
2-
==========================
1+
Google Cloud Java Client -- Core
2+
=========================================
33

4-
Java idiomatic client for [Google Cloud Platform][cloud-platform] services.
4+
This module provides common functionality required by service-specific modules of this library.
55

66
[![Build Status](https://travis-ci.org/GoogleCloudPlatform/gcloud-java.svg?branch=master)](https://travis-ci.org/GoogleCloudPlatform/gcloud-java)
77
[![Coverage Status](https://coveralls.io/repos/GoogleCloudPlatform/gcloud-java/badge.svg?branch=master)](https://coveralls.io/r/GoogleCloudPlatform/gcloud-java?branch=master)
8+
[![Maven](https://img.shields.io/maven-central/v/com.google.gcloud/gcloud-java-core.svg)](https://img.shields.io/maven-central/v/com.google.gcloud/gcloud-java-core.svg)
89

910
- [Homepage] (https://googlecloudplatform.github.io/gcloud-java/)
10-
- [API Documentation] (http://googlecloudplatform.github.io/gcloud-java/apidocs)
11-
- [Examples] (http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/examples/package-summary.html)
12-
13-
This module provides common functionality and is required by the other service specific modules.
11+
- [API Documentation] (http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/package-summary.html)
1412

1513
Quickstart
1614
----------
@@ -19,22 +17,22 @@ Add this to your pom.xml file
1917
<dependency>
2018
<groupId>com.google.gcloud</groupId>
2119
<artifactId>gcloud-java-core</artifactId>
22-
<version>0.0.7</version>
20+
<version>0.0.10</version>
2321
</dependency>
2422
```
2523

24+
Java Versions
25+
-------------
26+
27+
Java 7 or above is required for using this client.
28+
2629
Contributing
2730
------------
2831

2932
Contributions to this library are always welcome and highly encouraged.
3033

3134
See [CONTRIBUTING] for more information on how to get started.
3235

33-
Java Versions
34-
-------------
35-
36-
Java 7 or above is required for using this client.
37-
3836
Versioning
3937
----------
4038

gcloud-java-core/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<parent>
1212
<groupId>com.google.gcloud</groupId>
1313
<artifactId>gcloud-java-pom</artifactId>
14-
<version>0.0.8-SNAPSHOT</version>
14+
<version>0.0.11-SNAPSHOT</version>
1515
</parent>
1616
<dependencies>
1717
<dependency>
@@ -74,7 +74,7 @@
7474
<dependency>
7575
<groupId>joda-time</groupId>
7676
<artifactId>joda-time</artifactId>
77-
<version>RELEASE</version>
77+
<version>2.8.2</version>
7878
<scope>compile</scope>
7979
</dependency>
8080
<dependency>

0 commit comments

Comments
 (0)