All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkiverse.web.bundler.qute.components.deployment.WebBundlerQuteComponentsProcessor Maven / Gradle / Ivy

The newest version!
package io.quarkiverse.web.bundler.qute.components.deployment;

import static io.quarkiverse.web.bundler.qute.components.runtime.WebBundlerQuteContextRecorder.WEB_BUNDLER_ID_PREFIX;
import static io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT;

import java.io.IOException;
import java.nio.file.Files;
import java.util.*;

import org.jboss.logging.Logger;

import io.quarkiverse.web.bundler.deployment.items.QuteTagsBuildItem;
import io.quarkiverse.web.bundler.deployment.items.WebAsset;
import io.quarkiverse.web.bundler.qute.components.runtime.WebBundlerQuteContextRecorder;
import io.quarkiverse.web.bundler.qute.components.runtime.WebBundlerQuteEngineObserver;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.Record;

class WebBundlerQuteComponentsProcessor {

    private static final Logger LOGGER = Logger.getLogger(WebBundlerQuteComponentsProcessor.class);

    @BuildStep
    @Record(STATIC_INIT)
    void initQuteTags(
            BuildProducer additionalBeans,
            BuildProducer syntheticBeans,
            WebBundlerQuteContextRecorder recorder,
            Optional quteTags) {
        if (quteTags.isEmpty()) {
            return;
        }
        final Map templates = new HashMap<>();
        final List tags = new ArrayList<>();
        for (WebAsset webAsset : quteTags.get().getWebAssets()) {
            final String tag = webAsset.resource().path().getFileName().toString();
            final String tagName = tag.contains(".") ? tag.substring(0, tag.indexOf('.')) : tag;
            try {
                templates.put(WEB_BUNDLER_ID_PREFIX + tagName,
                        Files.readString(webAsset.resource().path(), webAsset.charset()));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            tags.add(tagName);
        }
        additionalBeans.produce(new AdditionalBeanBuildItem(WebBundlerQuteEngineObserver.class));
        syntheticBeans.produce(SyntheticBeanBuildItem.configure(WebBundlerQuteContextRecorder.WebBundlerQuteContext.class)
                .supplier(recorder.createContext(tags, templates))
                .done());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy