From 833b0736a72f891915182d25310b7a0c4975eedb Mon Sep 17 00:00:00 2001 From: Elliotte Harold Date: Fri, 25 Aug 2017 08:37:12 -0400 Subject: [PATCH 01/22] expand JSON test coverage --- .../tools/libraries/MavenCoordinates.java | 209 ++++++++++++++++++ .../cloud/tools/libraries/LibrariesTest.java | 84 ++++++- .../tools/libraries/MavenCoordinatesTest.java | 164 ++++++++++++++ 3 files changed, 446 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/google/cloud/tools/libraries/MavenCoordinates.java create mode 100644 src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java diff --git a/src/main/java/com/google/cloud/tools/libraries/MavenCoordinates.java b/src/main/java/com/google/cloud/tools/libraries/MavenCoordinates.java new file mode 100644 index 000000000..5fbe5eaf8 --- /dev/null +++ b/src/main/java/com/google/cloud/tools/libraries/MavenCoordinates.java @@ -0,0 +1,209 @@ +/* + * Copyright 2016 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.tools.libraries; + +import com.google.common.base.Preconditions; +import java.text.MessageFormat; + +/** + * Describes a Maven artifact. + */ +public class MavenCoordinates { + + public static final String LATEST_VERSION = "LATEST"; + public static final String JAR_TYPE = "jar"; + public static final String MAVEN_CENTRAL_REPO = "central"; + + private String repository = MAVEN_CENTRAL_REPO; + private String groupId; + private String artifactId; + private String version = LATEST_VERSION; + private String type = JAR_TYPE; + private String classifier; + + /** + * @param groupId the Maven group ID, cannot be null + * @param artifactId the Maven artifact ID, cannot be null + */ + public MavenCoordinates(String groupId, String artifactId) { + Preconditions.checkNotNull(groupId, "groupId null"); + Preconditions.checkNotNull(artifactId, "artifactId null"); + Preconditions.checkArgument(!groupId.isEmpty(), "groupId empty"); + Preconditions.checkArgument(!artifactId.isEmpty(), "artifactId empty"); + + this.groupId = groupId; + this.artifactId = artifactId; + } + + /** + * @return the Maven version of the artifact, defaults to special value + * {@link MavenCoordinates#LATEST_VERSION}, never null + */ + public String getVersion() { + return version; + } + + /** + * @return the Maven packaging type, defaults to jar, never null + */ + public String getType() { + return type; + } + + /** + * @return the Maven classifier or null if it was not set + */ + public String getClassifier() { + return classifier; + } + + /** + * @return the URI or the identifier of the repository used to download the artifact from, never + * null + */ + public String getRepository() { + return repository; + } + + /** + * @return the Maven group ID, never null + */ + public String getGroupId() { + return groupId; + } + + /** + * @return the Maven artifact ID, never null + */ + public String getArtifactId() { + return artifactId; + } + + @Override + public String toString() { + return MessageFormat.format("MavenCoordinates [repository={0}, {1}:{2}:{3}:{4}:{5}]", + repository, groupId, artifactId, type, classifier, version); + } + + @Override + public int hashCode() { + return (groupId + ":" + artifactId + ":" + version).hashCode(); + } + + @Override + public boolean equals(Object o) { + if (o == null || !(o instanceof MavenCoordinates)) { + return false; + } + MavenCoordinates other = (MavenCoordinates) o; + return other.artifactId.equals(artifactId) + && other.groupId.equals(groupId) + && other.version.equals(version); + } + + public Builder toBuilder() { + Builder builder = new Builder(); + builder.groupId = groupId; + builder.artifactId = artifactId; + builder.repository = repository; + builder.version = version; + builder.type = type; + builder.classifier = classifier; + return builder; + } + + public static class Builder { + private String repository = MAVEN_CENTRAL_REPO; + private String groupId; + private String artifactId; + private String version = LATEST_VERSION; + private String type = JAR_TYPE; + private String classifier; + + public MavenCoordinates build() { + MavenCoordinates coordinates = new MavenCoordinates(groupId, artifactId); + coordinates.repository = repository; + coordinates.version = version; + coordinates.type = type; + coordinates.classifier = classifier; + return coordinates; + } + + /** + * @param groupId the Maven group ID + */ + public Builder setGroupId(String groupId) { + Preconditions.checkNotNull(groupId, "groupId null"); + Preconditions.checkArgument(!groupId.isEmpty(), "groupId is empty"); + this.groupId = groupId; + return this; + } + + /** + * @param artifactId the Maven artifact ID + */ + public Builder setArtifactId(String artifactId) { + Preconditions.checkNotNull(artifactId, "artifactId null"); + Preconditions.checkArgument(!artifactId.isEmpty(), "artifactId is empty"); + this.artifactId = artifactId; + return this; + } + + /** + * @param repository the URI or the identifier of the repository used to download the artifact + * from. Cannot be null or empty string. + */ + public Builder setRepository(String repository) { + Preconditions.checkNotNull(repository, "repository null"); + Preconditions.checkArgument(!repository.isEmpty(), "repository is empty"); + this.repository = repository; + return this; + } + + /** + * @param type the Maven packaging type, defaults to jar, cannot be null + * or empty string. + */ + public Builder setType(String type) { + Preconditions.checkNotNull(type, "type is null"); + Preconditions.checkArgument(!type.isEmpty(), "type is empty"); + this.type = type; + return this; + } + + /** + * @param version the Maven version of the artifact, defaults to special value + * {@link MavenCoordinates#LATEST_VERSION}, cannot be null or empty string. + */ + public Builder setVersion(String version) { + Preconditions.checkNotNull(version, "version is null"); + Preconditions.checkArgument(!version.isEmpty(), "version is empty"); + this.version = version; + return this; + } + + /** + * @param classifier the Maven classifier, defaults to null. + */ + public Builder setClassifier(String classifier) { + this.classifier = classifier; + return this; + } + + } + +} \ No newline at end of file diff --git a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java index e15a1b891..f3ffc615f 100644 --- a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java +++ b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java @@ -1,4 +1,20 @@ -package com.google.cloud.tools.libraries; +/* + * Copyright 2017 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package com.google.cloud.tools.libraries; import java.io.File; import java.io.FileInputStream; @@ -7,7 +23,9 @@ import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; +import java.util.HashMap; import java.util.Iterator; +import java.util.Map; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -44,19 +62,63 @@ public void testJson() throws FileNotFoundException, URISyntaxException { Iterator apis = reader.readArray().iterator(); Assert.assertTrue(apis.hasNext()); for (JsonObject api = (JsonObject) apis.next(); apis.hasNext(); api = (JsonObject) apis.next()) { + verifyApi(api); + } + } + + private static void verifyApi(JsonObject api) throws URISyntaxException { + Assert.assertFalse(api.getString("name").isEmpty()); + Assert.assertFalse(api.getString("description").isEmpty()); + String transport = api.getString("transport"); + Assert.assertTrue("http".equals(transport) || "grpc".equals(transport)); + new URI(api.getString("documentation")); + new URI(api.getString("site")); + if (api.getString("icon") != null) { + new URI(api.getString("icon")); + } + JsonArray clients = api.getJsonArray("clients"); + Assert.assertFalse(clients.isEmpty()); + for (int i = 0; i < clients.size(); i++) { + JsonObject client = (JsonObject) clients.get(i); + String status = client.getString("status"); + Assert.assertTrue(status, + "beta".equals(status) || "alpha".equals(status) || "GA".equals(status)); + new URI(client.getString("apireference")); + Assert.assertTrue("1.7.0".equals(client.getString("languageLevel"))); + Assert.assertFalse(client.getString("version").isEmpty()); // todo regex + Assert.assertNotNull(client.getJsonObject("mavenCoordinates")); + if (client.getString("source") != null) { + new URI(client.getString("source")); + } + } + } + + @Test + public void testMavenCoordinates() throws FileNotFoundException, URISyntaxException { + JsonReaderFactory factory = Json.createReaderFactory(null); + InputStream in = + new FileInputStream("src/main/java/com/google/cloud/tools/libraries/libraries.json"); + JsonReader reader = factory.createReader(in); + Iterator apis = reader.readArray().iterator(); + Assert.assertTrue(apis.hasNext()); - new URI(api.getString("documentation")); - if (api.getString("icon") != null) { - new URI(api.getString("icon")); + Map map = new HashMap<>(); + for (JsonObject api = (JsonObject) apis.next(); apis.hasNext(); api = (JsonObject) apis.next()) { + String name = api.getString("name"); + if (map.containsKey(name)) { + Assert.fail(name + " is defined twice"); } - JsonArray clients = api.getJsonArray("clients"); - Assert.assertFalse(clients.isEmpty()); - for (int i = 0; i < clients.size(); i++) { - JsonObject client = (JsonObject) clients.get(i); - String status = client.getString("status"); - Assert.assertTrue(status, - "beta".equals(status) || "alpha".equals(status) || "GA".equals(status)); + JsonObject coordinates = + ((JsonObject) api.getJsonArray("clients").get(0)).getJsonObject("mavenCoordinates"); + MavenCoordinates mavenCoordinates = new MavenCoordinates.Builder() + .setGroupId(coordinates.getString("groupId")) + .setArtifactId(coordinates.getString("artifactId")) + .setVersion(coordinates.getString("version")) + .build(); + if (map.containsValue(mavenCoordinates)) { + Assert.fail(mavenCoordinates + " is defined twice"); } + map.put(name, mavenCoordinates); } } diff --git a/src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java b/src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java new file mode 100644 index 000000000..23f7de759 --- /dev/null +++ b/src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java @@ -0,0 +1,164 @@ +/* + * Copyright 2016 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.tools.libraries; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +public class MavenCoordinatesTest { + + @Test(expected = NullPointerException.class) + public void testConstructorGroupIdNull() { + new MavenCoordinates(null, "artifactId"); + } + + @Test(expected = NullPointerException.class) + public void testConstructorArtifactIdNull() { + new MavenCoordinates("groupId", null); + } + + @Test(expected = IllegalArgumentException.class) + public void testConstructorEmptyGroupId() { + new MavenCoordinates("", "artifactId"); + } + + @Test(expected = IllegalArgumentException.class) + public void testConstructorEmptyArtifactId() { + new MavenCoordinates("groupId", ""); + } + + @Test + public void testConstructorValidArguments() { + MavenCoordinates mavenCoordinates = new MavenCoordinates("groupId", "artifactId"); + assertThat(mavenCoordinates.getGroupId(), is("groupId")); + assertThat(mavenCoordinates.getArtifactId(), is("artifactId")); + } + + @Test + public void testRepositoryDefaultsToCentral() { + MavenCoordinates mavenCoordinates = new MavenCoordinates("b", "c"); + assertThat(mavenCoordinates.getRepository(), is(MavenCoordinates.MAVEN_CENTRAL_REPO)); + } + + @Test(expected = NullPointerException.class) + public void testSetRepositoryNull() { + new MavenCoordinates.Builder().setRepository(null); + } + + @Test(expected = IllegalArgumentException.class) + public void testSetEmptyRepository() { + new MavenCoordinates.Builder().setRepository(""); + } + + @Test + public void testVersionDefaultsToLatest() { + MavenCoordinates mavenCoordinates = new MavenCoordinates("groupId", "artifactId"); + assertThat(mavenCoordinates.getVersion(), is(MavenCoordinates.LATEST_VERSION)); + } + + @Test(expected = NullPointerException.class) + public void testSetNullVersion() { + new MavenCoordinates.Builder().setVersion(null); + } + + @Test(expected = IllegalArgumentException.class) + public void testSetEmptyVersion() { + new MavenCoordinates.Builder().setVersion(""); + } + + @Test + public void setVersion() { + MavenCoordinates mavenCoordinates = new MavenCoordinates.Builder() + .setGroupId("g") + .setArtifactId("a") + .setVersion("1") + .build(); + assertThat(mavenCoordinates.getVersion(), is("1")); + } + + @Test + public void testTypeDefaultsToJar() { + MavenCoordinates mavenCoordinates = new MavenCoordinates.Builder() + .setGroupId("g") + .setArtifactId("a") + .build(); + assertThat(mavenCoordinates.getType(), is(MavenCoordinates.JAR_TYPE)); + } + + @Test(expected = NullPointerException.class) + public void testSetNullType() { + new MavenCoordinates.Builder() + .setGroupId("g") + .setArtifactId("a") + .setType(null) + .build(); + } + + @Test(expected = IllegalArgumentException.class) + public void testSetEmptyType() { + new MavenCoordinates.Builder().setGroupId("g").setArtifactId("a").setType("").build(); + } + + @Test + public void testSetType() { + MavenCoordinates mavenCoordinates = new MavenCoordinates.Builder() + .setGroupId("g") + .setArtifactId("a") + .setType("war") + .build(); + assertThat(mavenCoordinates.getType(), is("war")); + } + + @Test + public void testClassifierDefaultsToNull() { + MavenCoordinates mavenCoordinates = new MavenCoordinates("groupId", "artifactId"); + assertNull(mavenCoordinates.getClassifier()); + } + + @Test + public void testSetClassifier() { + MavenCoordinates mavenCoordinates = new MavenCoordinates.Builder() + .setGroupId("g") + .setArtifactId("a") + .setClassifier("d") + .build(); + assertThat(mavenCoordinates.getClassifier(), is("d")); + } + + @Test + public void testSetNullClassifier() { + MavenCoordinates mavenCoordinates = new MavenCoordinates.Builder() + .setGroupId("g") + .setArtifactId("a") + .setClassifier(null) + .build(); + assertNull(mavenCoordinates.getClassifier()); + } + + @Test + public void testSetEmptyClassifier() { + MavenCoordinates mavenCoordinates = new MavenCoordinates.Builder() + .setGroupId("g") + .setArtifactId("a") + .setClassifier("") + .build(); + assertThat(mavenCoordinates.getClassifier(), is("")); + } +} \ No newline at end of file From 41e8f2928cce92119f15317e9519f3e7e36e94ab Mon Sep 17 00:00:00 2001 From: Elliotte Harold Date: Fri, 25 Aug 2017 10:48:48 -0400 Subject: [PATCH 02/22] add test for equals --- .../tools/libraries/MavenCoordinatesTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java b/src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java index 23f7de759..718ccee3b 100644 --- a/src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java +++ b/src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java @@ -17,6 +17,8 @@ package com.google.cloud.tools.libraries; import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; @@ -161,4 +163,23 @@ public void testSetEmptyClassifier() { .build(); assertThat(mavenCoordinates.getClassifier(), is("")); } + + @Test + public void testEquals() { + MavenCoordinates mavenCoordinates1 = new MavenCoordinates.Builder() + .setGroupId("g") + .setArtifactId("a") + .setClassifier("") + .build(); + MavenCoordinates mavenCoordinates2 = mavenCoordinates1.toBuilder().build(); + MavenCoordinates mavenCoordinates3 = mavenCoordinates1.toBuilder() + .setVersion("1.9.3") + .build(); + + assertEquals(mavenCoordinates1, mavenCoordinates2); + assertNotEquals(mavenCoordinates1, mavenCoordinates3); + assertNotEquals(mavenCoordinates1.hashCode(), mavenCoordinates3.hashCode()); + assertNotEquals(mavenCoordinates1, null); + assertNotEquals(mavenCoordinates1, "g:a:1.9.3"); + } } \ No newline at end of file From 896ac8f344c6729471aa2b979f3ee0ca36b95e86 Mon Sep 17 00:00:00 2001 From: Elliotte Harold Date: Fri, 25 Aug 2017 11:46:42 -0400 Subject: [PATCH 03/22] hamcrest --- pom.xml | 12 ++++++++++++ .../cloud/tools/libraries/LibrariesTest.java | 19 ++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 5c2f8fcde..3c48025f5 100644 --- a/pom.xml +++ b/pom.xml @@ -116,6 +116,18 @@ 2.7.17 test + + org.hamcrest + hamcrest-core + 1.3 + test + + + org.hamcrest + hamcrest-library + 1.3 + test + diff --git a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java index f3ffc615f..129036472 100644 --- a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java +++ b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java @@ -16,6 +16,8 @@ package com.google.cloud.tools.libraries; +import static org.hamcrest.collection.IsArrayContaining.hasItemInArray; + import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -27,6 +29,12 @@ import java.util.Iterator; import java.util.Map; +import javax.json.Json; +import javax.json.JsonArray; +import javax.json.JsonObject; +import javax.json.JsonReader; +import javax.json.JsonReaderFactory; +import javax.json.JsonValue; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; @@ -35,13 +43,6 @@ import org.junit.Test; import org.xml.sax.SAXException; -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonObject; -import javax.json.JsonReader; -import javax.json.JsonReaderFactory; -import javax.json.JsonValue; - public class LibrariesTest { @Test @@ -66,6 +67,8 @@ public void testJson() throws FileNotFoundException, URISyntaxException { } } + private static final String[] statuses = {"alpha", "beta", "GA"}; + private static void verifyApi(JsonObject api) throws URISyntaxException { Assert.assertFalse(api.getString("name").isEmpty()); Assert.assertFalse(api.getString("description").isEmpty()); @@ -81,6 +84,8 @@ private static void verifyApi(JsonObject api) throws URISyntaxException { for (int i = 0; i < clients.size(); i++) { JsonObject client = (JsonObject) clients.get(i); String status = client.getString("status"); + + Assert.assertThat(statuses, hasItemInArray(status)); Assert.assertTrue(status, "beta".equals(status) || "alpha".equals(status) || "GA".equals(status)); new URI(client.getString("apireference")); From 500ee93335f17893a1a68faf4314acc5965e6ac0 Mon Sep 17 00:00:00 2001 From: Elliotte Harold Date: Fri, 25 Aug 2017 11:58:17 -0400 Subject: [PATCH 04/22] redundant assert removed --- .../java/com/google/cloud/tools/libraries/LibrariesTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java index 129036472..b7d2b3188 100644 --- a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java +++ b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java @@ -86,8 +86,6 @@ private static void verifyApi(JsonObject api) throws URISyntaxException { String status = client.getString("status"); Assert.assertThat(statuses, hasItemInArray(status)); - Assert.assertTrue(status, - "beta".equals(status) || "alpha".equals(status) || "GA".equals(status)); new URI(client.getString("apireference")); Assert.assertTrue("1.7.0".equals(client.getString("languageLevel"))); Assert.assertFalse(client.getString("version").isEmpty()); // todo regex From eb8283a005262a842ca87f3391df96f7dc331d18 Mon Sep 17 00:00:00 2001 From: Elliotte Harold Date: Fri, 25 Aug 2017 12:09:07 -0400 Subject: [PATCH 05/22] fix loop --- .../java/com/google/cloud/tools/libraries/LibrariesTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java index b7d2b3188..19802cf00 100644 --- a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java +++ b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java @@ -75,7 +75,6 @@ private static void verifyApi(JsonObject api) throws URISyntaxException { String transport = api.getString("transport"); Assert.assertTrue("http".equals(transport) || "grpc".equals(transport)); new URI(api.getString("documentation")); - new URI(api.getString("site")); if (api.getString("icon") != null) { new URI(api.getString("icon")); } @@ -87,6 +86,7 @@ private static void verifyApi(JsonObject api) throws URISyntaxException { Assert.assertThat(statuses, hasItemInArray(status)); new URI(client.getString("apireference")); + new URI(client.getString("site")); Assert.assertTrue("1.7.0".equals(client.getString("languageLevel"))); Assert.assertFalse(client.getString("version").isEmpty()); // todo regex Assert.assertNotNull(client.getJsonObject("mavenCoordinates")); @@ -106,7 +106,8 @@ public void testMavenCoordinates() throws FileNotFoundException, URISyntaxExcept Assert.assertTrue(apis.hasNext()); Map map = new HashMap<>(); - for (JsonObject api = (JsonObject) apis.next(); apis.hasNext(); api = (JsonObject) apis.next()) { + while (apis.hasNext()) { + JsonObject api = (JsonObject) apis.next(); String name = api.getString("name"); if (map.containsKey(name)) { Assert.fail(name + " is defined twice"); From 568fd0e3ae6aba1bb9fef02de574536546684d01 Mon Sep 17 00:00:00 2001 From: Elliotte Harold Date: Fri, 25 Aug 2017 12:09:56 -0400 Subject: [PATCH 06/22] fix loop --- .../java/com/google/cloud/tools/libraries/LibrariesTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java index 19802cf00..841be9a54 100644 --- a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java +++ b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java @@ -62,7 +62,8 @@ public void testJson() throws FileNotFoundException, URISyntaxException { JsonReader reader = factory.createReader(in); Iterator apis = reader.readArray().iterator(); Assert.assertTrue(apis.hasNext()); - for (JsonObject api = (JsonObject) apis.next(); apis.hasNext(); api = (JsonObject) apis.next()) { + while (apis.hasNext()) { + JsonObject api = (JsonObject) apis.next(); verifyApi(api); } } From 653117fa68a330feef1f259d989e01ffcb43ac78 Mon Sep 17 00:00:00 2001 From: Elliotte Harold Date: Fri, 25 Aug 2017 12:14:36 -0400 Subject: [PATCH 07/22] regex versions --- .../java/com/google/cloud/tools/libraries/LibrariesTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java index 841be9a54..a97ab530c 100644 --- a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java +++ b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java @@ -88,8 +88,9 @@ private static void verifyApi(JsonObject api) throws URISyntaxException { Assert.assertThat(statuses, hasItemInArray(status)); new URI(client.getString("apireference")); new URI(client.getString("site")); - Assert.assertTrue("1.7.0".equals(client.getString("languageLevel"))); - Assert.assertFalse(client.getString("version").isEmpty()); // todo regex + Assert.assertTrue(client.getString("languageLevel").matches("1\\.\\d+\\.\\d+")); + String versionString = client.getString("version"); + Assert.assertTrue(versionString.matches("\\d+\\.\\d+\\.\\d+")); Assert.assertNotNull(client.getJsonObject("mavenCoordinates")); if (client.getString("source") != null) { new URI(client.getString("source")); From 4de1ae1b96b8eb434f4732c4fddfc2aa6328a591 Mon Sep 17 00:00:00 2001 From: Elliotte Harold Date: Fri, 25 Aug 2017 12:20:40 -0400 Subject: [PATCH 08/22] don't make repo a corrdinate --- .../tools/libraries/MavenCoordinates.java | 28 ++----------------- .../tools/libraries/MavenCoordinatesTest.java | 16 ----------- 2 files changed, 2 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/google/cloud/tools/libraries/MavenCoordinates.java b/src/main/java/com/google/cloud/tools/libraries/MavenCoordinates.java index 5fbe5eaf8..44508c1f6 100644 --- a/src/main/java/com/google/cloud/tools/libraries/MavenCoordinates.java +++ b/src/main/java/com/google/cloud/tools/libraries/MavenCoordinates.java @@ -26,9 +26,7 @@ public class MavenCoordinates { public static final String LATEST_VERSION = "LATEST"; public static final String JAR_TYPE = "jar"; - public static final String MAVEN_CENTRAL_REPO = "central"; - private String repository = MAVEN_CENTRAL_REPO; private String groupId; private String artifactId; private String version = LATEST_VERSION; @@ -71,14 +69,6 @@ public String getClassifier() { return classifier; } - /** - * @return the URI or the identifier of the repository used to download the artifact from, never - * null - */ - public String getRepository() { - return repository; - } - /** * @return the Maven group ID, never null */ @@ -95,8 +85,8 @@ public String getArtifactId() { @Override public String toString() { - return MessageFormat.format("MavenCoordinates [repository={0}, {1}:{2}:{3}:{4}:{5}]", - repository, groupId, artifactId, type, classifier, version); + return MessageFormat.format("MavenCoordinates [repository={0}, {1}:{2}:{3}:{4}]", + groupId, artifactId, type, classifier, version); } @Override @@ -119,7 +109,6 @@ public Builder toBuilder() { Builder builder = new Builder(); builder.groupId = groupId; builder.artifactId = artifactId; - builder.repository = repository; builder.version = version; builder.type = type; builder.classifier = classifier; @@ -127,7 +116,6 @@ public Builder toBuilder() { } public static class Builder { - private String repository = MAVEN_CENTRAL_REPO; private String groupId; private String artifactId; private String version = LATEST_VERSION; @@ -136,7 +124,6 @@ public static class Builder { public MavenCoordinates build() { MavenCoordinates coordinates = new MavenCoordinates(groupId, artifactId); - coordinates.repository = repository; coordinates.version = version; coordinates.type = type; coordinates.classifier = classifier; @@ -163,17 +150,6 @@ public Builder setArtifactId(String artifactId) { return this; } - /** - * @param repository the URI or the identifier of the repository used to download the artifact - * from. Cannot be null or empty string. - */ - public Builder setRepository(String repository) { - Preconditions.checkNotNull(repository, "repository null"); - Preconditions.checkArgument(!repository.isEmpty(), "repository is empty"); - this.repository = repository; - return this; - } - /** * @param type the Maven packaging type, defaults to jar, cannot be null * or empty string. diff --git a/src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java b/src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java index 718ccee3b..44f9a8b2c 100644 --- a/src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java +++ b/src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java @@ -53,22 +53,6 @@ public void testConstructorValidArguments() { assertThat(mavenCoordinates.getArtifactId(), is("artifactId")); } - @Test - public void testRepositoryDefaultsToCentral() { - MavenCoordinates mavenCoordinates = new MavenCoordinates("b", "c"); - assertThat(mavenCoordinates.getRepository(), is(MavenCoordinates.MAVEN_CENTRAL_REPO)); - } - - @Test(expected = NullPointerException.class) - public void testSetRepositoryNull() { - new MavenCoordinates.Builder().setRepository(null); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetEmptyRepository() { - new MavenCoordinates.Builder().setRepository(""); - } - @Test public void testVersionDefaultsToLatest() { MavenCoordinates mavenCoordinates = new MavenCoordinates("groupId", "artifactId"); From 614673780017b8a617872945d7ed94c6f2276277 Mon Sep 17 00:00:00 2001 From: Elliotte Harold Date: Fri, 25 Aug 2017 12:26:22 -0400 Subject: [PATCH 09/22] type to packaging --- .../tools/libraries/MavenCoordinates.java | 24 +++++++++---------- .../tools/libraries/MavenCoordinatesTest.java | 10 ++++---- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/google/cloud/tools/libraries/MavenCoordinates.java b/src/main/java/com/google/cloud/tools/libraries/MavenCoordinates.java index 44508c1f6..78789b4c4 100644 --- a/src/main/java/com/google/cloud/tools/libraries/MavenCoordinates.java +++ b/src/main/java/com/google/cloud/tools/libraries/MavenCoordinates.java @@ -27,10 +27,10 @@ public class MavenCoordinates { public static final String LATEST_VERSION = "LATEST"; public static final String JAR_TYPE = "jar"; - private String groupId; - private String artifactId; + private final String groupId; + private final String artifactId; private String version = LATEST_VERSION; - private String type = JAR_TYPE; + private String packaging = JAR_TYPE; private String classifier; /** @@ -58,8 +58,8 @@ public String getVersion() { /** * @return the Maven packaging type, defaults to jar, never null */ - public String getType() { - return type; + public String getPackaging() { + return packaging; } /** @@ -86,7 +86,7 @@ public String getArtifactId() { @Override public String toString() { return MessageFormat.format("MavenCoordinates [repository={0}, {1}:{2}:{3}:{4}]", - groupId, artifactId, type, classifier, version); + groupId, artifactId, packaging, classifier, version); } @Override @@ -110,7 +110,7 @@ public Builder toBuilder() { builder.groupId = groupId; builder.artifactId = artifactId; builder.version = version; - builder.type = type; + builder.packaging = packaging; builder.classifier = classifier; return builder; } @@ -119,13 +119,13 @@ public static class Builder { private String groupId; private String artifactId; private String version = LATEST_VERSION; - private String type = JAR_TYPE; + private String packaging = JAR_TYPE; private String classifier; public MavenCoordinates build() { MavenCoordinates coordinates = new MavenCoordinates(groupId, artifactId); coordinates.version = version; - coordinates.type = type; + coordinates.packaging = packaging; coordinates.classifier = classifier; return coordinates; } @@ -151,13 +151,13 @@ public Builder setArtifactId(String artifactId) { } /** - * @param type the Maven packaging type, defaults to jar, cannot be null + * @param type the Maven packaging type, defaults to jar. Cannot be null * or empty string. */ - public Builder setType(String type) { + public Builder setPackaging(String type) { Preconditions.checkNotNull(type, "type is null"); Preconditions.checkArgument(!type.isEmpty(), "type is empty"); - this.type = type; + this.packaging = type; return this; } diff --git a/src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java b/src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java index 44f9a8b2c..ca1ffd3bd 100644 --- a/src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java +++ b/src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java @@ -85,7 +85,7 @@ public void testTypeDefaultsToJar() { .setGroupId("g") .setArtifactId("a") .build(); - assertThat(mavenCoordinates.getType(), is(MavenCoordinates.JAR_TYPE)); + assertThat(mavenCoordinates.getPackaging(), is(MavenCoordinates.JAR_TYPE)); } @Test(expected = NullPointerException.class) @@ -93,13 +93,13 @@ public void testSetNullType() { new MavenCoordinates.Builder() .setGroupId("g") .setArtifactId("a") - .setType(null) + .setPackaging(null) .build(); } @Test(expected = IllegalArgumentException.class) public void testSetEmptyType() { - new MavenCoordinates.Builder().setGroupId("g").setArtifactId("a").setType("").build(); + new MavenCoordinates.Builder().setGroupId("g").setArtifactId("a").setPackaging("").build(); } @Test @@ -107,9 +107,9 @@ public void testSetType() { MavenCoordinates mavenCoordinates = new MavenCoordinates.Builder() .setGroupId("g") .setArtifactId("a") - .setType("war") + .setPackaging("war") .build(); - assertThat(mavenCoordinates.getType(), is("war")); + assertThat(mavenCoordinates.getPackaging(), is("war")); } @Test From 4e6949f8c1cf9e829c4e173a2c896cc3287c5927 Mon Sep 17 00:00:00 2001 From: Elliotte Harold Date: Fri, 25 Aug 2017 12:30:52 -0400 Subject: [PATCH 10/22] verify group ID artifact ID --- .../com/google/cloud/tools/libraries/LibrariesTest.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java index a97ab530c..3b1b6154a 100644 --- a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java +++ b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java @@ -107,7 +107,7 @@ public void testMavenCoordinates() throws FileNotFoundException, URISyntaxExcept Iterator apis = reader.readArray().iterator(); Assert.assertTrue(apis.hasNext()); - Map map = new HashMap<>(); + Map map = new HashMap<>(); while (apis.hasNext()) { JsonObject api = (JsonObject) apis.next(); String name = api.getString("name"); @@ -116,11 +116,8 @@ public void testMavenCoordinates() throws FileNotFoundException, URISyntaxExcept } JsonObject coordinates = ((JsonObject) api.getJsonArray("clients").get(0)).getJsonObject("mavenCoordinates"); - MavenCoordinates mavenCoordinates = new MavenCoordinates.Builder() - .setGroupId(coordinates.getString("groupId")) - .setArtifactId(coordinates.getString("artifactId")) - .setVersion(coordinates.getString("version")) - .build(); + String mavenCoordinates = + coordinates.getString("groupId") + ":" + coordinates.getString("artifactId"); if (map.containsValue(mavenCoordinates)) { Assert.fail(mavenCoordinates + " is defined twice"); } From 26e02d9c0f853bd396767edf74aa8796d91aafa7 Mon Sep 17 00:00:00 2001 From: Elliotte Harold Date: Fri, 25 Aug 2017 14:21:19 -0400 Subject: [PATCH 11/22] checkstyle fixes --- .../tools/libraries/MavenCoordinates.java | 64 +++++++++++++++---- .../tools/libraries/MavenCoordinatesTest.java | 2 +- 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/google/cloud/tools/libraries/MavenCoordinates.java b/src/main/java/com/google/cloud/tools/libraries/MavenCoordinates.java index 78789b4c4..74eef65d4 100644 --- a/src/main/java/com/google/cloud/tools/libraries/MavenCoordinates.java +++ b/src/main/java/com/google/cloud/tools/libraries/MavenCoordinates.java @@ -25,7 +25,7 @@ public class MavenCoordinates { public static final String LATEST_VERSION = "LATEST"; - public static final String JAR_TYPE = "jar"; + private static final String JAR_TYPE = "jar"; private final String groupId; private final String artifactId; @@ -34,6 +34,8 @@ public class MavenCoordinates { private String classifier; /** + * Create a new MavenCoordinates object. + * * @param groupId the Maven group ID, cannot be null * @param artifactId the Maven artifact ID, cannot be null */ @@ -48,14 +50,18 @@ public MavenCoordinates(String groupId, String artifactId) { } /** - * @return the Maven version of the artifact, defaults to special value - * {@link MavenCoordinates#LATEST_VERSION}, never null + * Returns the Maven version of the artifact. Defaults to the special value + * {@link MavenCoordinates#LATEST_VERSION}, + * + * @return the Maven version of the artifact, never null */ public String getVersion() { return version; } /** + * Returns the Maven packaging type, defaults to jar, never null. + * * @return the Maven packaging type, defaults to jar, never null */ public String getPackaging() { @@ -63,6 +69,8 @@ public String getPackaging() { } /** + * Returns the Maven classifier. + * * @return the Maven classifier or null if it was not set */ public String getClassifier() { @@ -70,6 +78,8 @@ public String getClassifier() { } /** + * Returns the Maven group ID. + * * @return the Maven group ID, never null */ public String getGroupId() { @@ -77,6 +87,8 @@ public String getGroupId() { } /** + * Returns the Maven artifact ID. + * * @return the Maven artifact ID, never null */ public String getArtifactId() { @@ -86,25 +98,41 @@ public String getArtifactId() { @Override public String toString() { return MessageFormat.format("MavenCoordinates [repository={0}, {1}:{2}:{3}:{4}]", - groupId, artifactId, packaging, classifier, version); + groupId, artifactId, packaging, classifier, version); } @Override public int hashCode() { - return (groupId + ":" + artifactId + ":" + version).hashCode(); + return getCoordinates().hashCode(); + } + + private String getCoordinates() { + String coordinates = groupId + ":" + artifactId + ":" + version; + if (classifier != null) { + coordinates += ":" + classifier; + } + if (!packaging.equals(JAR_TYPE)) { + coordinates += ":" + packaging; + } + return coordinates; } @Override - public boolean equals(Object o) { - if (o == null || !(o instanceof MavenCoordinates)) { + public boolean equals(Object other) { + if (other == null || !(other instanceof MavenCoordinates)) { return false; } - MavenCoordinates other = (MavenCoordinates) o; - return other.artifactId.equals(artifactId) - && other.groupId.equals(groupId) - && other.version.equals(version); + MavenCoordinates coordinates = (MavenCoordinates) other; + return coordinates.artifactId.equals(artifactId) + && coordinates.groupId.equals(groupId) + && coordinates.version.equals(version) + && coordinates.classifier.equals(classifier) + && coordinates.packaging.equals(packaging); } + /** + * A builder initially configured to create a copy of this object. + */ public Builder toBuilder() { Builder builder = new Builder(); builder.groupId = groupId; @@ -115,6 +143,9 @@ public Builder toBuilder() { return builder; } + /** + * A builder for immutable MavenCoordinates objects. + */ public static class Builder { private String groupId; private String artifactId; @@ -122,6 +153,9 @@ public static class Builder { private String packaging = JAR_TYPE; private String classifier; + /** + * Create a new MavenCoordinates object. + */ public MavenCoordinates build() { MavenCoordinates coordinates = new MavenCoordinates(groupId, artifactId); coordinates.version = version; @@ -131,6 +165,8 @@ public MavenCoordinates build() { } /** + * Specify the Maven group ID. + * * @param groupId the Maven group ID */ public Builder setGroupId(String groupId) { @@ -141,6 +177,8 @@ public Builder setGroupId(String groupId) { } /** + * Specify the Maven artifact ID. + * * @param artifactId the Maven artifact ID */ public Builder setArtifactId(String artifactId) { @@ -151,8 +189,8 @@ public Builder setArtifactId(String artifactId) { } /** - * @param type the Maven packaging type, defaults to jar. Cannot be null - * or empty string. + * @param type the Maven packaging type, defaults to jar. + * Cannot be null or empty string. */ public Builder setPackaging(String type) { Preconditions.checkNotNull(type, "type is null"); diff --git a/src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java b/src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java index ca1ffd3bd..0e0522eb5 100644 --- a/src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java +++ b/src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java @@ -85,7 +85,7 @@ public void testTypeDefaultsToJar() { .setGroupId("g") .setArtifactId("a") .build(); - assertThat(mavenCoordinates.getPackaging(), is(MavenCoordinates.JAR_TYPE)); + assertEquals("jar", mavenCoordinates.getPackaging()); } @Test(expected = NullPointerException.class) From a29e99305c3b6ef0a50b4bf6bbe5626122777323 Mon Sep 17 00:00:00 2001 From: Elliotte Harold Date: Fri, 25 Aug 2017 14:29:48 -0400 Subject: [PATCH 12/22] revert metadata for now --- .../tools/libraries/MavenCoordinates.java | 223 ------------------ .../tools/libraries/MavenCoordinatesTest.java | 169 ------------- 2 files changed, 392 deletions(-) delete mode 100644 src/main/java/com/google/cloud/tools/libraries/MavenCoordinates.java delete mode 100644 src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java diff --git a/src/main/java/com/google/cloud/tools/libraries/MavenCoordinates.java b/src/main/java/com/google/cloud/tools/libraries/MavenCoordinates.java deleted file mode 100644 index 74eef65d4..000000000 --- a/src/main/java/com/google/cloud/tools/libraries/MavenCoordinates.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud.tools.libraries; - -import com.google.common.base.Preconditions; -import java.text.MessageFormat; - -/** - * Describes a Maven artifact. - */ -public class MavenCoordinates { - - public static final String LATEST_VERSION = "LATEST"; - private static final String JAR_TYPE = "jar"; - - private final String groupId; - private final String artifactId; - private String version = LATEST_VERSION; - private String packaging = JAR_TYPE; - private String classifier; - - /** - * Create a new MavenCoordinates object. - * - * @param groupId the Maven group ID, cannot be null - * @param artifactId the Maven artifact ID, cannot be null - */ - public MavenCoordinates(String groupId, String artifactId) { - Preconditions.checkNotNull(groupId, "groupId null"); - Preconditions.checkNotNull(artifactId, "artifactId null"); - Preconditions.checkArgument(!groupId.isEmpty(), "groupId empty"); - Preconditions.checkArgument(!artifactId.isEmpty(), "artifactId empty"); - - this.groupId = groupId; - this.artifactId = artifactId; - } - - /** - * Returns the Maven version of the artifact. Defaults to the special value - * {@link MavenCoordinates#LATEST_VERSION}, - * - * @return the Maven version of the artifact, never null - */ - public String getVersion() { - return version; - } - - /** - * Returns the Maven packaging type, defaults to jar, never null. - * - * @return the Maven packaging type, defaults to jar, never null - */ - public String getPackaging() { - return packaging; - } - - /** - * Returns the Maven classifier. - * - * @return the Maven classifier or null if it was not set - */ - public String getClassifier() { - return classifier; - } - - /** - * Returns the Maven group ID. - * - * @return the Maven group ID, never null - */ - public String getGroupId() { - return groupId; - } - - /** - * Returns the Maven artifact ID. - * - * @return the Maven artifact ID, never null - */ - public String getArtifactId() { - return artifactId; - } - - @Override - public String toString() { - return MessageFormat.format("MavenCoordinates [repository={0}, {1}:{2}:{3}:{4}]", - groupId, artifactId, packaging, classifier, version); - } - - @Override - public int hashCode() { - return getCoordinates().hashCode(); - } - - private String getCoordinates() { - String coordinates = groupId + ":" + artifactId + ":" + version; - if (classifier != null) { - coordinates += ":" + classifier; - } - if (!packaging.equals(JAR_TYPE)) { - coordinates += ":" + packaging; - } - return coordinates; - } - - @Override - public boolean equals(Object other) { - if (other == null || !(other instanceof MavenCoordinates)) { - return false; - } - MavenCoordinates coordinates = (MavenCoordinates) other; - return coordinates.artifactId.equals(artifactId) - && coordinates.groupId.equals(groupId) - && coordinates.version.equals(version) - && coordinates.classifier.equals(classifier) - && coordinates.packaging.equals(packaging); - } - - /** - * A builder initially configured to create a copy of this object. - */ - public Builder toBuilder() { - Builder builder = new Builder(); - builder.groupId = groupId; - builder.artifactId = artifactId; - builder.version = version; - builder.packaging = packaging; - builder.classifier = classifier; - return builder; - } - - /** - * A builder for immutable MavenCoordinates objects. - */ - public static class Builder { - private String groupId; - private String artifactId; - private String version = LATEST_VERSION; - private String packaging = JAR_TYPE; - private String classifier; - - /** - * Create a new MavenCoordinates object. - */ - public MavenCoordinates build() { - MavenCoordinates coordinates = new MavenCoordinates(groupId, artifactId); - coordinates.version = version; - coordinates.packaging = packaging; - coordinates.classifier = classifier; - return coordinates; - } - - /** - * Specify the Maven group ID. - * - * @param groupId the Maven group ID - */ - public Builder setGroupId(String groupId) { - Preconditions.checkNotNull(groupId, "groupId null"); - Preconditions.checkArgument(!groupId.isEmpty(), "groupId is empty"); - this.groupId = groupId; - return this; - } - - /** - * Specify the Maven artifact ID. - * - * @param artifactId the Maven artifact ID - */ - public Builder setArtifactId(String artifactId) { - Preconditions.checkNotNull(artifactId, "artifactId null"); - Preconditions.checkArgument(!artifactId.isEmpty(), "artifactId is empty"); - this.artifactId = artifactId; - return this; - } - - /** - * @param type the Maven packaging type, defaults to jar. - * Cannot be null or empty string. - */ - public Builder setPackaging(String type) { - Preconditions.checkNotNull(type, "type is null"); - Preconditions.checkArgument(!type.isEmpty(), "type is empty"); - this.packaging = type; - return this; - } - - /** - * @param version the Maven version of the artifact, defaults to special value - * {@link MavenCoordinates#LATEST_VERSION}, cannot be null or empty string. - */ - public Builder setVersion(String version) { - Preconditions.checkNotNull(version, "version is null"); - Preconditions.checkArgument(!version.isEmpty(), "version is empty"); - this.version = version; - return this; - } - - /** - * @param classifier the Maven classifier, defaults to null. - */ - public Builder setClassifier(String classifier) { - this.classifier = classifier; - return this; - } - - } - -} \ No newline at end of file diff --git a/src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java b/src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java deleted file mode 100644 index 0e0522eb5..000000000 --- a/src/test/java/com/google/cloud/tools/libraries/MavenCoordinatesTest.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud.tools.libraries; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; - -import org.junit.Test; - -public class MavenCoordinatesTest { - - @Test(expected = NullPointerException.class) - public void testConstructorGroupIdNull() { - new MavenCoordinates(null, "artifactId"); - } - - @Test(expected = NullPointerException.class) - public void testConstructorArtifactIdNull() { - new MavenCoordinates("groupId", null); - } - - @Test(expected = IllegalArgumentException.class) - public void testConstructorEmptyGroupId() { - new MavenCoordinates("", "artifactId"); - } - - @Test(expected = IllegalArgumentException.class) - public void testConstructorEmptyArtifactId() { - new MavenCoordinates("groupId", ""); - } - - @Test - public void testConstructorValidArguments() { - MavenCoordinates mavenCoordinates = new MavenCoordinates("groupId", "artifactId"); - assertThat(mavenCoordinates.getGroupId(), is("groupId")); - assertThat(mavenCoordinates.getArtifactId(), is("artifactId")); - } - - @Test - public void testVersionDefaultsToLatest() { - MavenCoordinates mavenCoordinates = new MavenCoordinates("groupId", "artifactId"); - assertThat(mavenCoordinates.getVersion(), is(MavenCoordinates.LATEST_VERSION)); - } - - @Test(expected = NullPointerException.class) - public void testSetNullVersion() { - new MavenCoordinates.Builder().setVersion(null); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetEmptyVersion() { - new MavenCoordinates.Builder().setVersion(""); - } - - @Test - public void setVersion() { - MavenCoordinates mavenCoordinates = new MavenCoordinates.Builder() - .setGroupId("g") - .setArtifactId("a") - .setVersion("1") - .build(); - assertThat(mavenCoordinates.getVersion(), is("1")); - } - - @Test - public void testTypeDefaultsToJar() { - MavenCoordinates mavenCoordinates = new MavenCoordinates.Builder() - .setGroupId("g") - .setArtifactId("a") - .build(); - assertEquals("jar", mavenCoordinates.getPackaging()); - } - - @Test(expected = NullPointerException.class) - public void testSetNullType() { - new MavenCoordinates.Builder() - .setGroupId("g") - .setArtifactId("a") - .setPackaging(null) - .build(); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetEmptyType() { - new MavenCoordinates.Builder().setGroupId("g").setArtifactId("a").setPackaging("").build(); - } - - @Test - public void testSetType() { - MavenCoordinates mavenCoordinates = new MavenCoordinates.Builder() - .setGroupId("g") - .setArtifactId("a") - .setPackaging("war") - .build(); - assertThat(mavenCoordinates.getPackaging(), is("war")); - } - - @Test - public void testClassifierDefaultsToNull() { - MavenCoordinates mavenCoordinates = new MavenCoordinates("groupId", "artifactId"); - assertNull(mavenCoordinates.getClassifier()); - } - - @Test - public void testSetClassifier() { - MavenCoordinates mavenCoordinates = new MavenCoordinates.Builder() - .setGroupId("g") - .setArtifactId("a") - .setClassifier("d") - .build(); - assertThat(mavenCoordinates.getClassifier(), is("d")); - } - - @Test - public void testSetNullClassifier() { - MavenCoordinates mavenCoordinates = new MavenCoordinates.Builder() - .setGroupId("g") - .setArtifactId("a") - .setClassifier(null) - .build(); - assertNull(mavenCoordinates.getClassifier()); - } - - @Test - public void testSetEmptyClassifier() { - MavenCoordinates mavenCoordinates = new MavenCoordinates.Builder() - .setGroupId("g") - .setArtifactId("a") - .setClassifier("") - .build(); - assertThat(mavenCoordinates.getClassifier(), is("")); - } - - @Test - public void testEquals() { - MavenCoordinates mavenCoordinates1 = new MavenCoordinates.Builder() - .setGroupId("g") - .setArtifactId("a") - .setClassifier("") - .build(); - MavenCoordinates mavenCoordinates2 = mavenCoordinates1.toBuilder().build(); - MavenCoordinates mavenCoordinates3 = mavenCoordinates1.toBuilder() - .setVersion("1.9.3") - .build(); - - assertEquals(mavenCoordinates1, mavenCoordinates2); - assertNotEquals(mavenCoordinates1, mavenCoordinates3); - assertNotEquals(mavenCoordinates1.hashCode(), mavenCoordinates3.hashCode()); - assertNotEquals(mavenCoordinates1, null); - assertNotEquals(mavenCoordinates1, "g:a:1.9.3"); - } -} \ No newline at end of file From ec131517fdbf4a1e3d1050b9270f88599e99fa8e Mon Sep 17 00:00:00 2001 From: Elliotte Harold Date: Fri, 25 Aug 2017 15:04:12 -0400 Subject: [PATCH 13/22] code review --- .../cloud/tools/libraries/LibrariesTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java index 3b1b6154a..ac41be736 100644 --- a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java +++ b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java @@ -64,13 +64,13 @@ public void testJson() throws FileNotFoundException, URISyntaxException { Assert.assertTrue(apis.hasNext()); while (apis.hasNext()) { JsonObject api = (JsonObject) apis.next(); - verifyApi(api); + assertApi(api); } } private static final String[] statuses = {"alpha", "beta", "GA"}; - private static void verifyApi(JsonObject api) throws URISyntaxException { + private static void assertApi(JsonObject api) throws URISyntaxException { Assert.assertFalse(api.getString("name").isEmpty()); Assert.assertFalse(api.getString("description").isEmpty()); String transport = api.getString("transport"); @@ -99,7 +99,7 @@ private static void verifyApi(JsonObject api) throws URISyntaxException { } @Test - public void testMavenCoordinates() throws FileNotFoundException, URISyntaxException { + public void testDuplicates() throws FileNotFoundException, URISyntaxException { JsonReaderFactory factory = Json.createReaderFactory(null); InputStream in = new FileInputStream("src/main/java/com/google/cloud/tools/libraries/libraries.json"); @@ -107,21 +107,21 @@ public void testMavenCoordinates() throws FileNotFoundException, URISyntaxExcept Iterator apis = reader.readArray().iterator(); Assert.assertTrue(apis.hasNext()); - Map map = new HashMap<>(); + Map apiCoordinates = new HashMap<>(); while (apis.hasNext()) { JsonObject api = (JsonObject) apis.next(); String name = api.getString("name"); - if (map.containsKey(name)) { + if (apiCoordinates.containsKey(name)) { Assert.fail(name + " is defined twice"); } JsonObject coordinates = ((JsonObject) api.getJsonArray("clients").get(0)).getJsonObject("mavenCoordinates"); String mavenCoordinates = coordinates.getString("groupId") + ":" + coordinates.getString("artifactId"); - if (map.containsValue(mavenCoordinates)) { + if (apiCoordinates.containsValue(mavenCoordinates)) { Assert.fail(mavenCoordinates + " is defined twice"); } - map.put(name, mavenCoordinates); + apiCoordinates.put(name, mavenCoordinates); } } From 7ec06f6f4530b104963e8565670ac513501ef745 Mon Sep 17 00:00:00 2001 From: Elliotte Harold Date: Fri, 25 Aug 2017 15:36:43 -0400 Subject: [PATCH 14/22] add datastore api --- .../cloud/tools/libraries/libraries.json | 34 ++++++++++++++++--- .../cloud/tools/libraries/LibrariesTest.java | 4 +-- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/google/cloud/tools/libraries/libraries.json b/src/main/java/com/google/cloud/tools/libraries/libraries.json index 7c9871ef7..bb0e393ac 100644 --- a/src/main/java/com/google/cloud/tools/libraries/libraries.json +++ b/src/main/java/com/google/cloud/tools/libraries/libraries.json @@ -7,10 +7,10 @@ "icon":"https://cloud.google.com/_static/images/cloud/products/logos/svg/bigquery.svg", "clients": [ { + "name":"Google Cloud Java Client for BigQuery", "language":"java", "site":"https://cloud.google.com/bigquery/docs/reference/libraries#client-libraries-install-java", - "apireference":"https://googlecloudplatform.github.io/google-cloud-java/0.22.0/apidocs/com/google/cloud/bigquery/package-summary.html", - "version" : "0.22.0", + "apireference":"https://googlecloudplatform.github.io/google-cloud-java/latest/apidocs/com/google/cloud/bigquery/package-summary.html", "infotip":"The com.google.cloud.bigquery packages", "status" : "beta", "source" : "https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-bigquery", @@ -19,8 +19,32 @@ "groupId" : "com.google.cloud", "artifactId" : "google-cloud-bigquery", "version" : "0.22.0-beta" + } } - } - ] + ] + }, + { + "name": "Google Cloud Datastore ", + "documentation": "https://cloud.google.com/datastore/docs/reference/libraries", + "description":"Google Cloud Datastore is a NoSQL key-value database built for automatic scaling.", + "transport": "http", + "icon":"https://cloud.google.com/_static/images/cloud/products/logos/svg/datastore.svg", + "clients": [ + { + "name":"Cloud Datastore Client Library for Java", + "language":"java", + "site":"https://cloud.google.com/datastore/docs/reference/libraries#client-libraries-install-java", + "apireference":"https://googlecloudplatform.github.io/google-cloud-java/latest/apidocs/index.html?com/google/cloud/datastore/package-summary.html", + "infotip":"The com.google.cloud.datastore packages", + "status" : "GA", + "source" : "https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-bigquery", + "languageLevel" : "1.7.0", + "mavenCoordinates" : { + "groupId" : "com.google.cloud", + "artifactId" : "google-cloud-datastore", + "version" : "1.4.0" + } + } + ] } -] \ No newline at end of file +] diff --git a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java index ac41be736..5e3e46d8a 100644 --- a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java +++ b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java @@ -84,13 +84,11 @@ private static void assertApi(JsonObject api) throws URISyntaxException { for (int i = 0; i < clients.size(); i++) { JsonObject client = (JsonObject) clients.get(i); String status = client.getString("status"); - Assert.assertThat(statuses, hasItemInArray(status)); new URI(client.getString("apireference")); new URI(client.getString("site")); Assert.assertTrue(client.getString("languageLevel").matches("1\\.\\d+\\.\\d+")); - String versionString = client.getString("version"); - Assert.assertTrue(versionString.matches("\\d+\\.\\d+\\.\\d+")); + Assert.assertFalse(client.getString("name").isEmpty()); Assert.assertNotNull(client.getJsonObject("mavenCoordinates")); if (client.getString("source") != null) { new URI(client.getString("source")); From 6e23e1146cfc09ba2698908e3946cadf7905ad9d Mon Sep 17 00:00:00 2001 From: Elliotte Harold Date: Fri, 25 Aug 2017 15:48:00 -0400 Subject: [PATCH 15/22] toArray --- .../cloud/tools/libraries/LibrariesTest.java | 42 +++++++++---------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java index 5e3e46d8a..c5016290e 100644 --- a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java +++ b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java @@ -26,7 +26,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import javax.json.Json; @@ -34,17 +33,28 @@ import javax.json.JsonObject; import javax.json.JsonReader; import javax.json.JsonReaderFactory; -import javax.json.JsonValue; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import org.xml.sax.SAXException; public class LibrariesTest { + private JsonObject[] apis; + + @Before + public void parseJson() throws FileNotFoundException { + JsonReaderFactory factory = Json.createReaderFactory(null); + InputStream in = + new FileInputStream("src/main/java/com/google/cloud/tools/libraries/libraries.json"); + JsonReader reader = factory.createReader(in); + apis = reader.readArray().toArray(new JsonObject[0]); + } + @Test public void testWellFormed() throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); @@ -55,16 +65,10 @@ public void testWellFormed() throws ParserConfigurationException, SAXException, } @Test - public void testJson() throws FileNotFoundException, URISyntaxException { - JsonReaderFactory factory = Json.createReaderFactory(null); - InputStream in = - new FileInputStream("src/main/java/com/google/cloud/tools/libraries/libraries.json"); - JsonReader reader = factory.createReader(in); - Iterator apis = reader.readArray().iterator(); - Assert.assertTrue(apis.hasNext()); - while (apis.hasNext()) { - JsonObject api = (JsonObject) apis.next(); - assertApi(api); + public void testJson() throws URISyntaxException { + Assert.assertTrue(apis.length > 0); + for (int i = 0; i < apis.length; i++) { + assertApi(apis[i]); } } @@ -97,17 +101,11 @@ private static void assertApi(JsonObject api) throws URISyntaxException { } @Test - public void testDuplicates() throws FileNotFoundException, URISyntaxException { - JsonReaderFactory factory = Json.createReaderFactory(null); - InputStream in = - new FileInputStream("src/main/java/com/google/cloud/tools/libraries/libraries.json"); - JsonReader reader = factory.createReader(in); - Iterator apis = reader.readArray().iterator(); - Assert.assertTrue(apis.hasNext()); - + public void testDuplicates() throws URISyntaxException { + Map apiCoordinates = new HashMap<>(); - while (apis.hasNext()) { - JsonObject api = (JsonObject) apis.next(); + for (int i = 0; i < apis.length; i++) { + JsonObject api = apis[i]; String name = api.getString("name"); if (apiCoordinates.containsKey(name)) { Assert.fail(name + " is defined twice"); From fd5b6069a20ddea21a10c3e22f4fd1f9d19ea7e9 Mon Sep 17 00:00:00 2001 From: Elliotte Harold Date: Sat, 26 Aug 2017 08:17:49 -0400 Subject: [PATCH 16/22] GCS --- .../cloud/tools/libraries/libraries.json | 26 ++++++++++++++++++- .../cloud/tools/libraries/LibrariesTest.java | 4 +-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/google/cloud/tools/libraries/libraries.json b/src/main/java/com/google/cloud/tools/libraries/libraries.json index bb0e393ac..75a6e376c 100644 --- a/src/main/java/com/google/cloud/tools/libraries/libraries.json +++ b/src/main/java/com/google/cloud/tools/libraries/libraries.json @@ -24,7 +24,7 @@ ] }, { - "name": "Google Cloud Datastore ", + "name": "Google Cloud Datastore", "documentation": "https://cloud.google.com/datastore/docs/reference/libraries", "description":"Google Cloud Datastore is a NoSQL key-value database built for automatic scaling.", "transport": "http", @@ -46,5 +46,29 @@ } } ] + }, + { + "name": "Google Cloud Storage", + "documentation": "https://cloud.google.com/storage/docs/reference/libraries", + "description":"Unified BLOB storage for developers and enterprises, from live data serving to data analytics/ML to data archiving.", + "transport": "http", + "icon":"https://cloud.google.com/_static/images/cloud/products/logos/svg/storage.svg", + "clients": [ + { + "name":"Google Cloud Storage Client Library for Java", + "language":"java", + "site":"https://cloud.google.com/storage/docs/reference/libraries#client-libraries-install-java", + "apireference":"https://googlecloudplatform.github.io/google-cloud-java/latest/apidocs/index.html?com/google/cloud/storage/package-summary.html", + "infotip":"The com.google.cloud.storage packages for client side access to GCS", + "status" : "GA", + "source" : "https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-storage", + "languageLevel" : "1.7.0", + "mavenCoordinates" : { + "groupId" : "com.google.cloud", + "artifactId" : "google-cloud-storage", + "version" : "1.4.0" + } + } + ] } ] diff --git a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java index c5016290e..7b6867822 100644 --- a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java +++ b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java @@ -78,7 +78,8 @@ private static void assertApi(JsonObject api) throws URISyntaxException { Assert.assertFalse(api.getString("name").isEmpty()); Assert.assertFalse(api.getString("description").isEmpty()); String transport = api.getString("transport"); - Assert.assertTrue("http".equals(transport) || "grpc".equals(transport)); + Assert.assertTrue(transport + " is not a recognized transport", + "http".equals(transport) || "grpc".equals(transport)); new URI(api.getString("documentation")); if (api.getString("icon") != null) { new URI(api.getString("icon")); @@ -102,7 +103,6 @@ private static void assertApi(JsonObject api) throws URISyntaxException { @Test public void testDuplicates() throws URISyntaxException { - Map apiCoordinates = new HashMap<>(); for (int i = 0; i < apis.length; i++) { JsonObject api = apis[i]; From 867bd07c8fae9dd105082e22fbfec4a010d33737 Mon Sep 17 00:00:00 2001 From: Elliotte Harold Date: Wed, 30 Aug 2017 14:02:58 -0400 Subject: [PATCH 17/22] make transport an array --- .../java/com/google/cloud/tools/libraries/libraries.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/google/cloud/tools/libraries/libraries.json b/src/main/java/com/google/cloud/tools/libraries/libraries.json index 75a6e376c..61a4ff5e4 100644 --- a/src/main/java/com/google/cloud/tools/libraries/libraries.json +++ b/src/main/java/com/google/cloud/tools/libraries/libraries.json @@ -3,7 +3,7 @@ "name": "Google BigQuery API", "documentation": "https://cloud.google.com/bigquery/docs/reference/libraries", "description":"Google's fully managed, petabyte scale, serverless data warehouse for analytics", - "transport": "http", + "transport": ["http"], "icon":"https://cloud.google.com/_static/images/cloud/products/logos/svg/bigquery.svg", "clients": [ { @@ -27,7 +27,7 @@ "name": "Google Cloud Datastore", "documentation": "https://cloud.google.com/datastore/docs/reference/libraries", "description":"Google Cloud Datastore is a NoSQL key-value database built for automatic scaling.", - "transport": "http", + "transport": ["http"], "icon":"https://cloud.google.com/_static/images/cloud/products/logos/svg/datastore.svg", "clients": [ { @@ -51,7 +51,7 @@ "name": "Google Cloud Storage", "documentation": "https://cloud.google.com/storage/docs/reference/libraries", "description":"Unified BLOB storage for developers and enterprises, from live data serving to data analytics/ML to data archiving.", - "transport": "http", + "transport": ["http"], "icon":"https://cloud.google.com/_static/images/cloud/products/logos/svg/storage.svg", "clients": [ { From abaf73592922db7c83d2e8d71bd033ab299cd127 Mon Sep 17 00:00:00 2001 From: Elliotte Harold Date: Wed, 30 Aug 2017 14:05:23 -0400 Subject: [PATCH 18/22] make transport an array --- .../java/com/google/cloud/tools/libraries/LibrariesTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java index 7b6867822..7f87e56da 100644 --- a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java +++ b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java @@ -77,7 +77,7 @@ public void testJson() throws URISyntaxException { private static void assertApi(JsonObject api) throws URISyntaxException { Assert.assertFalse(api.getString("name").isEmpty()); Assert.assertFalse(api.getString("description").isEmpty()); - String transport = api.getString("transport"); + String transport = api.getJsonArray("transport").getString(0); Assert.assertTrue(transport + " is not a recognized transport", "http".equals(transport) || "grpc".equals(transport)); new URI(api.getString("documentation")); From 7517ae38a76ab1f649aa5a776e6827c7f9b18003 Mon Sep 17 00:00:00 2001 From: Elliotte Harold Date: Wed, 30 Aug 2017 14:12:10 -0400 Subject: [PATCH 19/22] launchStage --- .../java/com/google/cloud/tools/libraries/libraries.json | 6 +++--- .../com/google/cloud/tools/libraries/LibrariesTest.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/google/cloud/tools/libraries/libraries.json b/src/main/java/com/google/cloud/tools/libraries/libraries.json index 61a4ff5e4..ec106dab2 100644 --- a/src/main/java/com/google/cloud/tools/libraries/libraries.json +++ b/src/main/java/com/google/cloud/tools/libraries/libraries.json @@ -12,7 +12,7 @@ "site":"https://cloud.google.com/bigquery/docs/reference/libraries#client-libraries-install-java", "apireference":"https://googlecloudplatform.github.io/google-cloud-java/latest/apidocs/com/google/cloud/bigquery/package-summary.html", "infotip":"The com.google.cloud.bigquery packages", - "status" : "beta", + "launchStage" : "beta", "source" : "https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-bigquery", "languageLevel" : "1.7.0", "mavenCoordinates" : { @@ -36,7 +36,7 @@ "site":"https://cloud.google.com/datastore/docs/reference/libraries#client-libraries-install-java", "apireference":"https://googlecloudplatform.github.io/google-cloud-java/latest/apidocs/index.html?com/google/cloud/datastore/package-summary.html", "infotip":"The com.google.cloud.datastore packages", - "status" : "GA", + "launchStage" : "GA", "source" : "https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-bigquery", "languageLevel" : "1.7.0", "mavenCoordinates" : { @@ -60,7 +60,7 @@ "site":"https://cloud.google.com/storage/docs/reference/libraries#client-libraries-install-java", "apireference":"https://googlecloudplatform.github.io/google-cloud-java/latest/apidocs/index.html?com/google/cloud/storage/package-summary.html", "infotip":"The com.google.cloud.storage packages for client side access to GCS", - "status" : "GA", + "launchStage" : "GA", "source" : "https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-storage", "languageLevel" : "1.7.0", "mavenCoordinates" : { diff --git a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java index 7f87e56da..60c256d2a 100644 --- a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java +++ b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java @@ -72,7 +72,7 @@ public void testJson() throws URISyntaxException { } } - private static final String[] statuses = {"alpha", "beta", "GA"}; + private static final String[] statuses = {"early access", "alpha", "beta", "GA", "deprecated"}; private static void assertApi(JsonObject api) throws URISyntaxException { Assert.assertFalse(api.getString("name").isEmpty()); @@ -88,8 +88,8 @@ private static void assertApi(JsonObject api) throws URISyntaxException { Assert.assertFalse(clients.isEmpty()); for (int i = 0; i < clients.size(); i++) { JsonObject client = (JsonObject) clients.get(i); - String status = client.getString("status"); - Assert.assertThat(statuses, hasItemInArray(status)); + String launchStage = client.getString("launchStage"); + Assert.assertThat(statuses, hasItemInArray(launchStage)); new URI(client.getString("apireference")); new URI(client.getString("site")); Assert.assertTrue(client.getString("languageLevel").matches("1\\.\\d+\\.\\d+")); From 88a622ef0e0ecd96dabc90cf6b727336a7bbd2ad Mon Sep 17 00:00:00 2001 From: Elliotte Harold Date: Thu, 31 Aug 2017 16:43:44 -0400 Subject: [PATCH 20/22] pluralize transports --- .../java/com/google/cloud/tools/libraries/libraries.json | 6 +++--- .../com/google/cloud/tools/libraries/LibrariesTest.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/google/cloud/tools/libraries/libraries.json b/src/main/java/com/google/cloud/tools/libraries/libraries.json index ec106dab2..52dcf4b9e 100644 --- a/src/main/java/com/google/cloud/tools/libraries/libraries.json +++ b/src/main/java/com/google/cloud/tools/libraries/libraries.json @@ -3,7 +3,7 @@ "name": "Google BigQuery API", "documentation": "https://cloud.google.com/bigquery/docs/reference/libraries", "description":"Google's fully managed, petabyte scale, serverless data warehouse for analytics", - "transport": ["http"], + "transports": ["http"], "icon":"https://cloud.google.com/_static/images/cloud/products/logos/svg/bigquery.svg", "clients": [ { @@ -27,7 +27,7 @@ "name": "Google Cloud Datastore", "documentation": "https://cloud.google.com/datastore/docs/reference/libraries", "description":"Google Cloud Datastore is a NoSQL key-value database built for automatic scaling.", - "transport": ["http"], + "transports": ["http"], "icon":"https://cloud.google.com/_static/images/cloud/products/logos/svg/datastore.svg", "clients": [ { @@ -51,7 +51,7 @@ "name": "Google Cloud Storage", "documentation": "https://cloud.google.com/storage/docs/reference/libraries", "description":"Unified BLOB storage for developers and enterprises, from live data serving to data analytics/ML to data archiving.", - "transport": ["http"], + "transports": ["http"], "icon":"https://cloud.google.com/_static/images/cloud/products/logos/svg/storage.svg", "clients": [ { diff --git a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java index 60c256d2a..16ce7be46 100644 --- a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java +++ b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java @@ -77,7 +77,7 @@ public void testJson() throws URISyntaxException { private static void assertApi(JsonObject api) throws URISyntaxException { Assert.assertFalse(api.getString("name").isEmpty()); Assert.assertFalse(api.getString("description").isEmpty()); - String transport = api.getJsonArray("transport").getString(0); + String transport = api.getJsonArray("transports").getString(0); Assert.assertTrue(transport + " is not a recognized transport", "http".equals(transport) || "grpc".equals(transport)); new URI(api.getString("documentation")); From 2c8e5d8a3013c8eb622aa6be8ce4c6c4897a336c Mon Sep 17 00:00:00 2001 From: Elliotte Harold Date: Thu, 31 Aug 2017 16:44:26 -0400 Subject: [PATCH 21/22] pluralize transports --- .../com/google/cloud/tools/libraries/LibrariesTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java index 16ce7be46..09814e825 100644 --- a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java +++ b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java @@ -77,9 +77,9 @@ public void testJson() throws URISyntaxException { private static void assertApi(JsonObject api) throws URISyntaxException { Assert.assertFalse(api.getString("name").isEmpty()); Assert.assertFalse(api.getString("description").isEmpty()); - String transport = api.getJsonArray("transports").getString(0); - Assert.assertTrue(transport + " is not a recognized transport", - "http".equals(transport) || "grpc".equals(transport)); + String transports = api.getJsonArray("transports").getString(0); + Assert.assertTrue(transports + " is not a recognized transport", + "http".equals(transports) || "grpc".equals(transports)); new URI(api.getString("documentation")); if (api.getString("icon") != null) { new URI(api.getString("icon")); From 05e0d0903cc233796e784acc3bb407a0802c827e Mon Sep 17 00:00:00 2001 From: Elliotte Harold Date: Thu, 31 Aug 2017 16:46:51 -0400 Subject: [PATCH 22/22] add packages --- .../java/com/google/cloud/tools/libraries/libraries.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/google/cloud/tools/libraries/libraries.json b/src/main/java/com/google/cloud/tools/libraries/libraries.json index 52dcf4b9e..4919a8725 100644 --- a/src/main/java/com/google/cloud/tools/libraries/libraries.json +++ b/src/main/java/com/google/cloud/tools/libraries/libraries.json @@ -13,6 +13,7 @@ "apireference":"https://googlecloudplatform.github.io/google-cloud-java/latest/apidocs/com/google/cloud/bigquery/package-summary.html", "infotip":"The com.google.cloud.bigquery packages", "launchStage" : "beta", + "packages" : ["com.google.cloud.bigquery"], "source" : "https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-bigquery", "languageLevel" : "1.7.0", "mavenCoordinates" : { @@ -36,6 +37,7 @@ "site":"https://cloud.google.com/datastore/docs/reference/libraries#client-libraries-install-java", "apireference":"https://googlecloudplatform.github.io/google-cloud-java/latest/apidocs/index.html?com/google/cloud/datastore/package-summary.html", "infotip":"The com.google.cloud.datastore packages", + "packages" : ["com.google.cloud.datastore"], "launchStage" : "GA", "source" : "https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-bigquery", "languageLevel" : "1.7.0", @@ -58,7 +60,8 @@ "name":"Google Cloud Storage Client Library for Java", "language":"java", "site":"https://cloud.google.com/storage/docs/reference/libraries#client-libraries-install-java", - "apireference":"https://googlecloudplatform.github.io/google-cloud-java/latest/apidocs/index.html?com/google/cloud/storage/package-summary.html", + "apireference" : "https://googlecloudplatform.github.io/google-cloud-java/latest/apidocs/index.html?com/google/cloud/storage/package-summary.html", + "packages" : ["com.google.cloud.storage"], "infotip":"The com.google.cloud.storage packages for client side access to GCS", "launchStage" : "GA", "source" : "https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-storage",