-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ggj][codegen] feat: add package-info.java codegen (#414)
* fix: refactor requestBuilder into separate method in ServiceClientClassComposer * feat: add varargs to AnonClass and ref setter methods * feat: add HTTP annotation parsing/validation * feat: Generate RequestParamsExtractor in GrpcServiceStub * feat: add GrpcPublisherStub test to exercise HTTP subfields * fix: add ByteString to DefaultValueComposer * fix: Use repeated field name for paged RPC unit tests * fix: refactor exception field, use paged repeated field name, add pubsub client test * fix: ensure all testgen methods throw Exceptions * fix: Fix resname helper method names for of* and format* * fix: use only generated resnames in codegen * fix: propagate of*Name changes to resname codegen * fix: fix method arg resname mappings, add logging test * fix: ensure paged tests use the right repeated resp. type * feat: add PackageInfoDefinition AST node * feat: add package-info.java codegen
- Loading branch information
Showing
6 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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
43 changes: 43 additions & 0 deletions
43
src/main/java/com/google/api/generator/gapic/composer/ClientLibraryPackageInfoComposer.java
This file contains 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,43 @@ | ||
// Copyright 2020 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.gapic.composer; | ||
|
||
import com.google.api.generator.engine.ast.AnnotationNode; | ||
import com.google.api.generator.engine.ast.ConcreteReference; | ||
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.common.base.Preconditions; | ||
import javax.annotation.Generated; | ||
|
||
public class ClientLibraryPackageInfoComposer { | ||
public static GapicPackageInfo generatePackageInfo(GapicContext context) { | ||
Preconditions.checkState(!context.services().isEmpty(), "No services found to generate"); | ||
// Pick some service's package, as we assume they are all the same. | ||
String libraryPakkage = context.services().get(0).pakkage(); | ||
|
||
PackageInfoDefinition packageInfo = | ||
PackageInfoDefinition.builder() | ||
.setPakkage(libraryPakkage) | ||
.setAnnotations( | ||
AnnotationNode.builder() | ||
.setType(TypeNode.withReference(ConcreteReference.withClazz(Generated.class))) | ||
.setDescription("by gapic-generator-java") | ||
.build()) | ||
.build(); | ||
return GapicPackageInfo.with(packageInfo); | ||
} | ||
} |
This file contains 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
39 changes: 39 additions & 0 deletions
39
src/main/java/com/google/api/generator/gapic/model/GapicPackageInfo.java
This file contains 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,39 @@ | ||
// Copyright 2020 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.gapic.model; | ||
|
||
import com.google.api.generator.engine.ast.PackageInfoDefinition; | ||
import com.google.auto.value.AutoValue; | ||
|
||
/** A thin wrapper around PackageInfoDefinition to maintain a clean separation of concerns. */ | ||
@AutoValue | ||
public abstract class GapicPackageInfo { | ||
public abstract PackageInfoDefinition packageInfo(); | ||
|
||
public static GapicPackageInfo with(PackageInfoDefinition packageInfo) { | ||
return builder().setPackageInfo(packageInfo).build(); | ||
} | ||
|
||
static Builder builder() { | ||
return new AutoValue_GapicPackageInfo.Builder(); | ||
} | ||
|
||
@AutoValue.Builder | ||
abstract static class Builder { | ||
abstract Builder setPackageInfo(PackageInfoDefinition packageInfo); | ||
|
||
abstract GapicPackageInfo build(); | ||
} | ||
} |
This file contains 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