Most of the refactor. Need to switch machines.
This commit is contained in:
49
crates/java/src/lib.rs
Normal file
49
crates/java/src/lib.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
pub mod compiler;
|
||||
pub mod error;
|
||||
pub mod runtime;
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
pub use error::{Error, Result};
|
||||
use runtime::VMFlag;
|
||||
|
||||
pub const JAVA_BIN_VM: &str = "java";
|
||||
pub const JAVA_BIN_COMPILER: &str = "javac";
|
||||
|
||||
pub const JAVA_EXT_SOURCE: &str = "java";
|
||||
pub const JAVA_EXT_CLASS: &str = "class";
|
||||
|
||||
pub const F_JAVA_VERSION: &str = ".java-version";
|
||||
|
||||
/// Uses the java binary to parse its stdout for version information.
|
||||
///
|
||||
/// This is non-caching.
|
||||
pub fn get_javac_ver() -> Result<semver::Version> {
|
||||
// TODO: Consider making this pull the version info from javac instead?
|
||||
|
||||
/*
|
||||
* $ java --version
|
||||
* openjdk 21.0.9 2025-10-21
|
||||
* OpenJDK Runtime Environment (build 21.0.9+10)
|
||||
* OpenJDK 64-Bit Server VM (build 21.0.9+10, mixed mode, sharing)
|
||||
*/
|
||||
|
||||
Ok(semver::Version::from_str(
|
||||
get_java_version_info()?
|
||||
.lines()
|
||||
.nth(0)
|
||||
.ok_or(Error::EmptyStdout)?
|
||||
.split_ascii_whitespace()
|
||||
.nth(1)
|
||||
.ok_or(Error::NthOutOfBounds)?,
|
||||
)?)
|
||||
}
|
||||
|
||||
/// Calls the java binary, returning the complete stdout version information.
|
||||
fn get_java_version_info() -> Result<String> {
|
||||
Ok(
|
||||
io::run_process(&[JAVA_BIN_VM, VMFlag::Version.to_string().as_str()])?
|
||||
.0
|
||||
.ok_or(Error::EmptyStdout)?,
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user