-
Notifications
You must be signed in to change notification settings - Fork 70
feat(Spring CodeGen): Add customized spring composer for package info #1059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
787f666
Customize package info for spring and remove generation of gapic meta…
emmileaf 8dd72b0
Add descriptive title comment to package info
emmileaf 183ccae
Merge remote-tracking branch 'origin/autoconfig-gen-draft2' into auto…
emmileaf 7701be8
Add test for package info composer and use libname as fallback
emmileaf 5686a0c
Fix added unit test name
emmileaf f75a71b
Also add check for generated package-info in SpringComposerTest
emmileaf d89bbc1
Merge updates from autoconfig-gen-draft2 branch
emmileaf 5a24ae5
Update SpringpackageInfoComposer to use utils methods for naming logic
emmileaf 97361db
Update title comment
emmileaf 11cbe6d
Merge remote-tracking branch 'origin/autoconfig-gen-draft2' into auto…
emmileaf 2867963
Fix imports after merging updates
emmileaf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/com/google/api/generator/spring/composer/SpringPackageInfoComposer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // Copyright 2022 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package com.google.api.generator.spring.composer; | ||
|
|
||
| import com.google.api.generator.engine.ast.AnnotationNode; | ||
| import com.google.api.generator.engine.ast.CommentStatement; | ||
| import com.google.api.generator.engine.ast.ConcreteReference; | ||
| import com.google.api.generator.engine.ast.JavaDocComment; | ||
| import com.google.api.generator.engine.ast.PackageInfoDefinition; | ||
| import com.google.api.generator.engine.ast.TypeNode; | ||
| import com.google.api.generator.gapic.model.GapicContext; | ||
| import com.google.api.generator.gapic.model.GapicPackageInfo; | ||
| import com.google.api.generator.spring.utils.Utils; | ||
| import com.google.common.base.Preconditions; | ||
| import javax.annotation.Generated; | ||
|
|
||
| public class SpringPackageInfoComposer { | ||
| private static final String PACKAGE_INFO_TITLE_PATTERN = | ||
| "Spring Boot auto-configurations for %s."; | ||
|
|
||
| public static GapicPackageInfo generatePackageInfo(GapicContext context) { | ||
| Preconditions.checkState(!context.services().isEmpty(), "No services found to generate"); | ||
| PackageInfoDefinition packageInfo = | ||
| PackageInfoDefinition.builder() | ||
| .setPakkage(Utils.getSpringPackageName(Utils.getPackageName(context))) | ||
| .setHeaderCommentStatements(createPackageInfoJavadoc(context)) | ||
| .setAnnotations( | ||
| AnnotationNode.builder() | ||
| .setType(TypeNode.withReference(ConcreteReference.withClazz(Generated.class))) | ||
| .setDescription("by gapic-generator-java") | ||
| .build()) | ||
| .build(); | ||
| return GapicPackageInfo.with(packageInfo); | ||
| } | ||
|
|
||
| private static CommentStatement createPackageInfoJavadoc(GapicContext context) { | ||
| JavaDocComment.Builder javaDocCommentBuilder = JavaDocComment.builder(); | ||
| javaDocCommentBuilder = | ||
| javaDocCommentBuilder.addComment( | ||
| String.format(PACKAGE_INFO_TITLE_PATTERN, Utils.getLibName(context))); | ||
| return CommentStatement.withComment(javaDocCommentBuilder.build()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/test/java/com/google/api/generator/spring/composer/SpringPackageInfoComposerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // Copyright 2022 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package com.google.api.generator.spring.composer; | ||
|
|
||
| import com.google.api.generator.engine.writer.JavaWriterVisitor; | ||
| import com.google.api.generator.gapic.composer.common.TestProtoLoader; | ||
| import com.google.api.generator.gapic.model.GapicContext; | ||
| import com.google.api.generator.gapic.model.GapicPackageInfo; | ||
| import com.google.api.generator.test.framework.Assert; | ||
| import com.google.api.generator.test.framework.Utils; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| public class SpringPackageInfoComposerTest { | ||
| private GapicContext context; | ||
|
|
||
| @Before | ||
| public void setUp() { | ||
| this.context = TestProtoLoader.instance().parseShowcaseEcho(); | ||
| } | ||
|
|
||
| @Test | ||
| public void generateSpringPackageInfoTest() { | ||
| GapicPackageInfo packageInfo = SpringPackageInfoComposer.generatePackageInfo(this.context); | ||
| JavaWriterVisitor visitor = new JavaWriterVisitor(); | ||
| packageInfo.packageInfo().accept(visitor); | ||
| String fileName = "SpringPackageInfo.golden"; | ||
|
|
||
| Utils.saveCodegenToFile(this.getClass(), fileName, visitor.write()); | ||
| Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), fileName); | ||
| Assert.assertCodeEquals(goldenFilePath, visitor.write()); | ||
| } | ||
| } |
5 changes: 5 additions & 0 deletions
5
src/test/java/com/google/api/generator/spring/composer/goldens/SpringPackageInfo.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| /** Spring Boot auto-configurations for showcase. */ | ||
| @Generated("by gapic-generator-java") | ||
| package com.google.showcase.v1beta1.spring; | ||
|
|
||
| import javax.annotation.Generated; |
21 changes: 21 additions & 0 deletions
21
src/test/java/com/google/api/generator/spring/composer/goldens/SpringPackageInfoFull.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * Copyright 2022 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| /** Spring Boot auto-configurations for showcase. */ | ||
| @Generated("by gapic-generator-java") | ||
| package com.google.showcase.v1beta1.spring; | ||
|
|
||
| import javax.annotation.Generated; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.