Skip to content

Commit 9aaffa1

Browse files
authored
fix: resolve java version in jbang from target file if on web (#211)
1 parent 9a14a2b commit 9aaffa1

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/stage4/src/executors/jbang.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl Executor for JBangExecutor {
5454
) -> Pin<Box<dyn Future<Output = Vec<ExecutorDep>> + 'a>> {
5555
Box::pin(async move {
5656
let java_version = if let Some(file_path) = input.app_args.first() {
57-
get_jbang_java_version_from_file(file_path)
57+
get_jbang_java_version_from_file(file_path).await
5858
} else {
5959
None
6060
};
@@ -64,10 +64,28 @@ impl Executor for JBangExecutor {
6464
}
6565
}
6666

67-
pub fn get_jbang_java_version_from_file(file_path: &str) -> Option<String> {
67+
pub async fn get_jbang_java_version_from_file(file_path: &str) -> Option<String> {
6868
if let Ok(content) = fs::read_to_string(file_path) {
6969
return parse_jbang_java_version(&content);
7070
}
71+
72+
if file_path.starts_with("http://") || file_path.starts_with("https://") {
73+
// Gotta rewrite URLS to raw.githubusercontent.com to get the content - I believe jbang does the same internally
74+
let url = if file_path.contains("github.com") && file_path.contains("/blob/") {
75+
file_path
76+
.replace("/blob/", "/")
77+
.replace("github.com", "raw.githubusercontent.com")
78+
} else {
79+
file_path.to_string()
80+
};
81+
82+
if let Ok(response) = reqwest::get(&url).await {
83+
if let Ok(content) = response.text().await {
84+
return parse_jbang_java_version(&content);
85+
}
86+
}
87+
}
88+
7189
None
7290
}
7391

0 commit comments

Comments
 (0)