diff --git a/core/deployment/src/main/java/io/quarkus/deployment/steps/BannerProcessor.java b/core/deployment/src/main/java/io/quarkus/deployment/steps/BannerProcessor.java index c30633dccaed2..0b6c800271d9c 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/steps/BannerProcessor.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/steps/BannerProcessor.java @@ -1,12 +1,11 @@ package io.quarkus.deployment.steps; +import java.io.File; import java.io.IOException; import java.io.UncheckedIOException; -import java.net.URI; -import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.nio.file.Paths; +import java.nio.file.NoSuchFileException; import java.util.AbstractMap; import java.util.Enumeration; import java.util.Map; @@ -103,7 +102,7 @@ private Map.Entry getBanner(BannerConfig config) throws IOExceptio } } - private boolean isQuarkusCoreBanner(URL url) throws IOException { + protected boolean isQuarkusCoreBanner(URL url) throws IOException { if (!"jar".equals(url.getProtocol())) { return false; } @@ -114,9 +113,9 @@ private boolean isQuarkusCoreBanner(URL url) throws IOException { // We determine whether the banner is the default by checking to see if the jar that contains it also // contains this class. This way although somewhat complicated guarantees that any rename of artifacts // won't affect the check - try (JarFile jarFile = new JarFile(Paths.get(new URI(jarPath)).toFile())) { + try (JarFile jarFile = new JarFile(new File(jarPath))) { return jarFile.getJarEntry(thisClassName.replace('.', '/') + ".class") != null; - } catch (URISyntaxException e) { + } catch (NoSuchFileException e) { return false; } } diff --git a/core/deployment/src/test/java/io/quarkus/deployment/pkg/steps/BannerProcessorTest.java b/core/deployment/src/test/java/io/quarkus/deployment/pkg/steps/BannerProcessorTest.java new file mode 100644 index 0000000000000..8b8234d1368ff --- /dev/null +++ b/core/deployment/src/test/java/io/quarkus/deployment/pkg/steps/BannerProcessorTest.java @@ -0,0 +1,32 @@ +package io.quarkus.deployment.pkg.steps; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.net.URL; +import java.nio.file.Paths; + +import org.assertj.core.util.Files; +import org.junit.jupiter.api.Test; + +import io.quarkus.deployment.steps.BannerProcessor; + +public class BannerProcessorTest { + + class MyBannerProcessor extends BannerProcessor { + public boolean test(String file) throws Exception { + return this.isQuarkusCoreBanner(new URL("jar", null, 0, file)); + } + } + + @Test + public void checkQuarkusCoreBannerOnFilesystemWithSpecialCharacters() throws Exception { + MyBannerProcessor processor = new MyBannerProcessor(); + + assertFalse(processor.test(Paths.get("tmp", "Descărcări", "test", "something!").toFile().getAbsolutePath())); + assertFalse(processor.test(Paths.get(Files.currentFolder().getAbsolutePath(), "src", "test", "resources", "test", + "Descărcări", "without-class.jar!").toFile().getAbsolutePath())); + assertTrue(processor.test(Paths.get(Files.currentFolder().getAbsolutePath(), "src", "test", "resources", "test", + "Descărcări", "with-class.jar!").toFile().getAbsolutePath())); + } +} diff --git "a/core/deployment/src/test/resources/test/Desc\304\203rc\304\203ri/with-class.jar" "b/core/deployment/src/test/resources/test/Desc\304\203rc\304\203ri/with-class.jar" new file mode 100644 index 0000000000000..7cc7355144239 Binary files /dev/null and "b/core/deployment/src/test/resources/test/Desc\304\203rc\304\203ri/with-class.jar" differ diff --git "a/core/deployment/src/test/resources/test/Desc\304\203rc\304\203ri/without-class.jar" "b/core/deployment/src/test/resources/test/Desc\304\203rc\304\203ri/without-class.jar" new file mode 100644 index 0000000000000..df010a065473c Binary files /dev/null and "b/core/deployment/src/test/resources/test/Desc\304\203rc\304\203ri/without-class.jar" differ