From 37d713bdb7459cdd44707b350fd12fd59517b415 Mon Sep 17 00:00:00 2001 From: LexManos Date: Wed, 7 Nov 2018 16:09:09 -0800 Subject: Allow repos to provide maven-metadata.xml files to list known versions. --- .../artifactural/api/repository/Repository.java | 15 +++++++++++++++ .../artifactural/gradle/GradleRepositoryAdapter.java | 17 ++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/api/java/com/amadornes/artifactural/api/repository/Repository.java b/src/api/java/com/amadornes/artifactural/api/repository/Repository.java index da8aa69..2e1de79 100644 --- a/src/api/java/com/amadornes/artifactural/api/repository/Repository.java +++ b/src/api/java/com/amadornes/artifactural/api/repository/Repository.java @@ -19,6 +19,8 @@ package com.amadornes.artifactural.api.repository; +import java.io.File; + import com.amadornes.artifactural.api.artifact.Artifact; import com.amadornes.artifactural.api.artifact.ArtifactIdentifier; @@ -26,4 +28,17 @@ public interface Repository { Artifact getArtifact(ArtifactIdentifier identifier); + /** + * Returns a file in maven-metadata.xml format for the specified artifact, + * this is used by gradle to list all known versions, so that it can resolve wildcard + * dependencies such as foo:bar:1.+ + * + * @param group Group + * @param name Artifact name + * @return maven-metadata.xml file listing all versions of the artifact this repo can provide. Or null if you don't want to list any. + */ + default File getMavenMetadata(String group, String name) { + return null; + } + } diff --git a/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleRepositoryAdapter.java b/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleRepositoryAdapter.java index 834905c..64d6652 100644 --- a/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleRepositoryAdapter.java +++ b/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleRepositoryAdapter.java @@ -236,9 +236,7 @@ public class GradleRepositoryAdapter extends AbstractArtifactRepository implemen String relative = path.substring(root.length()); debug(" Relative: " + relative); Matcher matcher = URL_PATTERN.matcher(relative); - if (!matcher.matches()) { - log(" Matcher Failed: " + relative); - } else { + if (matcher.matches()) { ArtifactIdentifier identifier = new SimpleArtifactIdentifier( matcher.group("group").replace('/', '.'), matcher.group("name"), @@ -247,6 +245,19 @@ public class GradleRepositoryAdapter extends AbstractArtifactRepository implemen matcher.group("extension")); Artifact artifact = repository.getArtifact(identifier); return wrap(artifact, identifier); + } else if (relative.endsWith("maven-metadata.xml")) { + String tmp = relative.substring(0, relative.length() - "maven-metadata.xml".length() - 1); + int idx = tmp.lastIndexOf('/'); + if (idx != -1) { + File ret = repository.getMavenMetadata(tmp.substring(0, idx - 1), tmp.substring(idx)); + if (ret != null) { + return new LocalFileStandInExternalResource(ret, fileSystem); + } + } + } else if (relative.endsWith("/")) { + debug(" Directory listing not supported"); + } else { + log(" Matcher Failed: " + relative); } } else { log("Unknown root: " + path); -- cgit