Skip to content

Commit

Permalink
WIP: Attempt to replace property in artifact name
Browse files Browse the repository at this point in the history
  • Loading branch information
sghill committed Aug 8, 2024
1 parent bb2b393 commit 941e1ee
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class MavenPomDownloader {
private static final Pattern SNAPSHOT_TIMESTAMP = Pattern.compile("^(.*-)?([0-9]{8}\\.[0-9]{6}-[0-9]+)$");

private static final String SNAPSHOT = "SNAPSHOT";
private static final String PROPERTY_MARKER = "${";


private final MavenPomCache mavenCache;
Expand Down Expand Up @@ -183,7 +184,7 @@ private Map<GroupArtifactVersion, Pom> projectPomsByGav(Map<Path, Pom> projectPo
return result;
}

private Map<String, String> mergeProperties(final List<Pom> pomAncestry) {
private Map<String, String> mergeProperties(final Collection<Pom> pomAncestry) {
Map<String, String> mergedProperties = new HashMap<>();
for (final Pom pom : pomAncestry) {
for (final Map.Entry<String, String> property : pom.getProperties().entrySet()) {
Expand Down Expand Up @@ -221,7 +222,12 @@ private List<Pom> getAncestryWithinProject(Pom projectPom, Map<Path, Pom> projec
}

public MavenMetadata downloadMetadata(GroupArtifact groupArtifact, @Nullable ResolvedPom containingPom, List<MavenRepository> repositories) throws MavenDownloadingException {
return downloadMetadata(new GroupArtifactVersion(groupArtifact.getGroupId(), groupArtifact.getArtifactId(), null),
Map<String, String> properties = mergeProperties(projectPoms.values());
String artifactId = groupArtifact.getArtifactId();
if (artifactId.contains(PROPERTY_MARKER)) {
artifactId = ResolvedPom.placeholderHelper.replacePlaceholders(artifactId, properties::get);
}
return downloadMetadata(new GroupArtifactVersion(groupArtifact.getGroupId(), artifactId, null),
containingPom,
repositories);
}
Expand Down Expand Up @@ -714,7 +720,7 @@ Collection<MavenRepository> distinctNormalizedRepositories(
// If a repository URI contains an unresolved property placeholder, do not continue.
// There is also an edge case in which this condition is transient during `resolveParentPropertiesAndRepositoriesRecursively()`
// and therefore, we do not want to cache a null normalization result.
if (repository.getUri().contains("${")) {
if (repository.getUri().contains(PROPERTY_MARKER)) {
ctx.getResolutionListener().repositoryAccessFailed(repository.getUri(),
new IllegalArgumentException("Repository " + repository.getUri() + " contains an unresolved property placeholder."));
return null;
Expand Down

0 comments on commit 941e1ee

Please sign in to comment.