Skip to content

Commit

Permalink
Merge Pre-DIREGAPIC refactoring (#735)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
vam-google authored May 26, 2021
1 parent 44a42a0 commit 04c2faa
Show file tree
Hide file tree
Showing 92 changed files with 2,940 additions and 2,043 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
echo "The old one will disappear after 7 days."
- name: Unit Tests
run: bazel --batch test $(bazel query "//src/test/..." | grep "Test$") --noshow_progress
run: bazel --batch test $(bazel query "//src/test/..." | grep "Test$") --noshow_progress --test_output=errors

- name: Integration Tests
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
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

* 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))


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


Expand Down
3 changes: 1 addition & 2 deletions dependencies.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ version.com_google_protobuf=3.13.0
# 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.
version.google_java_format=1.7
version.com_google_api_common_java=1.9.3
# TODO(miraleung): Update this.
version.com_google_gax_java=1.62.0
version.io_grpc_java=1.30.2

# Common deps.
maven.com_google_guava_guava=com.google.guava:guava:26.0-jre
maven.com_google_guava_guava=com.google.guava:guava:30.1-android
maven.com_google_code_findbugs_jsr305=com.google.code.findbugs:jsr305:3.0.0
maven.com_google_auto_value_auto_value=com.google.auto.value:auto-value:1.7.2
maven.com_google_auto_value_auto_value_annotations=com.google.auto.value:auto-value-annotations:1.7.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ java_library(
"//src/main/java/com/google/api/generator/engine/writer",
"//src/main/java/com/google/api/generator/gapic:status_java_proto",
"//src/main/java/com/google/api/generator/gapic/composer/comment",
"//src/main/java/com/google/api/generator/gapic/composer/common",
"//src/main/java/com/google/api/generator/gapic/composer/defaultvalue",
"//src/main/java/com/google/api/generator/gapic/composer/grpc",
"//src/main/java/com/google/api/generator/gapic/composer/resourcename",
"//src/main/java/com/google/api/generator/gapic/composer/samplecode",
"//src/main/java/com/google/api/generator/gapic/composer/store",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
import com.google.api.generator.engine.ast.ClassDefinition;
import com.google.api.generator.engine.ast.ScopeNode;
import com.google.api.generator.gapic.composer.comment.CommentComposer;
import com.google.api.generator.gapic.composer.common.ServiceClientClassComposer;
import com.google.api.generator.gapic.composer.common.ServiceStubClassComposer;
import com.google.api.generator.gapic.composer.grpc.GrpcServiceCallableFactoryClassComposer;
import com.google.api.generator.gapic.composer.grpc.GrpcServiceStubClassComposer;
import com.google.api.generator.gapic.composer.grpc.MockServiceClassComposer;
import com.google.api.generator.gapic.composer.grpc.MockServiceImplClassComposer;
import com.google.api.generator.gapic.composer.grpc.ServiceClientTestClassComposer;
import com.google.api.generator.gapic.composer.grpc.ServiceSettingsClassComposer;
import com.google.api.generator.gapic.composer.grpc.ServiceStubSettingsClassComposer;
import com.google.api.generator.gapic.composer.resourcename.ResourceNameHelperClassComposer;
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.GapicClass.Kind;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class SettingsCommentComposer {
public static final CommentStatement DEFAULT_CREDENTIALS_PROVIDER_BUILDER_METHOD_COMMENT =
toSimpleComment("Returns a builder for the default credentials for this service.");

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

public static final CommentStatement NEW_BUILDER_METHOD_COMMENT =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,53 @@
public class StubCommentComposer {
private static final String STUB_CLASS_HEADER_SUMMARY_PATTERN =
"Base stub class for the %s service API.";
private static final String GRPC_CALLABLE_FACTORY_CLASS_HEADER_SUMMARY_PATTERN =
"gRPC callable factory implementation for the %s service API.";
private static final String GRPC_STUB_CLASS_HEADER_SUMMARY_PATTERN =
"gRPC stub implementation for the %s service API.";
private static final String TRANSPORT_CALLABLE_FACTORY_CLASS_HEADER_SUMMARY_PATTERN =
"%s callable factory implementation for the %s service API.";
private static final String TRANSPORT_STUB_CLASS_HEADER_SUMMARY_PATTERN =
"%s stub implementation for the %s service API.";

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

public static List<CommentStatement> createGrpcServiceStubClassHeaderComments(
private final String transportPrefix;

public StubCommentComposer(String transportPrefix) {
this.transportPrefix = transportPrefix;
}

public List<CommentStatement> createTransportServiceStubClassHeaderComments(
String serviceName, boolean isDeprecated) {
JavaDocComment.Builder javaDocBuilder = JavaDocComment.builder();
if (isDeprecated) {
javaDocBuilder = javaDocBuilder.setDeprecated(CommentComposer.DEPRECATED_CLASS_STRING);
}

return Arrays.asList(
CommentComposer.AUTO_GENERATED_CLASS_COMMENT,
CommentStatement.withComment(
javaDocBuilder
.addComment(String.format(GRPC_STUB_CLASS_HEADER_SUMMARY_PATTERN, serviceName))
.addComment(
String.format(
TRANSPORT_STUB_CLASS_HEADER_SUMMARY_PATTERN, transportPrefix, serviceName))
.addParagraph(ADVANCED_USAGE_API_REFLECTION_DESCRIPTION)
.build()));
}

public static List<CommentStatement> createGrpcServiceCallableFactoryClassHeaderComments(
public List<CommentStatement> createTransportServiceCallableFactoryClassHeaderComments(
String serviceName, boolean isDeprecated) {
JavaDocComment.Builder javaDocBuilder = JavaDocComment.builder();
if (isDeprecated) {
javaDocBuilder = javaDocBuilder.setDeprecated(CommentComposer.DEPRECATED_CLASS_STRING);
}

return Arrays.asList(
CommentComposer.AUTO_GENERATED_CLASS_COMMENT,
CommentStatement.withComment(
javaDocBuilder
.addComment(
String.format(GRPC_CALLABLE_FACTORY_CLASS_HEADER_SUMMARY_PATTERN, serviceName))
String.format(
TRANSPORT_CALLABLE_FACTORY_CLASS_HEADER_SUMMARY_PATTERN,
transportPrefix,
serviceName))
.addParagraph(ADVANCED_USAGE_DESCRIPTION)
.build()));
}
Expand Down
Loading

0 comments on commit 04c2faa

Please sign in to comment.