Skip to content

Commit

Permalink
Merge branch 'main' into chore/remove-unused-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeWang1127 committed Apr 30, 2024
2 parents a74fdec + 87069bc commit 31e4d04
Show file tree
Hide file tree
Showing 92 changed files with 3,267 additions and 461 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ about: Create a report to help us improve

Thanks for stopping by to let us know something could be better!

**PLEASE READ**: If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response.
**PLEASE READ**: Before creating a new issue, please read our [contributing guidelines](https://github.com/googleapis/gapic-generator-java/blob/main/CONTRIBUTING.md). If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response.

Please run down the following list and make sure you've tried the usual "quick fixes":

Expand Down
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ about: Suggest an idea for this library

Thanks for stopping by to let us know something could be better!

**PLEASE READ**: If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response.
**PLEASE READ**: Before creating a new issue, please read our [contributing guidelines](https://github.com/googleapis/gapic-generator-java/blob/main/CONTRIBUTING.md).
If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response.

**Is your feature request related to a problem? Please describe.**
What the problem is. Example: I'm always frustrated when [...]
Expand Down
5 changes: 2 additions & 3 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
Thank you for opening a Pull Request! For general contributing guidelines, please refer to [contributing guide](https://github.com/googleapis/gapic-generator-java/blob/main/CONTRIBUTING.md)

Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Thank you for opening a Pull Request! Before submitting your PR, please read our [contributing guidelines](https://github.com/googleapis/gapic-generator-java/blob/main/CONTRIBUTING.md).

There are a few things you can do to make sure it goes smoothly:
- [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/gapic-generator-java/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
distribution: temurin
cache: maven
- run: mvn -version
- name: Unit Tests
- name: Install
run: mvn install --errors --batch-mode --no-transfer-progress -Dcheckstyle.skip -T 1C
- name: Create issue if previous step fails
if: ${{ failure() }}
Expand Down
44 changes: 37 additions & 7 deletions .github/workflows/verify_library_generation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,38 @@ on:
branches:
- main
pull_request:
paths:
- library_generation/**

workflow_dispatch:
name: verify_library_generation
jobs:
integration_tests:
should-run-library-generation-tests:
runs-on: ubuntu-22.04
outputs:
should_run: ${{ steps.get_changed_directories.outputs.should_run }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: get changed directories in the pull request
id: get_changed_directories
shell: bash
run: |
set -ex
git checkout "${base_ref}"
git checkout "${head_ref}"
changed_directories="$(git diff --name-only ${base_ref} ${head_ref})"
if [[ ${changed_directories} =~ "library_generation/" ]]; then
echo "should_run=true" >> $GITHUB_OUTPUT
else
echo "should_run=false" >> $GITHUB_OUTPUT
fi
env:
base_ref: ${{ github.event.pull_request.base.ref }}
head_ref: ${{ github.event.pull_request.head.ref }}
library-generation-integration-tests:
runs-on: ubuntu-22.04
needs: should-run-library-generation-tests
if: needs.should-run-library-generation-tests.outputs.should_run == 'true'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand Down Expand Up @@ -41,12 +65,14 @@ jobs:
run: |
set -x
python -m unittest library_generation/test/integration_tests.py
unit_tests:
library-generation-unit-tests:
runs-on: ${{ matrix.os }}
needs: should-run-library-generation-tests
if: needs.should-run-library-generation-tests.outputs.should_run == 'true'
strategy:
matrix:
java: [ 8 ]
os: [ ubuntu-22.04, macos-12 ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: install utils (macos)
Expand Down Expand Up @@ -88,8 +114,10 @@ jobs:
run: |
set -x
python -m unittest discover -s library_generation/test/ -p "*unit_tests.py"
lint-shell:
library-generation-lint-shell:
runs-on: ubuntu-22.04
needs: should-run-library-generation-tests
if: needs.should-run-library-generation-tests.outputs.should_run == 'true'
steps:
- uses: actions/checkout@v4
- name: Run ShellCheck
Expand All @@ -98,8 +126,10 @@ jobs:
scandir: 'library_generation'
format: tty
severity: error
lint-python:
library-generation-lint-python:
runs-on: ubuntu-22.04
needs: should-run-library-generation-tests
if: needs.should-run-library-generation-tests.outputs.should_run == 'true'
steps:
- uses: actions/checkout@v4
- name: install python dependencies
Expand Down
11 changes: 0 additions & 11 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,6 @@ http_archive(
urls = ["https://github.com/googleapis/disco-to-proto3-converter/archive/%s.zip" % _disco_to_proto3_converter_commit],
)

# Showcase
_showcase_version = "0.28.2"

http_archive(
name = "com_google_gapic_showcase",
strip_prefix = "gapic-showcase-%s" % _showcase_version,
urls = [
"https://github.com/googleapis/gapic-showcase/archive/refs/tags/v%s.zip" % _showcase_version,
],
)

http_archive(
name = "rules_pkg",
sha256 = "8a298e832762eda1830597d64fe7db58178aa84cd5926d76d5b744d6558941c2",
Expand Down
2 changes: 1 addition & 1 deletion gapic-generator-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.2</version>
<version>3.5.3</version>
<executions>
<execution>
<phase>package</phase>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ static List<GapicClass> prepareExecutableSamples(List<GapicClass> clazzes) {
sample ->
samples.add(
addRegionTagAndHeaderToSample(
sample, gapicClass.apiShortName(), gapicClass.apiVersion())));
sample, gapicClass.apiShortName(), gapicClass.packageVersion())));
clazzesWithSamples.add(gapicClass.withSamples(samples));
});
return clazzesWithSamples;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public GapicClass generate(GapicContext context, Service service) {
updateGapicMetadata(context, service, className, grpcRpcsToJavaMethodNames);
return GapicClass.create(kind, classDef, SampleComposerUtil.handleDuplicateSamples(samples))
.withApiShortName(service.apiShortName())
.withApiVersion(service.apiVersion());
.withPackageVersion(service.packageVersion());
}

private static List<AnnotationNode> createClassAnnotations(Service service, TypeStore typeStore) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public GapicClass generate(GapicContext context, Service service) {
.build();
return GapicClass.create(kind, classDef, SampleComposerUtil.handleDuplicateSamples(samples))
.withApiShortName(service.apiShortName())
.withApiVersion(service.apiVersion());
.withPackageVersion(service.packageVersion());
}

private static List<CommentStatement> createClassHeaderComments(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public GapicClass generate(GapicContext context, Service service) {
return GapicClass.create(
GapicClass.Kind.STUB, classDef, SampleComposerUtil.handleDuplicateSamples(samples))
.withApiShortName(service.apiShortName())
.withApiVersion(service.apiVersion());
.withPackageVersion(service.packageVersion());
}

protected MethodDefinition createDefaultCredentialsProviderBuilderMethod() {
Expand Down Expand Up @@ -370,6 +370,16 @@ protected MethodDefinition createApiClientHeaderProviderBuilderMethod(
.setReturnType(returnType)
.build();

if (service.hasApiVersion()) {

returnExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(returnExpr)
.setMethodName("setApiVersionToken")
.setArguments(ValueExpr.withValue(StringObjectValue.withValue(service.apiVersion())))
.setReturnType(returnType)
.build();
}
return MethodDefinition.builder()
.setScope(ScopeNode.PUBLIC)
.setIsStatic(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public enum Kind {
public abstract String apiShortName();

// Only used for generating the region tag for samples; therefore only used in select Composers.
public abstract String apiVersion();
public abstract String packageVersion();

/**
* Create a GapicClass with minimal information. This is intended to be used for GapicClasses that
Expand Down Expand Up @@ -76,7 +76,7 @@ static Builder builder() {
return new AutoValue_GapicClass.Builder()
.setSamples(Collections.emptyList())
.setApiShortName("")
.setApiVersion("");
.setPackageVersion("");
}

abstract Builder toBuilder();
Expand All @@ -89,8 +89,8 @@ public final GapicClass withApiShortName(String apiShortName) {
return toBuilder().setApiShortName(apiShortName).build();
}

public final GapicClass withApiVersion(String apiVersion) {
return toBuilder().setApiVersion(apiVersion).build();
public final GapicClass withPackageVersion(String packageVersion) {
return toBuilder().setPackageVersion(packageVersion).build();
}

@AutoValue.Builder
Expand All @@ -103,7 +103,7 @@ abstract static class Builder {

abstract Builder setApiShortName(String apiShortName);

abstract Builder setApiVersion(String apiVersion);
abstract Builder setPackageVersion(String packageVersion);

abstract GapicClass build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
public abstract class Service {
public abstract String name();

@Nullable
public abstract String apiVersion();

public abstract String defaultHost();

public abstract ImmutableList<String> oauthScopes();
Expand All @@ -52,6 +55,10 @@ public boolean hasDescription() {
return !Strings.isNullOrEmpty(description());
}

public boolean hasApiVersion() {
return !Strings.isNullOrEmpty(apiVersion());
}

public String hostServiceName() {
// Host Service Name is guaranteed to exist and be non-null and non-empty
// Parser will fail if the default host is not supplied
Expand All @@ -65,9 +72,9 @@ public String apiShortName() {
return "";
}

public String apiVersion() {
public String packageVersion() {
if (!Strings.isNullOrEmpty(protoPakkage())) {
return parseApiVersion(protoPakkage());
return parsePackageVersion(protoPakkage());
}
return "";
}
Expand Down Expand Up @@ -158,6 +165,8 @@ public abstract static class Builder {

public abstract Builder setOverriddenName(String overriddenName);

public abstract Builder setApiVersion(String apiVersion);

public abstract Builder setDefaultHost(String defaultHost);

public abstract Builder setOauthScopes(List<String> oauthScopes);
Expand All @@ -177,17 +186,17 @@ public abstract static class Builder {
public abstract Service build();
}

private static String parseApiVersion(String protoPackage) {
// parse protoPackage for apiVersion
private static String parsePackageVersion(String protoPackage) {
// parse protoPackage for packageVersion
String[] pakkage = protoPackage.split("\\.");
String apiVersion;
String packageVersion;
// e.g. v1, v2, v1beta1
if (pakkage[pakkage.length - 1].matches("v[0-9].*")) {
apiVersion = pakkage[pakkage.length - 1];
packageVersion = pakkage[pakkage.length - 1];
} else {
apiVersion = "";
packageVersion = "";
}
return apiVersion;
return packageVersion;
}

// Parse the service name from the default host configured in the protos
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,11 @@ public static List<Service> parseService(
}
}

if (serviceOptions.hasExtension(ClientProto.apiVersion)) {
String apiVersion = serviceOptions.getExtension(ClientProto.apiVersion);
serviceBuilder.setApiVersion(apiVersion);
}

String serviceName = s.getName();
String overriddenServiceName = serviceName;
String pakkage = TypeParser.getPackage(fileDescriptor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ComposerTest {
GrpcServiceCallableFactoryClassComposer.instance()
.generate(context, echoProtoService)
.withApiShortName(echoProtoService.apiShortName())
.withApiVersion(echoProtoService.apiVersion()));
.withPackageVersion(echoProtoService.packageVersion()));
private final Sample sample =
Sample.builder()
.setRegionTag(
Expand Down Expand Up @@ -160,7 +160,7 @@ private List<GapicClass> getTestClassListFromService(Service testService) {
.generate(context, testService)
.withSamples(ListofSamples)
.withApiShortName(testService.apiShortName())
.withApiVersion(testService.apiVersion());
.withPackageVersion(testService.packageVersion());
List<GapicClass> testClassList = Arrays.asList(new GapicClass[] {testClass});
return testClassList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static Collection<Object[]> data() {
public String apiShortNameExpected;

@Parameterized.Parameter(3)
public String apiVersionExpected;
public String packageVersionExpected;

@Test
public void generateServiceClientClasses() {
Expand All @@ -83,6 +83,6 @@ public void generateServiceClientClasses() {
Assert.assertGoldenSamples(
this.getClass(), name, clazz.classDefinition().packageString(), clazz.samples());
Assert.assertCodeEquals(clazz.apiShortName(), apiShortNameExpected);
Assert.assertCodeEquals(clazz.apiVersion(), apiVersionExpected);
Assert.assertCodeEquals(clazz.packageVersion(), packageVersionExpected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static Collection<Object[]> data() {
public String apiShortNameExpected;

@Parameterized.Parameter(3)
public String apiVersionExpected;
public String packageVersionExpected;

@Test
public void generateServiceSettingsClasses() {
Expand All @@ -69,6 +69,6 @@ public void generateServiceSettingsClasses() {
clazz.classDefinition().packageString(),
clazz.samples());
Assert.assertCodeEquals(clazz.apiShortName(), apiShortNameExpected);
Assert.assertCodeEquals(clazz.apiVersion(), apiVersionExpected);
Assert.assertCodeEquals(clazz.packageVersion(), packageVersionExpected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static Collection<Object[]> data() {
public String apiShortNameExpected;

@Parameterized.Parameter(3)
public String apiVersionExpected;
public String packageVersionExpected;

@Test
public void generateServiceStubClasses() {
Expand All @@ -55,6 +55,6 @@ public void generateServiceStubClasses() {
Assert.assertGoldenClass(this.getClass(), clazz, name + ".golden");
Assert.assertEmptySamples(clazz.samples());
Assert.assertCodeEquals(clazz.apiShortName(), apiShortNameExpected);
Assert.assertCodeEquals(clazz.apiVersion(), apiVersionExpected);
Assert.assertCodeEquals(clazz.packageVersion(), packageVersionExpected);
}
}
Loading

0 comments on commit 31e4d04

Please sign in to comment.