Skip to content

Commit c1f5037

Browse files
authored
[b/342096412] Detect Java version in the main script (#434)
* [b/342096412] Detect Java version in the main script The `dwh-migration-dumper` script worked for Java version 9 and above. This change makes it compatible with Java 8 also in Linux environments. The `dwh-migration-dumper-java8` script is a wrapper for the old script with the same name. It is added to preserve backwards compatibility. The Java detection is not applied for Windows environments. The bat scripts are added to preserve backwards compatibility. The new scripts in the bin directory behave the same in the source and binary releases. * Use JDK_JAVA_OPTIONS to handle all Java versions The JDK_JAVA_OPTIONS is passed to Java 9+ only, so by using this environment variable, there is no need to use the Java version detection script.
1 parent b7bc229 commit c1f5037

File tree

6 files changed

+106
-20
lines changed

6 files changed

+106
-20
lines changed

bin/dwh-migration-dumper

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1-
#!/bin/sh -ex
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+
set -e
217

318
BASE_DIR=$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>&1 > /dev/null && cd .. && pwd)
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")
19+
BIN="${BASE_DIR}/dumper/app/build/install/app/bin/dwh-migration-dumper-starter"
720

821
if [ ! -x "$BIN" ] ; then
922
(cd "${BASE_DIR}" && ./gradlew --parallel :dumper:app:installDist)
1023
fi
1124

12-
exec "$BIN" "$@"
25+
export JDK_JAVA_OPTIONS="--add-opens=java.base/java.nio=ALL-UNNAMED"
26+
27+
exec "$BIN" "$@"

bin/dwh-migration-dumper.bat

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@rem Copyright 2024 Google LLC
2+
@rem
3+
@rem Licensed under the Apache License, Version 2.0 (the "License");
4+
@rem you may not use this file except in compliance with the License.
5+
@rem You may obtain a copy of the License at
6+
@rem
7+
@rem http://www.apache.org/licenses/LICENSE-2.0
8+
@rem
9+
@rem Unless required by applicable law or agreed to in writing, software
10+
@rem distributed under the License is distributed on an "AS IS" BASIS,
11+
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
@rem See the License for the specific language governing permissions and
13+
@rem limitations under the License.
14+
15+
@if "%DEBUG%"=="" @echo off
16+
set JDK_JAVA_OPTIONS="--add-opens=java.base/java.nio=ALL-UNNAMED"
17+
18+
set "DIRNAME=%~dp0..\dumper\app\build\install\app\bin"
19+
"%DIRNAME%\dwh-migration-dumper-starter.bat" %*

dumper/app/build.gradle

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,11 @@ jacocoTestReport {
123123
}
124124

125125
startScripts {
126+
applicationName = "dwh-migration-dumper-starter"
126127
classpath = files('$APP_HOME/lib/*')
127-
defaultJvmOpts = ["--add-opens=java.base/java.nio=ALL-UNNAMED"]
128-
}
129-
130-
task createStartScriptForJava8(type: CreateStartScripts) {
131-
mainClass = tasks.startScripts.mainClass
132-
applicationName = 'dwh-migration-dumper-java8'
133-
outputDir = tasks.startScripts.outputDir
134-
classpath = tasks.startScripts.classpath
135128
}
136129

137130
tasks.named('installDist') {
138-
dependsOn 'createStartScriptForJava8'
139131
dependsOn 'cloudExtractorStartScripts'
140132
dependsOn 'cloudExtractorStartScriptsForJava8'
141133
}
@@ -944,6 +936,12 @@ distributions {
944936
from(cloudExtractorStartScripts) {
945937
into "bin"
946938
}
939+
from("src/main/sh/dwh-migration-dumper") {
940+
into "bin"
941+
}
942+
from("src/main/sh/dwh-migration-dumper.bat") {
943+
into "bin"
944+
}
947945
from(generateLicenseReport) {
948946
into "docs/licenses"
949947
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
set -e
17+
18+
BASE_DIR=$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>&1 > /dev/null && cd .. && pwd)
19+
BIN="${BASE_DIR}/bin/dwh-migration-dumper-starter"
20+
21+
export JDK_JAVA_OPTIONS="--add-opens=java.base/java.nio=ALL-UNNAMED"
22+
23+
exec "$BIN" "$@"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@rem Copyright 2024 Google LLC
2+
@rem
3+
@rem Licensed under the Apache License, Version 2.0 (the "License");
4+
@rem you may not use this file except in compliance with the License.
5+
@rem You may obtain a copy of the License at
6+
@rem
7+
@rem http://www.apache.org/licenses/LICENSE-2.0
8+
@rem
9+
@rem Unless required by applicable law or agreed to in writing, software
10+
@rem distributed under the License is distributed on an "AS IS" BASIS,
11+
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
@rem See the License for the specific language governing permissions and
13+
@rem limitations under the License.
14+
15+
@if "%DEBUG%"=="" @echo off
16+
set JDK_JAVA_OPTIONS="--add-opens=java.base/java.nio=ALL-UNNAMED"
17+
18+
set "DIRNAME=%~dp0"
19+
"%DIRNAME%\dwh-migration-dumper-starter.bat" %*
Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
#!/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.
215

316
function is_java_greater_than_8() {
4-
java_path=$(which java)
5-
java_version_output=$($java_path -version 2>&1)
17+
java_version_output="$(java -version 2>&1)"
618

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)
19+
# Will return 1 for all versions before Java 9.
20+
java_major_version="$(echo "$java_version_output" | grep -Eoi 'version "?([0-9]+)' | head -1 | cut -d'"' -f2 | cut -d'.' -f1)"
921

1022
# Check if the major version is greater than 8.
11-
if [[ $java_major_version -gt 8 ]]; then
23+
if [[ "$java_major_version" -gt 8 ]]; then
1224
return 0 # True
1325
else
1426
return 1 # False
1527
fi
16-
}
28+
}

0 commit comments

Comments
 (0)