Skip to content

Commit

Permalink
fix: macOS GraalVM JDK download URL
Browse files Browse the repository at this point in the history
  • Loading branch information
1zun4 committed Nov 19, 2024
1 parent bb33a9c commit e5b7fc6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 16 additions & 9 deletions src-tauri/src/minecraft/java/distribution.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use serde::{Deserialize, Serialize};
use crate::utils::{ARCHITECTURE, OS};

#[derive(Deserialize, Serialize, Debug)]
pub enum JavaDistribution {
Expand All @@ -18,21 +19,26 @@ impl Default for JavaDistribution {
}

impl JavaDistribution {
pub fn get_url(
&self,
jre_version: &u32,
os_name: &str,
os_arch: &str,
archive_type: &str
) -> String {
match self {
pub fn get_url(&self, jre_version: &u32) -> anyhow::Result<String> {

let os_arch = ARCHITECTURE.get_simple_name()?;
let archive_type = OS.get_archive_type()?;

Ok(match self {
JavaDistribution::Temurin => {
let os_name = OS.get_adoptium_name()?;

format!(
"https://api.adoptium.net/v3/binary/latest/{}/ga/{}/{}/jre/hotspot/normal/eclipse?project=jdk",
jre_version, os_name, os_arch
)
}
JavaDistribution::GraalVM => {
let os_name = OS.get_graal_name()?;

// https://download.oracle.com/graalvm/21/latest/graalvm-jdk-21_windows-x64_bin.zip
// https://download.oracle.com/graalvm/21/latest/graalvm-jdk-21_linux-x64_bin.tar.gz
// https://download.oracle.com/graalvm/21/latest/graalvm-jdk-21_macos-x64_bin.tar.gz
format!(
"https://download.oracle.com/graalvm/{}/latest/graalvm-jdk-{}_{}-{}_bin.{}",
jre_version, jre_version, os_name, os_arch, archive_type
Expand All @@ -41,13 +47,14 @@ impl JavaDistribution {
JavaDistribution::OpenJDK => {
// use microsoft openjdk
// https://aka.ms/download-jdk/microsoft-jdk-21-linux-x64.tar.gz
let os_name = OS.get_graal_name();

format!(
"https://aka.ms/download-jdk/microsoft-jdk-{}_{}-{}.{}",
jre_version, os_name, os_arch, archive_type
)
}
}
})
}

pub fn get_name(&self) -> &str {
Expand Down
12 changes: 1 addition & 11 deletions src-tauri/src/minecraft/java/jre_downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,11 @@ where
runtimes_folder.join(format!("{}_{}", jre_distribution.get_name(), jre_version));

if runtime_path.exists() {
// Clear out folder
fs::remove_dir_all(&runtime_path).await?;
}

fs::create_dir_all(&runtime_path).await?;

// OS details
let os_name = OS.get_graal_name()?;
let os_arch = ARCHITECTURE.get_simple_name()?;
let archive_type = OS.get_archive_type()?;
let url = jre_distribution.get_url(jre_version, os_name, os_arch, archive_type);

// Download from JRE source and extract runtime files
fs::create_dir_all(&runtime_path).await?;

let url = jre_distribution.get_url(jre_version)?;
let retrieved_bytes = download_file(&url, on_progress).await?;
let cursor = Cursor::new(&retrieved_bytes[..]);

Expand Down
11 changes: 10 additions & 1 deletion src-tauri/src/utils/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl OperatingSystem {
})
}

pub fn get_graal_name(&self) -> Result<&'static str> {
pub fn get_adoptium_name(&self) -> Result<&'static str> {
Ok(match self {
OperatingSystem::WINDOWS => "windows",
OperatingSystem::LINUX => "linux",
Expand All @@ -109,6 +109,15 @@ impl OperatingSystem {
})
}

pub fn get_graal_name(&self) -> Result<&'static str> {
Ok(match self {
OperatingSystem::WINDOWS => "windows",
OperatingSystem::LINUX => "linux",
OperatingSystem::OSX => "macos",
_ => bail!("Invalid OS")
})
}

pub fn get_archive_type(&self) -> Result<&'static str> {
Ok(match self {
OperatingSystem::WINDOWS => "zip",
Expand Down

0 comments on commit e5b7fc6

Please sign in to comment.