Skip to content

Commit 582854f

Browse files
committed
Merge remote-tracking branch 'origin/fix/bazel' into fix/bazel
2 parents c45b413 + 2cb0609 commit 582854f

File tree

24 files changed

+684
-112
lines changed

24 files changed

+684
-112
lines changed

.github/workflows/ci.yaml

-5
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ jobs:
5151
- name: Integration Tests
5252
run: bazel --batch test //test/integration/...
5353

54-
- uses: actions/upload-artifact@v2
55-
if: ${{ failure() }}
56-
57-
run: bazel --batch test //test/integration/...
58-
5954
- uses: actions/upload-artifact@v2
6055
if: ${{ failure() }}
6156
with:

CHANGELOG.md

+31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
# Changelog
22

3+
### [1.0.15](https://www.github.com/googleapis/gapic-generator-java/compare/v1.0.14...v1.0.15) (2021-06-22)
4+
5+
6+
### Features
7+
8+
* Implement field presence support for DIREGAPIC ([#774](https://www.github.com/googleapis/gapic-generator-java/issues/774)) ([c820361](https://www.github.com/googleapis/gapic-generator-java/commit/c82036105d299b0a1192cd0def5e68253e4f542c))
9+
10+
11+
### Bug Fixes
12+
13+
* **service.yaml:** Remove allowlist restriction ([#776](https://www.github.com/googleapis/gapic-generator-java/issues/776)) ([8f42efd](https://www.github.com/googleapis/gapic-generator-java/commit/8f42efdb92d606a768a524517fe949c4f9112025))
14+
15+
16+
### Miscellaneous Chores
17+
18+
* release 1.0.15 ([f752478](https://www.github.com/googleapis/gapic-generator-java/commit/f75247845344540a94c4efcd416f34f96ea0c2a3))
19+
20+
### [1.0.14](https://www.github.com/googleapis/gapic-generator-java/compare/v1.0.13...v1.0.14) (2021-06-17)
21+
22+
23+
### Features
24+
25+
* Add DIREGAPIC-specific pagination ([#767](https://www.github.com/googleapis/gapic-generator-java/issues/767)) ([1294c29](https://www.github.com/googleapis/gapic-generator-java/commit/1294c298f50cc4474ae562e6a07f37a5f94fe5b8))
26+
27+
28+
### Bug Fixes
29+
30+
* **bazel:** Remove monolith rule deps from the Java µgen Bazel rules ([#764](https://www.github.com/googleapis/gapic-generator-java/issues/764)) ([bff3efc](https://www.github.com/googleapis/gapic-generator-java/commit/bff3efc25e43692ea5b6e769c20d25d5b9a1e3d2))
31+
32+
33+
334
### [1.0.13](https://www.github.com/googleapis/gapic-generator-java/compare/v1.0.12...v1.0.13) (2021-06-16)
435

536

rules_java_gapic/java_gapic.bzl

+1-13
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
load("@rules_gapic//:gapic.bzl", "proto_custom_library", "unzipped_srcjar")
1616

17-
SERVICE_YAML_ALLOWLIST = ["clouddms", "cloudkms", "datastream", "pubsub"]
1817
NO_GRPC_CONFIG_ALLOWLIST = ["library"]
1918

2019
def _java_gapic_postprocess_srcjar_impl(ctx):
@@ -144,19 +143,8 @@ def _java_gapic_srcjar(
144143
if gapic_yaml:
145144
file_args_dict[gapic_yaml] = "gapic-config"
146145

147-
# Check the allow-list.
148-
# TODO: Open this up after mixins are published, and gate on
149-
# the allowlisted "mixed-in" APIs present in Java.
150146
if service_yaml:
151-
service_yaml_in_allowlist = False
152-
for keyword in SERVICE_YAML_ALLOWLIST:
153-
if keyword in service_yaml:
154-
service_yaml_in_allowlist = True
155-
break
156-
if service_yaml_in_allowlist:
157-
file_args_dict[service_yaml] = "api-service-config"
158-
else:
159-
fail("Service.yaml is no longer supported in the Java microgenerator")
147+
file_args_dict[service_yaml] = "api-service-config"
160148

161149
output_suffix = ".srcjar"
162150
opt_args = []

src/main/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceStubClassComposer.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.google.api.generator.engine.ast.VariableExpr;
3535
import com.google.api.generator.gapic.composer.common.AbstractServiceStubClassComposer;
3636
import com.google.api.generator.gapic.composer.store.TypeStore;
37+
import com.google.api.generator.gapic.model.HttpBindings.HttpBinding;
3738
import com.google.api.generator.gapic.model.Method;
3839
import com.google.api.generator.gapic.model.Service;
3940
import com.google.api.generator.gapic.utils.JavaStyle;
@@ -288,11 +289,11 @@ private AnonymousClassExpr createRequestParamsExtractorAnonClass(Method method)
288289
VariableExpr.withVariable(
289290
Variable.builder().setType(method.inputType()).setName("request").build());
290291

291-
for (String httpBindingFieldName : method.httpBindings().pathParameters()) {
292+
for (HttpBinding httpBindingFieldBinding : method.httpBindings().pathParameters()) {
292293
// Handle foo.bar cases by descending into the subfields.
293294
MethodInvocationExpr.Builder requestFieldGetterExprBuilder =
294295
MethodInvocationExpr.builder().setExprReferenceExpr(requestVarExpr);
295-
String[] descendantFields = httpBindingFieldName.split("\\.");
296+
String[] descendantFields = httpBindingFieldBinding.name().split("\\.");
296297
for (int i = 0; i < descendantFields.length; i++) {
297298
String currFieldName = descendantFields[i];
298299
String bindingFieldMethodName =
@@ -319,7 +320,7 @@ private AnonymousClassExpr createRequestParamsExtractorAnonClass(Method method)
319320
.setExprReferenceExpr(paramsVarExpr)
320321
.setMethodName("put")
321322
.setArguments(
322-
ValueExpr.withValue(StringObjectValue.withValue(httpBindingFieldName)),
323+
ValueExpr.withValue(StringObjectValue.withValue(httpBindingFieldBinding.name())),
323324
valueOfExpr)
324325
.build();
325326
bodyExprs.add(paramsPutExpr);

src/main/java/com/google/api/generator/gapic/composer/rest/HttpJsonServiceStubClassComposer.java

+36-9
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.google.api.generator.engine.ast.EnumRefExpr;
3131
import com.google.api.generator.engine.ast.Expr;
3232
import com.google.api.generator.engine.ast.ExprStatement;
33+
import com.google.api.generator.engine.ast.IfStatement;
3334
import com.google.api.generator.engine.ast.MethodDefinition;
3435
import com.google.api.generator.engine.ast.MethodInvocationExpr;
3536
import com.google.api.generator.engine.ast.NewObjectExpr;
@@ -42,6 +43,7 @@
4243
import com.google.api.generator.engine.ast.VariableExpr;
4344
import com.google.api.generator.gapic.composer.common.AbstractServiceStubClassComposer;
4445
import com.google.api.generator.gapic.composer.store.TypeStore;
46+
import com.google.api.generator.gapic.model.HttpBindings.HttpBinding;
4547
import com.google.api.generator.gapic.model.Method;
4648
import com.google.api.generator.gapic.model.Service;
4749
import com.google.api.generator.gapic.utils.JavaStyle;
@@ -357,9 +359,9 @@ private List<Expr> setResponseParserExpr(Method protoMethod) {
357359
private Expr createFieldsExtractorAnonClass(
358360
Method method,
359361
TypeNode extractorReturnType,
360-
Set<String> httpBindingFieldNames,
362+
Set<HttpBinding> httpBindingFieldNames,
361363
String serializerMethodName) {
362-
List<Expr> bodyExprs = new ArrayList<>();
364+
List<Statement> bodyStatements = new ArrayList<>();
363365

364366
Expr returnExpr = null;
365367
VariableExpr fieldsVarExpr = null;
@@ -389,7 +391,7 @@ private Expr createFieldsExtractorAnonClass(
389391
.build())
390392
.build();
391393

392-
bodyExprs.add(fieldsAssignExpr);
394+
bodyStatements.add(ExprStatement.withExpr(fieldsAssignExpr));
393395
returnExpr = fieldsVarExpr;
394396

395397
TypeNode serializerVarType =
@@ -417,40 +419,57 @@ private Expr createFieldsExtractorAnonClass(
417419

418420
serializerExpr = serializerVarExpr;
419421

420-
bodyExprs.add(serializerAssignExpr);
422+
bodyStatements.add(ExprStatement.withExpr(serializerAssignExpr));
421423
}
422424

423425
VariableExpr requestVarExpr =
424426
VariableExpr.withVariable(
425427
Variable.builder().setType(method.inputType()).setName("request").build());
426428

427-
for (String httpBindingFieldName : httpBindingFieldNames) {
429+
for (HttpBinding httpBindingFieldName : httpBindingFieldNames) {
428430
// Handle foo.bar cases by descending into the subfields.
429431
MethodInvocationExpr.Builder requestFieldGetterExprBuilder =
430432
MethodInvocationExpr.builder().setExprReferenceExpr(requestVarExpr);
431-
String[] descendantFields = httpBindingFieldName.split("\\.");
433+
MethodInvocationExpr.Builder requestFieldHasExprBuilder =
434+
MethodInvocationExpr.builder().setExprReferenceExpr(requestVarExpr);
435+
String[] descendantFields = httpBindingFieldName.name().split("\\.");
432436
for (int i = 0; i < descendantFields.length; i++) {
433437
String currFieldName = descendantFields[i];
434438
String bindingFieldMethodName =
435439
String.format("get%s", JavaStyle.toUpperCamelCase(currFieldName));
436440
requestFieldGetterExprBuilder =
437441
requestFieldGetterExprBuilder.setMethodName(bindingFieldMethodName);
442+
443+
String bindingFieldHasMethodName =
444+
(i < descendantFields.length - 1)
445+
? bindingFieldMethodName
446+
: String.format("has%s", JavaStyle.toUpperCamelCase(currFieldName));
447+
requestFieldHasExprBuilder =
448+
requestFieldHasExprBuilder
449+
.setMethodName(bindingFieldHasMethodName)
450+
.setReturnType(TypeNode.BOOLEAN);
451+
438452
if (i < descendantFields.length - 1) {
439453
requestFieldGetterExprBuilder =
440454
MethodInvocationExpr.builder()
441455
.setExprReferenceExpr(requestFieldGetterExprBuilder.build());
456+
requestFieldHasExprBuilder =
457+
MethodInvocationExpr.builder()
458+
.setExprReferenceExpr(requestFieldHasExprBuilder.build());
442459
}
443460
}
444461

445462
MethodInvocationExpr requestBuilderExpr = requestFieldGetterExprBuilder.build();
463+
MethodInvocationExpr requestHasExpr = requestFieldHasExprBuilder.build();
446464

447465
ImmutableList.Builder<Expr> paramsPutArgs = ImmutableList.builder();
448466
if (fieldsVarExpr != null) {
449467
paramsPutArgs.add(fieldsVarExpr);
450468
}
451469
paramsPutArgs.add(
452470
ValueExpr.withValue(
453-
StringObjectValue.withValue(JavaStyle.toLowerCamelCase(httpBindingFieldName))));
471+
StringObjectValue.withValue(
472+
JavaStyle.toLowerCamelCase(httpBindingFieldName.name()))));
454473
paramsPutArgs.add(requestBuilderExpr);
455474

456475
Expr paramsPutExpr =
@@ -464,7 +483,15 @@ private Expr createFieldsExtractorAnonClass(
464483
if (fieldsVarExpr == null) {
465484
returnExpr = paramsPutExpr;
466485
} else {
467-
bodyExprs.add(paramsPutExpr);
486+
if (httpBindingFieldName.isOptional()) {
487+
bodyStatements.add(
488+
IfStatement.builder()
489+
.setConditionExpr(requestHasExpr)
490+
.setBody(Arrays.asList(ExprStatement.withExpr(paramsPutExpr)))
491+
.build());
492+
} else {
493+
bodyStatements.add(ExprStatement.withExpr(paramsPutExpr));
494+
}
468495
}
469496
}
470497

@@ -475,7 +502,7 @@ private Expr createFieldsExtractorAnonClass(
475502
.setReturnType(extractorReturnType)
476503
.setName("extract")
477504
.setArguments(requestVarExpr.toBuilder().setIsDecl(true).build())
478-
.setBody(bodyExprs.stream().map(ExprStatement::withExpr).collect(Collectors.toList()))
505+
.setBody(bodyStatements)
479506
.setReturnExpr(returnExpr)
480507
.build();
481508

src/main/java/com/google/api/generator/gapic/model/Field.java

+36-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,19 @@
1717
import com.google.api.generator.engine.ast.TypeNode;
1818
import com.google.auto.value.AutoValue;
1919
import java.util.Objects;
20+
import java.util.Optional;
2021
import javax.annotation.Nullable;
2122

2223
@AutoValue
2324
public abstract class Field {
25+
// The field's canonical name, potentially post-processed by conflict resolution logic.
2426
public abstract String name();
2527

28+
// The field's name as it appeared in the protobuf.
29+
// Not equal to name() only when there is a field name conflict, as per protoc's conflict
30+
// resolution behavior. For more context, please see the invocation site of the setter method.
31+
public abstract String originalName();
32+
2633
public abstract TypeNode type();
2734

2835
public abstract boolean isMessage();
@@ -35,12 +42,18 @@ public abstract class Field {
3542

3643
public abstract boolean isContainedInOneof();
3744

45+
public abstract boolean isProto3Optional();
46+
3847
@Nullable
3948
public abstract ResourceReference resourceReference();
4049

4150
@Nullable
4251
public abstract String description();
4352

53+
public boolean hasFieldNameConflict() {
54+
return !name().equals(originalName());
55+
}
56+
4457
public boolean hasDescription() {
4558
return description() != null;
4659
}
@@ -57,25 +70,29 @@ public boolean equals(Object o) {
5770

5871
Field other = (Field) o;
5972
return name().equals(other.name())
73+
&& originalName().equals(other.originalName())
6074
&& type().equals(other.type())
6175
&& isMessage() == other.isMessage()
6276
&& isEnum() == other.isEnum()
6377
&& isRepeated() == other.isRepeated()
6478
&& isMap() == other.isMap()
6579
&& isContainedInOneof() == other.isContainedInOneof()
80+
&& isProto3Optional() == other.isProto3Optional()
6681
&& Objects.equals(resourceReference(), other.resourceReference())
6782
&& Objects.equals(description(), other.description());
6883
}
6984

7085
@Override
7186
public int hashCode() {
7287
return 17 * name().hashCode()
88+
+ 31 * originalName().hashCode()
7389
+ 19 * type().hashCode()
7490
+ (isMessage() ? 1 : 0) * 23
7591
+ (isEnum() ? 1 : 0) * 29
7692
+ (isRepeated() ? 1 : 0) * 31
7793
+ (isMap() ? 1 : 0) * 37
7894
+ (isContainedInOneof() ? 1 : 0) * 41
95+
+ (isProto3Optional() ? 1 : 0) * 43
7996
+ (resourceReference() == null ? 0 : resourceReference().hashCode())
8097
+ (description() == null ? 0 : description().hashCode());
8198
}
@@ -88,13 +105,16 @@ public static Builder builder() {
88105
.setIsEnum(false)
89106
.setIsRepeated(false)
90107
.setIsMap(false)
91-
.setIsContainedInOneof(false);
108+
.setIsContainedInOneof(false)
109+
.setIsProto3Optional(false);
92110
}
93111

94112
@AutoValue.Builder
95113
public abstract static class Builder {
96114
public abstract Builder setName(String name);
97115

116+
public abstract Builder setOriginalName(String originalName);
117+
98118
public abstract Builder setType(TypeNode type);
99119

100120
public abstract Builder setIsMessage(boolean isMessage);
@@ -107,10 +127,24 @@ public abstract static class Builder {
107127

108128
public abstract Builder setIsContainedInOneof(boolean isContainedInOneof);
109129

130+
public abstract Builder setIsProto3Optional(boolean isProto3Optional);
131+
110132
public abstract Builder setResourceReference(ResourceReference resourceReference);
111133

112134
public abstract Builder setDescription(String description);
113135

114-
public abstract Field build();
136+
// Private accessors.
137+
abstract String name();
138+
139+
abstract Optional<String> originalName();
140+
141+
abstract Field autoBuild();
142+
143+
public Field build() {
144+
if (!originalName().isPresent()) {
145+
setOriginalName(name());
146+
}
147+
return autoBuild();
148+
}
115149
}
116150
}

0 commit comments

Comments
 (0)