Search in sources :

Example 1 with Assemble

use of org.jreleaser.model.Assemble in project jreleaser by jreleaser.

the class AssemblersValidator method validateAssemblers.

public static void validateAssemblers(JReleaserContext context, JReleaserContext.Mode mode, Errors errors) {
    if (mode == JReleaserContext.Mode.CHANGELOG) {
        return;
    }
    context.getLogger().debug("assemble");
    Assemble assemble = context.getModel().getAssemble();
    validateArchive(context, mode, errors);
    validateJlink(context, mode, errors);
    validateJpackage(context, mode, errors);
    validateNativeImage(context, mode, errors);
    // validate unique distribution names between exported assemblers
    Map<String, List<String>> byDistributionName = new LinkedHashMap<>();
    for (Archive archive : assemble.getActiveArchives()) {
        List<String> types = byDistributionName.computeIfAbsent(archive.getName(), k -> new ArrayList<>());
        types.add(archive.getType());
    }
    for (Jlink jlink : assemble.getActiveJlinks()) {
        List<String> types = byDistributionName.computeIfAbsent(jlink.getName(), k -> new ArrayList<>());
        if (jlink.isExported())
            types.add(jlink.getType());
    }
    for (Jpackage jpackage : assemble.getActiveJpackages()) {
        List<String> types = byDistributionName.computeIfAbsent(jpackage.getName(), k -> new ArrayList<>());
        if (jpackage.isExported())
            types.add(jpackage.getType());
    }
    for (NativeImage nativeImage : assemble.getActiveNativeImages()) {
        List<String> types = byDistributionName.computeIfAbsent(nativeImage.getName(), k -> new ArrayList<>());
        if (nativeImage.isExported())
            types.add(nativeImage.getType());
    }
    byDistributionName.forEach((name, types) -> {
        if (types.size() > 1) {
            errors.configuration(RB.$("validation_multiple_assemblers", "distribution." + name, types));
            assemble.setEnabled(false);
        }
    });
    if (!assemble.isEnabledSet()) {
        assemble.setEnabled(!assemble.getActiveArchives().isEmpty() || !assemble.getActiveJlinks().isEmpty() || !assemble.getActiveJpackages().isEmpty() || !assemble.getActiveNativeImages().isEmpty());
    }
}
Also used : JpackageValidator.validateJpackage(org.jreleaser.model.validation.JpackageValidator.validateJpackage) Jpackage(org.jreleaser.model.Jpackage) JpackageValidator.postValidateJpackage(org.jreleaser.model.validation.JpackageValidator.postValidateJpackage) Jlink(org.jreleaser.model.Jlink) JlinkValidator.validateJlink(org.jreleaser.model.validation.JlinkValidator.validateJlink) Archive(org.jreleaser.model.Archive) ArchiveValidator.validateArchive(org.jreleaser.model.validation.ArchiveValidator.validateArchive) NativeImageValidator.validateNativeImage(org.jreleaser.model.validation.NativeImageValidator.validateNativeImage) NativeImage(org.jreleaser.model.NativeImage) Assemble(org.jreleaser.model.Assemble) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with Assemble

use of org.jreleaser.model.Assemble in project jreleaser by jreleaser.

the class Assemblers method assemble.

public static void assemble(JReleaserContext context) {
    Assemble assemble = context.getModel().getAssemble();
    if (!assemble.isEnabled()) {
        context.getLogger().info(RB.$("assemblers.not.enabled"));
        return;
    }
    if (!context.getIncludedAssemblers().isEmpty()) {
        for (String assemblerType : context.getIncludedAssemblers()) {
            // check if the assemblerType is valid
            if (!Assemble.supportedAssemblers().contains(assemblerType)) {
                context.getLogger().warn(RB.$("ERROR_unsupported_assembler", assemblerType));
                continue;
            }
            Map<String, Assembler> assemblers = assemble.findAssemblersByType(assemblerType);
            if (assemblers.isEmpty()) {
                context.getLogger().debug(RB.$("assemblers.no.match"), assemblerType);
                return;
            }
            if (!context.getIncludedDistributions().isEmpty()) {
                for (String distributionName : context.getIncludedDistributions()) {
                    if (!assemblers.containsKey(distributionName)) {
                        context.getLogger().error(RB.$("assemblers.distribution.not.configured"), assemblerType, distributionName);
                        continue;
                    }
                    assemble.findAllAssemblers().stream().filter(a -> distributionName.equals(a.getName())).peek(assembler -> context.getLogger().info(RB.$("assemblers.assemble.distribution.with"), distributionName, assembler.getName())).forEach(assembler -> assemble(context, assembler));
                }
            } else {
                context.getLogger().info(RB.$("assemblers.assemble.all.distributions.with"), assemblerType);
                assemblers.values().forEach(assembler -> assemble(context, assembler));
            }
        }
    } else if (!context.getIncludedDistributions().isEmpty()) {
        for (String distributionName : context.getIncludedDistributions()) {
            context.getLogger().info(RB.$("assemblers.assemble.distribution.with.all"), distributionName);
            assemble.findAllAssemblers().stream().filter(a -> distributionName.equals(a.getName())).forEach(assembler -> assemble(context, assembler));
        }
    } else {
        context.getLogger().info(RB.$("assemblers.assemble.all.distributions"));
        for (Assembler assembler : assemble.findAllAssemblers()) {
            String assemblerType = assembler.getType();
            String distributionName = assembler.getName();
            if (context.getExcludedAssemblers().contains(assemblerType) || context.getExcludedDistributions().contains(distributionName)) {
                context.getLogger().info(RB.$("assemblers.assembler.excluded"), assemblerType, distributionName);
                continue;
            }
            assemble(context, assembler);
        }
    }
}
Also used : Map(java.util.Map) JReleaserContext(org.jreleaser.model.JReleaserContext) JReleaserException(org.jreleaser.util.JReleaserException) Assembler(org.jreleaser.model.Assembler) RB(org.jreleaser.bundle.RB) AssemblerProcessingException(org.jreleaser.model.assembler.spi.AssemblerProcessingException) Assemble(org.jreleaser.model.Assemble) Assemble(org.jreleaser.model.Assemble) Assembler(org.jreleaser.model.Assembler)

Aggregations

Assemble (org.jreleaser.model.Assemble)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 RB (org.jreleaser.bundle.RB)1 Archive (org.jreleaser.model.Archive)1 Assembler (org.jreleaser.model.Assembler)1 JReleaserContext (org.jreleaser.model.JReleaserContext)1 Jlink (org.jreleaser.model.Jlink)1 Jpackage (org.jreleaser.model.Jpackage)1 NativeImage (org.jreleaser.model.NativeImage)1 AssemblerProcessingException (org.jreleaser.model.assembler.spi.AssemblerProcessingException)1 ArchiveValidator.validateArchive (org.jreleaser.model.validation.ArchiveValidator.validateArchive)1 JlinkValidator.validateJlink (org.jreleaser.model.validation.JlinkValidator.validateJlink)1 JpackageValidator.postValidateJpackage (org.jreleaser.model.validation.JpackageValidator.postValidateJpackage)1 JpackageValidator.validateJpackage (org.jreleaser.model.validation.JpackageValidator.validateJpackage)1 NativeImageValidator.validateNativeImage (org.jreleaser.model.validation.NativeImageValidator.validateNativeImage)1 JReleaserException (org.jreleaser.util.JReleaserException)1