Search in sources :

Example 16 with Errors

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

the class HttpValidator method validateHttp.

public static void validateHttp(JReleaserContext context, JReleaserContext.Mode mode, Errors errors) {
    context.getLogger().debug("http");
    Map<String, Http> http = context.getModel().getUpload().getHttp();
    for (Map.Entry<String, Http> e : http.entrySet()) {
        e.getValue().setName(e.getKey());
        if (!mode.validateConfig()) {
            validateHttp(context, mode, e.getValue(), new Errors());
        } else {
            validateHttp(context, mode, e.getValue(), errors);
        }
    }
}
Also used : Errors(org.jreleaser.util.Errors) Http(org.jreleaser.model.Http) Map(java.util.Map)

Example 17 with Errors

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

the class JlinkValidator method validateJlink.

private static void validateJlink(JReleaserContext context, JReleaserContext.Mode mode, Jlink jlink, Errors errors) {
    context.getLogger().debug("jlink.{}", jlink.getName());
    if (!jlink.isActiveSet()) {
        jlink.setActive(Active.NEVER);
    }
    if (!jlink.resolveEnabled(context.getModel().getProject()))
        return;
    if (isBlank(jlink.getName())) {
        errors.configuration(RB.$("validation_must_not_be_blank", "jlink.name"));
        return;
    }
    context.getLogger().debug("jlink.{}.java", jlink.getName());
    if (!validateJava(context, jlink, errors)) {
        return;
    }
    Platform platform = jlink.getPlatform().merge(context.getModel().getPlatform());
    jlink.setPlatform(platform);
    if (isBlank(jlink.getImageName())) {
        jlink.setImageName(jlink.getJava().getGroupId() + "." + jlink.getJava().getArtifactId() + "-" + context.getModel().getProject().getResolvedVersion());
    }
    if (isBlank(jlink.getExecutable())) {
        jlink.setExecutable(jlink.getName());
    }
    int i = 0;
    for (Artifact targetJdk : jlink.getTargetJdks()) {
        validateJdk(context, mode, jlink, targetJdk, i++, errors);
    }
    // validate jdks.platform is unique
    Map<String, List<Artifact>> byPlatform = jlink.getTargetJdks().stream().collect(groupingBy(jdk -> isBlank(jdk.getPlatform()) ? "<nil>" : jdk.getPlatform()));
    if (byPlatform.containsKey("<nil>")) {
        errors.configuration(RB.$("validation_jlink_jdk_platform", jlink.getName()));
    }
    // check platforms
    byPlatform.forEach((p, jdks) -> {
        if (jdks.size() > 1) {
            errors.configuration(RB.$("validation_jlink_jdk_multiple_platforms", jlink.getName(), p));
        }
    });
    if (isBlank(jlink.getJdk().getPath())) {
        String currentPlatform = PlatformUtils.getCurrentFull();
        String javaHome = System.getProperty("java.home");
        if (jlink.getTargetJdks().isEmpty()) {
            if (isBlank(javaHome)) {
                // Can only happen when running as native-image, fail for now
                // TODO: native-image
                errors.configuration(RB.$("validation_java_home_missing"));
                return;
            }
            // Use current
            jlink.getJdk().setPath(javaHome);
            jlink.getJdk().setPlatform(currentPlatform);
            jlink.addTargetJdk(jlink.getJdk());
        } else {
            // find a compatible JDK in targets
            Optional<Artifact> jdk = jlink.getTargetJdks().stream().filter(j -> PlatformUtils.isCompatible(currentPlatform, j.getPlatform())).findFirst();
            if (jdk.isPresent()) {
                jlink.setJdk(jdk.get());
            } else {
                if (isBlank(javaHome)) {
                    // Can only happen when running as native-image, fail for now
                    // TODO: native-image
                    errors.configuration(RB.$("validation_java_home_missing"));
                    return;
                }
                // Can't tell if the current JDK will work but might as well use it
                jlink.getJdk().setPath(javaHome);
                jlink.getJdk().setPlatform(currentPlatform);
            }
        }
    }
    if (jlink.getArgs().isEmpty()) {
        jlink.getArgs().add("--no-header-files");
        jlink.getArgs().add("--no-man-pages");
        jlink.getArgs().add("--compress=2");
        jlink.getArgs().add("--strip-debug");
    }
    if (null == jlink.getMainJar()) {
        errors.configuration(RB.$("validation_is_null", "jlink." + jlink.getName() + ".mainJar"));
        return;
    }
    if (isBlank(jlink.getMainJar().getPath())) {
        errors.configuration(RB.$("validation_must_not_be_null", "jlink." + jlink.getName() + ".mainJar.path"));
    }
    validateGlobs(context, jlink.getJars(), "jlink." + jlink.getName() + ".jars", errors);
    if (mode == JReleaserContext.Mode.ASSEMBLE) {
        validateTemplate(context, jlink, errors);
    }
    if (!jlink.getFileSets().isEmpty()) {
        i = 0;
        for (FileSet fileSet : jlink.getFileSets()) {
            validateFileSet(context, mode, jlink, fileSet, i++, errors);
        }
    }
}
Also used : Artifact(org.jreleaser.model.Artifact) FileSet(org.jreleaser.model.FileSet) Jlink(org.jreleaser.model.Jlink) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) StringUtils.isBlank(org.jreleaser.util.StringUtils.isBlank) PlatformUtils(org.jreleaser.util.PlatformUtils) StringUtils.isNotBlank(org.jreleaser.util.StringUtils.isNotBlank) Platform(org.jreleaser.model.Platform) Project(org.jreleaser.model.Project) Active(org.jreleaser.model.Active) List(java.util.List) Errors(org.jreleaser.util.Errors) Map(java.util.Map) JReleaserContext(org.jreleaser.model.JReleaserContext) Optional(java.util.Optional) TemplateValidator.validateTemplate(org.jreleaser.model.validation.TemplateValidator.validateTemplate) RB(org.jreleaser.bundle.RB) Platform(org.jreleaser.model.Platform) FileSet(org.jreleaser.model.FileSet) List(java.util.List) Artifact(org.jreleaser.model.Artifact)

Example 18 with Errors

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

the class ArtifactoryValidator method validateArtifactory.

public static void validateArtifactory(JReleaserContext context, JReleaserContext.Mode mode, Errors errors) {
    context.getLogger().debug("artifactory");
    Map<String, Artifactory> artifactory = context.getModel().getUpload().getArtifactory();
    for (Map.Entry<String, Artifactory> e : artifactory.entrySet()) {
        e.getValue().setName(e.getKey());
        if (!mode.validateConfig()) {
            validateArtifactory(context, mode, e.getValue(), new Errors());
        } else {
            validateArtifactory(context, mode, e.getValue(), errors);
        }
    }
}
Also used : Errors(org.jreleaser.util.Errors) Artifactory(org.jreleaser.model.Artifactory) Map(java.util.Map)

Example 19 with Errors

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

the class GitServiceValidator method validateGitService.

public static void validateGitService(JReleaserContext context, JReleaserContext.Mode mode, GitService service, Errors errors) {
    JReleaserModel model = context.getModel();
    Project project = model.getProject();
    if (!service.isEnabledSet()) {
        service.setEnabled(true);
    }
    if (!service.isEnabled()) {
        return;
    }
    if (mode != JReleaserContext.Mode.ASSEMBLE) {
        if (isBlank(service.getOwner()) && !(service instanceof GenericGit)) {
            errors.configuration(RB.$("validation_must_not_be_blank", service.getServiceName() + ".owner"));
        }
    }
    if (isBlank(service.getName())) {
        service.setName(project.getName());
    }
    service.setUsername(checkProperty(context, service.getServiceName().toUpperCase() + "_USERNAME", service.getServiceName() + ".username", service.getUsername(), service.getOwner()));
    service.setToken(checkProperty(context, service.getServiceName().toUpperCase() + "_TOKEN", service.getServiceName() + ".token", service.getToken(), mode != JReleaserContext.Mode.ASSEMBLE ? errors : new Errors()));
    service.setTagName(checkProperty(context, TAG_NAME, service.getServiceName() + ".tagName", service.getTagName(), "v{{projectVersion}}"));
    if (service.isReleaseSupported()) {
        service.setReleaseName(checkProperty(context, RELEASE_NAME, service.getServiceName() + ".releaseName", service.getReleaseName(), "Release {{tagName}}"));
    }
    service.setBranch(checkProperty(context, BRANCH, service.getServiceName() + ".branch", service.getBranch(), "main"));
    if (!service.isOverwriteSet()) {
        service.setOverwrite(checkProperty(context, OVERWRITE, service.getServiceName() + ".overwrite", null, false));
    }
    if (service.isReleaseSupported()) {
        if (!service.getUpdate().isEnabledSet()) {
            service.getUpdate().setEnabled(checkProperty(context, UPDATE, service.getServiceName() + ".update", null, false));
        }
        if (service.getUpdate().isEnabled() && service.getUpdate().getSections().isEmpty()) {
            service.getUpdate().getSections().add(UpdateSection.ASSETS);
        }
    }
    if (!service.isSkipTagSet()) {
        service.setSkipTag(checkProperty(context, SKIP_TAG, service.getServiceName() + ".skipTag", null, false));
    }
    if (!service.isSkipReleaseSet()) {
        service.setSkipRelease(checkProperty(context, SKIP_RELEASE, service.getServiceName() + ".skipRelease", null, false));
    }
    if (isBlank(service.getTagName())) {
        service.setTagName("v" + project.getVersion());
    }
    if (service.isReleaseSupported()) {
        if (isBlank(service.getReleaseName())) {
            service.setReleaseName("Release {{ tagName }}");
        }
    }
    if (!service.getChangelog().isEnabledSet()) {
        service.getChangelog().setEnabled(true);
    }
    if (isBlank(service.getCommitAuthor().getName())) {
        service.getCommitAuthor().setName("jreleaserbot");
    }
    if (isBlank(service.getCommitAuthor().getEmail())) {
        service.getCommitAuthor().setEmail("jreleaser@kordamp.org");
    }
    validateTimeout(service);
    if (service.isReleaseSupported()) {
        // milestone
        service.getMilestone().setName(checkProperty(context, MILESTONE_NAME, service.getServiceName() + ".milestone.name", service.getMilestone().getName(), "{{tagName}}"));
    }
    // eager resolve
    service.getResolvedTagName(context.getModel());
    if (service.isReleaseSupported()) {
        service.getResolvedReleaseName(context.getModel());
        service.getMilestone().getResolvedName(service.props(context.getModel()));
    }
    if (project.isSnapshot()) {
        service.getChangelog().setEnabled(true);
        service.getChangelog().setExternal(null);
        service.getChangelog().setSort(Changelog.Sort.DESC);
        if (service.isReleaseSupported()) {
            service.setOverwrite(true);
        }
    }
    if (mode != JReleaserContext.Mode.ASSEMBLE) {
        validateChangelog(context, service, errors);
    }
    if (mode.validateConfig()) {
        if (service.isSign()) {
            if (model.getSigning().getMode() == Signing.Mode.COSIGN) {
                service.setSign(false);
                errors.warning(RB.$("validation_git_signing_cosign", service.getServiceName()));
                return;
            }
        }
        if (service.isSign() && !model.getSigning().isEnabled()) {
            if (context.isDryrun()) {
                service.setSign(false);
            } else {
                errors.configuration(RB.$("validation_git_signing", service.getServiceName()));
            }
        }
    }
}
Also used : Project(org.jreleaser.model.Project) Errors(org.jreleaser.util.Errors) JReleaserModel(org.jreleaser.model.JReleaserModel) GenericGit(org.jreleaser.model.GenericGit)

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