Search in sources :

Example 11 with Errors

use of org.jreleaser.util.Errors in project jreleaser by jreleaser.

the class Validator method checkProperty.

static boolean checkProperty(JReleaserContext context, String key, String property, Boolean value, boolean defaultValue) {
    if (null != value)
        return value;
    Environment environment = context.getModel().getEnvironment();
    String dsl = context.getConfigurer().toString();
    String configFilePath = environment.getPropertiesFile().toAbsolutePath().normalize().toString();
    Errors errors = new Errors();
    String result = Env.check(key, environment.getVariable(key), property, dsl, configFilePath, errors);
    return !errors.hasErrors() ? Boolean.parseBoolean(result) : defaultValue;
}
Also used : Errors(org.jreleaser.util.Errors) Environment(org.jreleaser.model.Environment)

Example 12 with Errors

use of org.jreleaser.util.Errors in project jreleaser by jreleaser.

the class AbstractJdksMojo method validate.

protected void validate() throws MojoFailureException {
    if (jdks == null || jdks.isEmpty())
        return;
    Errors errors = new Errors();
    jdks.forEach(jdk -> jdk.validate(errors));
    if (errors.hasErrors()) {
        StringWriter s = new StringWriter();
        PrintWriter w = new PrintWriter(s, true);
        errors.logErrors(w);
        throw new MojoFailureException(s.toString());
    }
}
Also used : Errors(org.jreleaser.util.Errors) StringWriter(java.io.StringWriter) MojoFailureException(org.apache.maven.plugin.MojoFailureException) PrintWriter(java.io.PrintWriter)

Example 13 with Errors

use of org.jreleaser.util.Errors in project jreleaser by jreleaser.

the class SetupDiscoMojo method validate.

private void validate() throws MojoFailureException {
    if (connectTimeout <= 0 || connectTimeout > 300) {
        connectTimeout = 20;
    }
    if (readTimeout <= 0 || readTimeout > 300) {
        readTimeout = 60;
    }
    Errors errors = new Errors();
    pkgs.forEach(pkg -> pkg.validate(errors));
    if (errors.hasErrors()) {
        StringWriter s = new StringWriter();
        PrintWriter w = new PrintWriter(s, true);
        errors.logErrors(w);
        throw new MojoFailureException(s.toString());
    }
}
Also used : Errors(org.jreleaser.util.Errors) StringWriter(java.io.StringWriter) MojoFailureException(org.apache.maven.plugin.MojoFailureException) PrintWriter(java.io.PrintWriter)

Example 14 with Errors

use of org.jreleaser.util.Errors in project jreleaser by jreleaser.

the class DistributionsValidator method validateArtifactPlatforms.

public static void validateArtifactPlatforms(JReleaserContext context, Distribution distribution, Packager packager, List<Artifact> candidateArtifacts, Errors errors) {
    // validate distribution type
    if (distribution.getType() == Distribution.DistributionType.BINARY || distribution.getType() == Distribution.DistributionType.JLINK || distribution.getType() == Distribution.DistributionType.NATIVE_IMAGE || distribution.getType() == Distribution.DistributionType.NATIVE_PACKAGE) {
        // ensure all artifacts define a platform
        AtomicBoolean universal = new AtomicBoolean();
        String noPlatform = "<nil>";
        Map<String, List<Artifact>> byPlatform = candidateArtifacts.stream().peek(artifact -> {
            if (distribution.getType() == Distribution.DistributionType.BINARY && artifact.extraPropertyIsTrue("universal")) {
                universal.compareAndSet(false, true);
            }
        }).collect(groupingBy(artifact -> isBlank(artifact.getPlatform()) ? noPlatform : artifact.getPlatform()));
        if (byPlatform.containsKey(noPlatform) && !universal.get()) {
            errors.configuration(RB.$("validation_distributions_platform_check", distribution.getName(), distribution.getType(), packager.getType()));
        }
        if (byPlatform.keySet().stream().noneMatch(packager::supportsPlatform) && !universal.get()) {
            context.getLogger().warn(RB.$("validation_distributions_disable", distribution.getName(), packager.getType()));
            packager.disable();
        }
    }
}
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) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayList(java.util.ArrayList) List(java.util.List)

Example 15 with Errors

use of org.jreleaser.util.Errors in project jreleaser by jreleaser.

the class GofishValidator method validateGofish.

public static void validateGofish(JReleaserContext context, Distribution distribution, Gofish packager, Errors errors) {
    JReleaserModel model = context.getModel();
    Gofish parentPackager = model.getPackagers().getGofish();
    if (!packager.isActiveSet() && parentPackager.isActiveSet()) {
        packager.setActive(parentPackager.getActive());
    }
    if (!packager.resolveEnabled(context.getModel().getProject(), distribution)) {
        packager.disable();
        return;
    }
    GitService service = model.getRelease().getGitService();
    if (!service.isReleaseSupported()) {
        packager.disable();
        return;
    }
    context.getLogger().debug("distribution.{}.gofish", distribution.getName());
    List<Artifact> candidateArtifacts = packager.resolveCandidateArtifacts(context, distribution);
    if (candidateArtifacts.size() == 0) {
        packager.setActive(Active.NEVER);
        packager.disable();
        return;
    } else if (candidateArtifacts.stream().filter(artifact -> isBlank(artifact.getPlatform())).count() > 1) {
        errors.configuration(RB.$("validation_packager_multiple_artifacts", "distribution." + distribution.getName() + ".gofish"));
        packager.disable();
        return;
    }
    validateCommitAuthor(packager, parentPackager);
    Gofish.GofishRepository repository = packager.getRepository();
    repository.resolveEnabled(model.getProject());
    validateTap(context, distribution, repository, parentPackager.getRepository(), "gofish.repository");
    validateTemplate(context, distribution, packager, parentPackager, errors);
    mergeExtraProperties(packager, parentPackager);
    validateContinueOnError(packager, parentPackager);
    if (isBlank(packager.getDownloadUrl())) {
        packager.setDownloadUrl(parentPackager.getDownloadUrl());
    }
    validateArtifactPlatforms(context, distribution, packager, candidateArtifacts, errors);
}
Also used : Artifact(org.jreleaser.model.Artifact) StringUtils.isBlank(org.jreleaser.util.StringUtils.isBlank) JReleaserModel(org.jreleaser.model.JReleaserModel) ExtraPropertiesValidator.mergeExtraProperties(org.jreleaser.model.validation.ExtraPropertiesValidator.mergeExtraProperties) Active(org.jreleaser.model.Active) List(java.util.List) Errors(org.jreleaser.util.Errors) Gofish(org.jreleaser.model.Gofish) JReleaserContext(org.jreleaser.model.JReleaserContext) DistributionsValidator.validateArtifactPlatforms(org.jreleaser.model.validation.DistributionsValidator.validateArtifactPlatforms) TemplateValidator.validateTemplate(org.jreleaser.model.validation.TemplateValidator.validateTemplate) Distribution(org.jreleaser.model.Distribution) GitService(org.jreleaser.model.GitService) RB(org.jreleaser.bundle.RB) Gofish(org.jreleaser.model.Gofish) JReleaserModel(org.jreleaser.model.JReleaserModel) GitService(org.jreleaser.model.GitService) Artifact(org.jreleaser.model.Artifact)

Aggregations

Errors (org.jreleaser.util.Errors)19 Map (java.util.Map)9 List (java.util.List)7 RB (org.jreleaser.bundle.RB)7 Active (org.jreleaser.model.Active)7 Artifact (org.jreleaser.model.Artifact)7 JReleaserContext (org.jreleaser.model.JReleaserContext)7 StringUtils.isBlank (org.jreleaser.util.StringUtils.isBlank)7 Project (org.jreleaser.model.Project)6 PlatformUtils (org.jreleaser.util.PlatformUtils)6 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)5 TemplateValidator.validateTemplate (org.jreleaser.model.validation.TemplateValidator.validateTemplate)5 StringUtils.isNotBlank (org.jreleaser.util.StringUtils.isNotBlank)5 Distribution (org.jreleaser.model.Distribution)4 Environment (org.jreleaser.model.Environment)4 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)3 ArrayList (java.util.ArrayList)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3