use std::path::PathBuf;
use url::Url;
use crate::artifact::Artifact;
#[derive(Debug, Clone)]
pub struct RemoteRepository {
pub id: String,
pub url: Url,
pub releases_enabled: bool,
pub snapshots_enabled: bool,
}
impl RemoteRepository {
pub fn new(id: impl Into<String>, url: Url) -> Self {
Self {
id: id.into(),
url,
releases_enabled: true,
snapshots_enabled: false,
}
}
pub fn artifact_url(&self, artifact: &Artifact) -> Url {
let group_path = artifact.coordinates.group_id.replace('.', "/");
let mut path = format!("{}/{}/", group_path, artifact.coordinates.artifact_id);
path.push_str(&artifact.coordinates.version);
path.push('/');
path.push_str(&artifact.file_name());
self.url.join(&path).unwrap_or_else(|_| self.url.clone())
}
pub fn metadata_url(&self, group_id: &str, artifact_id: &str) -> Url {
let group_path = group_id.replace('.', "/");
let path = format!("{group_path}/{artifact_id}/maven-metadata.xml");
self.url.join(&path).unwrap_or_else(|_| self.url.clone())
}
pub fn version_metadata_url(&self, group_id: &str, artifact_id: &str, version: &str) -> Url {
let group_path = group_id.replace('.', "/");
let path = format!("{group_path}/{artifact_id}/{version}/maven-metadata.xml");
self.url.join(&path).unwrap_or_else(|_| self.url.clone())
}
}
pub trait RepositoryManager {
fn resolve(&self, artifact: &Artifact) -> anyhow::Result<Option<PathBuf>>;
fn download(&self, artifact: &Artifact) -> anyhow::Result<PathBuf>;
}