diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildpackReference.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildpackReference.java index a9059fd71ad..ebbf7da1327 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildpackReference.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildpackReference.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package org.springframework.boot.buildpack.platform.build; import java.net.MalformedURLException; +import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; @@ -51,11 +52,11 @@ public final class BuildpackReference { try { URL url = new URL(this.value); if (url.getProtocol().equals("file")) { - return Paths.get(url.getPath()); + return Paths.get(url.toURI()); } return null; } - catch (MalformedURLException ex) { + catch (MalformedURLException | URISyntaxException ex) { // not a URL, fall through to attempting to find a plain file path } try { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/TarGzipBuildpackTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/TarGzipBuildpackTests.java index 561d370719e..a7ceb835eb7 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/TarGzipBuildpackTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/TarGzipBuildpackTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,9 +61,9 @@ class TarGzipBuildpackTests { @Test void resolveWhenFileUrlReturnsBuildpack() throws Exception { Path compressedArchive = this.testTarGzip.createArchive(); - BuildpackReference reference = BuildpackReference.of("file://" + compressedArchive.toString()); + BuildpackReference reference = BuildpackReference.of(compressedArchive.toUri().toString()); Buildpack buildpack = TarGzipBuildpack.resolve(this.resolverContext, reference); - assertThat(buildpack).isNotNull(); + assertThat(buildpack).as("Buildpack %s resolved from reference %s", buildpack, reference).isNotNull(); assertThat(buildpack.getCoordinates()).hasToString("example/buildpack1@0.0.1"); this.testTarGzip.assertHasExpectedLayers(buildpack); }