Skip to content

Commit

Permalink
Merge pull request #24635 from andreaTP/fix-banner-special-chars
Browse files Browse the repository at this point in the history
Fix Banner check on filesystem containing special chars
  • Loading branch information
gsmet authored Mar 31, 2022
2 parents f216507 + b05e852 commit 46fd4d8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
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.

0 comments on commit 46fd4d8

Please sign in to comment.