Search in sources :

Example 1 with Errors

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

the class DockerValidator method validateDocker.

public static void validateDocker(JReleaserContext context, Distribution distribution, Docker packager, Errors errors) {
    JReleaserModel model = context.getModel();
    Project project = model.getProject();
    Docker parentPackager = model.getPackagers().getDocker();
    if (!packager.isActiveSet() && parentPackager.isActiveSet()) {
        packager.setActive(parentPackager.getActive());
    }
    if (!packager.resolveEnabled(context.getModel().getProject(), distribution))
        return;
    String element = "distribution." + distribution.getName() + ".docker";
    context.getLogger().debug(element);
    List<Artifact> candidateArtifacts = packager.resolveCandidateArtifacts(context, distribution);
    if (candidateArtifacts.size() == 0) {
        packager.setActive(Active.NEVER);
        packager.disable();
        return;
    }
    // check specs for active status
    for (DockerSpec spec : packager.getSpecs().values()) {
        if (!spec.isActiveSet() && packager.isActiveSet()) {
            spec.setActive(packager.getActive());
        }
        spec.resolveEnabled(context.getModel().getProject(), distribution);
    }
    validateTemplate(context, distribution, packager, parentPackager, errors);
    validateCommitAuthor(packager, parentPackager);
    Docker.DockerRepository repository = packager.getRepository();
    repository.resolveEnabled(model.getProject());
    if (!repository.isVersionedSubfoldersSet()) {
        repository.setVersionedSubfolders(parentPackager.getRepository().isVersionedSubfolders());
    }
    if (isBlank(repository.getName())) {
        repository.setName(project.getName() + "-docker");
    }
    validateTap(context, distribution, repository, parentPackager.getRepository(), "docker.repository");
    mergeExtraProperties(packager, parentPackager);
    validateContinueOnError(packager, parentPackager);
    if (isBlank(packager.getDownloadUrl())) {
        packager.setDownloadUrl(parentPackager.getDownloadUrl());
    }
    if (isBlank(packager.getBaseImage())) {
        packager.setBaseImage(parentPackager.getBaseImage());
    }
    validateBaseImage(distribution, packager);
    if (packager.getImageNames().isEmpty()) {
        packager.setImageNames(parentPackager.getImageNames());
    }
    if (packager.getImageNames().isEmpty()) {
        packager.addImageName("{{repoOwner}}/{{distributionName}}:{{tagName}}");
    }
    if (context.getModel().getProject().isSnapshot()) {
        // find the 1st image that ends with :{{tagName}}
        Optional<String> imageName = packager.getImageNames().stream().filter(n -> n.endsWith(":{{tagName}}") || n.endsWith(":{{ tagName }}")).findFirst();
        packager.setImageNames(singleton(imageName.orElse("{{repoOwner}}/{{distributionName}}:{{tagName}}")));
    }
    validateCommands(packager, parentPackager);
    Map<String, String> labels = new LinkedHashMap<>();
    labels.putAll(parentPackager.getLabels());
    labels.putAll(packager.getLabels());
    packager.setLabels(labels);
    if (!packager.getLabels().containsKey(LABEL_OCI_IMAGE_TITLE)) {
        packager.getLabels().put(LABEL_OCI_IMAGE_TITLE, "{{distributionName}}");
    }
    validateLabels(packager);
    validateArtifactPlatforms(context, distribution, packager, candidateArtifacts, errors);
    validateRegistries(context, packager, parentPackager, errors, element);
    if (!packager.isUseLocalArtifactSet() && parentPackager.isUseLocalArtifactSet()) {
        packager.setUseLocalArtifact(parentPackager.isUseLocalArtifact());
    }
    if (distribution.getType() == Distribution.DistributionType.SINGLE_JAR) {
        packager.setUseLocalArtifact(true);
    }
    for (Map.Entry<String, DockerSpec> e : packager.getSpecs().entrySet()) {
        DockerSpec spec = e.getValue();
        if (isBlank(spec.getName())) {
            spec.setName(e.getKey());
        }
        validateDockerSpec(context, distribution, spec, packager, errors);
    }
}
Also used : Artifact(org.jreleaser.model.Artifact) DockerSpec(org.jreleaser.model.DockerSpec) DockerConfiguration(org.jreleaser.model.DockerConfiguration) LABEL_OCI_IMAGE_TITLE(org.jreleaser.model.Docker.LABEL_OCI_IMAGE_TITLE) StringUtils.isBlank(org.jreleaser.util.StringUtils.isBlank) JReleaserModel(org.jreleaser.model.JReleaserModel) LinkedHashMap(java.util.LinkedHashMap) Active(org.jreleaser.model.Active) Errors(org.jreleaser.util.Errors) Collections.singleton(java.util.Collections.singleton) LABEL_OCI_IMAGE_DESCRIPTION(org.jreleaser.model.Docker.LABEL_OCI_IMAGE_DESCRIPTION) Map(java.util.Map) JReleaserContext(org.jreleaser.model.JReleaserContext) Env(org.jreleaser.util.Env) DistributionsValidator.validateArtifactPlatforms(org.jreleaser.model.validation.DistributionsValidator.validateArtifactPlatforms) TemplateValidator.validateTemplate(org.jreleaser.model.validation.TemplateValidator.validateTemplate) Distribution(org.jreleaser.model.Distribution) LinkedHashSet(java.util.LinkedHashSet) LABEL_OCI_IMAGE_URL(org.jreleaser.model.Docker.LABEL_OCI_IMAGE_URL) LABEL_OCI_IMAGE_REVISION(org.jreleaser.model.Docker.LABEL_OCI_IMAGE_REVISION) LABEL_OCI_IMAGE_VERSION(org.jreleaser.model.Docker.LABEL_OCI_IMAGE_VERSION) Set(java.util.Set) PlatformUtils(org.jreleaser.util.PlatformUtils) Collectors(java.util.stream.Collectors) ExtraPropertiesValidator.mergeExtraProperties(org.jreleaser.model.validation.ExtraPropertiesValidator.mergeExtraProperties) Project(org.jreleaser.model.Project) List(java.util.List) Registry(org.jreleaser.model.Registry) LABEL_OCI_IMAGE_LICENSES(org.jreleaser.model.Docker.LABEL_OCI_IMAGE_LICENSES) Docker(org.jreleaser.model.Docker) Optional(java.util.Optional) GitService(org.jreleaser.model.GitService) RB(org.jreleaser.bundle.RB) Artifact(org.jreleaser.model.Artifact) LinkedHashMap(java.util.LinkedHashMap) Project(org.jreleaser.model.Project) Docker(org.jreleaser.model.Docker) JReleaserModel(org.jreleaser.model.JReleaserModel) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DockerSpec(org.jreleaser.model.DockerSpec)

Example 2 with Errors

use of org.jreleaser.util.Errors 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)

Example 3 with Errors

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

the class JpackageValidator method validateJpackage.

private static void validateJpackage(JReleaserContext context, JReleaserContext.Mode mode, Jpackage jpackage, Errors errors) {
    context.getLogger().debug("jpackage.{}", jpackage.getName());
    if (!jpackage.isActiveSet()) {
        jpackage.setActive(Active.NEVER);
    }
    Project project = context.getModel().getProject();
    if (!jpackage.resolveEnabled(project))
        return;
    Jpackage.PlatformPackager packager = jpackage.getResolvedPlatformPackager();
    Jpackage.ApplicationPackage applicationPackage = jpackage.getApplicationPackage();
    packager.enable();
    if (isNotBlank(jpackage.getJlink())) {
        Jlink jlink = context.getModel().getAssemble().findJlink(jpackage.getJlink());
        Path baseOutputDirectory = context.getAssembleDirectory().resolve(jlink.getName()).resolve(jlink.getType());
        String imageName = jlink.getResolvedImageName(context);
        List<Artifact> candidateRuntimeImages = new ArrayList<>();
        for (Artifact targetJdk : jlink.getTargetJdks()) {
            if (!context.isPlatformSelected(targetJdk))
                continue;
            String platform = targetJdk.getPlatform();
            Path path = baseOutputDirectory.resolve("work-" + platform).resolve(imageName + "-" + platform).toAbsolutePath();
            candidateRuntimeImages.add(Artifact.of(path, platform));
        }
        if (jpackage.getRuntimeImages().size() > 0 && jpackage.getRuntimeImages().size() != candidateRuntimeImages.size()) {
            errors.configuration(RB.$("validation_jpackage_jlink_application", jpackage.getName()));
        }
        int count = 0;
        for (Artifact runtimeImage : jpackage.getRuntimeImages()) {
            Path rp = runtimeImage.getResolvedPath(context, jpackage);
            Path tp = runtimeImage.getResolvedTransform(context, jpackage);
            Path path = tp != null ? tp : rp;
            if (candidateRuntimeImages.stream().anyMatch(a -> a.getPath().equals(path.toString()))) {
                count++;
            }
        }
        if (jpackage.getRuntimeImages().size() > 0 && count != candidateRuntimeImages.size()) {
            errors.configuration(RB.$("validation_jpackage_jlink_application", jpackage.getName()));
        }
        jpackage.setJava(jlink.getJava());
        jpackage.setMainJar(jlink.getMainJar());
        jpackage.setJars(jlink.getJars());
        packager.setJdk(jlink.getJdk());
        if (isBlank(jpackage.getExecutable())) {
            jpackage.setExecutable(jlink.getExecutable());
        }
        for (Artifact runtimeImage : candidateRuntimeImages) {
            runtimeImage.activate();
            jpackage.addRuntimeImage(runtimeImage);
        }
    }
    context.getLogger().debug("jpackage.{}.java", jpackage.getName());
    if (!validateJava(context, jpackage, errors)) {
        return;
    }
    if (isBlank(jpackage.getExecutable())) {
        jpackage.setExecutable(jpackage.getName());
    }
    if (jpackage.getRuntimeImages().size() == 0) {
        errors.configuration(RB.$("validation_jpackage_runtime_images_missing", jpackage.getName()));
        return;
    }
    int i = 0;
    for (Artifact runtimeImage : jpackage.getRuntimeImages()) {
        validateRuntimeImage(context, mode, jpackage, runtimeImage, i++, errors);
    }
    // validate jdks.platform is unique
    Map<String, List<Artifact>> byPlatform = jpackage.getRuntimeImages().stream().collect(groupingBy(ri -> isBlank(ri.getPlatform()) ? "<nil>" : ri.getPlatform()));
    if (byPlatform.containsKey("<nil>")) {
        errors.configuration(RB.$("validation_jpackage_runtime_image_platform", jpackage.getName()));
    }
    // check platforms
    byPlatform.forEach((p, jdks) -> {
        if (jdks.size() > 1) {
            errors.configuration(RB.$("validation_jpackage_runtime_image_multiple_platforms", jpackage.getName(), p));
        }
    });
    if (isBlank(packager.getJdk().getPath())) {
        String javaHome = System.getProperty("java.home");
        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;
        }
        packager.getJdk().setPath(javaHome);
        packager.getJdk().setPlatform(PlatformUtils.getCurrentFull());
    }
    if (packager.getTypes().isEmpty()) {
        packager.setTypes(singletonList(packager.getValidTypes().get(0)));
    }
    if (isBlank(applicationPackage.getAppName())) {
        applicationPackage.setAppName(jpackage.getName());
    }
    if (isBlank(applicationPackage.getAppVersion())) {
        applicationPackage.setAppVersion(project.getResolvedVersion());
    }
    // validate appVersion
    String appVersion = applicationPackage.getResolvedAppVersion(context, jpackage);
    try {
        SemVer v = SemVer.of(appVersion);
        if (isNotBlank(v.getBuild()) && isNotBlank(v.getTag()) && v.getMajor() <= 0) {
            errors.configuration(RB.$("validation_jpackage_invalid_appversion", appVersion));
        }
    } catch (IllegalArgumentException e) {
        // can't use this value
        errors.configuration(RB.$("validation_jpackage_invalid_appversion", appVersion));
    }
    if (isBlank(applicationPackage.getVendor())) {
        applicationPackage.setVendor(project.getVendor());
    }
    if (isBlank(applicationPackage.getVendor())) {
        errors.configuration(RB.$("validation_jpackage_missing_vendor", jpackage.getName()));
    }
    if (isBlank(applicationPackage.getCopyright())) {
        applicationPackage.setCopyright(project.getCopyright());
    }
    if (mode == JReleaserContext.Mode.ASSEMBLE) {
        validateTemplate(context, jpackage, errors);
    }
    if (isBlank(packager.getAppName())) {
        packager.setAppName(jpackage.getApplicationPackage().getAppName());
    }
    if (packager instanceof Jpackage.Linux) {
        validateLinux(context, jpackage, (Jpackage.Linux) packager, errors);
    }
    if (packager instanceof Jpackage.Osx) {
        validateOsx(context, jpackage, (Jpackage.Osx) packager, errors);
    }
    if (packager instanceof Jpackage.Windows) {
        validateWindows(context, jpackage, (Jpackage.Windows) packager, errors);
    }
}
Also used : Jpackage(org.jreleaser.model.Jpackage) Path(java.nio.file.Path) Artifact(org.jreleaser.model.Artifact) 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) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) 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) TemplateValidator.validateTemplate(org.jreleaser.model.validation.TemplateValidator.validateTemplate) SemVer(org.jreleaser.util.SemVer) Pattern(java.util.regex.Pattern) Jpackage(org.jreleaser.model.Jpackage) RB(org.jreleaser.bundle.RB) Path(java.nio.file.Path) Jlink(org.jreleaser.model.Jlink) ArrayList(java.util.ArrayList) SemVer(org.jreleaser.util.SemVer) Artifact(org.jreleaser.model.Artifact) Project(org.jreleaser.model.Project) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List)

Example 4 with Errors

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

the class NativeImageValidator method validateNativeImage.

private static void validateNativeImage(JReleaserContext context, JReleaserContext.Mode mode, NativeImage nativeImage, Errors errors) {
    context.getLogger().debug("nativeImage.{}", nativeImage.getName());
    if (!nativeImage.isActiveSet()) {
        nativeImage.setActive(Active.NEVER);
    }
    if (!nativeImage.resolveEnabled(context.getModel().getProject()))
        return;
    if (isBlank(nativeImage.getName())) {
        errors.configuration(RB.$("validation_must_not_be_blank", "nativeImage.name"));
        return;
    }
    if (null == nativeImage.getMainJar()) {
        errors.configuration(RB.$("validation_is_null", "nativeImage." + nativeImage.getName() + ".mainJar"));
        return;
    }
    Platform platform = nativeImage.getPlatform().merge(context.getModel().getPlatform());
    nativeImage.setPlatform(platform);
    if (isBlank(nativeImage.getExecutable())) {
        nativeImage.setExecutable(nativeImage.getName());
    }
    if (isBlank(nativeImage.getImageName())) {
        nativeImage.setImageName(nativeImage.getExecutable() + "-" + context.getModel().getProject().getResolvedVersion());
    }
    int i = 0;
    for (Artifact graalJdk : nativeImage.getGraalJdks()) {
        validateJdk(context, mode, nativeImage, graalJdk, i++, errors);
    }
    // validate jdks.platform is unique
    Map<String, List<Artifact>> byPlatform = nativeImage.getGraalJdks().stream().collect(groupingBy(jdk -> isBlank(jdk.getPlatform()) ? "<nil>" : jdk.getPlatform()));
    if (byPlatform.containsKey("<nil>")) {
        errors.configuration(RB.$("validation_nativeimage_jdk_platform", nativeImage.getName()));
    }
    // check platforms
    byPlatform.forEach((p, jdks) -> {
        if (jdks.size() > 1) {
            errors.configuration(RB.$("validation_nativeimage_jdk_multiple_platforms", nativeImage.getName(), p));
        }
    });
    if (isBlank(nativeImage.getGraal().getPath())) {
        String currentPlatform = PlatformUtils.getCurrentFull();
        String javaHome = System.getProperty("java.home");
        if (nativeImage.getGraalJdks().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
            nativeImage.getGraal().setPath(javaHome);
            nativeImage.getGraal().setPlatform(currentPlatform);
        } else {
            // find a compatible JDK in targets
            Optional<Artifact> jdk = nativeImage.getGraalJdks().stream().filter(j -> PlatformUtils.isCompatible(currentPlatform, j.getPlatform())).findFirst();
            if (jdk.isPresent()) {
                nativeImage.setGraal(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
                nativeImage.getGraal().setPath(javaHome);
                nativeImage.getGraal().setPlatform(currentPlatform);
            }
        }
    }
    if (isBlank(nativeImage.getMainJar().getPath())) {
        errors.configuration(RB.$("validation_must_not_be_null", "nativeImage." + nativeImage.getName() + ".mainJar.path"));
    }
    if (null == nativeImage.getArchiveFormat()) {
        nativeImage.setArchiveFormat(Archive.Format.ZIP);
    }
    validateGlobs(context, nativeImage.getJars(), "nativeImage." + nativeImage.getName() + ".jars", errors);
    if (mode == JReleaserContext.Mode.ASSEMBLE) {
        validateTemplate(context, nativeImage, errors);
    }
    if (!nativeImage.getFileSets().isEmpty()) {
        i = 0;
        for (FileSet fileSet : nativeImage.getFileSets()) {
            validateFileSet(context, mode, nativeImage, fileSet, i++, errors);
        }
    }
    NativeImage.Upx upx = nativeImage.getUpx();
    if (!upx.isActiveSet()) {
        upx.setActive(Active.NEVER);
    }
    if (!upx.resolveEnabled(context.getModel().getProject()))
        return;
    if (isBlank(upx.getVersion())) {
        errors.configuration(RB.$("validation_is_missing", "nativeImage." + nativeImage.getName() + ".upx.version"));
    }
}
Also used : Archive(org.jreleaser.model.Archive) Artifact(org.jreleaser.model.Artifact) FileSet(org.jreleaser.model.FileSet) 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) Active(org.jreleaser.model.Active) List(java.util.List) Errors(org.jreleaser.util.Errors) Map(java.util.Map) JReleaserContext(org.jreleaser.model.JReleaserContext) NativeImage(org.jreleaser.model.NativeImage) 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) NativeImage(org.jreleaser.model.NativeImage) List(java.util.List) Artifact(org.jreleaser.model.Artifact)

Example 5 with Errors

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

the class S3Validator method validateS3.

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

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