Skip to content

Commit

Permalink
Merge pull request #16664 from gsmet/netty-properties
Browse files Browse the repository at this point in the history
Concatenate io.netty.versions.properties instead of ignoring them
  • Loading branch information
gsmet authored Apr 21, 2021
2 parents 6c2f4ae + 524a9fd commit 9861d4f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.function.BiPredicate;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -106,6 +107,8 @@ public class JarResultBuildStep {
"META-INF/LICENSE",
"META-INF/LICENSE.txt",
"META-INF/LICENSE.md",
"META-INF/LGPL-3.0.txt",
"META-INF/ASL-2.0.txt",
"META-INF/NOTICE",
"META-INF/NOTICE.txt",
"META-INF/NOTICE.md",
Expand All @@ -115,7 +118,6 @@ public class JarResultBuildStep {
"META-INF/DEPENDENCIES",
"META-INF/DEPENDENCIES.txt",
"META-INF/beans.xml",
"META-INF/io.netty.versions.properties",
"META-INF/quarkus-config-roots.list",
"META-INF/quarkus-javadoc.properties",
"META-INF/quarkus-extension.properties",
Expand All @@ -127,6 +129,14 @@ public class JarResultBuildStep {
"META-INF/build.metadata", // present in the Red Hat Build of Quarkus
"LICENSE");

private static final Predicate<String> CONCATENATED_ENTRIES_PREDICATE = new Predicate<>() {
@Override
public boolean test(String path) {
return "META-INF/io.netty.versions.properties".equals(path) ||
(path.startsWith("META-INF/services/") && path.length() > 18);
}
};

private static final Logger log = Logger.getLogger(JarResultBuildStep.class);
// we shouldn't have to specify these flags when opening a ZipFS (since they are the default ones), but failure to do so
// makes a subsequent uberJar creation fail in java 8 (but works fine in Java 11)
Expand Down Expand Up @@ -296,7 +306,7 @@ private void buildUberJar0(CurateOutcomeBuildItem curateOutcomeBuildItem,

final Map<String, String> seen = new HashMap<>();
final Map<String, Set<AppDependency>> duplicateCatcher = new HashMap<>();
final Map<String, List<byte[]>> services = new HashMap<>();
final Map<String, List<byte[]>> concatenatedEntries = new HashMap<>();
Set<String> finalIgnoredEntries = new HashSet<>(IGNORED_ENTRIES);
packageConfig.userConfiguredIgnoredEntries.ifPresent(finalIgnoredEntries::addAll);

Expand All @@ -323,13 +333,13 @@ private void buildUberJar0(CurateOutcomeBuildItem curateOutcomeBuildItem,
if (!Files.isDirectory(resolvedDep)) {
try (FileSystem artifactFs = ZipUtils.newFileSystem(resolvedDep)) {
for (final Path root : artifactFs.getRootDirectories()) {
walkFileDependencyForDependency(root, runnerZipFs, seen, duplicateCatcher, services,
walkFileDependencyForDependency(root, runnerZipFs, seen, duplicateCatcher, concatenatedEntries,
finalIgnoredEntries, appDep, transformedFromThisArchive);
}
}
} else {
walkFileDependencyForDependency(resolvedDep, runnerZipFs, seen, duplicateCatcher,
services, finalIgnoredEntries, appDep, transformedFromThisArchive);
concatenatedEntries, finalIgnoredEntries, appDep, transformedFromThisArchive);
}
}
}
Expand All @@ -342,7 +352,8 @@ private void buildUberJar0(CurateOutcomeBuildItem curateOutcomeBuildItem,
}
}
}
copyCommonContent(runnerZipFs, services, applicationArchivesBuildItem, transformedClasses, generatedClasses,
copyCommonContent(runnerZipFs, concatenatedEntries, applicationArchivesBuildItem, transformedClasses,
generatedClasses,
generatedResources, seen, finalIgnoredEntries);
}

Expand Down Expand Up @@ -376,7 +387,7 @@ private static boolean includeAppDep(AppDependency appDep, Optional<Set<AppArtif
}

private void walkFileDependencyForDependency(Path root, FileSystem runnerZipFs, Map<String, String> seen,
Map<String, Set<AppDependency>> duplicateCatcher, Map<String, List<byte[]>> services,
Map<String, Set<AppDependency>> duplicateCatcher, Map<String, List<byte[]>> concatenatedEntries,
Set<String> finalIgnoredEntries, AppDependency appDep, Set<String> transformedFromThisArchive) throws IOException {
final Path metaInfDir = root.resolve("META-INF");
Files.walkFileTree(root, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE,
Expand Down Expand Up @@ -409,8 +420,8 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
boolean transformed = transformedFromThisArchive != null
&& transformedFromThisArchive.contains(relativePath);
if (!transformed) {
if (relativePath.startsWith("META-INF/services/") && relativePath.length() > 18) {
services.computeIfAbsent(relativePath, (u) -> new ArrayList<>())
if (CONCATENATED_ENTRIES_PREDICATE.test(relativePath)) {
concatenatedEntries.computeIfAbsent(relativePath, (u) -> new ArrayList<>())
.add(Files.readAllBytes(file));
return FileVisitResult.CONTINUE;
} else if (!finalIgnoredEntries.contains(relativePath)) {
Expand All @@ -420,11 +431,6 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
seen.put(relativePath, appDep.toString());
Files.copy(file, runnerZipFs.getPath(relativePath),
StandardCopyOption.REPLACE_EXISTING);
} else if (!relativePath.endsWith(".class")) {
//for .class entries we warn as a group
log.warn("Duplicate entry " + relativePath + " entry from " + appDep
+ " will be ignored. Existing file was provided by "
+ seen.get(relativePath));
}
}
}
Expand Down Expand Up @@ -1066,7 +1072,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
}
}

private void copyCommonContent(FileSystem runnerZipFs, Map<String, List<byte[]>> services,
private void copyCommonContent(FileSystem runnerZipFs, Map<String, List<byte[]>> concatenatedEntries,
ApplicationArchivesBuildItem appArchives, TransformedClassesBuildItem transformedClassesBuildItem,
List<GeneratedClassBuildItem> generatedClasses,
List<GeneratedResourceBuildItem> generatedResources, Map<String, String> seen,
Expand Down Expand Up @@ -1110,8 +1116,8 @@ private void copyCommonContent(FileSystem runnerZipFs, Map<String, List<byte[]>>
if (Files.exists(target)) {
continue;
}
if (i.getName().startsWith("META-INF/services")) {
services.computeIfAbsent(i.getName(), (u) -> new ArrayList<>()).add(i.getClassData());
if (i.getName().startsWith("META-INF/services/")) {
concatenatedEntries.computeIfAbsent(i.getName(), (u) -> new ArrayList<>()).add(i.getClassData());
} else {
try (final OutputStream os = wrapForJDK8232879(Files.newOutputStream(target, DEFAULT_OPEN_OPTIONS))) {
os.write(i.getClassData());
Expand All @@ -1120,10 +1126,10 @@ private void copyCommonContent(FileSystem runnerZipFs, Map<String, List<byte[]>>
}

for (Path root : appArchives.getRootArchive().getRootDirs()) {
copyFiles(root, runnerZipFs, services, ignoredEntries);
copyFiles(root, runnerZipFs, concatenatedEntries, ignoredEntries);
}

for (Map.Entry<String, List<byte[]>> entry : services.entrySet()) {
for (Map.Entry<String, List<byte[]>> entry : concatenatedEntries.entrySet()) {
try (final OutputStream os = wrapForJDK8232879(
Files.newOutputStream(runnerZipFs.getPath(entry.getKey()), DEFAULT_OPEN_OPTIONS))) {
for (byte[] i : entry.getValue()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javax.enterprise.context.ApplicationScoped;

import io.netty.util.Version;
import io.quarkus.vertx.web.Route;
import io.vertx.ext.web.RoutingContext;

Expand All @@ -23,4 +24,11 @@ public void greetings(RoutingContext rc) {
}
rc.response().end("hello " + name);
}

@Route(path = "/netty-version", methods = HttpMethod.GET)
public void nettyVersion(RoutingContext rc) {
rc.response().end(Version.identify().containsKey("netty-common") + ";" +
Version.identify().containsKey("netty-handler") + ";" +
Version.identify().containsKey("netty-codec"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public void testDeclarativeRoutes() {
.header("X-Header", "intercepting the request")
.statusCode(200)
.body(is("hello quarkus"));

RestAssured.get("/netty-version").then()
.statusCode(200)
.body(is("true;true;true"));
}

}

0 comments on commit 9861d4f

Please sign in to comment.