Search in sources :

Example 1 with KEY_SKIP_RELEASE_SIGNATURES

use of org.jreleaser.model.GitService.KEY_SKIP_RELEASE_SIGNATURES in project jreleaser by jreleaser.

the class DistributionsValidator method validateDistribution.

private static void validateDistribution(JReleaserContext context, Distribution distribution, Errors errors) {
    context.getLogger().debug("distribution.{}", distribution.getName());
    if (!distribution.isActiveSet()) {
        distribution.setActive(Active.ALWAYS);
    }
    if (!distribution.resolveEnabled(context.getModel().getProject()))
        return;
    if (!selectArtifactsByPlatform(context, distribution)) {
        distribution.setActive(Active.NEVER);
        distribution.disable();
        return;
    }
    if (isBlank(distribution.getName())) {
        errors.configuration(RB.$("validation_must_not_be_blank", "distribution.name"));
        return;
    }
    if (null == distribution.getType()) {
        errors.configuration(RB.$("validation_must_not_be_null", "distribution." + distribution.getName() + ".type"));
        return;
    }
    if (isBlank(distribution.getExecutable().getName())) {
        distribution.getExecutable().setName(distribution.getName());
    }
    if (isBlank(distribution.getExecutable().getWindowsExtension())) {
        switch(distribution.getType()) {
            case BINARY:
            case NATIVE_IMAGE:
                distribution.getExecutable().setWindowsExtension("exe");
                break;
            default:
                distribution.getExecutable().setWindowsExtension("bat");
        }
    }
    if (Distribution.JAVA_DISTRIBUTION_TYPES.contains(distribution.getType())) {
        context.getLogger().debug("distribution.{}.java", distribution.getName());
        if (!validateJava(context, distribution, errors)) {
            return;
        }
    }
    // validate distribution type
    if (!distribution.getJava().isEnabled() && Distribution.JAVA_DISTRIBUTION_TYPES.contains(distribution.getType())) {
        errors.configuration(RB.$("validation_distributions_java", "distribution." + distribution.getName() + ".type", distribution.getType(), "distribution." + distribution.getName() + ".java", "project.java"));
        return;
    }
    if (null == distribution.getArtifacts() || distribution.getArtifacts().isEmpty()) {
        errors.configuration(RB.$("validation_is_empty", "distribution." + distribution.getName() + ".artifacts"));
        return;
    }
    List<String> tags = new ArrayList<>();
    tags.addAll(context.getModel().getProject().getTags());
    tags.addAll(distribution.getTags());
    distribution.setTags(tags);
    int i = 0;
    for (Artifact artifact : distribution.getArtifacts()) {
        if (artifact.isActive()) {
            validateArtifact(context, distribution, artifact, i++, errors);
            if (distribution.getExtraProperties().containsKey(KEY_SKIP_RELEASE_SIGNATURES) && !artifact.getExtraProperties().containsKey(KEY_SKIP_RELEASE_SIGNATURES)) {
                artifact.getExtraProperties().put(KEY_SKIP_RELEASE_SIGNATURES, distribution.getExtraProperties().get(KEY_SKIP_RELEASE_SIGNATURES));
            }
        }
    }
    // validate artifact.platform is unique
    Map<String, List<Artifact>> byPlatform = distribution.getArtifacts().stream().filter(Artifact::isActive).collect(groupingBy(artifact -> isBlank(artifact.getPlatform()) ? "<nil>" : artifact.getPlatform()));
    // check platforms by extension
    byPlatform.forEach((p, artifacts) -> {
        String platform = "<nil>".equals(p) ? "no" : p;
        artifacts.stream().collect(groupingBy(artifact -> FileType.getFileType(artifact.getPath()))).forEach((ext, matches) -> {
            if (matches.size() > 1) {
                errors.configuration(RB.$("validation_distributions_multiple", "distribution." + distribution.getName(), platform, ext));
            }
        });
    });
    validateBrew(context, distribution, distribution.getBrew(), errors);
    validateChocolatey(context, distribution, distribution.getChocolatey(), errors);
    validateDocker(context, distribution, distribution.getDocker(), errors);
    validateGofish(context, distribution, distribution.getGofish(), errors);
    validateJbang(context, distribution, distribution.getJbang(), errors);
    validateMacports(context, distribution, distribution.getMacports(), errors);
    validateScoop(context, distribution, distribution.getScoop(), errors);
    validateSdkman(context, distribution, distribution.getSdkman(), errors);
    validateSnap(context, distribution, distribution.getSnap(), errors);
    validateSpec(context, distribution, distribution.getSpec(), errors);
}
Also used : Artifact(org.jreleaser.model.Artifact) ChocolateyValidator.validateChocolatey(org.jreleaser.model.validation.ChocolateyValidator.validateChocolatey) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ScoopValidator.validateScoop(org.jreleaser.model.validation.ScoopValidator.validateScoop) StringUtils.isBlank(org.jreleaser.util.StringUtils.isBlank) StringUtils.isNotBlank(org.jreleaser.util.StringUtils.isNotBlank) ArrayList(java.util.ArrayList) Active(org.jreleaser.model.Active) JbangValidator.validateJbang(org.jreleaser.model.validation.JbangValidator.validateJbang) Errors(org.jreleaser.util.Errors) JbangValidator.postValidateJBang(org.jreleaser.model.validation.JbangValidator.postValidateJBang) Map(java.util.Map) JReleaserContext(org.jreleaser.model.JReleaserContext) BrewValidator.validateBrew(org.jreleaser.model.validation.BrewValidator.validateBrew) Distribution(org.jreleaser.model.Distribution) ChocolateyValidator.postValidateChocolatey(org.jreleaser.model.validation.ChocolateyValidator.postValidateChocolatey) FileType(org.jreleaser.util.FileType) BrewValidator.postValidateBrew(org.jreleaser.model.validation.BrewValidator.postValidateBrew) KEY_SKIP_RELEASE_SIGNATURES(org.jreleaser.model.GitService.KEY_SKIP_RELEASE_SIGNATURES) DockerValidator.validateDocker(org.jreleaser.model.validation.DockerValidator.validateDocker) Packager(org.jreleaser.model.Packager) PlatformUtils(org.jreleaser.util.PlatformUtils) Collectors(java.util.stream.Collectors) SdkmanValidator.postValidateSdkman(org.jreleaser.model.validation.SdkmanValidator.postValidateSdkman) Project(org.jreleaser.model.Project) List(java.util.List) GofishValidator.validateGofish(org.jreleaser.model.validation.GofishValidator.validateGofish) SdkmanValidator.validateSdkman(org.jreleaser.model.validation.SdkmanValidator.validateSdkman) MacportsValidator.validateMacports(org.jreleaser.model.validation.MacportsValidator.validateMacports) SpecValidator.validateSpec(org.jreleaser.model.validation.SpecValidator.validateSpec) RB(org.jreleaser.bundle.RB) SnapValidator.validateSnap(org.jreleaser.model.validation.SnapValidator.validateSnap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Artifact(org.jreleaser.model.Artifact)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Collectors (java.util.stream.Collectors)1 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)1 RB (org.jreleaser.bundle.RB)1 Active (org.jreleaser.model.Active)1 Artifact (org.jreleaser.model.Artifact)1 Distribution (org.jreleaser.model.Distribution)1 KEY_SKIP_RELEASE_SIGNATURES (org.jreleaser.model.GitService.KEY_SKIP_RELEASE_SIGNATURES)1 JReleaserContext (org.jreleaser.model.JReleaserContext)1 Packager (org.jreleaser.model.Packager)1 Project (org.jreleaser.model.Project)1 BrewValidator.postValidateBrew (org.jreleaser.model.validation.BrewValidator.postValidateBrew)1 BrewValidator.validateBrew (org.jreleaser.model.validation.BrewValidator.validateBrew)1 ChocolateyValidator.postValidateChocolatey (org.jreleaser.model.validation.ChocolateyValidator.postValidateChocolatey)1 ChocolateyValidator.validateChocolatey (org.jreleaser.model.validation.ChocolateyValidator.validateChocolatey)1 DockerValidator.validateDocker (org.jreleaser.model.validation.DockerValidator.validateDocker)1 GofishValidator.validateGofish (org.jreleaser.model.validation.GofishValidator.validateGofish)1