/*
 * Copyright 2018 Red Hat, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.shamrock.vertx;

import javax.inject.Inject;

import org.jboss.shamrock.annotations.BuildProducer;
import org.jboss.shamrock.annotations.BuildStep;
import org.jboss.shamrock.deployment.builditem.substrate.ReflectiveClassBuildItem;
import org.jboss.shamrock.deployment.builditem.substrate.SubstrateConfigBuildItem;

class VertxProcessor {

    @Inject
    BuildProducer<ReflectiveClassBuildItem> reflectiveClass;

    @BuildStep
    SubstrateConfigBuildItem build() throws Exception {


        // This one may not be required after Vert.x 3.6.0 lands
        reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, "io.netty.channel.socket.nio.NioSocketChannel"));

        return SubstrateConfigBuildItem.builder()
                .addNativeImageSystemProperty("io.netty.noUnsafe", "true")
                .addRuntimeInitializedClass("io.netty.handler.codec.http.HttpObjectEncoder")
                .addRuntimeInitializedClass("io.netty.handler.codec.http2.Http2CodecUtil")
                .addRuntimeInitializedClass("io.netty.handler.codec.http2.DefaultHttp2FrameWriter")
                .addRuntimeInitializedClass("io.netty.handler.codec.http.websocketx.WebSocket00FrameEncoder")
                .build();
    }

}

@@ -655,16 +655,78 @@
 nject;%0A%0A
+import org.eclipse.microprofile.config.inject.ConfigProperty;%0A
 import o
@@ -849,146 +849,588 @@
 ock.
-deployment.builditem.substrate.ReflectiveClassBuildItem;%0Aimport org.jboss.shamrock.deployment.builditem.substrate.SubstrateConfigBuildItem
+annotations.ExecutionTime;%0Aimport org.jboss.shamrock.annotations.Record;%0Aimport org.jboss.shamrock.deployment.builditem.AdditionalBeanBuildItem;%0Aimport org.jboss.shamrock.deployment.builditem.substrate.ReflectiveClassBuildItem;%0Aimport org.jboss.shamrock.deployment.builditem.substrate.SubstrateConfigBuildItem;%0Aimport org.jboss.shamrock.deployment.cdi.BeanContainerListenerBuildItem;%0Aimport org.jboss.shamrock.vertx.runtime.VertxConfiguration;%0Aimport org.jboss.shamrock.vertx.runtime.VertxProducer;%0Aimport org.jboss.shamrock.vertx.runtime.VertxTemplate;%0A%0Aimport java.util.Optional
 ;%0A%0Ac
@@ -1582,28 +1582,9 @@
 d() 
-throws Exception %7B%0A%0A
+%7B
 %0A   
@@ -2323,10 +2323,649 @@
 %0A    %7D%0A%0A
+%0A    /**%0A     * The Vert.x configuration, if set.%0A     */%0A    @ConfigProperty(name = %22shamrock.vertx%22)%0A    Optional%3CVertxConfiguration%3E vertxConfig;%0A%0A    @BuildStep%0A    AdditionalBeanBuildItem registerBean() %7B%0A        return new AdditionalBeanBuildItem(VertxProducer.class);%0A    %7D%0A%0A    @BuildStep%0A    @Record(ExecutionTime.STATIC_INIT)%0A    BeanContainerListenerBuildItem build(VertxTemplate template) %7B%0A        return vertxConfig%0A                .map(conf -%3E new BeanContainerListenerBuildItem(template.configureVertx(conf)))%0A                .orElseGet(() -%3E new BeanContainerListenerBuildItem(template.configureVertx(null)));%0A    %7D%0A%0A%0A%0A%0A%0A%0A
 %7D%0A

Add the configuration processing and the bean registration.