Skip to content

Commit 09400df

Browse files
committed
Make URL creation more robust in Bomr's version resolver
Using URI#resolve is brittle as the behavior changes depending on whether or not the URI ends with a /. This can result in the original URI's path being lost and the URLs for the Maven metadata files being incorrect. See gh-42333
1 parent dbc4fae commit 09400df

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/MavenMetadataVersionResolver.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.springframework.http.converter.StringHttpMessageConverter;
4444
import org.springframework.web.client.HttpClientErrorException;
4545
import org.springframework.web.client.RestTemplate;
46+
import org.springframework.web.util.UriComponentsBuilder;
4647

4748
/**
4849
* A {@link VersionResolver} that examines {@code maven-metadata.xml} to determine the
@@ -76,7 +77,10 @@ public SortedSet<DependencyVersion> resolveVersions(String groupId, String artif
7677

7778
private Set<String> resolveVersions(String groupId, String artifactId, MavenArtifactRepository repository) {
7879
Set<String> versions = new HashSet<>();
79-
URI url = repository.getUrl().resolve(groupId.replace('.', '/') + "/" + artifactId + "/maven-metadata.xml");
80+
URI url = UriComponentsBuilder.fromUri(repository.getUrl())
81+
.pathSegment(groupId.replace('.', '/'), artifactId, "maven-metadata.xml")
82+
.build()
83+
.toUri();
8084
try {
8185
HttpHeaders headers = new HttpHeaders();
8286
String username = repository.getCredentials().getUsername();

0 commit comments

Comments
 (0)