-
Notifications
You must be signed in to change notification settings - Fork 2
fix(openjdk): preserve ea version aliases #473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||||||||||
| use std::{fs::File, path::PathBuf}; | ||||||||||||||||
| use std::{collections::HashMap, fs::File, path::PathBuf}; | ||||||||||||||||
|
|
||||||||||||||||
| use eyre::Result; | ||||||||||||||||
| use log::info; | ||||||||||||||||
|
|
@@ -76,7 +76,7 @@ impl ReleaseType { | |||||||||||||||
| for release_type in &release_types { | ||||||||||||||||
| for os in &oses { | ||||||||||||||||
| for arch in &archs { | ||||||||||||||||
| let data = db.export_release_type(release_type, arch, os)?; | ||||||||||||||||
| let data = with_openjdk_ea_aliases(db.export_release_type(release_type, arch, os)?); | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||||||||||||||||
|
|
||||||||||||||||
| let export_data = data | ||||||||||||||||
| .into_par_iter() | ||||||||||||||||
|
|
@@ -105,3 +105,90 @@ impl ReleaseType { | |||||||||||||||
| Ok(()) | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| fn with_openjdk_ea_aliases(mut data: Vec<JvmData>) -> Vec<JvmData> { | ||||||||||||||||
| let existing = data | ||||||||||||||||
| .iter() | ||||||||||||||||
| .filter(|item| item.vendor == "openjdk") | ||||||||||||||||
| .map(|item| item.version.as_str()) | ||||||||||||||||
| .collect::<std::collections::HashSet<&str>>(); | ||||||||||||||||
| let mut aliases: HashMap<String, (u64, JvmData)> = HashMap::new(); | ||||||||||||||||
|
|
||||||||||||||||
| for item in &data { | ||||||||||||||||
| if item.vendor != "openjdk" || item.release_type != "ea" { | ||||||||||||||||
| continue; | ||||||||||||||||
| } | ||||||||||||||||
| let Some((alias, build)) = item.version.split_once('+') else { | ||||||||||||||||
| continue; | ||||||||||||||||
| }; | ||||||||||||||||
| if !alias.ends_with("-ea") || existing.contains(alias) { | ||||||||||||||||
| continue; | ||||||||||||||||
| } | ||||||||||||||||
| let Ok(build) = build.parse::<u64>() else { | ||||||||||||||||
| continue; | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| let mut alias_item = item.clone(); | ||||||||||||||||
| alias_item.java_version = alias.to_string(); | ||||||||||||||||
| alias_item.version = alias.to_string(); | ||||||||||||||||
| aliases | ||||||||||||||||
| .entry(alias.to_string()) | ||||||||||||||||
| .and_modify(|(existing_build, existing_item)| { | ||||||||||||||||
| if build > *existing_build { | ||||||||||||||||
| *existing_build = build; | ||||||||||||||||
| *existing_item = alias_item.clone(); | ||||||||||||||||
| } | ||||||||||||||||
| }) | ||||||||||||||||
| .or_insert((build, alias_item)); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| data.extend(aliases.into_values().map(|(_, item)| item)); | ||||||||||||||||
| data | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| #[cfg(test)] | ||||||||||||||||
| mod tests { | ||||||||||||||||
| use super::*; | ||||||||||||||||
| use std::collections::HashSet; | ||||||||||||||||
|
|
||||||||||||||||
| fn openjdk(version: &str) -> JvmData { | ||||||||||||||||
| JvmData { | ||||||||||||||||
| architecture: "x86_64".to_string(), | ||||||||||||||||
| file_type: "tar.gz".to_string(), | ||||||||||||||||
| image_type: "jdk".to_string(), | ||||||||||||||||
| java_version: version.to_string(), | ||||||||||||||||
| jvm_impl: "hotspot".to_string(), | ||||||||||||||||
| os: "linux".to_string(), | ||||||||||||||||
| release_type: "ea".to_string(), | ||||||||||||||||
| url: format!("https://example.com/openjdk-{version}.tar.gz"), | ||||||||||||||||
| vendor: "openjdk".to_string(), | ||||||||||||||||
| version: version.to_string(), | ||||||||||||||||
| ..Default::default() | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| #[test] | ||||||||||||||||
| fn test_with_openjdk_ea_aliases() { | ||||||||||||||||
| let data = with_openjdk_ea_aliases(vec![openjdk("28.0.0-ea+1")]); | ||||||||||||||||
| let versions = data.iter().map(|item| item.version.as_str()).collect::<HashSet<_>>(); | ||||||||||||||||
|
|
||||||||||||||||
| assert!(versions.contains("28.0.0-ea+1")); | ||||||||||||||||
| assert!(versions.contains("28.0.0-ea")); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| #[test] | ||||||||||||||||
| fn test_with_openjdk_ea_aliases_keeps_existing_alias() { | ||||||||||||||||
| let data = with_openjdk_ea_aliases(vec![openjdk("28.0.0-ea+1"), openjdk("28.0.0-ea")]); | ||||||||||||||||
| let aliases = data.iter().filter(|item| item.version == "28.0.0-ea").count(); | ||||||||||||||||
|
|
||||||||||||||||
| assert_eq!(aliases, 1); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| #[test] | ||||||||||||||||
| fn test_with_openjdk_ea_aliases_uses_highest_build() { | ||||||||||||||||
| let data = with_openjdk_ea_aliases(vec![openjdk("28.0.0-ea+1"), openjdk("28.0.0-ea+2")]); | ||||||||||||||||
| let alias = data.iter().find(|item| item.version == "28.0.0-ea").unwrap(); | ||||||||||||||||
|
|
||||||||||||||||
| assert_eq!(alias.url, "https://example.com/openjdk-28.0.0-ea+2.tar.gz"); | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HashSetis used as a fully-qualified inline path whileHashMapis already imported at the top of the file. ImportingHashSetalongsideHashMapkeeps the usage consistent.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!