xref: /aosp_15_r20/external/sdk-platform-java/scripts/create_native_image_test_env.sh (revision 882aa7c72c3cd3b66e72a261bdd69b93f7de7670)
1#!/bin/bash
2
3# This script creates a submodule project with all the necessary repositories (forked) and changes needed to test
4# GraalVM updates with handwritten libraries (including, pubsub, bigquery, bigtable and spanner-jdbc).
5# It serves two main purposes; first, it allows for the creation of a testing environment that can be shared with
6# teammates and second, given that the submodule leverages creation of test branches in the (forked) repositories,
7# any extra configurations necessary for making the library compatible with GraalVM can easily be sent for review as a PR
8# from the branch itself.
9# At a high-level, the script will do the following:
10# - Modifies graal-sdk version in gapic-generator-java/gax
11# - Modifies the gapic-generator-bom version in java-shared-dependencies.
12# - Updates the version of native-maven-plugin in java-shared-config.
13# - Updates the java-shared-config and java-shared-dependencies versions in the handwritten libraries listed.
14# - Adds gapic-generator-java, java-shared-config and handwritten libraries listed previously
15#   with the associated changes, to the submodule project.
16set -eo pipefail
17
18function modify_shared_config() {
19  xmllint --shell pom.xml <<EOF
20  setns x=http://maven.apache.org/POM/4.0.0
21  cd .//x:artifactId[text()="google-cloud-shared-config"]
22  cd ../x:version
23  set ${SHARED_CONFIG_VERSION}
24  save pom.xml
25EOF
26}
27
28function modify_shared_dependencies() {
29  xmllint --shell pom.xml <<EOF
30  setns x=http://maven.apache.org/POM/4.0.0
31  cd .//x:artifactId[text()="google-cloud-shared-dependencies"]
32  cd ../x:version
33  set ${SHARED_DEPS_VERSION}
34  save pom.xml
35EOF
36}
37
38if [ -z "$GRAALVM_VERSION" ]; then
39  echo "Please specify the GRAALVM_VERSION."
40  exit 1
41fi
42
43if [ -z "$NATIVE_MAVEN_PLUGIN" ]; then
44  echo "Please specify the NATIVE_MAVEN_PLUGIN version you want to update to."
45  exit 1
46fi
47
48if [ -z "$ORGANIZATION" ]; then
49  echo "Please specify the ORGANIZATION where your updates need to be stored."
50  exit 1
51fi
52
53# This script assumes that you've already created a new github repository.
54if [ ! -d ".git" ]; then
55  echo "Missing '.git' file. Please make sure that you are running this script from a new github repository."
56  exit 1
57fi
58
59GRAALVM_BRANCH="${GRAALVM_VERSION}_update"
60
61## Round 1: Add gapic-generator-java and update graal-sdk version in GAX.
62if [ ! -d "gapic-generator-java" ]; then
63  echo "Create gapic-generator-java submodule if one does not exist"
64  git submodule add --force https://github.com/"${ORGANIZATION}"/gapic-generator-java.git
65fi
66
67# Modify graal-sdk version in GAX
68pushd gapic-generator-java/gax-java
69xmllint --shell pom.xml <<EOF
70setns x=http://maven.apache.org/POM/4.0.0
71cd .//x:artifactId[text()="graal-sdk"]
72cd ../x:version
73set ${GRAALVM_VERSION}
74save pom.xml
75EOF
76
77# Get java-shared-dependencies version
78popd
79pushd gapic-generator-java
80SHARED_DEPS_VERSION=$(sed -e 's/xmlns=".*"//' java-shared-dependencies/pom.xml | xmllint --xpath '/project/version/text()' -)
81echo $SHARED_DEPS_VERSION
82
83if [ ! "$(git branch --list "$GRAALVM_BRANCH")" ]
84then
85   git diff
86   git checkout -b "${GRAALVM_BRANCH}"
87   git add gax-java/pom.xml
88   git commit -m "chore: update graalvm-sdk's version (${GRAALVM_VERSION}) in GAX for testing"
89   git push origin "${GRAALVM_BRANCH}"
90fi
91
92popd
93
94## Round 2: Add java-shared-config if not present and update native-maven-plugin's version
95if [ ! -d "java-shared-config" ]; then
96  echo "Create java-shared-config submodule if one does not exist"
97  git submodule add --force https://github.com/"${ORGANIZATION}"/java-shared-config.git
98fi
99
100# Modify junit-platform-native and native-maven-plugin
101pushd java-shared-config
102SHARED_CONFIG_VERSION=$(sed -e 's/xmlns=".*"//' pom.xml | xmllint --xpath '/project/version/text()' -)
103
104xmllint --shell pom.xml <<EOF
105setns x=http://maven.apache.org/POM/4.0.0
106cd .//x:artifactId[text()="native-maven-plugin"]
107cd ../x:version
108set ${NATIVE_MAVEN_PLUGIN}
109save pom.xml
110EOF
111
112echo "Modified native-maven-plugin in shared-config"
113git diff
114
115# Create branch on github
116if [ ! "$(git branch --list "$GRAALVM_BRANCH")" ]
117then
118   git checkout -b "${GRAALVM_BRANCH}"
119   git add pom.xml
120   git commit -m "chore: update native-maven-plugin's version (${NATIVE_MAVEN_PLUGIN}) in java-shared-config for testing"
121   git push origin "${GRAALVM_BRANCH}"
122fi
123popd
124
125## Round 3: Add java-pubsub if not present and update versions of shared-dependencies and java-shared-config.
126if [ ! -d "java-pubsub" ]; then
127  echo "Create java-pubsub submodule if one does not exist"
128  git submodule add --force https://github.com/"${ORGANIZATION}"/java-pubsub.git
129fi
130
131# Update shared-config and shared-dependencies version
132pushd java-pubsub
133modify_shared_config
134modify_shared_dependencies
135echo "Modified shared-config and shared-dependencies versions in java-pubsub"
136git diff
137
138if [ ! "$(git branch --list "$GRAALVM_BRANCH")" ]
139then
140   git checkout -b "${GRAALVM_BRANCH}"
141   git add pom.xml
142   git commit -m "chore: update shared-config (${SHARED_CONFIG_VERSION}) shared-dependencies version (${SHARED_DEPS_VERSION}) for testing"
143   git push origin "${GRAALVM_BRANCH}"
144fi
145popd
146
147## Round 4: Add java-bigquery if not present and update versions of shared-dependencies and java-shared-config.
148if [ ! -d "java-bigquery" ]; then
149  echo "Create java-bigquery submodule if one does not exist"
150  git submodule add --force https://github.com/"${ORGANIZATION}"/java-bigquery.git
151fi
152
153# Update shared-config and shared-dependencies version
154pushd java-bigquery
155modify_shared_config
156modify_shared_dependencies
157echo "Modified shared-config and shared-dependencies versions in java-bigquery"
158git diff
159
160if [ ! "$(git branch --list "$GRAALVM_BRANCH")" ]
161then
162   git checkout -b "${GRAALVM_BRANCH}"
163   git add pom.xml
164   git commit -m "chore: update shared-config (${SHARED_CONFIG_VERSION}) shared-dependencies version (${SHARED_DEPS_VERSION}) for testing"
165   git push origin "${GRAALVM_BRANCH}"
166fi
167popd
168
169## Round 5: Add java-bigtable if not present and update versions of shared-dependencies and java-shared-config.
170if [ ! -d "java-bigtable" ]; then
171  echo "Create java-bigtable submodule if one does not exist"
172  git submodule add --force https://github.com/"${ORGANIZATION}"/java-bigtable.git
173fi
174
175# Update shared-config and shared-dependencies version
176pushd java-bigtable/google-cloud-bigtable-deps-bom
177modify_shared_config
178modify_shared_dependencies
179
180popd
181pushd java-bigtable/google-cloud-bigtable-bom
182modify_shared_config
183
184popd
185pushd java-bigtable
186modify_shared_config
187
188echo "Modified shared-config and shared-dependencies versions in java-bigtable"
189git diff
190
191if [ ! "$(git branch --list "$GRAALVM_BRANCH")" ]
192then
193   git checkout -b "${GRAALVM_BRANCH}"
194   git add pom.xml
195   git add google-cloud-bigtable-deps-bom/pom.xml
196   git add google-cloud-bigtable-bom/pom.xml
197   git commit -m "chore: update shared-config (${SHARED_CONFIG_VERSION}) shared-dependencies version (${SHARED_DEPS_VERSION}) for testing"
198   git push origin "${GRAALVM_BRANCH}"
199fi
200
201popd
202
203## Round 6: Add java-spanner-jdbc if not present and update versions of shared-dependencies and java-shared-config.
204if [ ! -d "java-spanner-jdbc" ]; then
205  echo "Create java-spanner-jdbc submodule if one does not exist"
206  git submodule add --force https://github.com/"${ORGANIZATION}"/java-spanner-jdbc.git
207fi
208
209# Update shared-config and shared-dependencies version
210pushd java-spanner-jdbc
211modify_shared_config
212modify_shared_dependencies
213echo "Modified shared-config and shared-dependencies versions in java-spanner-jdbc"
214git diff
215
216if [ ! "$(git branch --list "$GRAALVM_BRANCH")" ]
217then
218   git checkout -b "${GRAALVM_BRANCH}"
219   git add pom.xml
220   git commit -m "chore: update shared config (${SHARED_CONFIG_VERSION}) shared-dependencies version (${SHARED_DEPS_VERSION}) for testing"
221   git push origin "${GRAALVM_BRANCH}"
222fi
223popd
224
225## Round 7: Push modified repos to submodule repository.
226git add gapic-generator-java
227git add java-shared-config
228git add java-pubsub
229git add java-bigquery
230git add java-bigtable
231git add java-spanner-jdbc
232git commit -m "chore: populate the submodule project" --allow-empty
233git push origin main
234
235