Skip to content

Commit

Permalink
feat: Added support for changing OpenJDK versions
Browse files Browse the repository at this point in the history
* feat: added command to change OpenJDK version

* feat: Improve UX

* test: explicitely declared java_ver and javac_ver
  • Loading branch information
ryanbourdais authored Jun 22, 2022
1 parent cbdf150 commit 50be37b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
40 changes: 39 additions & 1 deletion .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,37 @@ prod-deploy-requires: &prod-deploy-requires
ui-tests-system-images;android-29;default;x86,
ui-tests-system-images;android-29;google_apis;x86_64,
test-emulator-commands,
test-start-emulator-and-run-tests
test-start-emulator-and-run-tests,
test-java-version
]

jobs:
test-java-version:
parameters:
executor:
type: executor
description: |
Which Android image/executor to use. Choose between 'android-docker'
and 'android-machine'.
java-version:
type: integer
description: |
Version to use in the change-java-version job
executor: <<parameters.executor>>
steps:
- checkout
- android/change-java-version:
java-version: << parameters.java-version >>
- run:
command: |
JAVA_VER="$( java -version 2>&1 | head -1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1 )"
JAVAC_VER="$( javac -version 2>&1 | head -1 | cut -f 2- -d ' ' | sed '/^1\./s///' | cut -d'.' -f1 )"
if [ "$JAVA_VER" -ne <<parameters.java-version>> ] || [ "$JAVAC_VER" -ne <<parameters.java-version>> ]; then
echo "Job failed because either the java version or javac version was not changed."
exit 1
fi
name: check for correctness

test-ndk-install:
parameters:
executor:
Expand Down Expand Up @@ -126,6 +153,17 @@ jobs:
workflows:
test-deploy:
jobs:
- test-java-version:
name: "Test OpenJDK version change"
executor:
name: android/android-docker
tag: "2021.10.1"
matrix:
parameters:
java-version:
- 8
- 11
- 13
- test-ndk-install:
name: "Test NDK Install on Android Docker"
matrix:
Expand Down
35 changes: 35 additions & 0 deletions src/commands/change-java-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
description: |
Change default java version from OpenJDK v11.
parameters:
java-version:
type: integer
default: 8
description: |
The version of OpenJDK to change to
steps:
- run:
command: |
CURRENT_JAVA_VER="$( java -version 2>&1 | head -1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1 )"
CURRENT_JAVAC_VER="$( javac -version 2>&1 | head -1 | cut -f 2- -d ' ' | sed '/^1\./s///' | cut -d'.' -f1 )"
echo "Current Java Version: $CURRENT_JAVA_VER"
echo "Current Java Compiler Version : $CURRENT_JAVAC_VER"
if [ "$CURRENT_JAVA_VER" -ne <<parameters.java-version>> ]; then
if [ <<parameters.java-version>> -eq 8 ] || [ <<parameters.java-version>> -eq 11 ]; then
if [ <<parameters.java-version>> -eq 8 ]; then
sudo update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
else
sudo update-alternatives --set java /usr/lib/jvm/java-11-openjdk-amd64/bin/java
fi
sudo update-alternatives --set javac /usr/lib/jvm/java-<<parameters.java-version>>-openjdk-amd64/bin/javac
else
sudo apt install openjdk-<<parameters.java-version>>-jdk
fi
echo "export JAVA_HOME=/usr/lib/jvm/java-<<parameters.java-version>>-openjdk-amd64" >>~/.bashrc
echo "export PATH=$JAVA_HOME/bin:$PATH" >>~/.bashrc
fi
NEW_JAVA_VER="$( java -version 2>&1 | head -1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1 )"
NEW_JAVAC_VER="$( javac -version 2>&1 | head -1 | cut -f 2- -d ' ' | sed '/^1\./s///' | cut -d'.' -f1 )"
echo "New Java Version : $NEW_JAVA_VER"
echo "New Java Compiler Version : $NEW_JAVAC_VER"
name: change OpenJDK version

0 comments on commit 50be37b

Please sign in to comment.