Skip to content

Commit

Permalink
Use the recommended directory layout for native-image metadata. Simpl…
Browse files Browse the repository at this point in the history
…ify automatic handler metadata generator usage. (netty#12951)

Motivation:

The recommended directory layout for native-image metadata is `META-INF/native-image/<groupId>/<artifactId>/...`. Recent Native Build Tools versions will print a warning if a `native-image.properties` file is detected and it's path doesn't adhere to the above layout.

Modification:

This PR moves all native-image related metadata so that it conforms to the above layout.
This PR also ensures the above layout is used for the automatically generated handler metadata. The new layout of this metadata is `META-INF/native-image/<groupId>/<artifactId>/automatic/handlers`.

Result:

Fixes netty#12934
  • Loading branch information
gradinac authored Nov 2, 2022
1 parent a45feed commit fe0b5ce
Show file tree
Hide file tree
Showing 45 changed files with 28 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public class NativeImageHandlerMetadataTest {

@Test
public void collectAndCompareMetadata() {
ChannelHandlerMetadataUtil.generateMetadata(
"codec-dns-handlers/reflect-config.json",
"io.netty.handler.codec.dns");
ChannelHandlerMetadataUtil.generateMetadata("io.netty.handler.codec.dns");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public class NativeImageHandlerMetadataTest {

@Test
public void collectAndCompareMetadata() {
ChannelHandlerMetadataUtil.generateMetadata(
"haproxy-handlers/reflect-config.json",
"io.netty.handler.codec.haproxy");
ChannelHandlerMetadataUtil.generateMetadata("io.netty.handler.codec.haproxy");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class NativeImageHandlerMetadataTest {
@Test
public void collectAndCompareMetadata() {
ChannelHandlerMetadataUtil.generateMetadata(
"codec-http-handlers/reflect-config.json",
"io.netty.handler.codec.http",
"io.netty.handler.codec.rtsp",
"io.netty.handler.codec.spdy");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public class NativeImageHandlerMetadataTest {

@Test
public void collectAndCompareMetadata() {
ChannelHandlerMetadataUtil.generateMetadata(
"codec-http2-handlers/reflect-config.json",
"io.netty.handler.codec.http2");
ChannelHandlerMetadataUtil.generateMetadata("io.netty.handler.codec.http2");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public class NativeImageHandlerMetadataTest {

@Test
public void collectAndCompareMetadata() {
ChannelHandlerMetadataUtil.generateMetadata(
"memcache-handlers/reflect-config.json",
"io.netty.handler.codec.memcache");
ChannelHandlerMetadataUtil.generateMetadata("io.netty.handler.codec.memcache");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public class NativeImageHandlerMetadataTest {

@Test
public void collectAndCompareMetadata() {
ChannelHandlerMetadataUtil.generateMetadata(
"codec-mqtt-handlers/reflect-config.json",
"io.netty.handler.codec.mqtt");
ChannelHandlerMetadataUtil.generateMetadata("io.netty.handler.codec.mqtt");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public class NativeImageHandlerMetadataTest {

@Test
public void collectAndCompareMetadata() {
ChannelHandlerMetadataUtil.generateMetadata(
"codec-redis-handlers/reflect-config.json",
"io.netty.handler.codec.redis");
ChannelHandlerMetadataUtil.generateMetadata("io.netty.handler.codec.redis");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public class NativeImageHandlerMetadataTest {

@Test
public void collectAndCompareMetadata() {
ChannelHandlerMetadataUtil.generateMetadata(
"codec-smtp-handlers/reflect-config.json",
"io.netty.handler.codec.smtp");
ChannelHandlerMetadataUtil.generateMetadata("io.netty.handler.codec.smtp");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class NativeImageHandlerMetadataTest {
@Test
public void collectAndCompareMetadata() {
ChannelHandlerMetadataUtil.generateMetadata(
"codec-socks-handlers/reflect-config.json",
"io.netty.handler.codec.socks", "io.netty.handler.codec.socksx");
"io.netty.handler.codec.socks",
"io.netty.handler.codec.socksx");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public class NativeImageHandlerMetadataTest {

@Test
public void collectAndCompareMetadata() {
ChannelHandlerMetadataUtil.generateMetadata(
"stomp-handlers/reflect-config.json",
"io.netty.handler.codec.stomp");
ChannelHandlerMetadataUtil.generateMetadata("io.netty.handler.codec.stomp");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public class NativeImageHandlerMetadataTest {

@Test
public void collectAndCompareMetadata() {
ChannelHandlerMetadataUtil.generateMetadata(
"codec-xml-handlers/reflect-config.json",
"io.netty.handler.codec.xml");
ChannelHandlerMetadataUtil.generateMetadata("io.netty.handler.codec.xml");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ public class NativeImageHandlerMetadataTest {

@Test
public void collectAndCompareMetadata() {
ChannelHandlerMetadataUtil.generateMetadata(
"codec-handlers/reflect-config.json",
"io.netty.handler.codec");
ChannelHandlerMetadataUtil.generateMetadata("io.netty.handler.codec");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public class NativeImageHandlerMetadataTest {

@Test
public void collectAndCompareMetadata() {
ChannelHandlerMetadataUtil.generateMetadata(
"handler-proxy-handlers/reflect-config.json",
"io.netty.handler.proxy");
ChannelHandlerMetadataUtil.generateMetadata("io.netty.handler.proxy");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public class NativeImageHandlerMetadataTest {

@Test
public void collectAndCompareMetadata() {
ChannelHandlerMetadataUtil.generateMetadata(
"handler-handlers/reflect-config.json",
"io.netty.handler");
ChannelHandlerMetadataUtil.generateMetadata("io.netty.handler");
}

}
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,9 @@
<systemPropertyVariables>
<logback.configurationFile>${logging.config}</logback.configurationFile>
<logLevel>${logging.logLevel}</logLevel>
<!-- Used by ChannelHandlerMetadataUtil to create the recommended directory layout for native-image metadata -->
<nativeImage.handlerMetadataGroupId>${project.groupId}</nativeImage.handlerMetadataGroupId>
<nativeimage.handlerMetadataArtifactId>${project.artifactId}</nativeimage.handlerMetadataArtifactId>
</systemPropertyVariables>
<argLine>${argLine.common} ${argLine.printGC} ${argLine.alpnAgent} ${argLine.leak} ${argLine.coverage} ${argLine.noUnsafe} ${argLine.java9} ${argLine.javaProperties}</argLine>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public class NativeImageHandlerMetadataTest {

@Test
public void collectAndCompareMetadata() {
ChannelHandlerMetadataUtil.generateMetadata(
"resolver-dns-handlers/reflect-config.json",
"io.netty.resolver.dns");
ChannelHandlerMetadataUtil.generateMetadata("io.netty.resolver.dns");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public class NativeImageHandlerMetadataTest {

@Test
public void collectAndCompareMetadata() {
ChannelHandlerMetadataUtil.generateMetadata(
"transport-sctp-handlers/reflect-config.json",
"io.netty.handler.codec.sctp");
ChannelHandlerMetadataUtil.generateMetadata("io.netty.handler.codec.sctp");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public class NativeImageHandlerMetadataTest {

@Test
public void collectAndCompareMetadata() {
ChannelHandlerMetadataUtil.generateMetadata(
"transport-handlers/reflect-config.json",
"io.netty.bootstrap", "io.netty.channel");
ChannelHandlerMetadataUtil.generateMetadata("io.netty.bootstrap", "io.netty.channel");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@
/**
* Generates native-image reflection metadata for subtypes of {@link io.netty.channel.ChannelHandler}.
* <p>
* To use, create a JUnit test in the desired Netty module and invoke {@link #generateMetadata(String, String...)} with:
* 1. The relative path to the native-image handler reflection metadata file in the Netty module.
* This path is relative to the root of the target Netty module.
* 2. A list of packages present in the target Netty module that may contain subtypes of the ChannelHandler.
* To use, create a JUnit test in the desired Netty module and invoke {@link #generateMetadata(String...)} with a list
* of packages present in the target Netty module that may contain subtypes of the ChannelHandler.
* <p>
* See {@link NativeImageHandlerMetadataTest}
*/
Expand All @@ -58,7 +56,10 @@ public final class ChannelHandlerMetadataUtil {
private ChannelHandlerMetadataUtil() {
}

public static void generateMetadata(String resourcePath, String... packageNames) {
public static void generateMetadata(String... packageNames) {
String projectGroupId = System.getProperty("nativeImage.handlerMetadataGroupId");
String projectArtifactId = System.getProperty("nativeimage.handlerMetadataArtifactId");

Set<Class<? extends ChannelHandler>> subtypes = findChannelHandlerSubclasses(packageNames);

if (Arrays.asList(packageNames).contains("io.netty.channel")) {
Expand All @@ -71,7 +72,8 @@ public static void generateMetadata(String resourcePath, String... packageNames)
handlerMetadata.add(new HandlerMetadata(subtype.getName(), new Condition(subtype.getName()), true));
}

String projectRelativeResourcePath = "src/main/resources/META-INF/native-image/" + resourcePath;
String projectRelativeResourcePath = "src/main/resources/META-INF/native-image/" + projectGroupId + "/" +
projectArtifactId + "/generated/handlers/reflect-config.json";
File existingMetadataFile = new File(projectRelativeResourcePath);
String existingMetadataPath = existingMetadataFile.getAbsolutePath();
if (!existingMetadataFile.exists()) {
Expand Down

0 comments on commit fe0b5ce

Please sign in to comment.