Search in sources :

Example 6 with Errors

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

the class Validator method checkProperty.

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

Example 7 with Errors

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

the class ListDiscoMojo 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 8 with Errors

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

the class SlackValidator method validateSlack.

public static void validateSlack(JReleaserContext context, Slack slack, Errors errors) {
    if (!slack.resolveEnabled(context.getModel().getProject()))
        return;
    context.getLogger().debug("announce.slack");
    Errors ignored = new Errors();
    slack.setToken(checkProperty(context, SLACK_TOKEN, "slack.token", slack.getToken(), ignored, context.isDryrun()));
    slack.setWebhook(checkProperty(context, SLACK_WEBHOOK, "slack.webhook", slack.getWebhook(), ignored, context.isDryrun()));
    String token = slack.getResolvedToken();
    String webhook = slack.getResolvedWebhook();
    if (!context.isDryrun() && isBlank(token) && isBlank(webhook)) {
        errors.configuration(RB.$("validation_slack_token"));
        return;
    }
    if (isBlank(slack.getChannel())) {
        slack.setChannel("#announce");
    }
    if (isBlank(slack.getMessage()) && isBlank(slack.getMessageTemplate())) {
        if (Files.exists(context.getBasedir().resolve(DEFAULT_SLACK_TPL))) {
            slack.setMessageTemplate(DEFAULT_SLACK_TPL);
        } else {
            slack.setMessage(RB.$("default.release.message"));
        }
    }
    if (isNotBlank(slack.getMessageTemplate()) && !Files.exists(context.getBasedir().resolve(slack.getMessageTemplate().trim()))) {
        errors.configuration(RB.$("validation_directory_not_exist", "slack.messageTemplate ", slack.getMessageTemplate()));
    }
    validateTimeout(slack);
}
Also used : Errors(org.jreleaser.util.Errors)

Example 9 with Errors

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

the class Validator method checkProperty.

static <T extends Enum<T>> String checkProperty(JReleaserContext context, String key, String property, T value, T defaultValue) {
    if (null != value)
        return value.name();
    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() ? result : (null != defaultValue ? defaultValue.name() : null);
}
Also used : Errors(org.jreleaser.util.Errors) Environment(org.jreleaser.model.Environment)

Example 10 with Errors

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

the class Validator method checkProperty.

static String checkProperty(JReleaserContext context, String key, String property, String value, String defaultValue) {
    if (isNotBlank(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() ? result : defaultValue;
}
Also used : Errors(org.jreleaser.util.Errors) Environment(org.jreleaser.model.Environment)

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