Skip to content

Commit

Permalink
struct JavaProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAlan404 committed Jun 25, 2024
1 parent cf1deb5 commit 62e816c
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/api/tools/java/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,41 @@ pub type JavaVersion = u32;
mod installation;
mod find;
mod check;
use std::{path::Path, process::Stdio};

use anyhow::{anyhow, Result};
use futures::StreamExt;
pub use installation::*;
pub use check::*;
use tokio::process::{Child, Command};

use crate::api::utils::pathdiff::diff_paths;

pub struct JavaProcess {

Check warning on line 17 in src/api/tools/java/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

struct `JavaProcess` is never constructed

warning: struct `JavaProcess` is never constructed --> src/api/tools/java/mod.rs:17:12 | 17 | pub struct JavaProcess { | ^^^^^^^^^^^

child: Child,
}

impl JavaProcess {
pub fn new(

Check warning on line 22 in src/api/tools/java/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

associated function `new` is never used

warning: associated function `new` is never used --> src/api/tools/java/mod.rs:22:12 | 21 | impl JavaProcess { | ---------------- associated function in this implementation 22 | pub fn new( | ^^^
dir: &Path,
java: &Path,
args: &[&str],
) -> Result<Self> {
let dir = diff_paths(dir, std::env::current_dir()?)
.ok_or(anyhow!("Couldn't diff paths"))?;

let child = Command::new(java)
.args(args)
.current_dir(dir)
.stderr(Stdio::inherit())
.stdout(Stdio::piped())
.stdin(Stdio::piped())
.spawn()?;

Ok(Self {
child,
})
}
}

pub async fn get_java_installations() -> Vec<JavaInstallation> {
Expand All @@ -22,3 +51,10 @@ pub async fn get_java_installations() -> Vec<JavaInstallation> {
.collect()
.await
}

pub async fn get_java_installation_for(ver: JavaVersion) -> Option<JavaInstallation> {

Check warning on line 55 in src/api/tools/java/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

function `get_java_installation_for` is never used

warning: function `get_java_installation_for` is never used --> src/api/tools/java/mod.rs:55:14 | 55 | pub async fn get_java_installation_for(ver: JavaVersion) -> Option<JavaInstallation> { | ^^^^^^^^^^^^^^^^^^^^^^^^^
get_java_installations()
.await
.into_iter()
.find(|v| v.version == ver)
}

0 comments on commit 62e816c

Please sign in to comment.