Skip to content

Commit 04c2faa

Browse files
authored
Merge Pre-DIREGAPIC refactoring (#735)
Prepare `gapic-generator-java` for the DIREGAPIC implementation changes. 1) Splitting Grpc-specific classes into their own package (mainly `composer` classes) 2) Extract the transport-agnostic logic of the composer classes into the set of abstract classes. 3) Convert most of the static methods in the `ClassComposer` classes into instance methods to leverage the class inheritance (transport-agnostic logic in abstract class, transport-specific portions are in transport-specific classes extending the abstract ones) 4) The resultant architecture resembles the [Template Method](https://en.wikipedia.org/wiki/Template_method_pattern) design pattern where `Abstract<Name>ClassComposer.generate()` (and potentially the the other private/protected methods called from `generate()`) call transport-specific logic (implemented in the concrete `<Transport><Name>ClassComposer` classes), when appropriate. 5) Refactor the tests and golden files file structure to match the main classes package structure. 6) The golden files were split to be placed under the same directory as the clases which generate them. This was matching the existing infrastructure the best: (1) as the golden files updater makes this assumption (golden file is under the same package as the `<Name>Test.java` which creates it); (2) the repo currently does not have a dedicated test resources directory (there are multiple resource-like subfolders under test, it is hard to keep thing under control and avoid propagating magical path constants); (3) keeping golden files and tests together seems ok, since if the golden files were smaller they would be simply put as the expected constants in the tests themselves. 7) This PR tries to preserve the original history of the files as accurately as possible (i.e. prioritizes clear move semantics over delete/create semantics in terms of file diff, where possible). The subsequent PR with rest implementation will looks something like [this](vam-google/gapic-generator-java@master...vam-google:diregapic_main)
1 parent 44a42a0 commit 04c2faa

File tree

92 files changed

+2940
-2043
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+2940
-2043
lines changed

.github/workflows/ci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
echo "The old one will disappear after 7 days."
4747
4848
- name: Unit Tests
49-
run: bazel --batch test $(bazel query "//src/test/..." | grep "Test$") --noshow_progress
49+
run: bazel --batch test $(bazel query "//src/test/..." | grep "Test$") --noshow_progress --test_output=errors
5050

5151
- name: Integration Tests
5252
run: bazel --batch test //test/integration:asset //test/integration:credentials //test/integration:iam //test/integration:kms //test/integration:logging //test/integration:pubsub //test/integration:redis //test/integration:library --noshow_progress

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
* Add PubSub to service.yaml / mixin allowlist ([#729](https://www.github.com/googleapis/gapic-generator-java/issues/729)) ([e7f6d33](https://www.github.com/googleapis/gapic-generator-java/commit/e7f6d33051e335504b05c402d3b98c387a9f0daf))
3030

31+
3132
### [1.0.6](https://www.github.com/googleapis/gapic-generator-java/compare/v1.0.5...v1.0.6) (2021-05-19)
3233

3334

dependencies.properties

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ version.com_google_protobuf=3.13.0
1111
# Version of google-java-format is downgraded from 1.8 to 1.7, because 1.8 supports java 11 minimum, while our JRE is java 8.
1212
version.google_java_format=1.7
1313
version.com_google_api_common_java=1.9.3
14-
# TODO(miraleung): Update this.
1514
version.com_google_gax_java=1.62.0
1615
version.io_grpc_java=1.30.2
1716

1817
# Common deps.
19-
maven.com_google_guava_guava=com.google.guava:guava:26.0-jre
18+
maven.com_google_guava_guava=com.google.guava:guava:30.1-android
2019
maven.com_google_code_findbugs_jsr305=com.google.code.findbugs:jsr305:3.0.0
2120
maven.com_google_auto_value_auto_value=com.google.auto.value:auto-value:1.7.2
2221
maven.com_google_auto_value_auto_value_annotations=com.google.auto.value:auto-value-annotations:1.7.2

src/main/java/com/google/api/generator/gapic/composer/BUILD.bazel

+2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ java_library(
1818
"//src/main/java/com/google/api/generator/engine/writer",
1919
"//src/main/java/com/google/api/generator/gapic:status_java_proto",
2020
"//src/main/java/com/google/api/generator/gapic/composer/comment",
21+
"//src/main/java/com/google/api/generator/gapic/composer/common",
2122
"//src/main/java/com/google/api/generator/gapic/composer/defaultvalue",
23+
"//src/main/java/com/google/api/generator/gapic/composer/grpc",
2224
"//src/main/java/com/google/api/generator/gapic/composer/resourcename",
2325
"//src/main/java/com/google/api/generator/gapic/composer/samplecode",
2426
"//src/main/java/com/google/api/generator/gapic/composer/store",

src/main/java/com/google/api/generator/gapic/composer/Composer.java

+9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717
import com.google.api.generator.engine.ast.ClassDefinition;
1818
import com.google.api.generator.engine.ast.ScopeNode;
1919
import com.google.api.generator.gapic.composer.comment.CommentComposer;
20+
import com.google.api.generator.gapic.composer.common.ServiceClientClassComposer;
21+
import com.google.api.generator.gapic.composer.common.ServiceStubClassComposer;
22+
import com.google.api.generator.gapic.composer.grpc.GrpcServiceCallableFactoryClassComposer;
23+
import com.google.api.generator.gapic.composer.grpc.GrpcServiceStubClassComposer;
24+
import com.google.api.generator.gapic.composer.grpc.MockServiceClassComposer;
25+
import com.google.api.generator.gapic.composer.grpc.MockServiceImplClassComposer;
26+
import com.google.api.generator.gapic.composer.grpc.ServiceClientTestClassComposer;
27+
import com.google.api.generator.gapic.composer.grpc.ServiceSettingsClassComposer;
28+
import com.google.api.generator.gapic.composer.grpc.ServiceStubSettingsClassComposer;
2029
import com.google.api.generator.gapic.composer.resourcename.ResourceNameHelperClassComposer;
2130
import com.google.api.generator.gapic.model.GapicClass;
2231
import com.google.api.generator.gapic.model.GapicClass.Kind;

src/main/java/com/google/api/generator/gapic/composer/comment/SettingsCommentComposer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class SettingsCommentComposer {
6767
public static final CommentStatement DEFAULT_CREDENTIALS_PROVIDER_BUILDER_METHOD_COMMENT =
6868
toSimpleComment("Returns a builder for the default credentials for this service.");
6969

70-
public static final CommentStatement DEFAULT_GRPC_TRANSPORT_PROVIDER_BUILDER_METHOD_COMMENT =
70+
public static final CommentStatement DEFAULT_TRANSPORT_PROVIDER_BUILDER_METHOD_COMMENT =
7171
toSimpleComment("Returns a builder for the default ChannelProvider for this service.");
7272

7373
public static final CommentStatement NEW_BUILDER_METHOD_COMMENT =

src/main/java/com/google/api/generator/gapic/composer/comment/StubCommentComposer.java

+19-10
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,53 @@
2222
public class StubCommentComposer {
2323
private static final String STUB_CLASS_HEADER_SUMMARY_PATTERN =
2424
"Base stub class for the %s service API.";
25-
private static final String GRPC_CALLABLE_FACTORY_CLASS_HEADER_SUMMARY_PATTERN =
26-
"gRPC callable factory implementation for the %s service API.";
27-
private static final String GRPC_STUB_CLASS_HEADER_SUMMARY_PATTERN =
28-
"gRPC stub implementation for the %s service API.";
25+
private static final String TRANSPORT_CALLABLE_FACTORY_CLASS_HEADER_SUMMARY_PATTERN =
26+
"%s callable factory implementation for the %s service API.";
27+
private static final String TRANSPORT_STUB_CLASS_HEADER_SUMMARY_PATTERN =
28+
"%s stub implementation for the %s service API.";
2929

3030
private static final String ADVANCED_USAGE_DESCRIPTION = "This class is for advanced usage.";
3131
private static final String ADVANCED_USAGE_API_REFLECTION_DESCRIPTION =
3232
"This class is for advanced usage and reflects the underlying API directly.";
3333

34-
public static List<CommentStatement> createGrpcServiceStubClassHeaderComments(
34+
private final String transportPrefix;
35+
36+
public StubCommentComposer(String transportPrefix) {
37+
this.transportPrefix = transportPrefix;
38+
}
39+
40+
public List<CommentStatement> createTransportServiceStubClassHeaderComments(
3541
String serviceName, boolean isDeprecated) {
3642
JavaDocComment.Builder javaDocBuilder = JavaDocComment.builder();
3743
if (isDeprecated) {
3844
javaDocBuilder = javaDocBuilder.setDeprecated(CommentComposer.DEPRECATED_CLASS_STRING);
3945
}
40-
4146
return Arrays.asList(
4247
CommentComposer.AUTO_GENERATED_CLASS_COMMENT,
4348
CommentStatement.withComment(
4449
javaDocBuilder
45-
.addComment(String.format(GRPC_STUB_CLASS_HEADER_SUMMARY_PATTERN, serviceName))
50+
.addComment(
51+
String.format(
52+
TRANSPORT_STUB_CLASS_HEADER_SUMMARY_PATTERN, transportPrefix, serviceName))
4653
.addParagraph(ADVANCED_USAGE_API_REFLECTION_DESCRIPTION)
4754
.build()));
4855
}
4956

50-
public static List<CommentStatement> createGrpcServiceCallableFactoryClassHeaderComments(
57+
public List<CommentStatement> createTransportServiceCallableFactoryClassHeaderComments(
5158
String serviceName, boolean isDeprecated) {
5259
JavaDocComment.Builder javaDocBuilder = JavaDocComment.builder();
5360
if (isDeprecated) {
5461
javaDocBuilder = javaDocBuilder.setDeprecated(CommentComposer.DEPRECATED_CLASS_STRING);
5562
}
56-
5763
return Arrays.asList(
5864
CommentComposer.AUTO_GENERATED_CLASS_COMMENT,
5965
CommentStatement.withComment(
6066
javaDocBuilder
6167
.addComment(
62-
String.format(GRPC_CALLABLE_FACTORY_CLASS_HEADER_SUMMARY_PATTERN, serviceName))
68+
String.format(
69+
TRANSPORT_CALLABLE_FACTORY_CLASS_HEADER_SUMMARY_PATTERN,
70+
transportPrefix,
71+
serviceName))
6372
.addParagraph(ADVANCED_USAGE_DESCRIPTION)
6473
.build()));
6574
}

0 commit comments

Comments
 (0)