-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Use consatnts.rs instead of dotenv (#8)
* Updated dotenv path * Removed dotenv * Added constants map * Added temporary functions for macos
- Loading branch information
1 parent
06e0f3f
commit 5ab6977
Showing
12 changed files
with
113 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod versions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
pub mod constants { | ||
pub const LINUX_ARTIFACT: &str = "jvem.tar.gz"; | ||
pub const WINDOWS_ARTIFACT: &str = "jvem.zip"; | ||
pub const AVAILABLE_VERSIONS: &str = "ZULU8,ZULU11,ZULU17,ZULU21"; | ||
pub const ZULU21_LINUX: &str = | ||
"https://cdn.azul.com/zulu/bin/zulu21.32.17-ca-jdk21.0.2-linux_x64.tar.gz"; | ||
pub const ZULU21_WINDOWS: &str = "https://cdn.azul.com/zulu/bin/zulu21.32.17-ca-jdk21.0.2-win_x64.zip?_gl=1*14dmzoc*_ga*MTg0NTAyMjU0LjE3MDg3MDUwMzU.*_ga_42DEGWGYD5*MTcwODcwNTAzNS4xLjEuMTcwODcwNTExMi40NC4wLjA."; | ||
// ZULU21_MACOS | ||
|
||
pub const ZULU17_LINUX: &str = | ||
"https://cdn.azul.com/zulu/bin/zulu17.48.15-ca-jdk17.0.10-linux_x64.tar.gz"; | ||
pub const ZULU17_WINDOWS: &str = "https://cdn.azul.com/zulu/bin/zulu17.48.15-ca-jdk17.0.10-win_x64.zip?_gl=1*1nexba0*_ga*MTg0NTAyMjU0LjE3MDg3MDUwMzU.*_ga_42DEGWGYD5*MTcwODcwNTAzNS4xLjEuMTcwODcwNTE0Ny45LjAuMA.."; | ||
// ZULU17_MACOS | ||
|
||
pub const ZULU11_LINUX: &str = | ||
"https://cdn.azul.com/zulu/bin/zulu11.70.15-ca-jdk11.0.22-linux_x64.tar.gz"; | ||
pub const ZULU11_WINDOWS: &str = "https://cdn.azul.com/zulu/bin/zulu11.70.15-ca-jdk11.0.22-win_x64.zip?_gl=1*2j7qzc*_ga*MTg0NTAyMjU0LjE3MDg3MDUwMzU.*_ga_42DEGWGYD5*MTcwODcwNTAzNS4xLjEuMTcwODcwNTIwNS4yNS4wLjA."; | ||
// ZULU11_MACOS | ||
|
||
pub const ZULU8_LINUX: &str = | ||
"https://cdn.azul.com/zulu/bin/zulu8.76.0.17-ca-jdk8.0.402-linux_i686.tar.gz"; | ||
pub const ZULU8_WINDOWS: &str ="https://cdn.azul.com/zulu/bin/zulu8.76.0.17-ca-jdk8.0.402-win_x64.zip?_gl=1*i45ppb*_ga*MTg0NTAyMjU0LjE3MDg3MDUwMzU.*_ga_42DEGWGYD5*MTcwODcwNTAzNS4xLjEuMTcwODcwNTIxMy4xNy4wLjA."; | ||
// ZULU8_MACOS | ||
|
||
pub fn get_constant(key: &str) -> Option<&'static str> { | ||
match key { | ||
"LINUX_ARTIFACT" => Some(LINUX_ARTIFACT), | ||
"WINDOWS_ARTIFACT" => Some(WINDOWS_ARTIFACT), | ||
"AVAILABLE_VERSIONS" => Some(AVAILABLE_VERSIONS), | ||
"ZULU21_LINUX" => Some(ZULU21_LINUX), | ||
"ZULU21_WINDOWS" => Some(ZULU21_WINDOWS), | ||
"ZULU17_LINUX" => Some(ZULU17_LINUX), | ||
"ZULU17_WINDOWS" => Some(ZULU17_WINDOWS), | ||
"ZULU11_LINUX" => Some(ZULU11_LINUX), | ||
"ZULU11_WINDOWS" => Some(ZULU11_WINDOWS), | ||
"ZULU8_LINUX" => Some(ZULU8_LINUX), | ||
"ZULU8_WINDOWS" => Some(ZULU8_WINDOWS), | ||
_ => None, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,22 @@ | ||
use std::error::Error; | ||
use crate::constants::versions::constants; | ||
|
||
pub fn read_versions() -> Result<(), Box<dyn std::error::Error>> { | ||
// Load environment variables from .env file | ||
dotenv::dotenv().ok(); | ||
let available_versions = constants::AVAILABLE_VERSIONS; | ||
let versions: Vec<&str> = available_versions.split(',').collect(); | ||
|
||
if let Ok(available_versions) = std::env::var("AVAILABLE_VERSIONS") { | ||
let versions: Vec<&str> = available_versions.split(',').collect(); | ||
|
||
for version in versions { | ||
println!("{}", version); | ||
} | ||
println!("Availaible Versions:"); | ||
for version in versions { | ||
println!("{}", version); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn get_download_link(name: String, os: &str) -> Result<String, Box<dyn Error>> { | ||
// Load environment variables from .env file | ||
dotenv::dotenv().ok(); | ||
|
||
// Access the environment variable for the specified name | ||
pub fn get_download_link(name: String, os: &str) -> Result<String, Box<dyn std::error::Error>> { | ||
let env_var_name = format!("{}_{}", name.to_uppercase(), os.to_uppercase()); | ||
match std::env::var(&env_var_name) { | ||
Ok(value) => Ok(value), | ||
Err(_) => Err("Couldn't recognize OS or the specified JDK is not available".into()), | ||
if let Some(value) = constants::get_constant(&env_var_name) { | ||
Ok(value.to_string()) | ||
} else { | ||
Err("Couldn't recognize OS or the specified JDK is not available".into()) | ||
} | ||
} | ||
} |