Skip to content

Commit ffafbb2

Browse files
committed
Merge branch 'main' into samplegen-pt3
2 parents 1742843 + b49f243 commit ffafbb2

23 files changed

Lines changed: 1095 additions & 45 deletions

.github/workflows/ci-maven.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
pull_request:
6+
name: ci-maven
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
strategy:
12+
matrix:
13+
java: [8, 11]
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions/setup-java@v1
17+
with:
18+
java-version: ${{ matrix.java }}
19+
- run: java -version
20+
21+
- name: Cache local Maven repository
22+
uses: actions/cache@v2
23+
with:
24+
path: ~/.m2/repository
25+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
26+
restore-keys: |
27+
${{ runner.os }}-maven-
28+
29+
- name: Unit Tests
30+
run: |
31+
mvn verify --batch-mode --no-transfer-progress
32+
33+
- name: Java Linter
34+
run: mvn fmt:check

.github/workflows/sonar.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: SonarCloud Build
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
types: [opened, synchronize, reopened]
8+
jobs:
9+
build:
10+
name: Build
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
with:
15+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
16+
- name: Set up JDK 11
17+
uses: actions/setup-java@v1
18+
with:
19+
java-version: 11
20+
- name: Cache SonarCloud packages
21+
uses: actions/cache@v1
22+
with:
23+
path: ~/.sonar/cache
24+
key: ${{ runner.os }}-sonar
25+
restore-keys: ${{ runner.os }}-sonar
26+
- name: Cache Maven packages
27+
uses: actions/cache@v1
28+
with:
29+
path: ~/.m2
30+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
31+
restore-keys: ${{ runner.os }}-m2
32+
- name: Build and analyze
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
35+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
36+
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

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Bazel.
21
bazel-*
32
.gradle/
3+
target/
44

55
# IDE
66
.idea

BUILD.bazel

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,24 @@ TEST_DEPS = [
4747
"@io_github_java_diff_utils//jar",
4848
]
4949

50+
proto_library(
51+
name = "service_config_proto",
52+
srcs = ["src/main/proto/service_config.proto"],
53+
deps = [
54+
"@com_google_googleapis//google/rpc:code_proto",
55+
"@com_google_protobuf//:duration_proto",
56+
"@com_google_protobuf//:wrappers_proto",
57+
"@com_google_protobuf//:struct_proto",
58+
],
59+
)
5060
java_proto_library(
5161
name = "service_config_java_proto",
52-
deps = ["@io_grpc_proto//:service_config_proto"],
62+
deps = [":service_config_proto"],
5363
)
5464

5565
proto_library(
5666
name = "test_protos",
57-
srcs = glob(["src/test/resources/*.proto"]),
67+
srcs = glob(["src/test/proto/*.proto"]),
5868
deps = [
5969
"@com_google_googleapis//google/api:annotations_proto",
6070
"@com_google_googleapis//google/api:client_proto",
@@ -85,14 +95,25 @@ java_plugin(
8595
deps = ["@com_google_auto_value_auto_value//jar"],
8696
)
8797

88-
java_binary(
89-
name = "protoc-gen-java_gapic",
98+
java_library(
99+
name = "gapic_generator_java",
90100
srcs = glob(["src/main/java/**/*.java"]),
91-
main_class = "com.google.api.generator.Main",
92101
plugins = [":autovalue_plugin"],
93102
deps = MAIN_DEPS,
94103
)
95104

105+
java_library(
106+
name = "gapic_generator_java_test",
107+
srcs = glob(["src/test/java/**/*.java"]),
108+
deps = [":gapic_generator_java"] + MAIN_DEPS + TEST_DEPS,
109+
)
110+
111+
java_binary(
112+
name = "protoc-gen-java_gapic",
113+
main_class = "com.google.api.generator.Main",
114+
runtime_deps = [":gapic_generator_java"] + MAIN_DEPS,
115+
)
116+
96117
# Request dumper binary, which dumps the CodeGeneratorRequest to a file on disk
97118
# which will be identical to the one passed to the protoc-gen-java_gapic during
98119
# normal execution. The dumped file then can be used to run this gapic-generator
@@ -112,7 +133,7 @@ java_binary(
112133
java_binary(
113134
name = "protoc-gen-code_generator_request_dumper",
114135
main_class = "com.google.api.generator.debug.CodeGeneratorRequestDumper",
115-
runtime_deps = [":protoc-gen-java_gapic"] + MAIN_DEPS + MAIN_DEPS_DEBUG_RUNTIME_ONLY,
136+
runtime_deps = [":gapic_generator_java"] + MAIN_DEPS + MAIN_DEPS_DEBUG_RUNTIME_ONLY,
116137
)
117138

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

131152
# another test resource
132153
genrule(
133154
name = "basic_proto_descriptor",
134-
srcs = ["src/test/resources/basic.proto"],
135-
outs = ["basic_proto.descriptor"],
155+
srcs = ["src/test/proto/basic.proto"],
156+
outs = ["test-proto.descriptorset"],
136157
cmd = "$(location @com_google_protobuf//:protoc) " +
137158
"--include_source_info --include_imports --descriptor_set_out=$(OUTS) $(SRCS)",
138159
message = "Generating proto descriptor",
@@ -143,9 +164,11 @@ genrule(
143164
# bazel test //:unit_com_google_api_generator_engine_JavaCodeGeneratorTest
144165
[java_test(
145166
name = "unit_" + file[14:-5].replace('/', '_'),
146-
srcs = glob(["src/test/java/**/*.java"]),
147167
test_class = file[14:-5].replace('/', '.'),
148-
deps = [":protoc-gen-java_gapic"] + MAIN_DEPS + TEST_DEPS,
168+
runtime_deps = [
169+
":gapic_generator_java",
170+
":gapic_generator_java_test",
171+
] + MAIN_DEPS + TEST_DEPS,
149172
data = [":basic_proto_descriptor"] + glob([
150173
"src/test/java/**/*.golden",
151174
"src/test/resources/**",
@@ -182,10 +205,12 @@ GOLDEN_UPDATING_UNIT_TESTS = [
182205
# bazel run //:update_com_google_api_generator_engine_JavaCodeGeneratorTest
183206
[java_binary(
184207
name = "update_%s" % test_class.replace('.', '_'),
185-
srcs = glob(["src/test/java/**/*.java"]),
186208
main_class = "com.google.api.generator.test.framework.SingleJUnitTestRunner",
187209
args = [test_class],
188-
deps = [":protoc-gen-java_gapic"] + MAIN_DEPS + TEST_DEPS,
210+
runtime_deps = [
211+
":gapic_generator_java",
212+
":gapic_generator_java-test",
213+
] + MAIN_DEPS + TEST_DEPS,
189214
data = glob([
190215
"src/test/java/**/*.golden",
191216
"src/test/resources/**",

DEVELOPMENT.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
java_proto_library(
4848
name = "showcase_java_proto",
4949
deps = [
50-
"showcase_proto",
50+
":showcase_proto",
5151
],
5252
)
5353
@@ -92,12 +92,20 @@
9292
```sh
9393
bazel run //:google_java_format_verification
9494
```
95+
or
96+
```sh
97+
mvn fmt:check
98+
```
9599

96100
- Format files.
97101

98102
```sh
99103
bazel run //:google_java_format
100104
```
105+
or
106+
```sh
107+
mvn fmt:format
108+
```
101109

102110
## Test Running
103111

@@ -112,18 +120,38 @@
112120
```sh
113121
bazel test //:units
114122
```
123+
or
124+
```sh
125+
mvn test
126+
```
115127

116-
- Run a single unit test like `JavaCodeGeneratorTest.java`
128+
- Run a single unit test like `JavaCodeGeneratorTest.java`:
117129

118130
```sh
119131
bazel test //:unit_com_google_api_generator_engine_JavaCodeGeneratorTest
120132
```
133+
or
134+
```sh
135+
mvn test -Dtest=JavaCodeGeneratorTest
121136
122-
- Update unit test golden files, for example `JavaCodeGeneratorTest.java`:
137+
mvn test "-Dtest=Basic*, !%regex[.*.Unstable.*], !%regex[.*.MyTest.class#one.*|two.*], %regex[#fast.*|slow.*]"
138+
```
139+
140+
- Update all unit test golden files:
141+
142+
```sh
143+
mvn test -DupdateUnitGoldens
144+
```
145+
146+
- Update a single unit test golden file, for example `JavaCodeGeneratorTest.java`:
123147

124148
```sh
125149
bazel run //:update_com_google_api_generator_engine_JavaCodeGeneratorTest
126150
```
151+
or
152+
```sh
153+
mvn test -DupdateUnitGoldens -Dtest=JavaCodeGeneratorTest
154+
```
127155

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

0 commit comments

Comments
 (0)