#[cfg(not(feature = "python"))]
use j4rs::{JvmBuilder, MavenArtifact, MavenArtifactRepo, MavenSettings, errors::J4RsError};
#[cfg(not(feature = "python"))]
use retry::{delay, delay::Exponential, retry};
#[cfg(feature = "python")]
use j4rs::Jvm;
#[cfg(feature = "movie")]
use ffmpeg_sidecar::download::auto_download;
fn main() -> anyhow::Result<()> {
println!("cargo::rerun-if-changed=build.rs");
if std::env::var("DOCS_RS").is_err() {
#[cfg(feature = "movie")]
auto_download()?;
#[cfg(not(feature = "python"))]
retry(
Exponential::from_millis(1000).map(delay::jitter).take(4),
deploy_java_artifacts,
)?;
#[cfg(feature = "python")]
{
let py_src_path = std::env::current_dir()?.join("py").join("ndbioimage");
let py_jassets_path = py_src_path.join("jassets");
let py_deps_path = py_src_path.join("deps");
if py_jassets_path.exists() {
std::fs::remove_dir_all(&py_jassets_path)?;
}
if py_deps_path.exists() {
std::fs::remove_dir_all(&py_deps_path)?;
}
Jvm::copy_j4rs_libs_under(py_src_path.to_str().unwrap())?;
for file in std::fs::read_dir(&py_deps_path)? {
let f = file?.path().to_str().unwrap().to_string();
if !f.ends_with("_") {
std::fs::rename(&f, std::format!("{f}_"))?;
}
}
for file in std::fs::read_dir(&py_jassets_path)? {
let f = file?.path();
if !f.file_name().unwrap().to_str().unwrap().starts_with("j4rs") {
std::fs::remove_file(&f)?;
}
}
}
}
Ok(())
}
#[cfg(not(feature = "python"))]
fn deploy_java_artifacts() -> Result<(), J4RsError> {
let jvm = JvmBuilder::new()
.skip_setting_native_lib()
.with_maven_settings(MavenSettings::new(vec![MavenArtifactRepo::from(
"openmicroscopy::https://artifacts.openmicroscopy.org/artifactory/ome.releases",
)]))
.build()?;
jvm.deploy_artifact(&MavenArtifact::from("ome:bioformats_package:8.3.0"))?;
#[cfg(feature = "gpl-formats")]
jvm.deploy_artifact(&MavenArtifact::from("ome:formats-gpl:8.3.0"))?;
Ok(())
}