Skip to content

Commit

Permalink
Merge branch 'main' into samplegen-pt3
Browse files Browse the repository at this point in the history
  • Loading branch information
eaball35 committed Feb 23, 2022
2 parents 1742843 + b49f243 commit ffafbb2
Show file tree
Hide file tree
Showing 23 changed files with 1,095 additions and 45 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/ci-maven.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
on:
push:
branches:
- main
pull_request:
name: ci-maven
jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
java: [8, 11]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
- run: java -version

- name: Cache local Maven repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Unit Tests
run: |
mvn verify --batch-mode --no-transfer-progress
- name: Java Linter
run: mvn fmt:check
36 changes: 36 additions & 0 deletions .github/workflows/sonar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: SonarCloud Build
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=googleapis_gapic-generator-java -Dsonar.organization=googleapis -Dsonar.host.url=https://sonarcloud.io
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Bazel.
bazel-*
.gradle/
target/

# IDE
.idea
Expand Down
51 changes: 38 additions & 13 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,24 @@ TEST_DEPS = [
"@io_github_java_diff_utils//jar",
]

proto_library(
name = "service_config_proto",
srcs = ["src/main/proto/service_config.proto"],
deps = [
"@com_google_googleapis//google/rpc:code_proto",
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:wrappers_proto",
"@com_google_protobuf//:struct_proto",
],
)
java_proto_library(
name = "service_config_java_proto",
deps = ["@io_grpc_proto//:service_config_proto"],
deps = [":service_config_proto"],
)

proto_library(
name = "test_protos",
srcs = glob(["src/test/resources/*.proto"]),
srcs = glob(["src/test/proto/*.proto"]),
deps = [
"@com_google_googleapis//google/api:annotations_proto",
"@com_google_googleapis//google/api:client_proto",
Expand Down Expand Up @@ -85,14 +95,25 @@ java_plugin(
deps = ["@com_google_auto_value_auto_value//jar"],
)

java_binary(
name = "protoc-gen-java_gapic",
java_library(
name = "gapic_generator_java",
srcs = glob(["src/main/java/**/*.java"]),
main_class = "com.google.api.generator.Main",
plugins = [":autovalue_plugin"],
deps = MAIN_DEPS,
)

java_library(
name = "gapic_generator_java_test",
srcs = glob(["src/test/java/**/*.java"]),
deps = [":gapic_generator_java"] + MAIN_DEPS + TEST_DEPS,
)

java_binary(
name = "protoc-gen-java_gapic",
main_class = "com.google.api.generator.Main",
runtime_deps = [":gapic_generator_java"] + MAIN_DEPS,
)

# Request dumper binary, which dumps the CodeGeneratorRequest to a file on disk
# which will be identical to the one passed to the protoc-gen-java_gapic during
# normal execution. The dumped file then can be used to run this gapic-generator
Expand All @@ -112,7 +133,7 @@ java_binary(
java_binary(
name = "protoc-gen-code_generator_request_dumper",
main_class = "com.google.api.generator.debug.CodeGeneratorRequestDumper",
runtime_deps = [":protoc-gen-java_gapic"] + MAIN_DEPS + MAIN_DEPS_DEBUG_RUNTIME_ONLY,
runtime_deps = [":gapic_generator_java"] + MAIN_DEPS + MAIN_DEPS_DEBUG_RUNTIME_ONLY,
)

# A binary similar to protoc-gen-java_gapic but reads the CodeGeneratorRequest
Expand All @@ -125,14 +146,14 @@ java_binary(
java_binary(
name = "code_generator_request_file_to_gapic_main",
main_class = "com.google.api.generator.debug.CodeGeneratorRequestFileToGapicMain",
runtime_deps = [":protoc-gen-java_gapic"] + MAIN_DEPS + MAIN_DEPS_DEBUG_RUNTIME_ONLY,
runtime_deps = [":gapic_generator_java"] + MAIN_DEPS + MAIN_DEPS_DEBUG_RUNTIME_ONLY,
)

# another test resource
genrule(
name = "basic_proto_descriptor",
srcs = ["src/test/resources/basic.proto"],
outs = ["basic_proto.descriptor"],
srcs = ["src/test/proto/basic.proto"],
outs = ["test-proto.descriptorset"],
cmd = "$(location @com_google_protobuf//:protoc) " +
"--include_source_info --include_imports --descriptor_set_out=$(OUTS) $(SRCS)",
message = "Generating proto descriptor",
Expand All @@ -143,9 +164,11 @@ genrule(
# bazel test //:unit_com_google_api_generator_engine_JavaCodeGeneratorTest
[java_test(
name = "unit_" + file[14:-5].replace('/', '_'),
srcs = glob(["src/test/java/**/*.java"]),
test_class = file[14:-5].replace('/', '.'),
deps = [":protoc-gen-java_gapic"] + MAIN_DEPS + TEST_DEPS,
runtime_deps = [
":gapic_generator_java",
":gapic_generator_java_test",
] + MAIN_DEPS + TEST_DEPS,
data = [":basic_proto_descriptor"] + glob([
"src/test/java/**/*.golden",
"src/test/resources/**",
Expand Down Expand Up @@ -182,10 +205,12 @@ GOLDEN_UPDATING_UNIT_TESTS = [
# bazel run //:update_com_google_api_generator_engine_JavaCodeGeneratorTest
[java_binary(
name = "update_%s" % test_class.replace('.', '_'),
srcs = glob(["src/test/java/**/*.java"]),
main_class = "com.google.api.generator.test.framework.SingleJUnitTestRunner",
args = [test_class],
deps = [":protoc-gen-java_gapic"] + MAIN_DEPS + TEST_DEPS,
runtime_deps = [
":gapic_generator_java",
":gapic_generator_java-test",
] + MAIN_DEPS + TEST_DEPS,
data = glob([
"src/test/java/**/*.golden",
"src/test/resources/**",
Expand Down
34 changes: 31 additions & 3 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
java_proto_library(
name = "showcase_java_proto",
deps = [
"showcase_proto",
":showcase_proto",
],
)
Expand Down Expand Up @@ -92,12 +92,20 @@
```sh
bazel run //:google_java_format_verification
```
or
```sh
mvn fmt:check
```

- Format files.

```sh
bazel run //:google_java_format
```
or
```sh
mvn fmt:format
```

## Test Running

Expand All @@ -112,18 +120,38 @@
```sh
bazel test //:units
```
or
```sh
mvn test
```

- Run a single unit test like `JavaCodeGeneratorTest.java`
- Run a single unit test like `JavaCodeGeneratorTest.java`:

```sh
bazel test //:unit_com_google_api_generator_engine_JavaCodeGeneratorTest
```
or
```sh
mvn test -Dtest=JavaCodeGeneratorTest
- Update unit test golden files, for example `JavaCodeGeneratorTest.java`:
mvn test "-Dtest=Basic*, !%regex[.*.Unstable.*], !%regex[.*.MyTest.class#one.*|two.*], %regex[#fast.*|slow.*]"
```
- Update all unit test golden files:

```sh
mvn test -DupdateUnitGoldens
```

- Update a single unit test golden file, for example `JavaCodeGeneratorTest.java`:

```sh
bazel run //:update_com_google_api_generator_engine_JavaCodeGeneratorTest
```
or
```sh
mvn test -DupdateUnitGoldens -Dtest=JavaCodeGeneratorTest
```

- Run a single integration test for API like `Redis`, it generates Java source
code using the Java microgenerator and compares them with the goldens files
Expand Down
Loading

0 comments on commit ffafbb2

Please sign in to comment.