Search in sources :

Example 1 with QuarkusBuildCloseablesBuildItem

use of io.quarkus.deployment.builditem.QuarkusBuildCloseablesBuildItem in project quarkus by quarkusio.

the class QuarkusAugmentor method run.

public BuildResult run() throws Exception {
    if (!JavaVersionUtil.isJava11OrHigher()) {
        throw new IllegalStateException("Quarkus applications require Java 11 or higher to build");
    }
    long time = System.currentTimeMillis();
    log.debug("Beginning Quarkus augmentation");
    ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
    QuarkusBuildCloseablesBuildItem buildCloseables = new QuarkusBuildCloseablesBuildItem();
    try {
        Thread.currentThread().setContextClassLoader(deploymentClassLoader);
        final BuildChainBuilder chainBuilder = BuildChain.builder();
        chainBuilder.setClassLoader(deploymentClassLoader);
        // provideCapabilities(chainBuilder);
        // TODO: we load everything from the deployment class loader
        // this allows the deployment config (application.properties) to be loaded, but in theory could result
        // in additional stuff from the deployment leaking in, this is unlikely but has a bit of a smell.
        ExtensionLoader.loadStepsFrom(deploymentClassLoader, buildSystemProperties == null ? new Properties() : buildSystemProperties, effectiveModel, launchMode, devModeType).accept(chainBuilder);
        Thread.currentThread().setContextClassLoader(classLoader);
        chainBuilder.loadProviders(classLoader);
        chainBuilder.addInitial(QuarkusBuildCloseablesBuildItem.class).addInitial(ArchiveRootBuildItem.class).addInitial(ShutdownContextBuildItem.class).addInitial(RawCommandLineArgumentsBuildItem.class).addInitial(LaunchModeBuildItem.class).addInitial(LiveReloadBuildItem.class).addInitial(AdditionalApplicationArchiveBuildItem.class).addInitial(CuratedApplicationShutdownBuildItem.class).addInitial(BuildSystemTargetBuildItem.class).addInitial(AppModelProviderBuildItem.class);
        for (Class<? extends BuildItem> i : finalResults) {
            chainBuilder.addFinal(i);
        }
        for (Consumer<BuildChainBuilder> i : buildChainCustomizers) {
            i.accept(chainBuilder);
        }
        if (launchMode.isDevOrTest()) {
            chainBuilder.addFinal(RuntimeApplicationShutdownBuildItem.class);
        }
        final ArchiveRootBuildItem.Builder rootBuilder = ArchiveRootBuildItem.builder();
        if (root != null) {
            rootBuilder.addArchiveRoots(root);
        }
        rootBuilder.setExcludedFromIndexing(excludedFromIndexing);
        BuildChain chain = chainBuilder.build();
        BuildExecutionBuilder execBuilder = chain.createExecutionBuilder("main").produce(buildCloseables).produce(liveReloadBuildItem).produce(rootBuilder.build(buildCloseables)).produce(new ShutdownContextBuildItem()).produce(new RawCommandLineArgumentsBuildItem()).produce(new CuratedApplicationShutdownBuildItem((QuarkusClassLoader) deploymentClassLoader.getParent(), !liveReloadBuildItem.isLiveReload())).produce(new LaunchModeBuildItem(launchMode, devModeType == null ? Optional.empty() : Optional.of(devModeType), auxiliaryApplication, auxiliaryDevModeType, test)).produce(new BuildSystemTargetBuildItem(targetDir, baseName, rebuild, buildSystemProperties == null ? new Properties() : buildSystemProperties)).produce(new AppModelProviderBuildItem(effectiveModel));
        for (PathCollection i : additionalApplicationArchives) {
            execBuilder.produce(new AdditionalApplicationArchiveBuildItem(i));
        }
        BuildResult buildResult = execBuilder.execute();
        String message = "Quarkus augmentation completed in " + (System.currentTimeMillis() - time) + "ms";
        if (launchMode == LaunchMode.NORMAL) {
            log.info(message);
        } else {
            // test and dev mode already report the total startup time, no need to add noise to the logs
            log.debug(message);
        }
        return buildResult;
    } finally {
        try {
            ConfigProviderResolver.instance().releaseConfig(ConfigProviderResolver.instance().getConfig(deploymentClassLoader));
        } catch (Exception ignore) {
        }
        if (deploymentClassLoader instanceof Closeable) {
            ((Closeable) deploymentClassLoader).close();
        }
        Thread.currentThread().setContextClassLoader(originalClassLoader);
        buildCloseables.close();
    }
}
Also used : PathCollection(io.quarkus.paths.PathCollection) LaunchModeBuildItem(io.quarkus.deployment.builditem.LaunchModeBuildItem) BuildChain(io.quarkus.builder.BuildChain) Closeable(java.io.Closeable) ArchiveRootBuildItem(io.quarkus.deployment.builditem.ArchiveRootBuildItem) Properties(java.util.Properties) QuarkusBuildCloseablesBuildItem(io.quarkus.deployment.builditem.QuarkusBuildCloseablesBuildItem) BuildExecutionBuilder(io.quarkus.builder.BuildExecutionBuilder) AdditionalApplicationArchiveBuildItem(io.quarkus.deployment.builditem.AdditionalApplicationArchiveBuildItem) CuratedApplicationShutdownBuildItem(io.quarkus.deployment.builditem.CuratedApplicationShutdownBuildItem) BuildResult(io.quarkus.builder.BuildResult) RawCommandLineArgumentsBuildItem(io.quarkus.deployment.builditem.RawCommandLineArgumentsBuildItem) BuildChainBuilder(io.quarkus.builder.BuildChainBuilder) QuarkusClassLoader(io.quarkus.bootstrap.classloading.QuarkusClassLoader) BuildSystemTargetBuildItem(io.quarkus.deployment.pkg.builditem.BuildSystemTargetBuildItem) AppModelProviderBuildItem(io.quarkus.deployment.builditem.AppModelProviderBuildItem) ShutdownContextBuildItem(io.quarkus.deployment.builditem.ShutdownContextBuildItem)

Aggregations

QuarkusClassLoader (io.quarkus.bootstrap.classloading.QuarkusClassLoader)1 BuildChain (io.quarkus.builder.BuildChain)1 BuildChainBuilder (io.quarkus.builder.BuildChainBuilder)1 BuildExecutionBuilder (io.quarkus.builder.BuildExecutionBuilder)1 BuildResult (io.quarkus.builder.BuildResult)1 AdditionalApplicationArchiveBuildItem (io.quarkus.deployment.builditem.AdditionalApplicationArchiveBuildItem)1 AppModelProviderBuildItem (io.quarkus.deployment.builditem.AppModelProviderBuildItem)1 ArchiveRootBuildItem (io.quarkus.deployment.builditem.ArchiveRootBuildItem)1 CuratedApplicationShutdownBuildItem (io.quarkus.deployment.builditem.CuratedApplicationShutdownBuildItem)1 LaunchModeBuildItem (io.quarkus.deployment.builditem.LaunchModeBuildItem)1 QuarkusBuildCloseablesBuildItem (io.quarkus.deployment.builditem.QuarkusBuildCloseablesBuildItem)1 RawCommandLineArgumentsBuildItem (io.quarkus.deployment.builditem.RawCommandLineArgumentsBuildItem)1 ShutdownContextBuildItem (io.quarkus.deployment.builditem.ShutdownContextBuildItem)1 BuildSystemTargetBuildItem (io.quarkus.deployment.pkg.builditem.BuildSystemTargetBuildItem)1 PathCollection (io.quarkus.paths.PathCollection)1 Closeable (java.io.Closeable)1 Properties (java.util.Properties)1