From 9799ced6a3a351ae07ed19371df5af494b29f69b Mon Sep 17 00:00:00 2001 From: Paulo Lopes Date: Thu, 16 May 2019 11:32:54 +0200 Subject: [PATCH 1/2] Added native-image examples --- native-image-examples/README.md | 10 ++ .../vertx-grpc-client/pom.xml | 122 ++++++++++++++++++ .../src/main/java/SVMSubstitutions.java | 65 ++++++++++ .../java/io/vertx/example/MainVerticle.java | 27 ++++ .../src/main/proto/helloworld.proto | 24 ++++ .../native-image.properties | 5 + .../reflection.json | 32 +++++ .../vertx-grpc-server/pom.xml | 122 ++++++++++++++++++ .../src/main/java/SVMSubstitutions.java | 65 ++++++++++ .../java/io/vertx/example/MainVerticle.java | 31 +++++ .../src/main/proto/helloworld.proto | 24 ++++ .../native-image.properties | 5 + .../reflection.json | 32 +++++ .../vertx-http-server/pom.xml | 86 ++++++++++++ .../src/main/java/SVMSubstitutions.java | 65 ++++++++++ .../java/io/vertx/example/MainVerticle.java | 23 ++++ .../native-image.properties | 5 + .../reflection.json | 26 ++++ .../vertx-https-server/certificates.keystore | Bin 0 -> 2589 bytes .../vertx-https-server/pom.xml | 86 ++++++++++++ .../src/main/java/SVMSubstitutions.java | 65 ++++++++++ .../java/io/vertx/example/MainVerticle.java | 32 +++++ .../native-image.properties | 5 + .../reflection.json | 26 ++++ .../vertx-web-client/pom.xml | 90 +++++++++++++ .../src/main/java/SVMSubstitutions.java | 65 ++++++++++ .../java/io/vertx/example/MainVerticle.java | 28 ++++ .../native-image.properties | 5 + .../reflection.json | 26 ++++ pom.xml | 18 +++ 30 files changed, 1215 insertions(+) create mode 100644 native-image-examples/README.md create mode 100644 native-image-examples/vertx-grpc-client/pom.xml create mode 100644 native-image-examples/vertx-grpc-client/src/main/java/SVMSubstitutions.java create mode 100644 native-image-examples/vertx-grpc-client/src/main/java/io/vertx/example/MainVerticle.java create mode 100644 native-image-examples/vertx-grpc-client/src/main/proto/helloworld.proto create mode 100644 native-image-examples/vertx-grpc-client/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-grpc-client-example/native-image.properties create mode 100644 native-image-examples/vertx-grpc-client/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-grpc-client-example/reflection.json create mode 100644 native-image-examples/vertx-grpc-server/pom.xml create mode 100644 native-image-examples/vertx-grpc-server/src/main/java/SVMSubstitutions.java create mode 100644 native-image-examples/vertx-grpc-server/src/main/java/io/vertx/example/MainVerticle.java create mode 100644 native-image-examples/vertx-grpc-server/src/main/proto/helloworld.proto create mode 100644 native-image-examples/vertx-grpc-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-grpc-server-example/native-image.properties create mode 100644 native-image-examples/vertx-grpc-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-grpc-server-example/reflection.json create mode 100644 native-image-examples/vertx-http-server/pom.xml create mode 100644 native-image-examples/vertx-http-server/src/main/java/SVMSubstitutions.java create mode 100644 native-image-examples/vertx-http-server/src/main/java/io/vertx/example/MainVerticle.java create mode 100644 native-image-examples/vertx-http-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-http-server-example/native-image.properties create mode 100644 native-image-examples/vertx-http-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-http-server-example/reflection.json create mode 100644 native-image-examples/vertx-https-server/certificates.keystore create mode 100644 native-image-examples/vertx-https-server/pom.xml create mode 100644 native-image-examples/vertx-https-server/src/main/java/SVMSubstitutions.java create mode 100644 native-image-examples/vertx-https-server/src/main/java/io/vertx/example/MainVerticle.java create mode 100644 native-image-examples/vertx-https-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-https-server-example/native-image.properties create mode 100644 native-image-examples/vertx-https-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-https-server-example/reflection.json create mode 100644 native-image-examples/vertx-web-client/pom.xml create mode 100644 native-image-examples/vertx-web-client/src/main/java/SVMSubstitutions.java create mode 100644 native-image-examples/vertx-web-client/src/main/java/io/vertx/example/MainVerticle.java create mode 100644 native-image-examples/vertx-web-client/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-web-client-example/native-image.properties create mode 100644 native-image-examples/vertx-web-client/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-web-client-example/reflection.json diff --git a/native-image-examples/README.md b/native-image-examples/README.md new file mode 100644 index 000000000..f77c2c254 --- /dev/null +++ b/native-image-examples/README.md @@ -0,0 +1,10 @@ +# Vert.x Native Image examples + +This directory includes basic example of vert.x applications that have been +compiled to a native image. + +* [vertx http server](./vertx-http-server) +* [vertx https server](./vertx-https-server) +* [vertx web client](./vertx-web-client) +* [vertx grpc server](./vertx-grpc-server) +* [vertx grpc client](./vertx-grpc-client) diff --git a/native-image-examples/vertx-grpc-client/pom.xml b/native-image-examples/vertx-grpc-client/pom.xml new file mode 100644 index 000000000..308483870 --- /dev/null +++ b/native-image-examples/vertx-grpc-client/pom.xml @@ -0,0 +1,122 @@ + + + + 4.0.0 + + io.vertx + vertx-native-image-grpc-client-example + 3.7.0 + + + io.vertx.example.MainVerticle + + UTF-8 + 1.8 + 1.8 + 1.8 + 1.8 + 19.0.0 + 1.16.1 + + + + + + io.vertx + vertx-stack-depchain + ${project.version} + pom + import + + + + + + + com.oracle.substratevm + svm-driver + ${graal.version} + provided + + + io.vertx + vertx-core + + + io.vertx + vertx-grpc + + + + + + + kr.motd.maven + os-maven-plugin + 1.4.1.Final + + + + + org.xolstice.maven.plugins + protobuf-maven-plugin + 0.5.0 + + + com.google.protobuf:protoc:3.6.1:exe:${os.detected.classifier} + grpc-java + io.vertx:protoc-gen-grpc-java:${vertx.grpc.version}:exe:${os.detected.classifier} + + + + compile + + compile + compile-custom + + + + + + io.reactiverse + vertx-maven-plugin + 1.0.18 + + + vmp + + initialize + package + + + + + true + + + + com.oracle.substratevm + native-image-maven-plugin + ${graal.version} + + + + native-image + + package + + + + ${project.artifactId} + io.vertx.core.Launcher + --report-unsupported-elements-at-runtime --allow-incomplete-classpath + + + + + diff --git a/native-image-examples/vertx-grpc-client/src/main/java/SVMSubstitutions.java b/native-image-examples/vertx-grpc-client/src/main/java/SVMSubstitutions.java new file mode 100644 index 000000000..6f2c75028 --- /dev/null +++ b/native-image-examples/vertx-grpc-client/src/main/java/SVMSubstitutions.java @@ -0,0 +1,65 @@ +// TODO: this file should be removed once core uses netty > 4.1.36 +import com.oracle.svm.core.annotate.*; +import org.graalvm.nativeimage.*; + +/** + * This substitution allows the usage of platform specific code to do low level + * buffer related tasks + */ +@TargetClass(className = "io.netty.util.internal.CleanerJava6") +final class Target_io_netty_util_internal_CleanerJava6 { + + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FieldOffset, declClassName = "java.nio.DirectByteBuffer", name = "cleaner") + private static long CLEANER_FIELD_OFFSET; +} + +/** + * This substitution allows the usage of platform specific code to do low level + * buffer related tasks + */ +@TargetClass(className = "io.netty.util.internal.PlatformDependent0") +final class Target_io_netty_util_internal_PlatformDependent0 { + + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FieldOffset, declClassName = "java.nio.Buffer", name = "address") + private static long ADDRESS_FIELD_OFFSET; +} + +@TargetClass(className = "io.netty.util.internal.PlatformDependent") +final class Target_io_netty_util_internal_PlatformDependent { + /** + * The class PlatformDependent caches the byte array base offset by reading the + * field from PlatformDependent0. The automatic recomputation of Substrate VM + * correctly recomputes the field in PlatformDependent0, but since the caching + * in PlatformDependent happens during image building, the non-recomputed value + * is cached. + */ + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.ArrayBaseOffset, declClass = byte[].class) + private static long BYTE_ARRAY_BASE_OFFSET; +} + +/** + * This substitution allows the usage of platform specific code to do low level + * buffer related tasks + */ +@TargetClass(className = "io.netty.util.internal.shaded.org.jctools.util.UnsafeRefArrayAccess") +final class Target_io_netty_util_internal_shaded_org_jctools_util_UnsafeRefArrayAccess { + + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.ArrayIndexShift, declClass = Object[].class) + public static int REF_ELEMENT_SHIFT; +} + +/** + * This substitution forces the usage of the blocking DNS resolver + */ +@TargetClass(className = "io.vertx.core.spi.resolver.ResolverProvider") +final class Target_io_vertx_core_spi_resolver_ResolverProvider { + + @Substitute + public static io.vertx.core.spi.resolver.ResolverProvider factory(io.vertx.core.Vertx vertx, io.vertx.core.dns.AddressResolverOptions options) { + return new io.vertx.core.impl.resolver.DefaultResolverProvider(); + } +} diff --git a/native-image-examples/vertx-grpc-client/src/main/java/io/vertx/example/MainVerticle.java b/native-image-examples/vertx-grpc-client/src/main/java/io/vertx/example/MainVerticle.java new file mode 100644 index 000000000..e9807b7b1 --- /dev/null +++ b/native-image-examples/vertx-grpc-client/src/main/java/io/vertx/example/MainVerticle.java @@ -0,0 +1,27 @@ +package io.vertx.example; + +import io.grpc.ManagedChannel; +import io.grpc.examples.helloworld.GreeterGrpc; +import io.grpc.examples.helloworld.HelloRequest; +import io.vertx.core.AbstractVerticle; +import io.vertx.grpc.VertxChannelBuilder; + +public class MainVerticle extends AbstractVerticle { + + @Override + public void start() { + ManagedChannel channel = VertxChannelBuilder + .forAddress(vertx, "localhost", 50051) + .usePlaintext(true) + .build(); + GreeterGrpc.GreeterVertxStub stub = GreeterGrpc.newVertxStub(channel); + HelloRequest request = HelloRequest.newBuilder().setName("Paulo").build(); + stub.sayHello(request, asyncResponse -> { + if (asyncResponse.succeeded()) { + System.out.println("Succeeded " + asyncResponse.result().getMessage()); + } else { + asyncResponse.cause().printStackTrace(); + } + }); + } +} diff --git a/native-image-examples/vertx-grpc-client/src/main/proto/helloworld.proto b/native-image-examples/vertx-grpc-client/src/main/proto/helloworld.proto new file mode 100644 index 000000000..688974b28 --- /dev/null +++ b/native-image-examples/vertx-grpc-client/src/main/proto/helloworld.proto @@ -0,0 +1,24 @@ +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "io.grpc.examples.helloworld"; +option java_outer_classname = "HelloWorldProto"; +option objc_class_prefix = "HLW"; + +package helloworld; + +// The greeting service definition. +service Greeter { + // Sends a greeting + rpc SayHello (HelloRequest) returns (HelloReply) {} +} + +// The request message containing the user's name. +message HelloRequest { + string name = 1; +} + +// The response message containing the greetings +message HelloReply { + string message = 1; +} diff --git a/native-image-examples/vertx-grpc-client/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-grpc-client-example/native-image.properties b/native-image-examples/vertx-grpc-client/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-grpc-client-example/native-image.properties new file mode 100644 index 000000000..bc0ec8dde --- /dev/null +++ b/native-image-examples/vertx-grpc-client/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-grpc-client-example/native-image.properties @@ -0,0 +1,5 @@ +Args = --initialize-at-build-time=io.netty,com.fasterxml.jackson,javax \ + --initialize-at-run-time=io.netty.handler.codec.http.HttpObjectEncoder,io.netty.handler.codec.http.websocketx.WebSocket00FrameEncoder,io.netty.handler.codec.http2.DefaultHttp2FrameWriter,io.netty.handler.ssl.ReferenceCountedOpenSslServerContext,io.netty.handler.ssl.JdkNpnApplicationProtocolNegotiator,io.netty.handler.ssl.ReferenceCountedOpenSslEngine,io.netty.handler.ssl.ConscryptAlpnSslEngine,io.netty.handler.ssl.JettyNpnSslEngine,io.netty.handler.ssl.ReferenceCountedOpenSslClientContext,io.vertx.core.net.impl.transport.EpollTransport,io.vertx.core.net.impl.transport.KQueueTransport \ + -H:+UseServiceLoaderFeature \ + -H:IncludeResources=(META-INF)/.* \ + -H:ReflectionConfigurationFiles=classes/${.}/reflection.json diff --git a/native-image-examples/vertx-grpc-client/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-grpc-client-example/reflection.json b/native-image-examples/vertx-grpc-client/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-grpc-client-example/reflection.json new file mode 100644 index 000000000..4472e9cb6 --- /dev/null +++ b/native-image-examples/vertx-grpc-client/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-grpc-client-example/reflection.json @@ -0,0 +1,32 @@ +[ + { + "name": "io.netty.channel.socket.nio.NioServerSocketChannel", + "methods": [ + { "name": "", "parameterTypes": [] } + ] + }, + { + "name": "io.vertx.core.impl.launcher.commands.RunCommand", + "allDeclaredConstructors": true, + "allDeclaredMethods": true + }, + { + "name": "io.vertx.core.impl.launcher.commands.VertxIsolatedDeployer", + "allDeclaredConstructors": true, + "allDeclaredMethods": true + }, + { + "name": "java.lang.Long", + "allDeclaredConstructors": true + }, + { + "name": "java.lang.Integer", + "allDeclaredConstructors": true + }, + + { + "name": "io.vertx.example.MainVerticle", + "allDeclaredConstructors": true, + "allDeclaredMethods": true + } +] diff --git a/native-image-examples/vertx-grpc-server/pom.xml b/native-image-examples/vertx-grpc-server/pom.xml new file mode 100644 index 000000000..6382c3c01 --- /dev/null +++ b/native-image-examples/vertx-grpc-server/pom.xml @@ -0,0 +1,122 @@ + + + + 4.0.0 + + io.vertx + vertx-native-image-grpc-server-example + 3.7.0 + + + io.vertx.example.MainVerticle + + UTF-8 + 1.8 + 1.8 + 1.8 + 1.8 + 19.0.0 + 1.16.1 + + + + + + io.vertx + vertx-stack-depchain + ${project.version} + pom + import + + + + + + + com.oracle.substratevm + svm-driver + ${graal.version} + provided + + + io.vertx + vertx-core + + + io.vertx + vertx-grpc + + + + + + + kr.motd.maven + os-maven-plugin + 1.4.1.Final + + + + + org.xolstice.maven.plugins + protobuf-maven-plugin + 0.5.0 + + + com.google.protobuf:protoc:3.6.1:exe:${os.detected.classifier} + grpc-java + io.vertx:protoc-gen-grpc-java:${vertx.grpc.version}:exe:${os.detected.classifier} + + + + compile + + compile + compile-custom + + + + + + io.reactiverse + vertx-maven-plugin + 1.0.18 + + + vmp + + initialize + package + + + + + true + + + + com.oracle.substratevm + native-image-maven-plugin + ${graal.version} + + + + native-image + + package + + + + ${project.artifactId} + io.vertx.core.Launcher + --report-unsupported-elements-at-runtime --allow-incomplete-classpath + + + + + diff --git a/native-image-examples/vertx-grpc-server/src/main/java/SVMSubstitutions.java b/native-image-examples/vertx-grpc-server/src/main/java/SVMSubstitutions.java new file mode 100644 index 000000000..6f2c75028 --- /dev/null +++ b/native-image-examples/vertx-grpc-server/src/main/java/SVMSubstitutions.java @@ -0,0 +1,65 @@ +// TODO: this file should be removed once core uses netty > 4.1.36 +import com.oracle.svm.core.annotate.*; +import org.graalvm.nativeimage.*; + +/** + * This substitution allows the usage of platform specific code to do low level + * buffer related tasks + */ +@TargetClass(className = "io.netty.util.internal.CleanerJava6") +final class Target_io_netty_util_internal_CleanerJava6 { + + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FieldOffset, declClassName = "java.nio.DirectByteBuffer", name = "cleaner") + private static long CLEANER_FIELD_OFFSET; +} + +/** + * This substitution allows the usage of platform specific code to do low level + * buffer related tasks + */ +@TargetClass(className = "io.netty.util.internal.PlatformDependent0") +final class Target_io_netty_util_internal_PlatformDependent0 { + + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FieldOffset, declClassName = "java.nio.Buffer", name = "address") + private static long ADDRESS_FIELD_OFFSET; +} + +@TargetClass(className = "io.netty.util.internal.PlatformDependent") +final class Target_io_netty_util_internal_PlatformDependent { + /** + * The class PlatformDependent caches the byte array base offset by reading the + * field from PlatformDependent0. The automatic recomputation of Substrate VM + * correctly recomputes the field in PlatformDependent0, but since the caching + * in PlatformDependent happens during image building, the non-recomputed value + * is cached. + */ + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.ArrayBaseOffset, declClass = byte[].class) + private static long BYTE_ARRAY_BASE_OFFSET; +} + +/** + * This substitution allows the usage of platform specific code to do low level + * buffer related tasks + */ +@TargetClass(className = "io.netty.util.internal.shaded.org.jctools.util.UnsafeRefArrayAccess") +final class Target_io_netty_util_internal_shaded_org_jctools_util_UnsafeRefArrayAccess { + + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.ArrayIndexShift, declClass = Object[].class) + public static int REF_ELEMENT_SHIFT; +} + +/** + * This substitution forces the usage of the blocking DNS resolver + */ +@TargetClass(className = "io.vertx.core.spi.resolver.ResolverProvider") +final class Target_io_vertx_core_spi_resolver_ResolverProvider { + + @Substitute + public static io.vertx.core.spi.resolver.ResolverProvider factory(io.vertx.core.Vertx vertx, io.vertx.core.dns.AddressResolverOptions options) { + return new io.vertx.core.impl.resolver.DefaultResolverProvider(); + } +} diff --git a/native-image-examples/vertx-grpc-server/src/main/java/io/vertx/example/MainVerticle.java b/native-image-examples/vertx-grpc-server/src/main/java/io/vertx/example/MainVerticle.java new file mode 100644 index 000000000..e916a1cff --- /dev/null +++ b/native-image-examples/vertx-grpc-server/src/main/java/io/vertx/example/MainVerticle.java @@ -0,0 +1,31 @@ +package io.vertx.example; + +import io.grpc.examples.helloworld.GreeterGrpc; +import io.grpc.examples.helloworld.HelloReply; +import io.grpc.examples.helloworld.HelloRequest; +import io.vertx.core.AbstractVerticle; +import io.vertx.core.Future; +import io.vertx.grpc.VertxServer; +import io.vertx.grpc.VertxServerBuilder; + +public class MainVerticle extends AbstractVerticle { + + @Override + public void start() { + VertxServer server = VertxServerBuilder.forAddress(vertx, "127.0.0.1", 50051).addService(new GreeterGrpc.GreeterVertxImplBase() { + @Override + public void sayHello(HelloRequest request, Future future) { + System.out.println("Hello " + request.getName()); + future.complete(HelloReply.newBuilder().setMessage("Hi there, " + request.getName()).build()); + } + }).build(); + server.start(ar -> { + if (ar.succeeded()) { + System.out.println("gRPC service started"); + } else { + System.out.println("Could not start server " + ar.cause().getMessage()); + ar.cause().printStackTrace(); + } + }); + } +} diff --git a/native-image-examples/vertx-grpc-server/src/main/proto/helloworld.proto b/native-image-examples/vertx-grpc-server/src/main/proto/helloworld.proto new file mode 100644 index 000000000..688974b28 --- /dev/null +++ b/native-image-examples/vertx-grpc-server/src/main/proto/helloworld.proto @@ -0,0 +1,24 @@ +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "io.grpc.examples.helloworld"; +option java_outer_classname = "HelloWorldProto"; +option objc_class_prefix = "HLW"; + +package helloworld; + +// The greeting service definition. +service Greeter { + // Sends a greeting + rpc SayHello (HelloRequest) returns (HelloReply) {} +} + +// The request message containing the user's name. +message HelloRequest { + string name = 1; +} + +// The response message containing the greetings +message HelloReply { + string message = 1; +} diff --git a/native-image-examples/vertx-grpc-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-grpc-server-example/native-image.properties b/native-image-examples/vertx-grpc-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-grpc-server-example/native-image.properties new file mode 100644 index 000000000..ed0685a1b --- /dev/null +++ b/native-image-examples/vertx-grpc-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-grpc-server-example/native-image.properties @@ -0,0 +1,5 @@ +Args = --initialize-at-build-time=io.netty,com.fasterxml.jackson,javax,com.google.protobuf.ExtensionRegistry \ + --initialize-at-run-time=io.netty.handler.codec.http.HttpObjectEncoder,io.netty.handler.codec.http.websocketx.WebSocket00FrameEncoder,io.netty.handler.codec.http2.Http2CodecUtil,io.netty.handler.codec.http2.DefaultHttp2FrameWriter,io.netty.handler.ssl.ReferenceCountedOpenSslServerContext,io.netty.handler.ssl.JdkNpnApplicationProtocolNegotiator,io.netty.handler.ssl.ReferenceCountedOpenSslEngine,io.netty.handler.ssl.ConscryptAlpnSslEngine,io.netty.handler.ssl.JettyNpnSslEngine,io.netty.handler.ssl.ReferenceCountedOpenSslClientContext,io.vertx.core.net.impl.transport.EpollTransport,io.vertx.core.net.impl.transport.KQueueTransport \ + -H:+UseServiceLoaderFeature \ + -H:IncludeResources=(META-INF)/.* \ + -H:ReflectionConfigurationFiles=classes/${.}/reflection.json diff --git a/native-image-examples/vertx-grpc-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-grpc-server-example/reflection.json b/native-image-examples/vertx-grpc-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-grpc-server-example/reflection.json new file mode 100644 index 000000000..4472e9cb6 --- /dev/null +++ b/native-image-examples/vertx-grpc-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-grpc-server-example/reflection.json @@ -0,0 +1,32 @@ +[ + { + "name": "io.netty.channel.socket.nio.NioServerSocketChannel", + "methods": [ + { "name": "", "parameterTypes": [] } + ] + }, + { + "name": "io.vertx.core.impl.launcher.commands.RunCommand", + "allDeclaredConstructors": true, + "allDeclaredMethods": true + }, + { + "name": "io.vertx.core.impl.launcher.commands.VertxIsolatedDeployer", + "allDeclaredConstructors": true, + "allDeclaredMethods": true + }, + { + "name": "java.lang.Long", + "allDeclaredConstructors": true + }, + { + "name": "java.lang.Integer", + "allDeclaredConstructors": true + }, + + { + "name": "io.vertx.example.MainVerticle", + "allDeclaredConstructors": true, + "allDeclaredMethods": true + } +] diff --git a/native-image-examples/vertx-http-server/pom.xml b/native-image-examples/vertx-http-server/pom.xml new file mode 100644 index 000000000..0d3577c13 --- /dev/null +++ b/native-image-examples/vertx-http-server/pom.xml @@ -0,0 +1,86 @@ + + + + 4.0.0 + + io.vertx + vertx-native-image-http-server-example + 3.7.0 + + + io.vertx.example.MainVerticle + + UTF-8 + 1.8 + 1.8 + 1.8 + 1.8 + 19.0.0 + + + + + + io.vertx + vertx-stack-depchain + ${project.version} + pom + import + + + + + + + com.oracle.substratevm + svm-driver + ${graal.version} + provided + + + io.vertx + vertx-core + + + + + + + io.reactiverse + vertx-maven-plugin + 1.0.18 + + + vmp + + initialize + package + + + + + true + + + + com.oracle.substratevm + native-image-maven-plugin + ${graal.version} + + + + native-image + + package + + + + ${project.artifactId} + io.vertx.core.Launcher + --report-unsupported-elements-at-runtime --allow-incomplete-classpath + + + + + diff --git a/native-image-examples/vertx-http-server/src/main/java/SVMSubstitutions.java b/native-image-examples/vertx-http-server/src/main/java/SVMSubstitutions.java new file mode 100644 index 000000000..6f2c75028 --- /dev/null +++ b/native-image-examples/vertx-http-server/src/main/java/SVMSubstitutions.java @@ -0,0 +1,65 @@ +// TODO: this file should be removed once core uses netty > 4.1.36 +import com.oracle.svm.core.annotate.*; +import org.graalvm.nativeimage.*; + +/** + * This substitution allows the usage of platform specific code to do low level + * buffer related tasks + */ +@TargetClass(className = "io.netty.util.internal.CleanerJava6") +final class Target_io_netty_util_internal_CleanerJava6 { + + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FieldOffset, declClassName = "java.nio.DirectByteBuffer", name = "cleaner") + private static long CLEANER_FIELD_OFFSET; +} + +/** + * This substitution allows the usage of platform specific code to do low level + * buffer related tasks + */ +@TargetClass(className = "io.netty.util.internal.PlatformDependent0") +final class Target_io_netty_util_internal_PlatformDependent0 { + + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FieldOffset, declClassName = "java.nio.Buffer", name = "address") + private static long ADDRESS_FIELD_OFFSET; +} + +@TargetClass(className = "io.netty.util.internal.PlatformDependent") +final class Target_io_netty_util_internal_PlatformDependent { + /** + * The class PlatformDependent caches the byte array base offset by reading the + * field from PlatformDependent0. The automatic recomputation of Substrate VM + * correctly recomputes the field in PlatformDependent0, but since the caching + * in PlatformDependent happens during image building, the non-recomputed value + * is cached. + */ + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.ArrayBaseOffset, declClass = byte[].class) + private static long BYTE_ARRAY_BASE_OFFSET; +} + +/** + * This substitution allows the usage of platform specific code to do low level + * buffer related tasks + */ +@TargetClass(className = "io.netty.util.internal.shaded.org.jctools.util.UnsafeRefArrayAccess") +final class Target_io_netty_util_internal_shaded_org_jctools_util_UnsafeRefArrayAccess { + + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.ArrayIndexShift, declClass = Object[].class) + public static int REF_ELEMENT_SHIFT; +} + +/** + * This substitution forces the usage of the blocking DNS resolver + */ +@TargetClass(className = "io.vertx.core.spi.resolver.ResolverProvider") +final class Target_io_vertx_core_spi_resolver_ResolverProvider { + + @Substitute + public static io.vertx.core.spi.resolver.ResolverProvider factory(io.vertx.core.Vertx vertx, io.vertx.core.dns.AddressResolverOptions options) { + return new io.vertx.core.impl.resolver.DefaultResolverProvider(); + } +} diff --git a/native-image-examples/vertx-http-server/src/main/java/io/vertx/example/MainVerticle.java b/native-image-examples/vertx-http-server/src/main/java/io/vertx/example/MainVerticle.java new file mode 100644 index 000000000..916a1332a --- /dev/null +++ b/native-image-examples/vertx-http-server/src/main/java/io/vertx/example/MainVerticle.java @@ -0,0 +1,23 @@ +package io.vertx.example; + +import io.vertx.core.AbstractVerticle; + +public class MainVerticle extends AbstractVerticle { + + @Override + public void start() { + // your code goes here... + + vertx.createHttpServer().requestHandler(req -> { + req.response() + .putHeader("content-type", "text/plain") + .end("Hello from Vert.x!"); + }).listen(8080, res -> { + if (res.failed()) { + res.cause().printStackTrace(); + } else { + System.out.println("Server listening at: http://localhost:8080/"); + } + }); + } +} diff --git a/native-image-examples/vertx-http-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-http-server-example/native-image.properties b/native-image-examples/vertx-http-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-http-server-example/native-image.properties new file mode 100644 index 000000000..b2adb3a1b --- /dev/null +++ b/native-image-examples/vertx-http-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-http-server-example/native-image.properties @@ -0,0 +1,5 @@ +Args = --initialize-at-build-time=io.netty,com.fasterxml.jackson,javax \ + --initialize-at-run-time=io.netty.handler.codec.http.HttpObjectEncoder,io.netty.handler.codec.http.websocketx.WebSocket00FrameEncoder,io.netty.handler.codec.http2.Http2CodecUtil,io.netty.handler.codec.http2.DefaultHttp2FrameWriter,io.netty.handler.ssl.ReferenceCountedOpenSslServerContext,io.netty.handler.ssl.JdkNpnApplicationProtocolNegotiator,io.netty.handler.ssl.ReferenceCountedOpenSslEngine,io.netty.handler.ssl.ConscryptAlpnSslEngine,io.netty.handler.ssl.JettyNpnSslEngine,io.netty.handler.ssl.ReferenceCountedOpenSslClientContext,io.vertx.core.net.impl.transport.EpollTransport,io.vertx.core.net.impl.transport.KQueueTransport \ + -H:+UseServiceLoaderFeature \ + -H:IncludeResources=(META-INF)/.* \ + -H:ReflectionConfigurationFiles=classes/${.}/reflection.json diff --git a/native-image-examples/vertx-http-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-http-server-example/reflection.json b/native-image-examples/vertx-http-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-http-server-example/reflection.json new file mode 100644 index 000000000..c27024086 --- /dev/null +++ b/native-image-examples/vertx-http-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-http-server-example/reflection.json @@ -0,0 +1,26 @@ +[ + { + "name": "io.vertx.core.impl.launcher.commands.RunCommand", + "allDeclaredConstructors": true, + "allDeclaredMethods": true + }, + { + "name": "io.vertx.core.impl.launcher.commands.VertxIsolatedDeployer", + "allDeclaredConstructors": true, + "allDeclaredMethods": true + }, + { + "name": "java.lang.Long", + "allDeclaredConstructors": true + }, + { + "name": "java.lang.Integer", + "allDeclaredConstructors": true + }, + + { + "name": "io.vertx.example.MainVerticle", + "allDeclaredConstructors": true, + "allDeclaredMethods": true + } +] diff --git a/native-image-examples/vertx-https-server/certificates.keystore b/native-image-examples/vertx-https-server/certificates.keystore new file mode 100644 index 0000000000000000000000000000000000000000..f77d831439f2919553cc57d7e8530e4bcb346e9f GIT binary patch literal 2589 zcmY+EX*d*$8pmhGEM}7CFvU<3S;|y1*_k1feP0S4dt*tFvTwuKMfPp%vQ%U2Df@^b z4Kj8W*_Td*$sVqIpL@@F?uYkzpXc}gzwgH%mW)7yfNWSYoC$?rjMR+WIu3*Z3&`*e zFd5!EL_thU+wK zsV|IMfQ=fHtvQNLpUhX2a6i$p8MP2Sh83TivBs}ix~n{%_OSjiZ(_daACz>p8Ip{* zG)UaRA0ugaH;#{sv}JfOe1leh<<4ewPaD^eer8e7|_9T*3%%!X_` z7hjMLNLDK($A3i%rPs-3DSHz-#qcSm1J4HUyuCT}hkl z!a}>C>KIBIGBB?VKia#M}+2h)j#qzdF;m+d|2g(}5ba-0=Ej z(%C}S8>&p^n6h;9rzC%6&T;p2sDR=M@e)@L0nCeMy;-`NNtHVLG=IruF1T(>P|@d> z`u%hV=JDD7-HEBOpgzUTTU{@JDO72>;4a%`O0tpWqcXT|v(kaK2Z`eMMvJ2PHuK@n zn|^av5vr#aQK)j>0N+j*Qq@^c;}toYg~N{61cq+TRhbC$&5Hx?LF-L}U{e7vAtBYA z%d|VFcERMnhImNxaG{Sgm^VPeq~Nn$x4?O915ZJ=QH$QPl^Mlg-1|&?d3E@ebzxiN zVO}k(M2hv4YvHQZZm1qShA=2J!eJVC0W-cPdWhhoW;t?Bp1MtBi`wn1&PVy0QWTAm zm3=KkYsAG$=|?)1m1)_O?oxyogH`9*v;w+pcT2F5PL8*8746a zvdhcIXG`dOowYPgaHh0)NL1&P0;E`VaWm{izNL-|7JjE$nwOs-r=ouo;~%{P_|>{@ z41^(zNg{^ps@$U8GBG;QtQt(V1EtQB&U^57?_`rkc<2zlJQwow810loy}nFVqGIRpvrF7QBg}7pmu_!v zunj;az;0~r&j=|I5uA(bDH{$5YMxqeo8orz69i$rDpfw=%cF;K#$%C>o;MD!@B8=n z*e(_nsD7{5-kG%dY)L%Ok_)PBz2?W4*R*9&`b|YJgqIZfdm~wAG{gW` zP>^F&mVA(;J%4R98#5qZ8+;-gp2i58dMr^Upjs)H&%+U(R7yx&*%0TbG#5vRN6|!x z4kCIpTF1-=Q6E}sRNCkDmt`L{9~Mn1qzJaERBaNX zkI8#;mmi+%tSB`jJRS9DjdAW4nV*ipZ@@MS;a^)kch2u~Jq<3&QVSHRHtCTMx^xX^ zH@1g{9l#ps2WAY<(}hiTc4Ai4X67GaJws0Zo_l^>89JFSFZveLocXHHk*M~YU7Jq5 zo>+W7kUNwGvsu1JvuZYO;xlqHn(Jfyw6m_9R##uOb=leFwXfjZ7V1~7o8XwG74z=| zo=E5|#}3KVSnH1tSD#E(o?RcFfrD+)0l>B1oAoyDOzxwht`s?R2g|u?g$s*Y-w5#;xNsjGwQh5k8~XDV`AvlNGX2~{_xQaWHK;teI~~gc5*cJR8;Hx z5)drlQ}pZ#`+|4G8otuLc6h4-nDUwf#6q`LkWYsg+eoVnc(w5+3XeDq6bZ%AA2j-h zXE=c~#>Eg6wXI=q4H;Yf%EVuH>l1sll!?Bk zd673-VK@||W+cLP85G&Cu*6AS@o94Sp0ll5{L07k(JVIiOR0mdjD9e@|GMcH z)_fR#AT{0}$CR1M2!EF$e=`cNj?<0BDq+uI;ZTSKCmV2F^IX}tXlPykLU42qFd^FT4n; + + + 4.0.0 + + io.vertx + vertx-native-image-https-server-example + 3.7.0 + + + io.vertx.example.MainVerticle + + UTF-8 + 1.8 + 1.8 + 1.8 + 1.8 + 19.0.0 + + + + + + io.vertx + vertx-stack-depchain + ${project.version} + pom + import + + + + + + + com.oracle.substratevm + svm-driver + ${graal.version} + provided + + + io.vertx + vertx-core + + + + + + + io.reactiverse + vertx-maven-plugin + 1.0.18 + + + vmp + + initialize + package + + + + + true + + + + com.oracle.substratevm + native-image-maven-plugin + ${graal.version} + + + + native-image + + package + + + + ${project.artifactId} + io.vertx.core.Launcher + --enable-all-security-services --report-unsupported-elements-at-runtime --allow-incomplete-classpath + + + + + diff --git a/native-image-examples/vertx-https-server/src/main/java/SVMSubstitutions.java b/native-image-examples/vertx-https-server/src/main/java/SVMSubstitutions.java new file mode 100644 index 000000000..6f2c75028 --- /dev/null +++ b/native-image-examples/vertx-https-server/src/main/java/SVMSubstitutions.java @@ -0,0 +1,65 @@ +// TODO: this file should be removed once core uses netty > 4.1.36 +import com.oracle.svm.core.annotate.*; +import org.graalvm.nativeimage.*; + +/** + * This substitution allows the usage of platform specific code to do low level + * buffer related tasks + */ +@TargetClass(className = "io.netty.util.internal.CleanerJava6") +final class Target_io_netty_util_internal_CleanerJava6 { + + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FieldOffset, declClassName = "java.nio.DirectByteBuffer", name = "cleaner") + private static long CLEANER_FIELD_OFFSET; +} + +/** + * This substitution allows the usage of platform specific code to do low level + * buffer related tasks + */ +@TargetClass(className = "io.netty.util.internal.PlatformDependent0") +final class Target_io_netty_util_internal_PlatformDependent0 { + + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FieldOffset, declClassName = "java.nio.Buffer", name = "address") + private static long ADDRESS_FIELD_OFFSET; +} + +@TargetClass(className = "io.netty.util.internal.PlatformDependent") +final class Target_io_netty_util_internal_PlatformDependent { + /** + * The class PlatformDependent caches the byte array base offset by reading the + * field from PlatformDependent0. The automatic recomputation of Substrate VM + * correctly recomputes the field in PlatformDependent0, but since the caching + * in PlatformDependent happens during image building, the non-recomputed value + * is cached. + */ + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.ArrayBaseOffset, declClass = byte[].class) + private static long BYTE_ARRAY_BASE_OFFSET; +} + +/** + * This substitution allows the usage of platform specific code to do low level + * buffer related tasks + */ +@TargetClass(className = "io.netty.util.internal.shaded.org.jctools.util.UnsafeRefArrayAccess") +final class Target_io_netty_util_internal_shaded_org_jctools_util_UnsafeRefArrayAccess { + + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.ArrayIndexShift, declClass = Object[].class) + public static int REF_ELEMENT_SHIFT; +} + +/** + * This substitution forces the usage of the blocking DNS resolver + */ +@TargetClass(className = "io.vertx.core.spi.resolver.ResolverProvider") +final class Target_io_vertx_core_spi_resolver_ResolverProvider { + + @Substitute + public static io.vertx.core.spi.resolver.ResolverProvider factory(io.vertx.core.Vertx vertx, io.vertx.core.dns.AddressResolverOptions options) { + return new io.vertx.core.impl.resolver.DefaultResolverProvider(); + } +} diff --git a/native-image-examples/vertx-https-server/src/main/java/io/vertx/example/MainVerticle.java b/native-image-examples/vertx-https-server/src/main/java/io/vertx/example/MainVerticle.java new file mode 100644 index 000000000..be4b1eb0f --- /dev/null +++ b/native-image-examples/vertx-https-server/src/main/java/io/vertx/example/MainVerticle.java @@ -0,0 +1,32 @@ +package io.vertx.example; + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.http.HttpServerOptions; +import io.vertx.core.net.JksOptions; + +public class MainVerticle extends AbstractVerticle { + + @Override + public void start() { + vertx.createHttpServer( + new HttpServerOptions() + .setSsl(true) + .setKeyStoreOptions( + new JksOptions() + .setPath("certificates.keystore") + .setPassword("localhost") + ) + ).requestHandler(req -> { + req.response() + .putHeader("content-type", "text/plain") + .end("Hello from Vert.x!"); + }).listen(8443, listen -> { + if (listen.succeeded()) { + System.out.println("Server listening on https://localhost:8443/"); + } else { + listen.cause().printStackTrace(); + System.exit(1); + } + }); + } +} diff --git a/native-image-examples/vertx-https-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-https-server-example/native-image.properties b/native-image-examples/vertx-https-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-https-server-example/native-image.properties new file mode 100644 index 000000000..b2adb3a1b --- /dev/null +++ b/native-image-examples/vertx-https-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-https-server-example/native-image.properties @@ -0,0 +1,5 @@ +Args = --initialize-at-build-time=io.netty,com.fasterxml.jackson,javax \ + --initialize-at-run-time=io.netty.handler.codec.http.HttpObjectEncoder,io.netty.handler.codec.http.websocketx.WebSocket00FrameEncoder,io.netty.handler.codec.http2.Http2CodecUtil,io.netty.handler.codec.http2.DefaultHttp2FrameWriter,io.netty.handler.ssl.ReferenceCountedOpenSslServerContext,io.netty.handler.ssl.JdkNpnApplicationProtocolNegotiator,io.netty.handler.ssl.ReferenceCountedOpenSslEngine,io.netty.handler.ssl.ConscryptAlpnSslEngine,io.netty.handler.ssl.JettyNpnSslEngine,io.netty.handler.ssl.ReferenceCountedOpenSslClientContext,io.vertx.core.net.impl.transport.EpollTransport,io.vertx.core.net.impl.transport.KQueueTransport \ + -H:+UseServiceLoaderFeature \ + -H:IncludeResources=(META-INF)/.* \ + -H:ReflectionConfigurationFiles=classes/${.}/reflection.json diff --git a/native-image-examples/vertx-https-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-https-server-example/reflection.json b/native-image-examples/vertx-https-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-https-server-example/reflection.json new file mode 100644 index 000000000..c27024086 --- /dev/null +++ b/native-image-examples/vertx-https-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-https-server-example/reflection.json @@ -0,0 +1,26 @@ +[ + { + "name": "io.vertx.core.impl.launcher.commands.RunCommand", + "allDeclaredConstructors": true, + "allDeclaredMethods": true + }, + { + "name": "io.vertx.core.impl.launcher.commands.VertxIsolatedDeployer", + "allDeclaredConstructors": true, + "allDeclaredMethods": true + }, + { + "name": "java.lang.Long", + "allDeclaredConstructors": true + }, + { + "name": "java.lang.Integer", + "allDeclaredConstructors": true + }, + + { + "name": "io.vertx.example.MainVerticle", + "allDeclaredConstructors": true, + "allDeclaredMethods": true + } +] diff --git a/native-image-examples/vertx-web-client/pom.xml b/native-image-examples/vertx-web-client/pom.xml new file mode 100644 index 000000000..37b8f4775 --- /dev/null +++ b/native-image-examples/vertx-web-client/pom.xml @@ -0,0 +1,90 @@ + + + + 4.0.0 + + io.vertx + vertx-native-image-web-client-example + 3.7.0 + + + io.vertx.example.MainVerticle + + UTF-8 + 1.8 + 1.8 + 1.8 + 1.8 + 19.0.0 + + + + + + io.vertx + vertx-stack-depchain + ${project.version} + pom + import + + + + + + + com.oracle.substratevm + svm-driver + ${graal.version} + provided + + + io.vertx + vertx-core + + + io.vertx + vertx-web-client + + + + + + + io.reactiverse + vertx-maven-plugin + 1.0.18 + + + vmp + + initialize + package + + + + + true + + + + com.oracle.substratevm + native-image-maven-plugin + ${graal.version} + + + + native-image + + package + + + + ${project.artifactId} + io.vertx.core.Launcher + --enable-all-security-services --report-unsupported-elements-at-runtime --allow-incomplete-classpath + + + + + diff --git a/native-image-examples/vertx-web-client/src/main/java/SVMSubstitutions.java b/native-image-examples/vertx-web-client/src/main/java/SVMSubstitutions.java new file mode 100644 index 000000000..6f2c75028 --- /dev/null +++ b/native-image-examples/vertx-web-client/src/main/java/SVMSubstitutions.java @@ -0,0 +1,65 @@ +// TODO: this file should be removed once core uses netty > 4.1.36 +import com.oracle.svm.core.annotate.*; +import org.graalvm.nativeimage.*; + +/** + * This substitution allows the usage of platform specific code to do low level + * buffer related tasks + */ +@TargetClass(className = "io.netty.util.internal.CleanerJava6") +final class Target_io_netty_util_internal_CleanerJava6 { + + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FieldOffset, declClassName = "java.nio.DirectByteBuffer", name = "cleaner") + private static long CLEANER_FIELD_OFFSET; +} + +/** + * This substitution allows the usage of platform specific code to do low level + * buffer related tasks + */ +@TargetClass(className = "io.netty.util.internal.PlatformDependent0") +final class Target_io_netty_util_internal_PlatformDependent0 { + + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FieldOffset, declClassName = "java.nio.Buffer", name = "address") + private static long ADDRESS_FIELD_OFFSET; +} + +@TargetClass(className = "io.netty.util.internal.PlatformDependent") +final class Target_io_netty_util_internal_PlatformDependent { + /** + * The class PlatformDependent caches the byte array base offset by reading the + * field from PlatformDependent0. The automatic recomputation of Substrate VM + * correctly recomputes the field in PlatformDependent0, but since the caching + * in PlatformDependent happens during image building, the non-recomputed value + * is cached. + */ + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.ArrayBaseOffset, declClass = byte[].class) + private static long BYTE_ARRAY_BASE_OFFSET; +} + +/** + * This substitution allows the usage of platform specific code to do low level + * buffer related tasks + */ +@TargetClass(className = "io.netty.util.internal.shaded.org.jctools.util.UnsafeRefArrayAccess") +final class Target_io_netty_util_internal_shaded_org_jctools_util_UnsafeRefArrayAccess { + + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.ArrayIndexShift, declClass = Object[].class) + public static int REF_ELEMENT_SHIFT; +} + +/** + * This substitution forces the usage of the blocking DNS resolver + */ +@TargetClass(className = "io.vertx.core.spi.resolver.ResolverProvider") +final class Target_io_vertx_core_spi_resolver_ResolverProvider { + + @Substitute + public static io.vertx.core.spi.resolver.ResolverProvider factory(io.vertx.core.Vertx vertx, io.vertx.core.dns.AddressResolverOptions options) { + return new io.vertx.core.impl.resolver.DefaultResolverProvider(); + } +} diff --git a/native-image-examples/vertx-web-client/src/main/java/io/vertx/example/MainVerticle.java b/native-image-examples/vertx-web-client/src/main/java/io/vertx/example/MainVerticle.java new file mode 100644 index 000000000..4cc7328cb --- /dev/null +++ b/native-image-examples/vertx-web-client/src/main/java/io/vertx/example/MainVerticle.java @@ -0,0 +1,28 @@ +package io.vertx.example; + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.buffer.Buffer; +import io.vertx.ext.web.client.HttpResponse; +import io.vertx.ext.web.client.WebClient; +import io.vertx.ext.web.client.WebClientOptions; + +public class MainVerticle extends AbstractVerticle { + + @Override + public void start() { + WebClient client = WebClient.create(vertx, new WebClientOptions().setSsl(true).setTrustAll(true)); + + client + .get(443, "icanhazdadjoke.com", "/") + .putHeader("Accept", "text/plain") + .send(ar -> { + if (ar.succeeded()) { + HttpResponse response = ar.result(); + System.out.println("Got HTTP response with status " + response.statusCode() + " with data " + + response.body().toString("ISO-8859-1")); + } else { + ar.cause().printStackTrace(); + } + }); + } +} diff --git a/native-image-examples/vertx-web-client/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-web-client-example/native-image.properties b/native-image-examples/vertx-web-client/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-web-client-example/native-image.properties new file mode 100644 index 000000000..21336d4b1 --- /dev/null +++ b/native-image-examples/vertx-web-client/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-web-client-example/native-image.properties @@ -0,0 +1,5 @@ +Args = --initialize-at-build-time=io.netty,com.fasterxml.jackson,javax,io.vertx.ext.web.client.predicate.ResponsePredicate,io.vertx.ext.web.client.predicate.ErrorConverter \ + --initialize-at-run-time=io.netty.handler.codec.http.HttpObjectEncoder,io.netty.handler.codec.http.websocketx.WebSocket00FrameEncoder,io.netty.handler.codec.http2.Http2CodecUtil,io.netty.handler.codec.http2.DefaultHttp2FrameWriter,io.netty.handler.ssl.ReferenceCountedOpenSslServerContext,io.netty.handler.ssl.JdkNpnApplicationProtocolNegotiator,io.netty.handler.ssl.ReferenceCountedOpenSslEngine,io.netty.handler.ssl.ConscryptAlpnSslEngine,io.netty.handler.ssl.JettyNpnSslEngine,io.netty.handler.ssl.ReferenceCountedOpenSslClientContext,io.vertx.core.net.impl.transport.EpollTransport,io.vertx.core.net.impl.transport.KQueueTransport \ + -H:+UseServiceLoaderFeature \ + -H:IncludeResources=(META-INF)/.* \ + -H:ReflectionConfigurationFiles=classes/${.}/reflection.json diff --git a/native-image-examples/vertx-web-client/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-web-client-example/reflection.json b/native-image-examples/vertx-web-client/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-web-client-example/reflection.json new file mode 100644 index 000000000..c27024086 --- /dev/null +++ b/native-image-examples/vertx-web-client/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-web-client-example/reflection.json @@ -0,0 +1,26 @@ +[ + { + "name": "io.vertx.core.impl.launcher.commands.RunCommand", + "allDeclaredConstructors": true, + "allDeclaredMethods": true + }, + { + "name": "io.vertx.core.impl.launcher.commands.VertxIsolatedDeployer", + "allDeclaredConstructors": true, + "allDeclaredMethods": true + }, + { + "name": "java.lang.Long", + "allDeclaredConstructors": true + }, + { + "name": "java.lang.Integer", + "allDeclaredConstructors": true + }, + + { + "name": "io.vertx.example.MainVerticle", + "allDeclaredConstructors": true, + "allDeclaredMethods": true + } +] diff --git a/pom.xml b/pom.xml index 93ec743e5..ccefa9076 100644 --- a/pom.xml +++ b/pom.xml @@ -85,6 +85,24 @@ docker-examples/vertx-docker-java-fatjar + + + + native + + + !skipNative + + + + native-image-examples/vertx-http-server + native-image-examples/vertx-https-server + native-image-examples/vertx-web-client + native-image-examples/vertx-grpc-server + native-image-examples/vertx-grpc-client + + + staging From b60950b39156572f343b634b05bb780adc4f8d95 Mon Sep 17 00:00:00 2001 From: Paulo Lopes Date: Fri, 17 May 2019 15:42:44 +0200 Subject: [PATCH 2/2] Fix build to avoid fat jar --- .../vertx-http-server/pom.xml | 24 +++++++++---------- .../native-image.properties | 4 ++-- .../vertx-https-server/pom.xml | 24 +++++++++---------- .../native-image.properties | 4 ++-- .../vertx-web-client/pom.xml | 24 +++++++++---------- .../java/io/vertx/example/MainVerticle.java | 2 +- .../native-image.properties | 6 ++--- 7 files changed, 41 insertions(+), 47 deletions(-) diff --git a/native-image-examples/vertx-http-server/pom.xml b/native-image-examples/vertx-http-server/pom.xml index 0d3577c13..87de12c63 100644 --- a/native-image-examples/vertx-http-server/pom.xml +++ b/native-image-examples/vertx-http-server/pom.xml @@ -47,20 +47,18 @@ - io.reactiverse - vertx-maven-plugin - 1.0.18 - - - vmp - - initialize - package - - - + org.apache.maven.plugins + maven-jar-plugin + 2.4 - true + + + io.vertx.core.Launcher + + + ${vertx.verticle} + + diff --git a/native-image-examples/vertx-http-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-http-server-example/native-image.properties b/native-image-examples/vertx-http-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-http-server-example/native-image.properties index b2adb3a1b..a0eba7c77 100644 --- a/native-image-examples/vertx-http-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-http-server-example/native-image.properties +++ b/native-image-examples/vertx-http-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-http-server-example/native-image.properties @@ -1,5 +1,5 @@ -Args = --initialize-at-build-time=io.netty,com.fasterxml.jackson,javax \ +Args = --initialize-at-build-time=io.netty,io.vertx,com.fasterxml.jackson,javax \ --initialize-at-run-time=io.netty.handler.codec.http.HttpObjectEncoder,io.netty.handler.codec.http.websocketx.WebSocket00FrameEncoder,io.netty.handler.codec.http2.Http2CodecUtil,io.netty.handler.codec.http2.DefaultHttp2FrameWriter,io.netty.handler.ssl.ReferenceCountedOpenSslServerContext,io.netty.handler.ssl.JdkNpnApplicationProtocolNegotiator,io.netty.handler.ssl.ReferenceCountedOpenSslEngine,io.netty.handler.ssl.ConscryptAlpnSslEngine,io.netty.handler.ssl.JettyNpnSslEngine,io.netty.handler.ssl.ReferenceCountedOpenSslClientContext,io.vertx.core.net.impl.transport.EpollTransport,io.vertx.core.net.impl.transport.KQueueTransport \ -H:+UseServiceLoaderFeature \ - -H:IncludeResources=(META-INF)/.* \ + -H:IncludeResources=META-INF/.* \ -H:ReflectionConfigurationFiles=classes/${.}/reflection.json diff --git a/native-image-examples/vertx-https-server/pom.xml b/native-image-examples/vertx-https-server/pom.xml index d148b06eb..1db8ebf7a 100644 --- a/native-image-examples/vertx-https-server/pom.xml +++ b/native-image-examples/vertx-https-server/pom.xml @@ -47,20 +47,18 @@ - io.reactiverse - vertx-maven-plugin - 1.0.18 - - - vmp - - initialize - package - - - + org.apache.maven.plugins + maven-jar-plugin + 2.4 - true + + + io.vertx.core.Launcher + + + ${vertx.verticle} + + diff --git a/native-image-examples/vertx-https-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-https-server-example/native-image.properties b/native-image-examples/vertx-https-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-https-server-example/native-image.properties index b2adb3a1b..a0eba7c77 100644 --- a/native-image-examples/vertx-https-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-https-server-example/native-image.properties +++ b/native-image-examples/vertx-https-server/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-https-server-example/native-image.properties @@ -1,5 +1,5 @@ -Args = --initialize-at-build-time=io.netty,com.fasterxml.jackson,javax \ +Args = --initialize-at-build-time=io.netty,io.vertx,com.fasterxml.jackson,javax \ --initialize-at-run-time=io.netty.handler.codec.http.HttpObjectEncoder,io.netty.handler.codec.http.websocketx.WebSocket00FrameEncoder,io.netty.handler.codec.http2.Http2CodecUtil,io.netty.handler.codec.http2.DefaultHttp2FrameWriter,io.netty.handler.ssl.ReferenceCountedOpenSslServerContext,io.netty.handler.ssl.JdkNpnApplicationProtocolNegotiator,io.netty.handler.ssl.ReferenceCountedOpenSslEngine,io.netty.handler.ssl.ConscryptAlpnSslEngine,io.netty.handler.ssl.JettyNpnSslEngine,io.netty.handler.ssl.ReferenceCountedOpenSslClientContext,io.vertx.core.net.impl.transport.EpollTransport,io.vertx.core.net.impl.transport.KQueueTransport \ -H:+UseServiceLoaderFeature \ - -H:IncludeResources=(META-INF)/.* \ + -H:IncludeResources=META-INF/.* \ -H:ReflectionConfigurationFiles=classes/${.}/reflection.json diff --git a/native-image-examples/vertx-web-client/pom.xml b/native-image-examples/vertx-web-client/pom.xml index 37b8f4775..c998f00c7 100644 --- a/native-image-examples/vertx-web-client/pom.xml +++ b/native-image-examples/vertx-web-client/pom.xml @@ -51,20 +51,18 @@ - io.reactiverse - vertx-maven-plugin - 1.0.18 - - - vmp - - initialize - package - - - + org.apache.maven.plugins + maven-jar-plugin + 2.4 - true + + + io.vertx.core.Launcher + + + ${vertx.verticle} + + diff --git a/native-image-examples/vertx-web-client/src/main/java/io/vertx/example/MainVerticle.java b/native-image-examples/vertx-web-client/src/main/java/io/vertx/example/MainVerticle.java index 4cc7328cb..cda175ca2 100644 --- a/native-image-examples/vertx-web-client/src/main/java/io/vertx/example/MainVerticle.java +++ b/native-image-examples/vertx-web-client/src/main/java/io/vertx/example/MainVerticle.java @@ -19,7 +19,7 @@ public void start() { if (ar.succeeded()) { HttpResponse response = ar.result(); System.out.println("Got HTTP response with status " + response.statusCode() + " with data " - + response.body().toString("ISO-8859-1")); + + response.body()); } else { ar.cause().printStackTrace(); } diff --git a/native-image-examples/vertx-web-client/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-web-client-example/native-image.properties b/native-image-examples/vertx-web-client/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-web-client-example/native-image.properties index 21336d4b1..186f34bbc 100644 --- a/native-image-examples/vertx-web-client/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-web-client-example/native-image.properties +++ b/native-image-examples/vertx-web-client/src/main/resources/META-INF/native-image/io.vertx/vertx-native-image-web-client-example/native-image.properties @@ -1,5 +1,5 @@ -Args = --initialize-at-build-time=io.netty,com.fasterxml.jackson,javax,io.vertx.ext.web.client.predicate.ResponsePredicate,io.vertx.ext.web.client.predicate.ErrorConverter \ - --initialize-at-run-time=io.netty.handler.codec.http.HttpObjectEncoder,io.netty.handler.codec.http.websocketx.WebSocket00FrameEncoder,io.netty.handler.codec.http2.Http2CodecUtil,io.netty.handler.codec.http2.DefaultHttp2FrameWriter,io.netty.handler.ssl.ReferenceCountedOpenSslServerContext,io.netty.handler.ssl.JdkNpnApplicationProtocolNegotiator,io.netty.handler.ssl.ReferenceCountedOpenSslEngine,io.netty.handler.ssl.ConscryptAlpnSslEngine,io.netty.handler.ssl.JettyNpnSslEngine,io.netty.handler.ssl.ReferenceCountedOpenSslClientContext,io.vertx.core.net.impl.transport.EpollTransport,io.vertx.core.net.impl.transport.KQueueTransport \ +Args = --initialize-at-build-time=io.netty,io.vertx,com.fasterxml.jackson,javax \ + --initialize-at-run-time=io.netty.util.internal.logging.Log4JLogger,io.netty.handler.codec.http.HttpObjectEncoder,io.netty.handler.codec.http.websocketx.WebSocket00FrameEncoder,io.netty.handler.codec.http2.Http2CodecUtil,io.netty.handler.codec.http2.DefaultHttp2FrameWriter,io.netty.handler.ssl.ReferenceCountedOpenSslServerContext,io.netty.handler.ssl.JdkNpnApplicationProtocolNegotiator,io.netty.handler.ssl.ReferenceCountedOpenSslEngine,io.netty.handler.ssl.ConscryptAlpnSslEngine,io.netty.handler.ssl.JettyNpnSslEngine,io.netty.handler.ssl.ReferenceCountedOpenSslClientContext,io.vertx.core.net.impl.transport.EpollTransport,io.vertx.core.net.impl.transport.KQueueTransport,io.vertx.core.http.impl.VertxHttp2ClientUpgradeCodec \ -H:+UseServiceLoaderFeature \ - -H:IncludeResources=(META-INF)/.* \ + -H:IncludeResources=META-INF/.* \ -H:ReflectionConfigurationFiles=classes/${.}/reflection.json