-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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.
- Loading branch information
Showing
6 changed files
with
106 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,27 @@ | ||
#!/bin/sh -ex | ||
#!/bin/bash | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -e | ||
|
||
BASE_DIR=$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>&1 > /dev/null && cd .. && pwd) | ||
. "${BASE_DIR}/dumper/app/src/main/sh/java_versioning.sh" | ||
BASE_BIN_DIR="${BASE_DIR}/dumper/app/build/install/app/bin" | ||
BIN=$(is_java_greater_than_8 && echo "${BASE_BIN_DIR}/dwh-migration-dumper" || echo "${BASE_BIN_DIR}/dwh-migration-dumper-java8") | ||
BIN="${BASE_DIR}/dumper/app/build/install/app/bin/dwh-migration-dumper-starter" | ||
|
||
if [ ! -x "$BIN" ] ; then | ||
(cd "${BASE_DIR}" && ./gradlew --parallel :dumper:app:installDist) | ||
fi | ||
|
||
exec "$BIN" "$@" | ||
export JDK_JAVA_OPTIONS="--add-opens=java.base/java.nio=ALL-UNNAMED" | ||
|
||
exec "$BIN" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@rem Copyright 2024 Google LLC | ||
@rem | ||
@rem Licensed under the Apache License, Version 2.0 (the "License"); | ||
@rem you may not use this file except in compliance with the License. | ||
@rem You may obtain a copy of the License at | ||
@rem | ||
@rem http://www.apache.org/licenses/LICENSE-2.0 | ||
@rem | ||
@rem Unless required by applicable law or agreed to in writing, software | ||
@rem distributed under the License is distributed on an "AS IS" BASIS, | ||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
@rem See the License for the specific language governing permissions and | ||
@rem limitations under the License. | ||
|
||
@if "%DEBUG%"=="" @echo off | ||
set JDK_JAVA_OPTIONS="--add-opens=java.base/java.nio=ALL-UNNAMED" | ||
|
||
set "DIRNAME=%~dp0..\dumper\app\build\install\app\bin" | ||
"%DIRNAME%\dwh-migration-dumper-starter.bat" %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -e | ||
|
||
BASE_DIR=$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>&1 > /dev/null && cd .. && pwd) | ||
BIN="${BASE_DIR}/bin/dwh-migration-dumper-starter" | ||
|
||
export JDK_JAVA_OPTIONS="--add-opens=java.base/java.nio=ALL-UNNAMED" | ||
|
||
exec "$BIN" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@rem Copyright 2024 Google LLC | ||
@rem | ||
@rem Licensed under the Apache License, Version 2.0 (the "License"); | ||
@rem you may not use this file except in compliance with the License. | ||
@rem You may obtain a copy of the License at | ||
@rem | ||
@rem http://www.apache.org/licenses/LICENSE-2.0 | ||
@rem | ||
@rem Unless required by applicable law or agreed to in writing, software | ||
@rem distributed under the License is distributed on an "AS IS" BASIS, | ||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
@rem See the License for the specific language governing permissions and | ||
@rem limitations under the License. | ||
|
||
@if "%DEBUG%"=="" @echo off | ||
set JDK_JAVA_OPTIONS="--add-opens=java.base/java.nio=ALL-UNNAMED" | ||
|
||
set "DIRNAME=%~dp0" | ||
"%DIRNAME%\dwh-migration-dumper-starter.bat" %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,28 @@ | ||
#!/bin/bash | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
function is_java_greater_than_8() { | ||
java_path=$(which java) | ||
java_version_output=$($java_path -version 2>&1) | ||
java_version_output="$(java -version 2>&1)" | ||
|
||
# Will return 1 for all versions before Java 9, but we do not care. | ||
java_major_version=$(echo "$java_version_output" | grep -Eoi 'version "?([0-9]+)' | head -1 | cut -d'"' -f2 | cut -d'.' -f1) | ||
# Will return 1 for all versions before Java 9. | ||
java_major_version="$(echo "$java_version_output" | grep -Eoi 'version "?([0-9]+)' | head -1 | cut -d'"' -f2 | cut -d'.' -f1)" | ||
|
||
# Check if the major version is greater than 8. | ||
if [[ $java_major_version -gt 8 ]]; then | ||
if [[ "$java_major_version" -gt 8 ]]; then | ||
return 0 # True | ||
else | ||
return 1 # False | ||
fi | ||
} | ||
} |