Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,26 @@ jobs:
os: [ ubuntu-latest, macos-latest, windows-latest ]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'adopt'
- name: Build Rust with Cargo
run: cargo build --verbose
- name: Test Rust with Cargo
run: cargo test --verbose -- --nocapture
run: cargo test --verbose -- --nocapture

test-legacy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up JDK 8
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'
- name: Test Rust with Cargo
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this should be JAVA_HOME?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, thank you!

run: JAVAM_HOME="" cargo test --features=legacy-java-compat --verbose -- --nocapture
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ glob = "0.3"
docopt = { version = "1.1", optional = true }

[features]
build-binary = ["docopt"]
build-binary = ["docopt"]
legacy-java-compat = []
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,17 @@ fn do_locate_java_home() -> Result<String> {
home_path.pop();
home_path.pop();

// Java 8(aka 1.8) has a slightly different directory structure,
// where java is in the ${JAVA_HOME}/jre/bin/java directory, and ${JAVA_HOME}/bin/java is just a symlink.
// Since we recursively follow symlinks, we end up in the wrong directory,
// so we need to pop one more time.
#[cfg(feature = "legacy-java-compat")]
if let Some(last_section) = home_path.file_name() {
if last_section == "jre" {
home_path.pop();
}
}

home_path
.into_os_string()
.into_string()
Expand Down Expand Up @@ -276,4 +287,10 @@ mod unit_tests {
fn locate_java_from_exec_test() {
println!("do_locate_java_home: {}", do_locate_java_home().unwrap());
}

#[test]
fn jni_headers_test() {
let java_home = do_locate_java_home().unwrap();
assert!(PathBuf::from(java_home).join("include").join("jni.h").exists());
}
}
Loading