Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Banner check on filesystem containing special chars #24635

Merged
merged 1 commit into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -103,7 +102,7 @@ private Map.Entry<URL, Boolean> 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;
}
Expand All @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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()));
}
}
Binary file not shown.
Binary file not shown.