Skip to content

Commit

Permalink
Fix Banner check on filesystem containing special chars
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP committed Mar 30, 2022
1 parent 3e16452 commit 9932bac
Show file tree
Hide file tree
Showing 4 changed files with 34 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,10 @@ 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,28 @@
package io.quarkus.deployment.pkg.steps;

import io.quarkus.deployment.steps.BannerProcessor;
import org.assertj.core.util.Files;
import org.junit.jupiter.api.Test;

import java.net.URL;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

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("file:///tmp/Descărcări/test/something!"));
assertFalse(processor.test(Files.currentFolder() + "/src/test/resources/test/Descărcări/without-class.jar!"));
assertTrue(processor.test(Files.currentFolder() + "/src/test/resources/test/Descărcări/with-class.jar!"));
}
}
Binary file not shown.
Binary file not shown.

0 comments on commit 9932bac

Please sign in to comment.