Skip to content

Commit 4c04043

Browse files
Merge branch 'main' into future-tostring
2 parents 5a92d26 + cb24fdb commit 4c04043

File tree

8 files changed

+177
-53
lines changed

8 files changed

+177
-53
lines changed

.github/workflows/downstream.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,20 @@ jobs:
4747
run: ./.kokoro/presubmit/common_test.sh
4848
- name: Perform downstream compatibility testing
4949
run: REPOS_UNDER_TEST="${{ matrix.repo }}" ./.kokoro/presubmit/downstream-compatibility.sh
50+
downstream-compatibility-spring-generator:
51+
runs-on: ubuntu-22.04
52+
strategy:
53+
fail-fast: false
54+
steps:
55+
- uses: actions/checkout@v3
56+
- uses: actions/setup-java@v3
57+
with:
58+
java-version: 17
59+
distribution: temurin
60+
- run: mvn -version
61+
- name: Install xmllint
62+
run: |
63+
sudo apt-get update
64+
sudo apt-get -y install libxml2-utils
65+
- name: Perform downstream compatibility testing
66+
run: ./.kokoro/presubmit/downstream-compatibility-spring.sh

.github/workflows/verify_library_generation.yaml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,11 @@ jobs:
7373
set -x
7474
python -m unittest library_generation/test/integration_tests.py
7575
library-generation-unit-tests:
76-
runs-on: ${{ matrix.os }}
76+
runs-on: ubuntu-22.04
7777
needs: should-run-library-generation-tests
7878
if: needs.should-run-library-generation-tests.outputs.should_run == 'true'
79-
strategy:
80-
matrix:
81-
java: [ 8 ]
82-
os: [ ubuntu-22.04, macos-12 ]
8379
steps:
8480
- uses: actions/checkout@v4
85-
- name: install utils (macos)
86-
if: matrix.os == 'macos-12'
87-
shell: bash
88-
run: |
89-
brew update --preinstall
90-
brew install coreutils
9181
- uses: actions/setup-python@v5
9282
with:
9383
python-version: 3.11

.kokoro/presubmit/common.sh

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
commonScriptDir=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
17+
1618
# In the given directory ($1),
1719
# update the pom.xml's dependency on the given artifact ($2) to the given version ($3)
1820
# ex: update_dependency google-cloud-java/google-cloud-jar-parent google-cloud-shared-dependencies 1.2.3
@@ -70,20 +72,41 @@ function parse_pom_version {
7072
# ex: find_last_release_version java-bigtable
7173
# ex: find_last_release_version java-storage 2.22.x
7274
function find_last_release_version {
75+
repo=$1
7376
branch=${2-"main"} # Default to using main branch
74-
curl -s -o "versions_$1.txt" "https://raw.githubusercontent.com/googleapis/$1/$branch/versions.txt"
77+
org=${3-"googleapis"}
78+
curl -s -o "versions_${repo}.txt" "https://raw.githubusercontent.com/${org}/${repo}/${branch}/versions.txt"
7579

7680
# First check to see if there's an entry for the overall repo. Used for google-cloud-java.
77-
primary_artifact=$(grep -E "^$1" "versions_$1.txt" | head -n 1)
78-
if [ -z "$primary_artifact" ]; then
81+
primary_artifact=$(grep -E "^${repo}" "versions_${repo}.txt" | head -n 1)
82+
if [ -z "${primary_artifact}" ]; then
7983
# Otherwise, use the first google-cloud-* artifact's version.
8084
primary_artifact=$(grep -E "^google-cloud-" "versions_$1.txt" | head -n 1)
8185
fi
82-
if [ -z "$primary_artifact" ]; then
86+
if [ -z "${primary_artifact}" ]; then
8387
echo "Unable to identify primary artifact for $1"
8488
exit 1
8589
fi
8690

8791
parts=($(echo "$primary_artifact" | tr ":" "\n"))
8892
echo "${parts[1]}"
8993
}
94+
95+
# copies settings.xml from the root of sdk-platform-java into Maven's home
96+
# folder
97+
function setup_maven_mirror {
98+
echo "Setup maven mirror"
99+
mkdir -p "${HOME}/.m2"
100+
cp "${commonScriptDir}/../../settings.xml" "${HOME}/.m2"
101+
}
102+
103+
function install_repo_modules {
104+
target_projects="$1"
105+
projects_arg=""
106+
if [ -n "${target_projects}" ]; then
107+
projects_arg="--projects ${target_projects}"
108+
fi
109+
echo "Installing this repo's modules to local maven."
110+
mvn -q -B -ntp install ${projects_arg} \
111+
-Dcheckstyle.skip -Dfmt.skip -DskipTests -T 1C
112+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
# Copyright 2024 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# This script is only meant to test spring-cloud-gpc, specifically on its
17+
# autoconfig generation workflow
18+
19+
set -eox pipefail
20+
21+
# Get the directory of the build script
22+
scriptDir=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
23+
cd "${scriptDir}/../.." # cd to the root of this repo
24+
source "$scriptDir/common.sh"
25+
26+
install_repo_modules
27+
GAPIC_GENERATOR_VERSION=$(parse_pom_version "gapic-generator-java-bom")
28+
echo "Install complete. gapic-generator-java-bom = $GAPIC_GENERATOR_VERSION"
29+
30+
pushd gapic-generator-java/target
31+
# Download and configure spring-cloud-gcp for testing
32+
last_release=$(find_last_release_version "spring-cloud-gcp" "main" "GoogleCloudPlatform")
33+
git clone "https://github.com/GoogleCloudPlatform/spring-cloud-gcp.git" --depth=1 --branch "v$last_release"
34+
update_all_poms_dependency "spring-cloud-gcp" "gapic-generator-java-bom" "${GAPIC_GENERATOR_VERSION}"
35+
36+
# Install spring-cloud-gcp modules
37+
pushd spring-cloud-gcp/spring-cloud-generator
38+
../mvnw \
39+
-U \
40+
--batch-mode \
41+
--no-transfer-progress \
42+
--show-version \
43+
--threads 1.5C \
44+
--define maven.test.skip=true \
45+
--define maven.javadoc.skip=true \
46+
install
47+
48+
49+
# Generate showcase autoconfig
50+
./scripts/generate-showcase.sh
51+
pushd showcase/showcase-spring-starter
52+
mvn verify
53+
popd # showcase/showcase-spring-starter
54+
55+
popd # spring-cloud-gcp/spring-cloud-generator
56+
popd # gapic-generator-java/target

.kokoro/presubmit/downstream-compatibility.sh

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,15 @@ if [ -z "${REPOS_UNDER_TEST}" ]; then
2121
exit 1
2222
fi
2323

24+
2425
# Get the directory of the build script
2526
scriptDir=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
2627
cd "${scriptDir}/../.." # cd to the root of this repo
2728
source "$scriptDir/common.sh"
2829

29-
echo "Setup maven mirror"
30-
mkdir -p "${HOME}/.m2"
31-
cp settings.xml "${HOME}/.m2"
30+
setup_maven_mirror
3231

33-
echo "Installing this repo's modules to local maven."
34-
mvn -q -B -ntp install --projects '!gapic-generator-java' \
35-
-Dcheckstyle.skip -Dfmt.skip -DskipTests -T 1C
32+
install_repo_modules '!gapic-generator-java'
3633
SHARED_DEPS_VERSION=$(parse_pom_version java-shared-dependencies)
3734
echo "Install complete. java-shared-dependencies = $SHARED_DEPS_VERSION"
3835

gapic-generator-java/DEVELOPMENT.md

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,7 @@ To generate a production GAPIC API:
9999
100100
Replace the following section in googleapis
101101
```
102-
_gapic_generator_java_version = "2.13.0"
103-
104-
maven_install(
105-
artifacts = [
106-
"com.google.api:gapic-generator-java:" + _gapic_generator_java_version,
107-
],
108-
#Update this False for local development
109-
fail_on_missing_checksum = True,
110-
repositories = [
111-
"m2Local",
112-
"https://repo.maven.apache.org/maven2/",
113-
]
114-
)
102+
_gapic_generator_java_version = "2.43.0"
115103
116104
http_archive(
117105
name = "gapic_generator_java",
@@ -129,20 +117,8 @@ To generate a production GAPIC API:
129117
130118
to
131119
```
132-
_gapic_generator_java_version = "2.15.4-SNAPSHOT"
133-
134-
maven_install(
135-
artifacts = [
136-
"com.google.api:gapic-generator-java:" + _gapic_generator_java_version,
137-
],
138-
#Update this False for local development
139-
fail_on_missing_checksum = False,
140-
repositories = [
141-
"m2Local",
142-
"https://repo.maven.apache.org/maven2/",
143-
]
144-
)
145-
120+
_gapic_generator_java_version = "2.43.1-SNAPSHOT"
121+
146122
local_repository(
147123
name = "gapic_generator_java",
148124
path = "/absolute/path/to/your/local/sdk-platform-java",
@@ -155,7 +131,26 @@ To generate a production GAPIC API:
155131
)
156132
```
157133
158-
Note: At the time of writing, the gapic-generator version was `2.13.0`. Update the version to the latest version in the pom.xml
134+
Note: At the time of writing, the gapic-generator version was `2.43.0`. Update the version to the latest version in the pom.xml
135+
136+
Then update `fail_on_missing_checksum = False` in this `maven_install` target:
137+
138+
```
139+
maven_install(
140+
artifacts = [
141+
"com.google.api:gapic-generator-java:" + _gapic_generator_java_version,
142+
] + PROTOBUF_MAVEN_ARTIFACTS +
143+
IO_GRPC_GRPC_JAVA_ARTIFACTS,
144+
generate_compat_repositories = True,
145+
override_targets = IO_GRPC_GRPC_JAVA_OVERRIDE_TARGETS,
146+
#Update this False for local development
147+
fail_on_missing_checksum = True,
148+
repositories = [
149+
"m2Local",
150+
"https://repo.maven.apache.org/maven2/",
151+
]
152+
)
153+
```
159154
160155
3. Build the new target.
161156

gax-java/gax/src/main/java/com/google/api/gax/util/TimeConversionUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,27 @@ public static java.time.Duration toJavaTimeDuration(org.threeten.bp.Duration sou
3535
if (source == null) {
3636
return null;
3737
}
38-
return java.time.Duration.ofNanos(source.toNanos());
38+
return java.time.Duration.ofSeconds(source.getSeconds(), source.getNano());
3939
}
4040

4141
public static org.threeten.bp.Duration toThreetenDuration(java.time.Duration source) {
4242
if (source == null) {
4343
return null;
4444
}
45-
return org.threeten.bp.Duration.ofNanos(source.toNanos());
45+
return org.threeten.bp.Duration.ofSeconds(source.getSeconds(), source.getNano());
4646
}
4747

4848
public static java.time.Instant toJavaTimeInstant(org.threeten.bp.Instant source) {
4949
if (source == null) {
5050
return null;
5151
}
52-
return java.time.Instant.ofEpochMilli(source.toEpochMilli());
52+
return java.time.Instant.ofEpochSecond(source.getEpochSecond(), source.getNano());
5353
}
5454

5555
public static org.threeten.bp.Instant toThreetenInstant(java.time.Instant source) {
5656
if (source == null) {
5757
return null;
5858
}
59-
return org.threeten.bp.Instant.ofEpochMilli(source.toEpochMilli());
59+
return org.threeten.bp.Instant.ofEpochSecond(source.getEpochSecond(), source.getNano());
6060
}
6161
}

gax-java/gax/src/test/java/com/google/api/gax/util/TimeConversionUtilsTest.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737

3838
public class TimeConversionUtilsTest {
3939

40+
// 0.999999999 seconds (1 second - 1 nano) - we need to subtract the nano or the Duration would
41+
// overflow otherwise
42+
final long MAX_DURATION_NANOS =
43+
1 * 1000 /*=1 micro*/ * 1000 /*=1 milli*/ * 1000 /*=1 second*/ - 1;
44+
45+
// Arbitrary durations/instants to confirm conversion works as expected
4046
final org.threeten.bp.Duration ttDuration = org.threeten.bp.Duration.ofMillis(123);
4147
final org.threeten.bp.Instant ttInstant = org.threeten.bp.Instant.ofEpochMilli(123);
4248
final java.time.Duration jtDuration = java.time.Duration.ofMillis(345);
@@ -69,4 +75,44 @@ void testToThreetenTimeInstant_validInput_succeeds() {
6975
jtInstant.toEpochMilli(), TimeConversionUtils.toThreetenInstant(jtInstant).toEpochMilli());
7076
assertNull(TimeConversionUtils.toThreetenInstant(null));
7177
}
78+
79+
@Test
80+
void testToThreeteenInstant_bigInput_doesNotOverflow() {
81+
// defaults to MAX_SECONDS plus the max value of long for the nanos part
82+
java.time.Instant jtInstant = java.time.Instant.MAX;
83+
org.threeten.bp.Instant ttInstant = TimeConversionUtils.toThreetenInstant(jtInstant);
84+
assertEquals(jtInstant.getEpochSecond(), ttInstant.getEpochSecond());
85+
assertEquals(jtInstant.getNano(), ttInstant.getNano());
86+
}
87+
88+
@Test
89+
void testToJavaTimeInstant_bigInput_doesNotOverflow() {
90+
// defaults to MAX_SECONDS plus the max value of long for the nanos part
91+
org.threeten.bp.Instant ttInstant = org.threeten.bp.Instant.MAX;
92+
java.time.Instant jtInstant = TimeConversionUtils.toJavaTimeInstant(ttInstant);
93+
assertEquals(jtInstant.getEpochSecond(), ttInstant.getEpochSecond());
94+
assertEquals(jtInstant.getNano(), ttInstant.getNano());
95+
}
96+
97+
@Test
98+
void testToThreeteenDuration_bigInput_doesNotOverflow() {
99+
// we use the max long value for the seconds part and an arbitrary int for the nanos part, so we
100+
// can confirm that both components are preserved
101+
java.time.Duration jtDuration =
102+
java.time.Duration.ofSeconds(Long.MAX_VALUE, MAX_DURATION_NANOS);
103+
org.threeten.bp.Duration ttDuration = TimeConversionUtils.toThreetenDuration(jtDuration);
104+
assertEquals(jtDuration.getSeconds(), ttDuration.getSeconds());
105+
assertEquals(jtDuration.getNano(), ttDuration.getNano());
106+
}
107+
108+
@Test
109+
void testToJavaTimeDuration_bigInput_doesNotOverflow() {
110+
// we use the max long value for the seconds part and an arbitrary int for the nanos part, so we
111+
// can confirm that both components are preserved
112+
org.threeten.bp.Duration ttDuration =
113+
org.threeten.bp.Duration.ofSeconds(Long.MAX_VALUE, MAX_DURATION_NANOS);
114+
java.time.Duration jtDuration = TimeConversionUtils.toJavaTimeDuration(ttDuration);
115+
assertEquals(jtDuration.getSeconds(), ttDuration.getSeconds());
116+
assertEquals(jtDuration.getNano(), ttDuration.getNano());
117+
}
72118
}

0 commit comments

Comments
 (0)