Search in sources :

Example 1 with Platform

use of org.jreleaser.model.Platform in project jreleaser by jreleaser.

the class ArchiveValidator method validateArchive.

private static void validateArchive(JReleaserContext context, JReleaserContext.Mode mode, Archive archive, Errors errors) {
    context.getLogger().debug("archive.{}", archive.getName());
    if (!archive.isActiveSet()) {
        archive.setActive(Active.NEVER);
    }
    if (!archive.resolveEnabled(context.getModel().getProject()))
        return;
    if (isBlank(archive.getName())) {
        errors.configuration(RB.$("validation_must_not_be_blank", "archive.name"));
        return;
    }
    Platform platform = archive.getPlatform().merge(context.getModel().getPlatform());
    archive.setPlatform(platform);
    if (null == archive.getDistributionType()) {
        archive.setDistributionType(Distribution.DistributionType.BINARY);
    }
    if (isBlank(archive.getArchiveName())) {
        archive.setArchiveName("{{distributionName}}-{{projectVersion}}");
    }
    if (archive.getFormats().isEmpty()) {
        archive.addFormat(Archive.Format.ZIP);
    }
    if (archive.getFileSets().isEmpty()) {
        errors.configuration(RB.$("validation_archive_empty_fileset", archive.getName()));
    } else {
        int i = 0;
        for (FileSet fileSet : archive.getFileSets()) {
            validateFileSet(context, mode, archive, fileSet, i++, errors);
        }
    }
}
Also used : Platform(org.jreleaser.model.Platform) FileSet(org.jreleaser.model.FileSet)

Example 2 with Platform

use of org.jreleaser.model.Platform 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 3 with Platform

use of org.jreleaser.model.Platform 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)

Aggregations

FileSet (org.jreleaser.model.FileSet)3 Platform (org.jreleaser.model.Platform)3 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)2 RB (org.jreleaser.bundle.RB)2 Active (org.jreleaser.model.Active)2 Artifact (org.jreleaser.model.Artifact)2 JReleaserContext (org.jreleaser.model.JReleaserContext)2 TemplateValidator.validateTemplate (org.jreleaser.model.validation.TemplateValidator.validateTemplate)2 Errors (org.jreleaser.util.Errors)2 PlatformUtils (org.jreleaser.util.PlatformUtils)2 StringUtils.isBlank (org.jreleaser.util.StringUtils.isBlank)2 StringUtils.isNotBlank (org.jreleaser.util.StringUtils.isNotBlank)2 Archive (org.jreleaser.model.Archive)1 Jlink (org.jreleaser.model.Jlink)1 NativeImage (org.jreleaser.model.NativeImage)1 Project (org.jreleaser.model.Project)1