Search in sources :

Example 1 with AppCDSResultBuildItem

use of io.quarkus.deployment.pkg.builditem.AppCDSResultBuildItem in project quarkus by quarkusio.

the class AppCDSBuildStep method build.

@BuildStep
public void build(Optional<AppCDSRequestedBuildItem> appCDsRequested, JarBuildItem jarResult, OutputTargetBuildItem outputTarget, PackageConfig packageConfig, Optional<AppCDSContainerImageBuildItem> appCDSContainerImage, BuildProducer<AppCDSResultBuildItem> appCDS, BuildProducer<ArtifactResultBuildItem> artifactResult) throws Exception {
    if (!appCDsRequested.isPresent()) {
        return;
    }
    // to actually execute the commands needed to generate the AppCDS file, either the JVM in the container image will be used
    // (if specified), or the JVM running the build
    String containerImage = determineContainerImage(packageConfig, appCDSContainerImage);
    String javaBinPath = null;
    if (containerImage == null) {
        javaBinPath = System.getProperty("java.home") + File.separator + "bin" + File.separator + JavaBinFinder.simpleBinaryName();
        if (!new File(javaBinPath).canExecute()) {
            log.warnf("In order to create AppCDS the JDK used to build the Quarkus application must contain an executable named '%s' in its 'bin' directory.", javaBinPath);
            return;
        }
    }
    Path classesLstPath = createClassesLst(jarResult, outputTarget, javaBinPath, containerImage, appCDsRequested.get().getAppCDSDir(), packageConfig.isFastJar());
    if (classesLstPath == null) {
        return;
    }
    log.debugf("'%s' successfully created.", CLASSES_LIST_FILE_NAME);
    log.info("Launching AppCDS creation process.");
    Path appCDSPath = createAppCDS(jarResult, outputTarget, javaBinPath, containerImage, classesLstPath, packageConfig.isFastJar());
    if (appCDSPath == null) {
        log.warn("Unable to create AppCDS.");
        return;
    }
    log.infof("AppCDS successfully created at: '%s'.", appCDSPath.toAbsolutePath().toString());
    if (containerImage == null) {
        log.infof("To ensure they are loaded properly, " + "run the application jar from its directory and also add the '-XX:SharedArchiveFile=app-cds.jsa' " + "JVM flag.\nMoreover, make sure to use the exact same Java version (%s) to run the application as was used to build it.", System.getProperty("java.version"));
    }
    appCDS.produce(new AppCDSResultBuildItem(appCDSPath));
    artifactResult.produce(new ArtifactResultBuildItem(appCDSPath, "appCDS", Collections.emptyMap()));
}
Also used : Path(java.nio.file.Path) AppCDSResultBuildItem(io.quarkus.deployment.pkg.builditem.AppCDSResultBuildItem) ArtifactResultBuildItem(io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem) File(java.io.File) BuildStep(io.quarkus.deployment.annotations.BuildStep) MainClassBuildStep(io.quarkus.deployment.steps.MainClassBuildStep)

Aggregations

BuildStep (io.quarkus.deployment.annotations.BuildStep)1 AppCDSResultBuildItem (io.quarkus.deployment.pkg.builditem.AppCDSResultBuildItem)1 ArtifactResultBuildItem (io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem)1 MainClassBuildStep (io.quarkus.deployment.steps.MainClassBuildStep)1 File (java.io.File)1 Path (java.nio.file.Path)1