Search in sources :

Example 1 with BuildSystemTargetBuildItem

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

the class JarResultBuildStep method outputTarget.

@BuildStep
OutputTargetBuildItem outputTarget(BuildSystemTargetBuildItem bst, PackageConfig packageConfig) {
    String name = packageConfig.outputName.orElseGet(bst::getBaseName);
    Path path = packageConfig.outputDirectory.map(s -> bst.getOutputDirectory().resolve(s)).orElseGet(bst::getOutputDirectory);
    Optional<Set<ArtifactKey>> includedOptionalDependencies;
    if (packageConfig.filterOptionalDependencies) {
        includedOptionalDependencies = Optional.of(packageConfig.includedOptionalDependencies.map(set -> set.stream().map(s -> (ArtifactKey) GACT.fromString(s)).collect(Collectors.toSet())).orElse(Collections.emptySet()));
    } else {
        includedOptionalDependencies = Optional.empty();
    }
    return new OutputTargetBuildItem(path, name, bst.isRebuild(), bst.getBuildSystemProps(), includedOptionalDependencies);
}
Also used : Path(java.nio.file.Path) Manifest(java.util.jar.Manifest) TransformedClassesBuildItem(io.quarkus.deployment.builditem.TransformedClassesBuildItem) Arrays(java.util.Arrays) BufferedInputStream(java.io.BufferedInputStream) Enumeration(java.util.Enumeration) URL(java.net.URL) UberJarIgnoredResourceBuildItem(io.quarkus.deployment.pkg.builditem.UberJarIgnoredResourceBuildItem) BooleanSupplier(java.util.function.BooleanSupplier) QuarkusBuildCloseablesBuildItem(io.quarkus.deployment.builditem.QuarkusBuildCloseablesBuildItem) Map(java.util.Map) ZipFile(java.util.zip.ZipFile) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) EnumSet(java.util.EnumSet) PathVisit(io.quarkus.paths.PathVisit) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) ZipUtils(io.quarkus.fs.util.ZipUtils) Predicate(java.util.function.Predicate) JarBuildItem(io.quarkus.deployment.pkg.builditem.JarBuildItem) Collection(java.util.Collection) StandardOpenOption(java.nio.file.StandardOpenOption) MutableJarApplicationModel(io.quarkus.bootstrap.model.MutableJarApplicationModel) SerializedApplication(io.quarkus.bootstrap.runner.SerializedApplication) Set(java.util.Set) PathVisitor(io.quarkus.paths.PathVisitor) FileSystem(java.nio.file.FileSystem) Attributes(java.util.jar.Attributes) Collectors(java.util.stream.Collectors) AdditionalApplicationArchiveBuildItem(io.quarkus.deployment.builditem.AdditionalApplicationArchiveBuildItem) StandardCharsets(java.nio.charset.StandardCharsets) PackageConfig(io.quarkus.deployment.pkg.PackageConfig) UncheckedIOException(java.io.UncheckedIOException) FileUtil(io.quarkus.deployment.util.FileUtil) FileVisitResult(java.nio.file.FileVisitResult) LegacyJarRequiredBuildItem(io.quarkus.deployment.pkg.builditem.LegacyJarRequiredBuildItem) NativeImageSourceJarBuildItem(io.quarkus.deployment.pkg.builditem.NativeImageSourceJarBuildItem) List(java.util.List) Stream(java.util.stream.Stream) GACT(io.quarkus.maven.dependency.GACT) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) Optional(java.util.Optional) GeneratedNativeImageClassBuildItem(io.quarkus.deployment.builditem.GeneratedNativeImageClassBuildItem) ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) QuarkusEntryPoint(io.quarkus.bootstrap.runner.QuarkusEntryPoint) Logger(org.jboss.logging.Logger) HashMap(java.util.HashMap) CurateOutcomeBuildItem(io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BiPredicate(java.util.function.BiPredicate) BuildStep(io.quarkus.deployment.annotations.BuildStep) IoUtils(io.quarkus.bootstrap.util.IoUtils) ArtifactKey(io.quarkus.maven.dependency.ArtifactKey) ClassLoadingConfig(io.quarkus.deployment.configuration.ClassLoadingConfig) Dependency(io.quarkus.maven.dependency.Dependency) ObjectOutputStream(java.io.ObjectOutputStream) BuildSystemTargetBuildItem(io.quarkus.deployment.pkg.builditem.BuildSystemTargetBuildItem) OutputStream(java.io.OutputStream) GeneratedResourceBuildItem(io.quarkus.deployment.builditem.GeneratedResourceBuildItem) ApplicationArchivesBuildItem(io.quarkus.deployment.builditem.ApplicationArchivesBuildItem) UberJarRequiredBuildItem(io.quarkus.deployment.pkg.builditem.UberJarRequiredBuildItem) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) SystemUtils(org.apache.commons.lang3.SystemUtils) FileOutputStream(java.io.FileOutputStream) ArtifactResultBuildItem(io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Consumer(java.util.function.Consumer) ApplicationArchive(io.quarkus.deployment.ApplicationArchive) GeneratedClassBuildItem(io.quarkus.deployment.builditem.GeneratedClassBuildItem) FileVisitOption(java.nio.file.FileVisitOption) Paths(java.nio.file.Paths) OutputTargetBuildItem(io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem) ZipUtils.wrapForJDK8232879(io.quarkus.fs.util.ZipUtils.wrapForJDK8232879) ApplicationInfoBuildItem(io.quarkus.deployment.builditem.ApplicationInfoBuildItem) AppCDSRequestedBuildItem(io.quarkus.deployment.pkg.builditem.AppCDSRequestedBuildItem) UberJarMergedResourceBuildItem(io.quarkus.deployment.pkg.builditem.UberJarMergedResourceBuildItem) Comparator(java.util.Comparator) Collections(java.util.Collections) MainClassBuildItem(io.quarkus.deployment.builditem.MainClassBuildItem) InputStream(java.io.InputStream) EnumSet(java.util.EnumSet) Set(java.util.Set) HashSet(java.util.HashSet) ArtifactKey(io.quarkus.maven.dependency.ArtifactKey) OutputTargetBuildItem(io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 2 with BuildSystemTargetBuildItem

use of io.quarkus.deployment.pkg.builditem.BuildSystemTargetBuildItem 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 3 with BuildSystemTargetBuildItem

use of io.quarkus.deployment.pkg.builditem.BuildSystemTargetBuildItem 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

BuildSystemTargetBuildItem (io.quarkus.deployment.pkg.builditem.BuildSystemTargetBuildItem)3 QuarkusClassLoader (io.quarkus.bootstrap.classloading.QuarkusClassLoader)2 BuildResult (io.quarkus.builder.BuildResult)2 AdditionalApplicationArchiveBuildItem (io.quarkus.deployment.builditem.AdditionalApplicationArchiveBuildItem)2 QuarkusBuildCloseablesBuildItem (io.quarkus.deployment.builditem.QuarkusBuildCloseablesBuildItem)2 ArtifactResultBuildItem (io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem)2 JarBuildItem (io.quarkus.deployment.pkg.builditem.JarBuildItem)2 ArtifactResult (io.quarkus.bootstrap.app.ArtifactResult)1 AugmentResult (io.quarkus.bootstrap.app.AugmentResult)1 MutableJarApplicationModel (io.quarkus.bootstrap.model.MutableJarApplicationModel)1 QuarkusEntryPoint (io.quarkus.bootstrap.runner.QuarkusEntryPoint)1 SerializedApplication (io.quarkus.bootstrap.runner.SerializedApplication)1 IoUtils (io.quarkus.bootstrap.util.IoUtils)1 BuildChain (io.quarkus.builder.BuildChain)1 BuildChainBuilder (io.quarkus.builder.BuildChainBuilder)1 BuildExecutionBuilder (io.quarkus.builder.BuildExecutionBuilder)1 ApplicationArchive (io.quarkus.deployment.ApplicationArchive)1 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 AppModelProviderBuildItem (io.quarkus.deployment.builditem.AppModelProviderBuildItem)1 ApplicationArchivesBuildItem (io.quarkus.deployment.builditem.ApplicationArchivesBuildItem)1