Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
45 changes: 2 additions & 43 deletions crates/konvoy-engine/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fn update(project_root: &Path) -> Result<UpdateResult, EngineError> {
message: format!("dependency `{dep_name}` is missing `version` field"),
})?;

let (group_id, artifact_id) = split_maven_coordinate(maven)?;
let (group_id, artifact_id) = crate::common::split_maven_coordinate(maven)?;

direct_deps.push(ResolvedMavenDep {
name: (*dep_name).clone(),
Expand Down Expand Up @@ -511,7 +511,7 @@ fn resolve_transitive(
continue;
}

let dep_name = derive_dep_name(&base_artifact_id);
let dep_name = base_artifact_id.clone();
let parent_name = requirer
.clone()
.or_else(|| {
Expand Down Expand Up @@ -619,13 +619,6 @@ fn fetch_metadata_cached(
// Helpers
// ---------------------------------------------------------------------------

/// Split a `groupId:artifactId` string into its two parts.
///
/// Re-export of [`crate::common::split_maven_coordinate`] for backward compatibility.
pub(crate) fn split_maven_coordinate(maven: &str) -> Result<(&str, &str), EngineError> {
crate::common::split_maven_coordinate(maven)
}

/// Return `true` if this dependency should be filtered from transitive resolution.
///
/// Filters `kotlin-stdlib` and `kotlin-stdlib-common` which are JVM artifacts.
Expand All @@ -646,15 +639,6 @@ fn is_filtered_dependency(group_id: &str, artifact_id: &str) -> bool {
false
}

/// Derive a user-friendly dependency name from a Maven artifact ID.
///
/// Examples:
/// - `"kotlinx-coroutines-core"` → `"kotlinx-coroutines-core"`
/// - `"atomicfu"` → `"atomicfu"`
fn derive_dep_name(artifact_id: &str) -> String {
artifact_id.to_owned()
}

/// Extract the Maven classifier from a cinterop file URL.
///
/// Given a URL like `"atomicfu-linuxx64-0.23.1-cinterop-interop.klib"`,
Expand Down Expand Up @@ -866,22 +850,6 @@ kotlinx-coroutines = { maven = "org.jetbrains.kotlinx:kotlinx-coroutines-core",
}
}

#[test]
fn split_maven_coordinate_valid() {
let (g, a) =
split_maven_coordinate("org.jetbrains.kotlinx:kotlinx-coroutines-core").unwrap();
assert_eq!(g, "org.jetbrains.kotlinx");
assert_eq!(a, "kotlinx-coroutines-core");
}

#[test]
fn split_maven_coordinate_invalid() {
let result = split_maven_coordinate("no-colon-here");
assert!(result.is_err());
let err = result.unwrap_err().to_string();
assert!(err.contains("invalid maven coordinate"), "error was: {err}");
}

#[test]
fn is_filtered_kotlin_stdlib() {
assert!(is_filtered_dependency(
Expand Down Expand Up @@ -911,15 +879,6 @@ kotlinx-coroutines = { maven = "org.jetbrains.kotlinx:kotlinx-coroutines-core",
assert!(!is_filtered_dependency("org.jetbrains.kotlinx", "atomicfu"));
}

#[test]
fn derive_dep_name_from_artifact_id() {
assert_eq!(
derive_dep_name("kotlinx-coroutines-core"),
"kotlinx-coroutines-core"
);
assert_eq!(derive_dep_name("atomicfu"), "atomicfu");
}

#[test]
fn version_conflict_error_format() {
let err = EngineError::MavenVersionConflict {
Expand Down
3 changes: 1 addition & 2 deletions crates/konvoy-util/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![forbid(unsafe_code)]
//! Hashing, filesystem utilities, and process helpers for Konvoy.
//! Hashing, filesystem utilities, and download helpers for Konvoy.

pub mod artifact;
pub mod download;
Expand All @@ -10,4 +10,3 @@ pub mod maven;
pub mod metadata;
pub mod module_metadata;
pub mod pom;
pub mod process;
17 changes: 10 additions & 7 deletions crates/konvoy-util/src/maven.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ use crate::error::UtilError;
/// Maven Central repository URL.
pub const MAVEN_CENTRAL: &str = "https://repo1.maven.org/maven2";

/// Build a Maven Central URL for an artifact file with the given extension.
///
/// Pattern: `{MAVEN_CENTRAL}/{group_path}/{artifact_id}/{version}/{artifact_id}-{version}.{ext}`
pub fn maven_artifact_url(group_id: &str, artifact_id: &str, version: &str, ext: &str) -> String {
let group_path = group_id.replace('.', "/");
format!("{MAVEN_CENTRAL}/{group_path}/{artifact_id}/{version}/{artifact_id}-{version}.{ext}")
}

/// A parsed Maven coordinate identifying a single artifact.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MavenCoordinate {
Expand Down Expand Up @@ -157,14 +165,9 @@ impl MavenCoordinate {

/// Return the local cache path for this artifact, rooted at `cache_root`.
///
/// Uses the same directory layout as `repository_path` but as a `PathBuf`.
/// Uses the same directory layout as [`Self::repository_path`].
pub fn cache_path(&self, cache_root: &Path) -> PathBuf {
let group_path = self.group_id.replace('.', "/");
cache_root
.join(group_path)
.join(&self.artifact_id)
.join(&self.version)
.join(self.filename())
cache_root.join(self.repository_path())
}
}

Expand Down
4 changes: 1 addition & 3 deletions crates/konvoy-util/src/module_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use serde::Deserialize;

use crate::error::UtilError;
use crate::maven::MAVEN_CENTRAL;
use crate::metadata::{ArtifactMetadata, MetadataDep, MetadataFile};

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -124,8 +123,7 @@ pub fn parse_module_metadata(json: &str) -> Result<ArtifactMetadata, UtilError>
/// The URL pattern is:
/// `{MAVEN_CENTRAL}/{group_path}/{artifact_id}/{version}/{artifact_id}-{version}.module`
pub fn module_metadata_url(group_id: &str, artifact_id: &str, version: &str) -> String {
let group_path = group_id.replace('.', "/");
format!("{MAVEN_CENTRAL}/{group_path}/{artifact_id}/{version}/{artifact_id}-{version}.module")
crate::maven::maven_artifact_url(group_id, artifact_id, version, "module")
}

/// Fetch a Gradle Module Metadata file from Maven Central.
Expand Down
4 changes: 1 addition & 3 deletions crates/konvoy-util/src/pom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//! - Property placeholders beyond `${project.version}` / `${project.groupId}`

use crate::error::UtilError;
use crate::maven::MAVEN_CENTRAL;
use crate::metadata::{ArtifactMetadata, MetadataDep};

/// A parsed Maven POM, containing identity and compile-scope dependencies.
Expand Down Expand Up @@ -302,8 +301,7 @@ pub fn parse_pom(
///
/// where `group_path` replaces dots in `group_id` with `/`.
pub fn pom_url(group_id: &str, artifact_id: &str, version: &str) -> String {
let group_path = group_id.replace('.', "/");
format!("{MAVEN_CENTRAL}/{group_path}/{artifact_id}/{version}/{artifact_id}-{version}.pom")
crate::maven::maven_artifact_url(group_id, artifact_id, version, "pom")
}

/// Fetch a POM file from Maven Central and return its contents as a string.
Expand Down
76 changes: 0 additions & 76 deletions crates/konvoy-util/src/process.rs

This file was deleted.

Loading