Skip to content

Commit

Permalink
Merge branch 'main' into explicit-dynamic-routing-header
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeli0 committed Jan 25, 2022
2 parents b824c94 + babfd46 commit 39c727e
Show file tree
Hide file tree
Showing 39 changed files with 575 additions and 294 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
mkdir /tmp/java-storage
tar zxvf bazel-bin/test/integration/google-cloud-storage-v2-java.tar.gz -C /tmp/java-storage
pushd /tmp/java-storage/google-cloud-storage-v2-java
./gradlew clean build publishToMavenLocal
./gradlew clean build publishToMavenLocal sourcesJar allJars
popd
- name: Gradle Build Generated Compute Client Library
Expand All @@ -62,7 +62,7 @@ jobs:
bazel --batch build @com_google_googleapis//google/cloud/compute/v1small:google-cloud-compute-small-v1-java
tar zxvf bazel-bin/external/com_google_googleapis/google/cloud/compute/v1small/google-cloud-compute-small-v1-java.tar.gz -C /tmp/java-compute
pushd /tmp/java-compute/google-cloud-compute-small-v1-java
./gradlew clean build publishToMavenLocal
./gradlew clean build publishToMavenLocal sourcesJar allJars
popd
- uses: actions/upload-artifact@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Bazel.
bazel-*
.gradle/

# IDE
.idea
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## [2.5.0](https://github.com/googleapis/gapic-generator-java/compare/v2.4.1...v2.5.0) (2022-01-22)


### Features

* add server streaming support for REST transport ([#902](https://github.com/googleapis/gapic-generator-java/issues/902)) ([3b2dec6](https://github.com/googleapis/gapic-generator-java/commit/3b2dec6adf46823eeb6859e93362e63f00d84ffc))
* make generated test values comply with url path template ([#903](https://github.com/googleapis/gapic-generator-java/issues/903)) ([bfb35cd](https://github.com/googleapis/gapic-generator-java/commit/bfb35cd31c05b5fbd2ea8073bcdcfdd3496bca12))

### [2.4.1](https://github.com/googleapis/gapic-generator-java/compare/v2.4.0...v2.4.1) (2022-01-14)


### Bug Fixes

* expose extra deps transitively to library users ([#899](https://github.com/googleapis/gapic-generator-java/issues/899)) ([8fa2660](https://github.com/googleapis/gapic-generator-java/commit/8fa2660022cf65ebed011165378683173989332b))
* fix broken Gradle allJars task on generated libs ([#901](https://github.com/googleapis/gapic-generator-java/issues/901)) ([e990105](https://github.com/googleapis/gapic-generator-java/commit/e99010596d85f891a738de71be3b5fb9c857594a))

## [2.4.0](https://github.com/googleapis/gapic-generator-java/compare/v2.3.1...v2.4.0) (2022-01-11)


Expand Down
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jvm_maven_import_external(
# which in its turn, prioritizes actual generated clients runtime dependencies
# over the generator dependencies.

_gax_java_version = "2.7.1"
_gax_java_version = "2.10.0"

http_archive(
name = "com_google_api_gax_java",
Expand Down
100 changes: 0 additions & 100 deletions rules_bazel/java/integration_test.bzl
Original file line number Diff line number Diff line change
@@ -1,103 +1,3 @@
def _diff_integration_goldens_impl(ctx):
# Extract the Java source files from the generated 3 srcjars from API bazel target,
# and put them in the temporary folder `codegen_tmp`.
# Compare the `codegen_tmp` with the goldens folder e.g `test/integration/goldens/redis`
# and save the differences in output file `diff_output.txt`.

diff_output = ctx.outputs.diff_output
check_diff_script = ctx.outputs.check_diff_script
gapic_library = ctx.attr.gapic_library
resource_name_library = ctx.attr.resource_name_library
test_library = ctx.attr.test_library
srcs = ctx.files.srcs
api_name = ctx.attr.name

script = """
mkdir codegen_tmp
unzip {input} -d codegen_tmp
unzip {input_resource_name} -d codegen_tmp
unzip {input_test} -d codegen_tmp
cd codegen_tmp
# Remove unneeded non-Java files, like MANIFEST
rm -rf $(find ./ -type f ! -name '*.java' -a ! -name '*gapic_metadata.json')
rm -rf $(find ./ -type f -name 'PlaceholderFile.java')
rm -r $(find ./ -type d -empty)
cd ..
diff -r codegen_tmp test/integration/goldens/{api_name} > {diff_output}
# Bash `diff` command will return exit code 1 when there are differences between the two
# folders. So we explicitly `exit 0` after the diff command to avoid build failure.
exit 0
""".format(
diff_output = diff_output.path,
input = gapic_library[JavaInfo].source_jars[0].path,
input_resource_name = resource_name_library[JavaInfo].source_jars[0].path,
input_test = test_library[JavaInfo].source_jars[0].path,
api_name = api_name,
)
ctx.actions.run_shell(
inputs = srcs + [
gapic_library[JavaInfo].source_jars[0],
resource_name_library[JavaInfo].source_jars[0],
test_library[JavaInfo].source_jars[0],
],
outputs = [diff_output],
command = script,
)

# Check the generated diff_output file, if it is empty, that means there is no difference
# between generated source code and goldens files, test should pass. If it is not empty, then
# test will fail by exiting 1.

check_diff_script_content = """
# This will not print diff_output to the console unless `--test_output=all` option
# is enabled, it only emits the comparison results to the test.log.
# We could not copy the diff_output.txt to the test.log ($XML_OUTPUT_FILE) because that
# file is not existing at the moment. It is generated once test is finished.
cat $PWD/test/integration/{api_name}_diff_output.txt
if [ -s $PWD/test/integration/{api_name}_diff_output.txt ]
then
exit 1
fi
""".format(
api_name = api_name,
)

ctx.actions.write(
output = check_diff_script,
content = check_diff_script_content,
)
runfiles = ctx.runfiles(files = [ctx.outputs.diff_output])
return [DefaultInfo(executable = check_diff_script, runfiles = runfiles)]

diff_integration_goldens_test = rule(
attrs = {
"gapic_library": attr.label(),
"resource_name_library": attr.label(),
"test_library": attr.label(),
"srcs": attr.label_list(
allow_files = True,
mandatory = True,
),
},
outputs = {
"diff_output": "%{name}_diff_output.txt",
"check_diff_script": "%{name}_check_diff_script.sh",
},
implementation = _diff_integration_goldens_impl,
test = True,
)

def integration_test(name, target, data):
# Bazel target `java_gapic_library` will generate 3 source jars including the
# the source Java code of the gapic_library, resource_name_library and test_library.
diff_integration_goldens_test(
name = name,
gapic_library = target,
resource_name_library = "%s_resource_name" % target,
test_library = "%s_test" % target,
srcs = data,
)

def _overwrite_golden_impl(ctx):
# Extract the Java source files from the generated 3 srcjars from API bazel target,
# and put them in the temporary folder `codegen_tmp`, zip as `goldens_output_zip`.
Expand Down
2 changes: 1 addition & 1 deletion rules_java_gapic/java_gapic_pkg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def _java_gapic_build_configs_pkg_impl(ctx):

substitutions = dict(ctx.attr.static_substitutions)
substitutions["{{extra_deps}}"] = _construct_extra_deps({
"implementation": ctx.attr.deps,
"api": ctx.attr.deps,
"testImplementation": ctx.attr.test_deps,
}, substitutions)

Expand Down
4 changes: 2 additions & 2 deletions rules_java_gapic/resources/gradle/client_grpc.gradle.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ clean {
task allJars(type: Copy) {
dependsOn test, jar
into 'all-jars'
// Replace with `from configurations.testRuntimeOnly, jar` to include test dependencies
from configurations.runtimeOnly, jar
// Replace with `from configurations.testRuntimeClasspath, jar` to include test dependencies
from configurations.runtimeClasspath, jar
}
4 changes: 2 additions & 2 deletions rules_java_gapic/resources/gradle/client_grpcrest.gradle.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ clean {
task allJars(type: Copy) {
dependsOn test, jar
into 'all-jars'
// Replace with `from configurations.testRuntimeOnly, jar` to include test dependencies
from configurations.runtimeOnly, jar
// Replace with `from configurations.testRuntimeClasspath, jar` to include test dependencies
from configurations.runtimeClasspath, jar
}
4 changes: 2 additions & 2 deletions rules_java_gapic/resources/gradle/client_rest.gradle.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ clean {
task allJars(type: Copy) {
dependsOn test, jar
into 'all-jars'
// Replace with `from configurations.testRuntimeOnly, jar` to include test dependencies
from configurations.runtimeOnly, jar
// Replace with `from configurations.testRuntimeClasspath, jar` to include test dependencies
from configurations.runtimeClasspath, jar
}
3 changes: 3 additions & 0 deletions scripts/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package(default_visibility = ["//test/integration:__pkg__"])

exports_files(["diff_gen_and_golden.sh"])
23 changes: 23 additions & 0 deletions scripts/diff_gen_and_golden.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

set -o errexit

API_NAME=$1
RAW_SRCJAR=$( find . -name '*_java_gapic_srcjar_raw.srcjar' )

mkdir unpacked src
cd unpacked
unzip -q -c "../${RAW_SRCJAR}" temp-codegen.srcjar | jar x
cp -rf src/main/java/* ../src
cp -rf src/test/java/* ../src
[ -d proto ] && cp -rf proto/src/main/java/* ../src
cd ..

# Remove unneeded non-Java files, like MANIFEST
find src -type f ! -name '*.java' -a ! -name '*gapic_metadata.json' -delete
find src -type f -name 'PlaceholderFile.java' -delete
find src -type d -empty -delete

# This will not print diff_output to the console unless `--test_output=all` option
# is enabled, it only emits the comparison results to the test.log.
diff -ru src test/integration/goldens/${API_NAME}
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,28 @@ protected MethodDefinition createBatchingCallableMethod(Service service, TypeSto
protected abstract MethodDefinition createOperationCallableMethod(
Service service, TypeStore typeStore);

protected MethodDefinition createServerStreamingCallableMethod(
Service service, TypeStore typeStore) {
String methodVariantName = "ServerStreaming";
String requestTemplateName = "RequestT";
String responseTemplateName = "ResponseT";
List<String> methodTemplateNames = Arrays.asList(requestTemplateName, responseTemplateName);
return createGenericCallableMethod(
service,
typeStore,
/*methodTemplateNames=*/ methodTemplateNames,
/*returnCallableKindName=*/ methodVariantName,
/*returnCallableTemplateNames=*/ methodTemplateNames,
/*methodVariantName=*/ methodVariantName,
/*grpcCallSettingsTemplateObjects=*/ methodTemplateNames.stream()
.map(n -> (Object) n)
.collect(Collectors.toList()),
/*callSettingsVariantName=*/ methodVariantName,
/*callSettingsTemplateObjects=*/ methodTemplateNames.stream()
.map(n -> (Object) n)
.collect(Collectors.toList()));
}

protected MethodDefinition createGenericCallableMethod(
Service service,
TypeStore typeStore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ private MethodDefinition createRpcTestMethod(
AssignmentExpr.builder()
.setVariableExpr(responsesElementVarExpr.toBuilder().setIsDecl(true).build())
.setValueExpr(
DefaultValueComposer.createDefaultValue(
DefaultValueComposer.createValue(
Field.builder()
.setType(repeatedResponseType)
.setName("responsesElement")
Expand All @@ -377,23 +377,23 @@ private MethodDefinition createRpcTestMethod(
method.name(), methodOutputMessage.name()));

expectedResponseValExpr =
DefaultValueComposer.createSimplePagedResponse(
DefaultValueComposer.createSimplePagedResponseValue(
method.outputType(),
firstRepeatedField.name(),
responsesElementVarExpr,
firstRepeatedField.isMap());
} else {
if (messageTypes.containsKey(methodOutputType.reference().fullName())) {
expectedResponseValExpr =
DefaultValueComposer.createSimpleMessageBuilderExpr(
DefaultValueComposer.createSimpleMessageBuilderValue(
messageTypes.get(methodOutputType.reference().fullName()),
resourceNames,
messageTypes);
} else {
// Wrap this in a field so we don't have to split the helper into lots of different methods,
// or duplicate it for VariableExpr.
expectedResponseValExpr =
DefaultValueComposer.createDefaultValue(
DefaultValueComposer.createValue(
Field.builder()
.setType(methodOutputType)
.setIsMessage(true)
Expand Down Expand Up @@ -422,7 +422,7 @@ private MethodDefinition createRpcTestMethod(
AssignmentExpr.builder()
.setVariableExpr(resultOperationVarExpr.toBuilder().setIsDecl(true).build())
.setValueExpr(
DefaultValueComposer.createSimpleOperationBuilderExpr(
DefaultValueComposer.createSimpleOperationBuilderValue(
String.format("%sTest", JavaStyle.toLowerCamelCase(method.name())),
expectedResponseVarExpr))
.build());
Expand Down Expand Up @@ -457,22 +457,32 @@ private MethodDefinition createRpcTestMethod(
argExprs.add(requestVarExpr);
requestMessage = messageTypes.get(method.inputType().reference().fullName());
Preconditions.checkNotNull(requestMessage);
Map<String, String> pathParamValuePatterns = Collections.emptyMap();
if (getTransportContext().useValuePatterns() && method.hasHttpBindings()) {
pathParamValuePatterns = method.httpBindings().getPathParametersValuePatterns();
}
Expr valExpr =
DefaultValueComposer.createSimpleMessageBuilderExpr(
requestMessage, resourceNames, messageTypes);
DefaultValueComposer.createSimpleMessageBuilderValue(
requestMessage, resourceNames, messageTypes, pathParamValuePatterns);
methodExprs.add(
AssignmentExpr.builder()
.setVariableExpr(requestVarExpr.toBuilder().setIsDecl(true).build())
.setValueExpr(valExpr)
.build());
} else {
Map<String, String> valuePatterns = Collections.emptyMap();
if (getTransportContext().useValuePatterns() && method.hasHttpBindings()) {
valuePatterns = method.httpBindings().getPathParametersValuePatterns();
}
for (MethodArgument methodArg : methodSignature) {
String methodArgName = JavaStyle.toLowerCamelCase(methodArg.name());
VariableExpr varExpr =
VariableExpr.withVariable(
Variable.builder().setType(methodArg.type()).setName(methodArgName).build());
argExprs.add(varExpr);
Expr valExpr = createDefaultValue(methodArg, resourceNames);
Expr valExpr =
DefaultValueComposer.createMethodArgValue(
methodArg, resourceNames, messageTypes, valuePatterns);
methodExprs.add(
AssignmentExpr.builder()
.setVariableExpr(varExpr.toBuilder().setIsDecl(true).build())
Expand Down Expand Up @@ -737,9 +747,6 @@ protected abstract List<Statement> createStreamingRpcExceptionTestStatements(
Map<String, ResourceName> resourceNames,
Map<String, Message> messageTypes);

protected abstract Expr createDefaultValue(
MethodArgument methodArg, Map<String, ResourceName> resourceNames);

protected List<Statement> createRpcExceptionTestStatements(
Method method,
List<MethodArgument> methodSignature,
Expand All @@ -748,6 +755,7 @@ protected List<Statement> createRpcExceptionTestStatements(
Map<String, Message> messageTypes) {
List<VariableExpr> argVarExprs = new ArrayList<>();
List<Expr> tryBodyExprs = new ArrayList<>();

if (methodSignature.isEmpty()) {
// Construct the actual request.
VariableExpr varExpr =
Expand All @@ -756,22 +764,32 @@ protected List<Statement> createRpcExceptionTestStatements(
argVarExprs.add(varExpr);
Message requestMessage = messageTypes.get(method.inputType().reference().fullName());
Preconditions.checkNotNull(requestMessage);
Map<String, String> valuePatterns = Collections.emptyMap();
if (getTransportContext().useValuePatterns() && method.hasHttpBindings()) {
valuePatterns = method.httpBindings().getPathParametersValuePatterns();
}
Expr valExpr =
DefaultValueComposer.createSimpleMessageBuilderExpr(
requestMessage, resourceNames, messageTypes);
DefaultValueComposer.createSimpleMessageBuilderValue(
requestMessage, resourceNames, messageTypes, valuePatterns);
tryBodyExprs.add(
AssignmentExpr.builder()
.setVariableExpr(varExpr.toBuilder().setIsDecl(true).build())
.setValueExpr(valExpr)
.build());
} else {
Map<String, String> valuePatterns = Collections.emptyMap();
if (getTransportContext().useValuePatterns() && method.hasHttpBindings()) {
valuePatterns = method.httpBindings().getPathParametersValuePatterns();
}
for (MethodArgument methodArg : methodSignature) {
String methodArgName = JavaStyle.toLowerCamelCase(methodArg.name());
VariableExpr varExpr =
VariableExpr.withVariable(
Variable.builder().setType(methodArg.type()).setName(methodArgName).build());
argVarExprs.add(varExpr);
Expr valExpr = createDefaultValue(methodArg, resourceNames);
Expr valExpr =
DefaultValueComposer.createMethodArgValue(
methodArg, resourceNames, messageTypes, valuePatterns);
tryBodyExprs.add(
AssignmentExpr.builder()
.setVariableExpr(varExpr.toBuilder().setIsDecl(true).build())
Expand Down
Loading

0 comments on commit 39c727e

Please sign in to comment.