Search in sources :

Example 1 with BuildResult

use of io.quarkus.builder.BuildResult in project quarkus by quarkusio.

the class AugmentActionImpl method createProductionApplication.

@Override
public AugmentResult createProductionApplication() {
    if (launchMode != LaunchMode.NORMAL) {
        throw new IllegalStateException("Can only create a production application when using NORMAL launch mode");
    }
    ClassLoader classLoader = curatedApplication.createDeploymentClassLoader();
    BuildResult result = runAugment(true, Collections.emptySet(), null, classLoader, ArtifactResultBuildItem.class, DeploymentResultBuildItem.class);
    writeDebugSourceFile(result);
    JarBuildItem jarBuildItem = result.consumeOptional(JarBuildItem.class);
    NativeImageBuildItem nativeImageBuildItem = result.consumeOptional(NativeImageBuildItem.class);
    List<ArtifactResultBuildItem> artifactResultBuildItems = result.consumeMulti(ArtifactResultBuildItem.class);
    BuildSystemTargetBuildItem buildSystemTargetBuildItem = result.consume(BuildSystemTargetBuildItem.class);
    // this depends on the fact that the order in which we can obtain MultiBuildItems is the same as they are produced
    // we want to write result of the final artifact created
    ArtifactResultBuildItem lastResult = artifactResultBuildItems.get(artifactResultBuildItems.size() - 1);
    writeArtifactResultMetadataFile(buildSystemTargetBuildItem, lastResult);
    return new AugmentResult(artifactResultBuildItems.stream().map(a -> new ArtifactResult(a.getPath(), a.getType(), a.getMetadata())).collect(Collectors.toList()), jarBuildItem != null ? jarBuildItem.toJarResult() : null, nativeImageBuildItem != null ? nativeImageBuildItem.getPath() : null);
}
Also used : BuildResult(io.quarkus.builder.BuildResult) JarBuildItem(io.quarkus.deployment.pkg.builditem.JarBuildItem) QuarkusClassLoader(io.quarkus.bootstrap.classloading.QuarkusClassLoader) ArtifactResultBuildItem(io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem) BuildSystemTargetBuildItem(io.quarkus.deployment.pkg.builditem.BuildSystemTargetBuildItem) AugmentResult(io.quarkus.bootstrap.app.AugmentResult) NativeImageBuildItem(io.quarkus.deployment.pkg.builditem.NativeImageBuildItem) ArtifactResult(io.quarkus.bootstrap.app.ArtifactResult)

Example 2 with BuildResult

use of io.quarkus.builder.BuildResult 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)

Example 3 with BuildResult

use of io.quarkus.builder.BuildResult in project quarkus by quarkusio.

the class AugmentActionImpl method reloadExistingApplication.

@Override
public StartupActionImpl reloadExistingApplication(boolean hasStartedSuccessfully, Set<String> changedResources, ClassChangeInformation classChangeInformation) {
    if (launchMode != LaunchMode.DEVELOPMENT) {
        throw new IllegalStateException("Only application with launch mode DEVELOPMENT can restart");
    }
    ClassLoader classLoader = curatedApplication.createDeploymentClassLoader();
    @SuppressWarnings("unchecked") BuildResult result = runAugment(!hasStartedSuccessfully, changedResources, classChangeInformation, classLoader, NON_NORMAL_MODE_OUTPUTS);
    return new StartupActionImpl(curatedApplication, result);
}
Also used : BuildResult(io.quarkus.builder.BuildResult) QuarkusClassLoader(io.quarkus.bootstrap.classloading.QuarkusClassLoader)

Example 4 with BuildResult

use of io.quarkus.builder.BuildResult in project quarkus by quarkusio.

the class AugmentActionImpl method createInitialRuntimeApplication.

@Override
public StartupActionImpl createInitialRuntimeApplication() {
    if (launchMode == LaunchMode.NORMAL) {
        throw new IllegalStateException("Cannot launch a runtime application with NORMAL launch mode");
    }
    ClassLoader classLoader = curatedApplication.createDeploymentClassLoader();
    @SuppressWarnings("unchecked") BuildResult result = runAugment(true, Collections.emptySet(), null, classLoader, NON_NORMAL_MODE_OUTPUTS);
    return new StartupActionImpl(curatedApplication, result);
}
Also used : BuildResult(io.quarkus.builder.BuildResult) QuarkusClassLoader(io.quarkus.bootstrap.classloading.QuarkusClassLoader)

Example 5 with BuildResult

use of io.quarkus.builder.BuildResult in project quarkus by quarkusio.

the class AugmentActionImpl method performCustomBuild.

@Override
public void performCustomBuild(String resultHandler, Object context, String... finalOutputs) {
    ClassLoader classLoader = curatedApplication.createDeploymentClassLoader();
    Class<? extends BuildItem>[] targets = Arrays.stream(finalOutputs).map(new Function<String, Class<? extends BuildItem>>() {

        @Override
        public Class<? extends BuildItem> apply(String s) {
            try {
                return (Class<? extends BuildItem>) Class.forName(s, false, classLoader);
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
        }
    }).toArray(Class[]::new);
    BuildResult result = runAugment(true, Collections.emptySet(), null, classLoader, targets);
    writeDebugSourceFile(result);
    try {
        BiConsumer<Object, BuildResult> consumer = (BiConsumer<Object, BuildResult>) Class.forName(resultHandler, false, classLoader).getConstructor().newInstance();
        consumer.accept(context, result);
    } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | ClassNotFoundException | InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}
Also used : TransformedClassesBuildItem(io.quarkus.deployment.builditem.TransformedClassesBuildItem) NativeImageBuildItem(io.quarkus.deployment.pkg.builditem.NativeImageBuildItem) ApplicationClassNameBuildItem(io.quarkus.deployment.builditem.ApplicationClassNameBuildItem) JarBuildItem(io.quarkus.deployment.pkg.builditem.JarBuildItem) BuildItem(io.quarkus.builder.item.BuildItem) BuildSystemTargetBuildItem(io.quarkus.deployment.pkg.builditem.BuildSystemTargetBuildItem) DeploymentResultBuildItem(io.quarkus.deployment.pkg.builditem.DeploymentResultBuildItem) GeneratedResourceBuildItem(io.quarkus.deployment.builditem.GeneratedResourceBuildItem) ArtifactResultBuildItem(io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem) GeneratedFileSystemResourceHandledBuildItem(io.quarkus.deployment.builditem.GeneratedFileSystemResourceHandledBuildItem) GeneratedClassBuildItem(io.quarkus.deployment.builditem.GeneratedClassBuildItem) LiveReloadBuildItem(io.quarkus.deployment.builditem.LiveReloadBuildItem) MainClassBuildItem(io.quarkus.deployment.builditem.MainClassBuildItem) InvocationTargetException(java.lang.reflect.InvocationTargetException) Function(java.util.function.Function) BuildResult(io.quarkus.builder.BuildResult) QuarkusClassLoader(io.quarkus.bootstrap.classloading.QuarkusClassLoader) BiConsumer(java.util.function.BiConsumer)

Aggregations

QuarkusClassLoader (io.quarkus.bootstrap.classloading.QuarkusClassLoader)6 BuildResult (io.quarkus.builder.BuildResult)6 ArtifactResultBuildItem (io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem)3 BuildSystemTargetBuildItem (io.quarkus.deployment.pkg.builditem.BuildSystemTargetBuildItem)3 NativeImageBuildItem (io.quarkus.deployment.pkg.builditem.NativeImageBuildItem)3 BuildChainBuilder (io.quarkus.builder.BuildChainBuilder)2 ApplicationClassNameBuildItem (io.quarkus.deployment.builditem.ApplicationClassNameBuildItem)2 GeneratedClassBuildItem (io.quarkus.deployment.builditem.GeneratedClassBuildItem)2 GeneratedResourceBuildItem (io.quarkus.deployment.builditem.GeneratedResourceBuildItem)2 LiveReloadBuildItem (io.quarkus.deployment.builditem.LiveReloadBuildItem)2 MainClassBuildItem (io.quarkus.deployment.builditem.MainClassBuildItem)2 TransformedClassesBuildItem (io.quarkus.deployment.builditem.TransformedClassesBuildItem)2 DeploymentResultBuildItem (io.quarkus.deployment.pkg.builditem.DeploymentResultBuildItem)2 JarBuildItem (io.quarkus.deployment.pkg.builditem.JarBuildItem)2 BiConsumer (java.util.function.BiConsumer)2 AdditionalDependency (io.quarkus.bootstrap.app.AdditionalDependency)1 ArtifactResult (io.quarkus.bootstrap.app.ArtifactResult)1 AugmentResult (io.quarkus.bootstrap.app.AugmentResult)1 CuratedApplication (io.quarkus.bootstrap.app.CuratedApplication)1 QuarkusBootstrap (io.quarkus.bootstrap.app.QuarkusBootstrap)1