Skip to content

Auto-update dependencies. #908

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

Merged
merged 2 commits into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
[![ghit.me](https://ghit.me/badge.svg?repo=GoogleCloudPlatform/java-docs-samples)](https://ghit.me/repo/GoogleCloudPlatform/java-docs-samples)
[![Coverage Status](https://codecov.io/gh/GoogleCloudPlatform/java-docs-samples/branch/master/graph/badge.svg)](https://codecov.io/gh/GoogleCloudPlatform/java-docs-samples)


While this library is still supported, we suggest trying the newer [Cloud Client Library](https://developers.google.com/api-client-library/java/apis/vision/v1) for Google Cloud Vision, especially for new projects. For more information, please see the notice on the [API Client Library Page](https://developers.google.com/api-client-library/java/apis/vision/v1).

This is a repository that contains java code snippets on [Cloud Platform Documentation](https://cloud.google.com/docs/).

The repo is organized as follows:
Expand Down
2 changes: 1 addition & 1 deletion appengine-java8/gaeinfo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Copyright 2017 Google Inc.
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.8.RELEASE</version>
<version>3.0.9.RELEASE</version>
</dependency>

</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion appengine-java8/metadata/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Copyright 2017 Google Inc.
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.8.RELEASE</version>
<version>3.0.9.RELEASE</version>
</dependency>

</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion appengine/sockets/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<!-- jsoup HTML parser library @ http://jsoup.org/ -->
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.10.3</version>
<version>1.11.1</version>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion compute/signed-metadata/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.2.0</version>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand Down
2 changes: 1 addition & 1 deletion flexible/gaeinfo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Copyright 2017 Google Inc.
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.8.RELEASE</version>
<version>3.0.9.RELEASE</version>
</dependency>

</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion vision/face-detection/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-vision</artifactId>
<version>v1-rev364-1.23.0</version>
<version>v1-rev365-1.23.0</version>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.vision.v1.Vision;
import com.google.api.services.vision.v1.VisionScopes;
import com.google.api.services.vision.v1.model.AnnotateImageRequest;
import com.google.api.services.vision.v1.model.AnnotateImageResponse;
import com.google.api.services.vision.v1.model.BatchAnnotateImagesRequest;
import com.google.api.services.vision.v1.model.BatchAnnotateImagesResponse;
import com.google.api.services.vision.v1.model.FaceAnnotation;
import com.google.api.services.vision.v1.model.Feature;
import com.google.api.services.vision.v1.model.Image;
import com.google.api.services.vision.v1.model.Vertex;
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1AnnotateImageRequest;
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1AnnotateImageResponse;
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1BatchAnnotateImagesRequest;
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1BatchAnnotateImagesResponse;
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1FaceAnnotation;
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1Feature;
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1Image;
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1Vertex;
import com.google.common.collect.ImmutableList;

import java.awt.BasicStroke;
Expand Down Expand Up @@ -81,7 +81,7 @@ public static void main(String[] args) throws IOException, GeneralSecurityExcept
}

FaceDetectApp app = new FaceDetectApp(getVisionService());
List<FaceAnnotation> faces = app.detectFaces(inputPath, MAX_RESULTS);
List<GoogleCloudVisionV1FaceAnnotation> faces = app.detectFaces(inputPath, MAX_RESULTS);
System.out.printf("Found %d face%s\n", faces.size(), faces.size() == 1 ? "" : "s");
System.out.printf("Writing to file %s\n", outputPath);
app.writeWithFaces(inputPath, outputPath, faces);
Expand Down Expand Up @@ -115,25 +115,25 @@ public FaceDetectApp(Vision vision) {
/**
* Gets up to {@code maxResults} faces for an image stored at {@code path}.
*/
public List<FaceAnnotation> detectFaces(Path path, int maxResults) throws IOException {
public List<GoogleCloudVisionV1FaceAnnotation> detectFaces(Path path, int maxResults) throws IOException {
byte[] data = Files.readAllBytes(path);

AnnotateImageRequest request =
new AnnotateImageRequest()
.setImage(new Image().encodeContent(data))
GoogleCloudVisionV1AnnotateImageRequest request =
new GoogleCloudVisionV1AnnotateImageRequest()
.setImage(new GoogleCloudVisionV1Image().encodeContent(data))
.setFeatures(ImmutableList.of(
new Feature()
new GoogleCloudVisionV1Feature()
.setType("FACE_DETECTION")
.setMaxResults(maxResults)));
Vision.Images.Annotate annotate =
vision.images()
.annotate(new BatchAnnotateImagesRequest().setRequests(ImmutableList.of(request)));
.annotate(new GoogleCloudVisionV1BatchAnnotateImagesRequest().setRequests(ImmutableList.of(request)));
// Due to a bug: requests to Vision API containing large images fail when GZipped.
annotate.setDisableGZipContent(true);

BatchAnnotateImagesResponse batchResponse = annotate.execute();
GoogleCloudVisionV1BatchAnnotateImagesResponse batchResponse = annotate.execute();
assert batchResponse.getResponses().size() == 1;
AnnotateImageResponse response = batchResponse.getResponses().get(0);
GoogleCloudVisionV1AnnotateImageResponse response = batchResponse.getResponses().get(0);
if (response.getFaceAnnotations() == null) {
throw new IOException(
response.getError() != null
Expand All @@ -148,7 +148,7 @@ public List<FaceAnnotation> detectFaces(Path path, int maxResults) throws IOExce
/**
* Reads image {@code inputPath} and writes {@code outputPath} with {@code faces} outlined.
*/
private static void writeWithFaces(Path inputPath, Path outputPath, List<FaceAnnotation> faces)
private static void writeWithFaces(Path inputPath, Path outputPath, List<GoogleCloudVisionV1FaceAnnotation> faces)
throws IOException {
BufferedImage img = ImageIO.read(inputPath.toFile());
annotateWithFaces(img, faces);
Expand All @@ -158,19 +158,19 @@ private static void writeWithFaces(Path inputPath, Path outputPath, List<FaceAnn
/**
* Annotates an image {@code img} with a polygon around each face in {@code faces}.
*/
public static void annotateWithFaces(BufferedImage img, List<FaceAnnotation> faces) {
for (FaceAnnotation face : faces) {
public static void annotateWithFaces(BufferedImage img, List<GoogleCloudVisionV1FaceAnnotation> faces) {
for (GoogleCloudVisionV1FaceAnnotation face : faces) {
annotateWithFace(img, face);
}
}

/**
* Annotates an image {@code img} with a polygon defined by {@code face}.
*/
private static void annotateWithFace(BufferedImage img, FaceAnnotation face) {
private static void annotateWithFace(BufferedImage img, GoogleCloudVisionV1FaceAnnotation face) {
Graphics2D gfx = img.createGraphics();
Polygon poly = new Polygon();
for (Vertex vertex : face.getFdBoundingPoly().getVertices()) {
for (GoogleCloudVisionV1Vertex vertex : face.getFdBoundingPoly().getVertices()) {
poly.addPoint(vertex.getX(), vertex.getY());
}
gfx.setStroke(new BasicStroke(5));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;

import com.google.api.services.vision.v1.model.FaceAnnotation;
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1FaceAnnotation;

import org.junit.Before;
import org.junit.Test;
Expand All @@ -45,7 +45,7 @@ public class FaceDetectAppIT {
}

@Test public void detectFaces_withFace_returnsAtLeastOneFace() throws Exception {
List<FaceAnnotation> faces =
List<GoogleCloudVisionV1FaceAnnotation> faces =
appUnderTest.detectFaces(Paths.get("data/face.jpg"), MAX_RESULTS);

assertThat(faces).named("face.jpg faces").isNotEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

import static com.google.common.truth.Truth.assertThat;

import com.google.api.services.vision.v1.model.BoundingPoly;
import com.google.api.services.vision.v1.model.FaceAnnotation;
import com.google.api.services.vision.v1.model.Vertex;
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1BoundingPoly;
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1FaceAnnotation;
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1Vertex;
import com.google.common.collect.ImmutableList;

import org.junit.Test;
Expand All @@ -36,21 +36,21 @@
public class FaceDetectAppTest {
@Test public void annotateWithFaces_manyFaces_outlinesFaces() throws Exception {
// Arrange
ImmutableList<FaceAnnotation> faces =
ImmutableList<GoogleCloudVisionV1FaceAnnotation> faces =
ImmutableList.of(
new FaceAnnotation()
new GoogleCloudVisionV1FaceAnnotation()
.setFdBoundingPoly(
new BoundingPoly().setVertices(ImmutableList.of(
new Vertex().setX(10).setY(5),
new Vertex().setX(20).setY(5),
new Vertex().setX(20).setY(25),
new Vertex().setX(10).setY(25)))),
new FaceAnnotation()
new GoogleCloudVisionV1BoundingPoly().setVertices(ImmutableList.of(
new GoogleCloudVisionV1Vertex().setX(10).setY(5),
new GoogleCloudVisionV1Vertex().setX(20).setY(5),
new GoogleCloudVisionV1Vertex().setX(20).setY(25),
new GoogleCloudVisionV1Vertex().setX(10).setY(25)))),
new GoogleCloudVisionV1FaceAnnotation()
.setFdBoundingPoly(
new BoundingPoly().setVertices(ImmutableList.of(
new Vertex().setX(60).setY(50),
new Vertex().setX(70).setY(60),
new Vertex().setX(50).setY(60)))));
new GoogleCloudVisionV1BoundingPoly().setVertices(ImmutableList.of(
new GoogleCloudVisionV1Vertex().setX(60).setY(50),
new GoogleCloudVisionV1Vertex().setX(70).setY(60),
new GoogleCloudVisionV1Vertex().setX(50).setY(60)))));
BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);

// Act
Expand Down
2 changes: 1 addition & 1 deletion vision/label/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-vision</artifactId>
<version>v1-rev364-1.23.0</version>
<version>v1-rev365-1.23.0</version>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.vision.v1.Vision;
import com.google.api.services.vision.v1.VisionScopes;
import com.google.api.services.vision.v1.model.AnnotateImageRequest;
import com.google.api.services.vision.v1.model.AnnotateImageResponse;
import com.google.api.services.vision.v1.model.BatchAnnotateImagesRequest;
import com.google.api.services.vision.v1.model.BatchAnnotateImagesResponse;
import com.google.api.services.vision.v1.model.EntityAnnotation;
import com.google.api.services.vision.v1.model.Feature;
import com.google.api.services.vision.v1.model.Image;
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1AnnotateImageRequest;
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1AnnotateImageResponse;
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1BatchAnnotateImagesRequest;
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1BatchAnnotateImagesResponse;
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1EntityAnnotation;
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1Feature;
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1Image;
import com.google.common.collect.ImmutableList;

import java.io.IOException;
Expand Down Expand Up @@ -74,9 +74,9 @@ public static void main(String[] args) throws IOException, GeneralSecurityExcept
/**
* Prints the labels received from the Vision API.
*/
public static void printLabels(PrintStream out, Path imagePath, List<EntityAnnotation> labels) {
public static void printLabels(PrintStream out, Path imagePath, List<GoogleCloudVisionV1EntityAnnotation> labels) {
out.printf("Labels for image %s:\n", imagePath);
for (EntityAnnotation label : labels) {
for (GoogleCloudVisionV1EntityAnnotation label : labels) {
out.printf(
"\t%s (score: %.3f)\n",
label.getDescription(),
Expand Down Expand Up @@ -114,28 +114,28 @@ public LabelApp(Vision vision) {
/**
* Gets up to {@code maxResults} labels for an image stored at {@code path}.
*/
public List<EntityAnnotation> labelImage(Path path, int maxResults) throws IOException {
public List<GoogleCloudVisionV1EntityAnnotation> labelImage(Path path, int maxResults) throws IOException {
// [START construct_request]
byte[] data = Files.readAllBytes(path);

AnnotateImageRequest request =
new AnnotateImageRequest()
.setImage(new Image().encodeContent(data))
GoogleCloudVisionV1AnnotateImageRequest request =
new GoogleCloudVisionV1AnnotateImageRequest()
.setImage(new GoogleCloudVisionV1Image().encodeContent(data))
.setFeatures(ImmutableList.of(
new Feature()
new GoogleCloudVisionV1Feature()
.setType("LABEL_DETECTION")
.setMaxResults(maxResults)));
Vision.Images.Annotate annotate =
vision.images()
.annotate(new BatchAnnotateImagesRequest().setRequests(ImmutableList.of(request)));
.annotate(new GoogleCloudVisionV1BatchAnnotateImagesRequest().setRequests(ImmutableList.of(request)));
// Due to a bug: requests to Vision API containing large images fail when GZipped.
annotate.setDisableGZipContent(true);
// [END construct_request]

// [START parse_response]
BatchAnnotateImagesResponse batchResponse = annotate.execute();
GoogleCloudVisionV1BatchAnnotateImagesResponse batchResponse = annotate.execute();
assert batchResponse.getResponses().size() == 1;
AnnotateImageResponse response = batchResponse.getResponses().get(0);
GoogleCloudVisionV1AnnotateImageResponse response = batchResponse.getResponses().get(0);
if (response.getLabelAnnotations() == null) {
throw new IOException(
response.getError() != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;

import com.google.api.services.vision.v1.model.EntityAnnotation;
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1EntityAnnotation;
import com.google.common.collect.ImmutableSet;

import org.junit.Before;
Expand All @@ -46,11 +46,11 @@ public class LabelAppIT {
}

@Test public void labelImage_cat_returnsCatDescription() throws Exception {
List<EntityAnnotation> labels =
List<GoogleCloudVisionV1EntityAnnotation> labels =
appUnderTest.labelImage(Paths.get("data/cat.jpg"), MAX_LABELS);

ImmutableSet.Builder<String> builder = ImmutableSet.builder();
for (EntityAnnotation label : labels) {
for (GoogleCloudVisionV1EntityAnnotation label : labels) {
builder.add(label.getDescription());
}
ImmutableSet<String> descriptions = builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import static com.google.common.truth.Truth.assertThat;

import com.google.api.services.vision.v1.model.EntityAnnotation;
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1EntityAnnotation;
import com.google.common.collect.ImmutableList;

import org.junit.Test;
Expand All @@ -42,7 +42,7 @@ public class LabelAppTest {

// Act
LabelApp.printLabels(
out, Paths.get("path/to/some/image.jpg"), ImmutableList.<EntityAnnotation>of());
out, Paths.get("path/to/some/image.jpg"), ImmutableList.<GoogleCloudVisionV1EntityAnnotation>of());

// Assert
assertThat(bout.toString()).contains("No labels found.");
Expand All @@ -52,11 +52,11 @@ public class LabelAppTest {
// Arrange
ByteArrayOutputStream bout = new ByteArrayOutputStream();
PrintStream out = new PrintStream(bout);
ImmutableList<EntityAnnotation> labels =
ImmutableList<GoogleCloudVisionV1EntityAnnotation> labels =
ImmutableList.of(
new EntityAnnotation().setDescription("dog").setScore(0.7564f),
new EntityAnnotation().setDescription("husky").setScore(0.67891f),
new EntityAnnotation().setDescription("poodle").setScore(0.1233f));
new GoogleCloudVisionV1EntityAnnotation().setDescription("dog").setScore(0.7564f),
new GoogleCloudVisionV1EntityAnnotation().setDescription("husky").setScore(0.67891f),
new GoogleCloudVisionV1EntityAnnotation().setDescription("poodle").setScore(0.1233f));

// Act
LabelApp.printLabels(out, Paths.get("path/to/some/image.jpg"), labels);
Expand Down
2 changes: 1 addition & 1 deletion vision/landmark-detection/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-vision</artifactId>
<version>v1-rev364-1.23.0</version>
<version>v1-rev365-1.23.0</version>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
Expand Down
Loading