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

Prevent BannerProcessor from failing when builds done in parallel #7693

Merged
merged 1 commit into from
Mar 9, 2020
Merged
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
Expand Up @@ -2,20 +2,16 @@

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.jar.JarFile;

import org.jboss.logging.Logger;

Expand Down Expand Up @@ -105,16 +101,14 @@ private boolean isQuarkusCoreBanner(URL url) throws IOException {
return false;
}

String thisClassName = this.getClass().getName();
String jarPath = url.getPath().substring(0, url.getPath().lastIndexOf('!'));

// 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 (FileSystem fileSystem = FileSystems.newFileSystem(url.toURI(), Collections.emptyMap())) {
String thisClassName = this.getClass().getName();
String[] parts = thisClassName.split("\\.");
List<String> rest = new ArrayList<>(parts.length - 1);
rest.addAll(Arrays.asList(parts).subList(1, parts.length - 1));
rest.add(parts[parts.length - 1] + ".class");
return Files.exists(fileSystem.getPath(parts[0], rest.toArray(new String[] {})));
try (JarFile jarFile = new JarFile(Paths.get(new URI(jarPath)).toFile())) {
return jarFile.getJarEntry(thisClassName.replace('.', '/') + ".class") != null;
} catch (URISyntaxException e) {
return false;
}
Expand Down