Skip to content

Commit

Permalink
feat: Add REST AIP-151 LRO suport
Browse files Browse the repository at this point in the history
  • Loading branch information
vam-google committed Oct 8, 2021
1 parent 8ae8e6f commit ec1eb8d
Show file tree
Hide file tree
Showing 120 changed files with 678 additions and 660 deletions.
2 changes: 1 addition & 1 deletion .github/release-please.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
releaseType: simple
handleGHRelease: true
primaryBranch: master
primaryBranch: main
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
on:
push:
branches:
- master
- main
pull_request:
name: ci
jobs:
build:
runs-on: ubuntu-latest
container: gcr.io/gapic-images/googleapis-bazel:20210105
# Dockerfile for this image: https://github.com/googleapis/googleapis-discovery/blob/master/Dockerfile
# Dockerfile for this image: https://github.com/googleapis/googleapis-discovery/blob/main/Dockerfile
# If you update its version, please also update it below in
# 'Cache Bazel files' - unfortunately it cannot accept variables at this
# time.
Expand Down
26 changes: 21 additions & 5 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,40 @@
## Running the Plugin

1. Clone [googleapis](https://github.com/googleapis/googleapis) and
[gapic-showcase](https://github.com/googleapis/gapic-showcase/) and install
protoc.
[gapic-showcase](https://github.com/googleapis/gapic-showcase/).

2. Copy the protos from Showcase into googleapis/google/showcase.

```sh
cp gapic-showcase/schema/google/showcase/v1beta1 googleapis/google/showcase/v1beta
mkdir googleapis/google/showcase
cp -r gapic-showcase/schema/google/showcase/v1beta1 googleapis/google/showcase/v1beta1
```

3. Add the new microgenerator rules to the protobuf directory's `BUILD.bazel`
file as follows:
3. Add the new microgenerator rules to
`googleapis/google/showcase/v1beta1/BUILD.bazel` file as follows:

```python
load(
"@com_google_googleapis_imports//:imports.bzl",
# Existing rules here.
"java_gapic_assembly_gradle_pkg",
"java_gapic_library",
"java_proto_library",
"proto_library_with_info",
)
proto_library_with_info(
name = "showcase_proto_with_info",
deps = [
":showcase_proto",
],
)
java_proto_library(
name = "showcase_java_proto",
deps = [
"showcase_proto",
],
)
# This should either replace the existing monolith target or have a unique name
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![codecov](https://codecov.io/gh/googleapis/gapic-generator-java/branch/master/graph/badge.svg?token=3RUU37GX9U)](https://codecov.io/gh/googleapis/gapic-generator-java)
[![codecov](https://codecov.io/gh/googleapis/gapic-generator-java/branch/main/graph/badge.svg?token=3RUU37GX9U)](https://codecov.io/gh/googleapis/gapic-generator-java)
# API Client Generator for Java

Generates a Java client library from protocol buffers.
Expand Down
6 changes: 3 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ load("@bazel_tools//tools/build_defs/repo:jvm.bzl", "jvm_maven_import_external")
# like protobuf will build.
http_archive(
name = "bazel_skylib",
sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44",
sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
],
)

Expand Down
6 changes: 2 additions & 4 deletions repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,12 @@ def gapic_generator_java_repositories():
],
)

# TODO: replace with upstream googleapis-discovery link once
# https://github.com/googleapis/googleapis-discovery/pull/59 is merged
_maybe(
http_archive,
name = "com_google_googleapis_discovery",
strip_prefix = "googleapis-discovery-bb8a053b93ef8698297c41634aa9201f7e075277",
strip_prefix = "googleapis-discovery-34478e2969042ed837d33684360f1ee3be7d2f74",
urls = [
"https://github.com/vam-google/googleapis-discovery/archive/bb8a053b93ef8698297c41634aa9201f7e075277.zip",
"https://github.com/googleapis/googleapis-discovery/archive/34478e2969042ed837d33684360f1ee3be7d2f74.zip",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public abstract class AnnotationNode implements AstNode {
public static AnnotationNode DEPRECATED =
AnnotationNode.builder().setType(annotationType(Deprecated.class)).build();

private static TypeNode annotationType(Class clazz) {
private static TypeNode annotationType(Class<?> clazz) {
return TypeNode.withReference(ConcreteReference.withClazz(clazz));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ public abstract class ArithmeticOperationExpr implements OperationExpr {

public abstract Expr rhsExpr();

@Override
public abstract OperatorKind operatorKind();

@Override
public abstract TypeNode type();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public abstract class AssignmentOperationExpr implements OperationExpr {

public abstract Expr valueExpr();

@Override
public abstract OperatorKind operatorKind();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

@AutoValue
public abstract class BlockComment implements Comment {
@Override
public abstract String comment();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public abstract class ConcreteReference implements Reference {
private static final String RIGHT_ANGLE = ">";
private static final String QUESTION_MARK = "?";

private static final Class WILDCARD_CLAZZ = ReferenceWildcard.class;
private static final Class<?> WILDCARD_CLAZZ = ReferenceWildcard.class;

// Private.
abstract Class clazz();
abstract Class<?> clazz();

@Override
public void accept(AstNodeVisitor visitor) {
Expand Down Expand Up @@ -105,7 +105,7 @@ public ImmutableList<String> enclosingClassNames() {
}
// The innermost type will be the last element in the list.
ImmutableList.Builder<String> listBuilder = new ImmutableList.Builder<>();
Class currentClz = clazz();
Class<?> currentClz = clazz();
while (currentClz.getEnclosingClass() != null) {
listBuilder.add(currentClz.getEnclosingClass().getSimpleName());
currentClz = currentClz.getEnclosingClass();
Expand Down Expand Up @@ -198,7 +198,7 @@ public Reference copyAndSetGenerics(List<Reference> generics) {
return toBuilder().setGenerics(generics).build();
}

public static ConcreteReference withClazz(Class clazz) {
public static ConcreteReference withClazz(Class<?> clazz) {
return builder().setClazz(clazz).build();
}

Expand All @@ -222,7 +222,7 @@ public static Builder builder() {

@AutoValue.Builder
public abstract static class Builder {
public abstract Builder setClazz(Class clazz);
public abstract Builder setClazz(Class<?> clazz);

public abstract Builder setUseFullName(boolean useFullName);

Expand All @@ -239,7 +239,7 @@ public Builder setGenerics(Reference... references) {
public abstract ConcreteReference autoBuild();

// Private.
abstract Class clazz();
abstract Class<?> clazz();

abstract ImmutableList<Reference> generics();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
public abstract class EnumRefExpr implements Expr {
public abstract IdentifierNode identifier();

@Override
public abstract TypeNode type();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
public interface Expr extends AstNode {
TypeNode type();

@Override
void accept(AstNodeVisitor visitor);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public abstract class LogicalOperationExpr implements OperationExpr {

public abstract Expr rhsExpr();

@Override
public abstract OperatorKind operatorKind();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,20 +244,18 @@ public MethodDefinition build() {
"Abstract methods cannot be static, final, or private");
}

// If this method overrides another, ensure that the Override annotaiton is the last one.
// If this method overrides another, ensure that the Override annotation is the last one.
ImmutableList<AnnotationNode> processedAnnotations = annotations();
if (isOverride()) {
processedAnnotations =
annotations()
.<AnnotationNode>builder()
ImmutableList.<AnnotationNode>builder()
.addAll(annotations())
.add(AnnotationNode.OVERRIDE)
.build();
}
// Remove duplicates while maintaining insertion order.
setAnnotations(
new LinkedHashSet<AnnotationNode>(processedAnnotations)
.stream().collect(Collectors.toList()));
new LinkedHashSet<>(processedAnnotations).stream().collect(Collectors.toList()));

MethodDefinition method = autoBuild();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

@AutoValue
public abstract class NewObjectExpr implements Expr {
@Override
public abstract TypeNode type();

public abstract ImmutableList<Expr> arguments();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
package com.google.api.generator.engine.ast;

public interface ObjectValue extends Value {
@Override
TypeNode type();

@Override
String value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public interface OperationExpr extends Expr {

OperatorKind operatorKind();

@Override
TypeNode type();

@Override
void accept(AstNodeVisitor visitor);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import javax.annotation.Nullable;

public interface Reference extends AstNode {
@Override
void accept(AstNodeVisitor visitor);

ImmutableList<Reference> generics();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public enum KeywordKind {
SUPER
}

@Override
public abstract TypeNode type();

public abstract KeywordKind keywordKind();
Expand Down Expand Up @@ -73,7 +74,7 @@ public Builder setArguments(Expr... arguments) {
public ReferenceConstructorExpr build() {
ReferenceConstructorExpr referenceConstructorExpr = autoBuild();
Preconditions.checkState(
referenceConstructorExpr.type().isReferenceType(referenceConstructorExpr.type()),
TypeNode.isReferenceType(referenceConstructorExpr.type()),
"A this/super constructor must have a reference type.");

NodeValidator.checkNoNullElements(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public abstract class RelationalOperationExpr implements OperationExpr {

public abstract Expr rhsExpr();

@Override
public abstract OperatorKind operatorKind();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
package com.google.api.generator.engine.ast;

public interface Statement extends AstNode {
@Override
void accept(AstNodeVisitor visitor);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

@AutoValue
public abstract class StringObjectValue implements ObjectValue {
@Override
public abstract String value();

@Override
Expand Down
22 changes: 4 additions & 18 deletions src/main/java/com/google/api/generator/engine/ast/TypeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public int compareTo(TypeNode other) {
return -1;
}

if (this.equals(TypeNode.NULL)) {
if (equals(TypeNode.NULL)) {
// Can't self-compare, so we don't need to check whether the other one is TypeNode.NULL.
return other.isPrimitiveType() ? 1 : -1;
}
Expand Down Expand Up @@ -161,7 +161,7 @@ public static TypeNode withReference(Reference reference) {
return TypeNode.builder().setTypeKind(TypeKind.OBJECT).setReference(reference).build();
}

public static TypeNode withExceptionClazz(Class clazz) {
public static TypeNode withExceptionClazz(Class<?> clazz) {
Preconditions.checkState(Exception.class.isAssignableFrom(clazz));
return withReference(ConcreteReference.withClazz(clazz));
}
Expand Down Expand Up @@ -200,11 +200,11 @@ public boolean isPrimitiveType() {
}

public boolean isProtoPrimitiveType() {
return isPrimitiveType() || this.equals(TypeNode.STRING) || this.equals(TypeNode.BYTESTRING);
return isPrimitiveType() || equals(TypeNode.STRING) || equals(TypeNode.BYTESTRING);
}

public boolean isSupertypeOrEquals(TypeNode other) {
boolean oneTypeIsNull = this.equals(TypeNode.NULL) ^ other.equals(TypeNode.NULL);
boolean oneTypeIsNull = equals(TypeNode.NULL) ^ other.equals(TypeNode.NULL);
return !isPrimitiveType()
&& !other.isPrimitiveType()
&& isArray() == other.isArray()
Expand Down Expand Up @@ -256,20 +256,6 @@ boolean isBoxedTypeEquals(TypeNode other) {
return Objects.equals(other, BOXED_TYPE_MAP.get(this));
}

private static TypeNode createPrimitiveType(TypeKind typeKind) {
if (!isPrimitiveType(typeKind)) {
throw new IllegalArgumentException("Object is not a primitive type.");
}
return TypeNode.builder().setTypeKind(typeKind).build();
}

private static TypeNode createPrimitiveArrayType(TypeKind typeKind) {
if (typeKind.equals(TypeKind.OBJECT)) {
throw new IllegalArgumentException("Object is not a primitive type.");
}
return TypeNode.builder().setTypeKind(typeKind).setIsArray(true).build();
}

private static boolean isPrimitiveType(TypeKind typeKind) {
return !typeKind.equals(TypeKind.OBJECT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ public abstract class UnaryOperationExpr implements OperationExpr {

public abstract Expr expr();

@Override
public abstract OperatorKind operatorKind();

@Override
public abstract TypeNode type();

@Override
public void accept(AstNodeVisitor visitor) {
visitor.visit(this);
}
Expand Down
Loading

0 comments on commit ec1eb8d

Please sign in to comment.