diff options
| author | 2026-01-18 12:20:42 +0800 | |
|---|---|---|
| committer | 2026-01-18 12:20:42 +0800 | |
| commit | 373fb81604451f085bf9fbccf9251acb17e400a9 (patch) | |
| tree | 30b888202a82a28dbd480340ab231af411037913 /src-tauri/src | |
| parent | 76086e65a7caf1bb8aa54a9404c70a714bc00da8 (diff) | |
| download | DropOut-373fb81604451f085bf9fbccf9251acb17e400a9.tar.gz DropOut-373fb81604451f085bf9fbccf9251acb17e400a9.zip | |
fix(java): handle build metadata and underscore formats in version parsing
Update parse_java_version() to properly handle:
- Build metadata (strip '+' and everything after)
- Trailing garbage (strip '-' and everything after, e.g. -Ubuntu)
- Underscore version separators (1.8.0_411 -> 1.8.0.411)
This ensures Java versions are correctly parsed on all platforms:
- Old format: 1.8.0_411 (Java 8 update 411)
- New format: 21.0.3+13-Ubuntu (Java 21 with build metadata)
- Short format: 17.0.1 (Java 17 update 1).
Diffstat (limited to 'src-tauri/src')
| -rw-r--r-- | src-tauri/src/core/java.rs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src-tauri/src/core/java.rs b/src-tauri/src/core/java.rs index 0c7769b..d3e1bb9 100644 --- a/src-tauri/src/core/java.rs +++ b/src-tauri/src/core/java.rs @@ -850,8 +850,27 @@ fn parse_version_string(output: &str) -> Option<String> { /// Parse version for comparison (returns major version number) fn parse_java_version(version: &str) -> u32 { - // Handle both old format (1.8.0_xxx) and new format (11.0.x, 17.0.x) - let parts: Vec<&str> = version.split('.').collect(); + // Handle various formats: + // - Old format: 1.8.0_xxx (Java 8 with update) + // - New format: 17.0.1, 11.0.5+10 (Java 11+) + // - Format with build: 21.0.3+13-Ubuntu-0ubuntu0.24.04.1 + // - Format with underscores: 1.8.0_411 + + // First, strip build metadata (everything after '+') + let version_only = version.split('+').next().unwrap_or(version); + + // Remove trailing junk (like "-Ubuntu-0ubuntu0.24.04.1") + let version_only = version_only + .split('-') + .next() + .unwrap_or(version_only); + + // Replace underscores with dots (1.8.0_411 -> 1.8.0.411) + let normalized = version_only.replace('_', "."); + + // Split by dots + let parts: Vec<&str> = normalized.split('.').collect(); + if let Some(first) = parts.first() { if *first == "1" { // Old format: 1.8.0 -> major is 8 |