use std::path::PathBuf;
use crate::artifact::artifact::Artifact;
pub trait LocalRepository: Send + Sync {
fn base_directory(&self) -> &PathBuf;
fn artifact_path(&self, artifact: &Artifact) -> PathBuf {
let mut path = self.base_directory().clone();
path.push(artifact.repository_path());
path
}
fn artifact_exists(&self, artifact: &Artifact) -> bool {
self.artifact_path(artifact).exists()
}
}
pub struct DefaultLocalRepository {
base_directory: PathBuf,
}
impl DefaultLocalRepository {
pub fn new(base_directory: PathBuf) -> Self {
Self { base_directory }
}
}
impl Default for DefaultLocalRepository {
fn default() -> Self {
let home = std::env::var("HOME").unwrap_or_else(|_| ".".to_string());
let mut path = PathBuf::from(home);
path.push(".m2");
path.push("repository");
Self::new(path)
}
}
impl LocalRepository for DefaultLocalRepository {
fn base_directory(&self) -> &PathBuf {
&self.base_directory
}
}