Skip to content

Commit 12f432c

Browse files
Wrap `--add-opens=java.base/java.nio=ALL-UNNAMED as a default envir… (#364)
* Wrap ``--add-opens=java.base/java.nio=ALL-UNNAMED` as a default environment variable for the .sh script. This is required to deal with Snowflake JDBC error https://community.snowflake.com/s/article/JDBC-Driver-Compatibility-Issue-With-JDK-16-and-Later , which recently re-emerged and is likely to re-emerge again. * Preserve existing _JAVA_OPTIONS arguments * Apply the env argument to dwh-migration-dumper application instead. * Really apply the env argument to dwh-migration-dumper application instead. * Let gradle build 2 versions of startup scripts for each app and add run-time logic to choose which one based on java version. The two apps are dwh-migration-dumper and dwh-cloud-extractor. The versioning logic is applied in dwh-migration-dumper wrapper and in gce_launcher.sh script. Maneually tested file generation and executing dwh-migration-dumper with different java versions. Tested versions: java8, java11, java17 * Fix Gradle mysterious dependencies * Fix Gradle mysterious dependencies * Make the logic more readable.
1 parent 124ff2f commit 12f432c

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

bin/dwh-migration-dumper

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#!/bin/sh -ex
22

33
BASE_DIR=$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>&1 > /dev/null && cd .. && pwd)
4-
BIN="${BASE_DIR}/dumper/app/build/install/app/bin/dwh-migration-dumper"
4+
. "${BASE_DIR}/dumper/app/src/main/sh/java_versioning.sh"
5+
BASE_BIN_DIR="${BASE_DIR}/dumper/app/build/install/app/bin"
6+
BIN=$(is_java_greater_than_8 && echo "${BASE_BIN_DIR}/dwh-migration-dumper" || echo "${BASE_BIN_DIR}/dwh-migration-dumper-java8")
57

68
if [ ! -x "$BIN" ] ; then
79
(cd "${BASE_DIR}" && ./gradlew --parallel :dumper:app:installDist)
810
fi
911

10-
exec "$BIN" "$@"
12+
exec "$BIN" "$@"

dumper/app/build.gradle

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ dependencies {
9494

9595
startScripts {
9696
classpath = files('$APP_HOME/lib/*')
97+
defaultJvmOpts = ["--add-opens=java.base/java.nio=ALL-UNNAMED"]
98+
}
99+
100+
task createStartScriptForJava8(type: CreateStartScripts) {
101+
mainClass = tasks.startScripts.mainClass
102+
applicationName = 'dwh-migration-dumper-java8'
103+
outputDir = tasks.startScripts.outputDir
104+
classpath = tasks.startScripts.classpath
105+
}
106+
107+
tasks.named('installDist') {
108+
dependsOn 'createStartScriptForJava8'
109+
dependsOn 'cloudExtractorStartScripts'
110+
dependsOn 'cloudExtractorStartScriptsForJava8'
97111
}
98112

99113
application {
@@ -102,13 +116,22 @@ application {
102116
applicationName = 'dwh-migration-dumper'
103117
}
104118

105-
task cloudExtractorStartScripts(type: CreateStartScripts) {
119+
task cloudExtractorStartScriptsForJava8(type: CreateStartScripts) {
106120
outputDir = layout.buildDirectory.dir('install/cloud-extractor/bin').get().asFile
107121
classpath = tasks.startScripts.classpath
108122
mainClass = 'com.google.edwmigration.dumper.application.dumper.clouddumper.Main'
109123
applicationName = 'dwh-cloud-extractor'
110124
}
111125

126+
task cloudExtractorStartScripts(type: CreateStartScripts) {
127+
outputDir = tasks.cloudExtractorStartScriptsForJava8.outputDir
128+
classpath = tasks.cloudExtractorStartScriptsForJava8.classpath
129+
mainClass = tasks.cloudExtractorStartScriptsForJava8.mainClass
130+
applicationName = 'dwh-cloud-extractor-java8'
131+
defaultJvmOpts = ["--add-opens=java.base/java.nio=ALL-UNNAMED"]
132+
dependsOn 'cloudExtractorStartScriptsForJava8'
133+
}
134+
112135
licenseReport {
113136
// onlyIf { ! gradle.startParameter.offline }
114137
filters = [
@@ -551,6 +574,14 @@ tasks.named('check') {
551574
dependsOn 'checkLicense'
552575
}
553576

577+
tasks.named('distTar') {
578+
dependsOn 'installDist'
579+
}
580+
581+
tasks.named('distZip') {
582+
dependsOn 'installDist'
583+
}
584+
554585
tasks.register('generateSourceMirror', Copy) {
555586
from {
556587
dependencies.createArtifactResolutionQuery()

dumper/app/src/main/sh/cloud_extractor/gce_launcher.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ main() {
110110
die "ZIP file did not contain dwh-migration-tools."
111111
fi
112112

113+
. "${dwh_home}/dumper/app/src/main/sh/java_versioning.sh"
113114
dwh_cloud_extractor="${dwh_home}/bin/dwh-cloud-extractor"
115+
dwh_cloud_extractor=$(is_java_greater_than_8 && echo "${dwh_home}/bin/dwh-cloud-extractor" || echo "${dwh_home}/bin/dwh-cloud-extractor-java8")
116+
114117
if [[ ! -x "${dwh_cloud_extractor}" ]]; then
115118
die "Could not find cloud extractor bin. Got no executable '${dwh_cloud_extractor}'."
116119
fi
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
function is_java_greater_than_8() {
4+
java_path=$(which java)
5+
java_version_output=$($java_path -version 2>&1)
6+
7+
# Will return 1 for all versions before Java 9, but we do not care.
8+
java_major_version=$(echo "$java_version_output" | grep -Eoi 'version "?([0-9]+)' | head -1 | cut -d'"' -f2 | cut -d'.' -f1)
9+
10+
# Check if the major version is greater than 8.
11+
if [[ $java_major_version -gt 8 ]]; then
12+
return 0 # True
13+
else
14+
return 1 # False
15+
fi
16+
}

0 commit comments

Comments
 (0)