Skip to content

Commit

Permalink
fix(java): wrong version number when using Android Studio JDK (#4966)
Browse files Browse the repository at this point in the history
The regular expression would get the revision number found in:

    with gcc Android (7284624, based on r416183b)

so it would print "7284624".
  • Loading branch information
agateau committed Apr 7, 2023
1 parent 95a036b commit de7e948
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/modules/java.rs
Expand Up @@ -5,7 +5,8 @@ use crate::utils::get_command_string_output;
use std::path::PathBuf;

use regex::Regex;
const JAVA_VERSION_PATTERN: &str = "(?:JRE.*\\(|OpenJ9 )(?P<version>[\\d]+(?:\\.\\d+){0,2})";
const JAVA_VERSION_PATTERN: &str =
"(?:JRE.*\\(|OpenJ9 )(?P<version>\\d+(?:\\.\\d+){0,2}).*, built on";

/// Creates a module with the current Java version
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
Expand Down Expand Up @@ -154,6 +155,12 @@ mod tests {
assert_eq!(parse_java_version(java_11), Some("11.0.4".to_string()));
}

#[test]
fn test_parse_java_version_android_studio_jdk() {
let java_11 = "OpenJDK 64-Bit Server VM (11.0.15+0-b2043.56-8887301) for linux-amd64 JRE (11.0.15+0-b2043.56-8887301), built on Jul 29 2022 22:12:21 by \"androidbuild\" with gcc Android (7284624, based on r416183b) Clang 12.0.5 (https://android.googlesource.com/toolchain/llvm-project c935d99d7cf2016289302412d708641d52d2f7ee)}";
assert_eq!(parse_java_version(java_11), Some("11.0.15".to_string()));
}

#[test]
fn test_parse_java_version_unknown() {
let unknown_jre = "Unknown JRE";
Expand Down

0 comments on commit de7e948

Please sign in to comment.