Search in sources :

Example 1 with SemVer

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

the class Distribution method props.

public Map<String, Object> props() {
    Map<String, Object> props = new LinkedHashMap<>();
    applyTemplates(props, getResolvedExtraProperties());
    props.put(KEY_DISTRIBUTION_NAME, name);
    props.put(KEY_DISTRIBUTION_EXECUTABLE, executable.getName());
    props.put(KEY_DISTRIBUTION_EXECUTABLE_NAME, executable.getName());
    props.put(KEY_DISTRIBUTION_EXECUTABLE_UNIX, executable.resolveExecutable("linux"));
    props.put(KEY_DISTRIBUTION_EXECUTABLE_WINDOWS, executable.resolveExecutable("windows"));
    safePut(KEY_DISTRIBUTION_EXECUTABLE_EXTENSION_UNIX, executable.resolveUnixExtension(), props, true);
    safePut(KEY_DISTRIBUTION_EXECUTABLE_EXTENSION_WINDOWS, executable.resolveWindowsExtension(), props, true);
    props.put(KEY_DISTRIBUTION_TAGS_BY_SPACE, String.join(" ", tags));
    props.put(KEY_DISTRIBUTION_TAGS_BY_COMMA, String.join(",", tags));
    props.putAll(java.getResolvedExtraProperties());
    safePut(KEY_DISTRIBUTION_JAVA_GROUP_ID, java.getGroupId(), props, true);
    safePut(KEY_DISTRIBUTION_JAVA_ARTIFACT_ID, java.getArtifactId(), props, true);
    safePut(KEY_DISTRIBUTION_JAVA_MAIN_CLASS, java.getMainClass(), props, true);
    if (isNotBlank(java.getVersion())) {
        props.put(KEY_DISTRIBUTION_JAVA_VERSION, java.getVersion());
        SemVer jv = SemVer.of(java.getVersion());
        safePut(KEY_DISTRIBUTION_JAVA_VERSION_MAJOR, jv.getMajor(), props, true);
        safePut(KEY_DISTRIBUTION_JAVA_VERSION_MINOR, jv.getMinor(), props, true);
        safePut(KEY_DISTRIBUTION_JAVA_VERSION_PATCH, jv.getPatch(), props, true);
        safePut(KEY_DISTRIBUTION_JAVA_VERSION_TAG, jv.getTag(), props, true);
        safePut(KEY_DISTRIBUTION_JAVA_VERSION_BUILD, jv.getBuild(), props, true);
    } else {
        props.put(KEY_DISTRIBUTION_JAVA_VERSION, "");
        props.put(KEY_DISTRIBUTION_JAVA_VERSION_MAJOR, "");
        props.put(KEY_DISTRIBUTION_JAVA_VERSION_MINOR, "");
        props.put(KEY_DISTRIBUTION_JAVA_VERSION_PATCH, "");
        props.put(KEY_DISTRIBUTION_JAVA_VERSION_TAG, "");
        props.put(KEY_DISTRIBUTION_JAVA_VERSION_BUILD, "");
    }
    return props;
}
Also used : SemVer(org.jreleaser.util.SemVer) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with SemVer

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

the class JReleaserModel method fillProjectProperties.

private void fillProjectProperties(Map<String, Object> props, Project project) {
    props.putAll(environment.getProperties());
    props.putAll(environment.getSourcedProperties());
    props.put(Constants.KEY_TIMESTAMP, timestamp);
    if (commit != null) {
        props.put(Constants.KEY_COMMIT_SHORT_HASH, commit.getShortHash());
        props.put(Constants.KEY_COMMIT_FULL_HASH, commit.getFullHash());
    }
    props.put(Constants.KEY_PROJECT_NAME, project.getName());
    props.put(Constants.KEY_PROJECT_NAME_CAPITALIZED, getClassNameForLowerCaseHyphenSeparatedName(project.getName()));
    props.put(Constants.KEY_PROJECT_VERSION, project.getVersion());
    props.put(Constants.KEY_PROJECT_EFFECTIVE_VERSION, project.getEffectiveVersion());
    props.put(Constants.KEY_PROJECT_SNAPSHOT, String.valueOf(project.isSnapshot()));
    if (isNotBlank(project.getDescription())) {
        props.put(Constants.KEY_PROJECT_DESCRIPTION, MustacheUtils.passThrough(project.getDescription()));
    }
    if (isNotBlank(project.getLongDescription())) {
        props.put(Constants.KEY_PROJECT_LONG_DESCRIPTION, MustacheUtils.passThrough(project.getLongDescription()));
    }
    if (isNotBlank(project.getWebsite())) {
        props.put(Constants.KEY_PROJECT_WEBSITE, project.getWebsite());
    }
    if (isNotBlank(project.getLicense())) {
        props.put(Constants.KEY_PROJECT_LICENSE, project.getLicense());
    }
    if (isNotBlank(project.getLicense())) {
        props.put(Constants.KEY_PROJECT_LICENSE_URL, project.getLicenseUrl());
    }
    if (isNotBlank(project.getDocsUrl())) {
        props.put(Constants.KEY_PROJECT_DOCS_URL, project.getDocsUrl());
    }
    if (isNotBlank(project.getCopyright())) {
        props.put(Constants.KEY_PROJECT_COPYRIGHT, project.getCopyright());
    }
    if (isNotBlank(project.getVendor())) {
        props.put(Constants.KEY_PROJECT_VENDOR, project.getVendor());
    }
    props.put(Constants.KEY_PROJECT_AUTHORS_BY_SPACE, String.join(" ", project.getAuthors()));
    props.put(Constants.KEY_PROJECT_AUTHORS_BY_COMMA, String.join(",", project.getAuthors()));
    props.put(Constants.KEY_PROJECT_TAGS_BY_SPACE, String.join(" ", project.getTags()));
    props.put(Constants.KEY_PROJECT_TAGS_BY_COMMA, String.join(",", project.getTags()));
    if (project.getJava().isEnabled()) {
        props.putAll(project.getJava().getResolvedExtraProperties());
        props.put(Constants.KEY_PROJECT_JAVA_GROUP_ID, project.getJava().getGroupId());
        props.put(Constants.KEY_PROJECT_JAVA_ARTIFACT_ID, project.getJava().getArtifactId());
        props.put(Constants.KEY_PROJECT_JAVA_VERSION, project.getJava().getVersion());
        props.put(Constants.KEY_PROJECT_JAVA_MAIN_CLASS, project.getJava().getMainClass());
        SemVer jv = SemVer.of(project.getJava().getVersion());
        props.put(Constants.KEY_PROJECT_JAVA_VERSION_MAJOR, jv.getMajor());
        if (jv.hasMinor())
            props.put(Constants.KEY_PROJECT_JAVA_VERSION_MINOR, jv.getMinor());
        if (jv.hasPatch())
            props.put(Constants.KEY_PROJECT_JAVA_VERSION_PATCH, jv.getPatch());
        if (jv.hasTag())
            props.put(Constants.KEY_PROJECT_JAVA_VERSION_TAG, jv.getTag());
        if (jv.hasBuild())
            props.put(Constants.KEY_PROJECT_JAVA_VERSION_BUILD, jv.getBuild());
    }
    project.parseVersion();
    props.putAll(project.getResolvedExtraProperties());
}
Also used : SemVer(org.jreleaser.util.SemVer)

Example 3 with SemVer

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

the class AbstractJavaAssembler method props.

@Override
public Map<String, Object> props() {
    Map<String, Object> props = super.props();
    props.put(Constants.KEY_DISTRIBUTION_EXECUTABLE, executable);
    props.putAll(java.getResolvedExtraProperties());
    safePut(Constants.KEY_DISTRIBUTION_JAVA_GROUP_ID, java.getGroupId(), props, true);
    safePut(Constants.KEY_DISTRIBUTION_JAVA_ARTIFACT_ID, java.getArtifactId(), props, true);
    safePut(Constants.KEY_DISTRIBUTION_JAVA_MAIN_CLASS, java.getMainClass(), props, true);
    if (isNotBlank(java.getVersion())) {
        props.put(Constants.KEY_DISTRIBUTION_JAVA_VERSION, java.getVersion());
        SemVer jv = SemVer.of(java.getVersion());
        safePut(Constants.KEY_DISTRIBUTION_JAVA_VERSION_MAJOR, jv.getMajor(), props, true);
        safePut(Constants.KEY_DISTRIBUTION_JAVA_VERSION_MINOR, jv.getMinor(), props, true);
        safePut(Constants.KEY_DISTRIBUTION_JAVA_VERSION_PATCH, jv.getPatch(), props, true);
        safePut(Constants.KEY_DISTRIBUTION_JAVA_VERSION_TAG, jv.getTag(), props, true);
        safePut(Constants.KEY_DISTRIBUTION_JAVA_VERSION_BUILD, jv.getBuild(), props, true);
    } else {
        props.put(Constants.KEY_DISTRIBUTION_JAVA_VERSION, "");
        props.put(Constants.KEY_DISTRIBUTION_JAVA_VERSION_MAJOR, "");
        props.put(Constants.KEY_DISTRIBUTION_JAVA_VERSION_MINOR, "");
        props.put(Constants.KEY_DISTRIBUTION_JAVA_VERSION_PATCH, "");
        props.put(Constants.KEY_DISTRIBUTION_JAVA_VERSION_TAG, "");
        props.put(Constants.KEY_DISTRIBUTION_JAVA_VERSION_BUILD, "");
    }
    return props;
}
Also used : SemVer(org.jreleaser.util.SemVer)

Example 4 with SemVer

use of org.jreleaser.util.SemVer 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 5 with SemVer

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

the class JlinkAssemblerProcessor method doAssemble.

@Override
protected void doAssemble(Map<String, Object> props) throws AssemblerProcessingException {
    // verify jdk
    Path jdkPath = assembler.getJdk().getEffectivePath(context, assembler);
    SemVer jdkVersion = SemVer.of(readJavaVersion(jdkPath));
    context.getLogger().debug(RB.$("assembler.jlink.jdk"), jdkVersion, jdkPath.toAbsolutePath().toString());
    // verify jdks
    for (Artifact targetJdk : assembler.getTargetJdks()) {
        if (!context.isPlatformSelected(targetJdk))
            continue;
        Path targetJdkPath = targetJdk.getEffectivePath(context, assembler);
        SemVer targetJdkVersion = SemVer.of(readJavaVersion(targetJdkPath));
        context.getLogger().debug(RB.$("assembler.jlink.target"), jdkVersion, targetJdkPath.toAbsolutePath().toString());
        if (jdkVersion.getMajor() != targetJdkVersion.getMajor()) {
            throw new AssemblerProcessingException(RB.$("ERROR_jlink_target_not_compatible", targetJdkVersion, jdkVersion));
        }
    }
    Path assembleDirectory = (Path) props.get(Constants.KEY_DISTRIBUTION_ASSEMBLE_DIRECTORY);
    Path inputsDirectory = assembleDirectory.resolve("inputs");
    // run jlink x jdk
    String imageName = assembler.getResolvedImageName(context);
    if (isNotBlank(assembler.getImageNameTransform())) {
        imageName = assembler.getResolvedImageNameTransform(context);
    }
    for (Artifact targetJdk : assembler.getTargetJdks()) {
        if (!context.isPlatformSelected(targetJdk))
            continue;
        String platform = targetJdk.getPlatform();
        // copy jars to assembly
        Path jarsDirectory = inputsDirectory.resolve("jars");
        Path universalJarsDirectory = jarsDirectory.resolve("universal");
        context.getLogger().debug(RB.$("assembler.copy.jars"), context.relativizeToBasedir(universalJarsDirectory));
        Set<Path> jars = copyJars(context, assembler, universalJarsDirectory, "");
        Path platformJarsDirectory = jarsDirectory.resolve(platform);
        context.getLogger().debug(RB.$("assembler.copy.jars"), context.relativizeToBasedir(platformJarsDirectory));
        jars.addAll(copyJars(context, assembler, platformJarsDirectory, platform));
        // resolve module names
        Set<String> moduleNames = new TreeSet<>(resolveModuleNames(context, jdkPath, jarsDirectory, platform, props));
        context.getLogger().debug(RB.$("assembler.resolved.module.names"), moduleNames);
        if (moduleNames.isEmpty()) {
            throw new AssemblerProcessingException(RB.$("ERROR_assembler_no_module_names"));
        }
        moduleNames.addAll(assembler.getAdditionalModuleNames());
        if (isNotBlank(assembler.getJava().getMainModule())) {
            moduleNames.add(assembler.getJava().getMainModule());
        }
        context.getLogger().debug(RB.$("assembler.module.names"), moduleNames);
        String str = targetJdk.getExtraProperties().getOrDefault("archiveFormat", "ZIP").toString();
        Archive.Format archiveFormat = Archive.Format.of(str);
        jlink(assembleDirectory, jdkPath, targetJdk, moduleNames, imageName, archiveFormat);
    }
}
Also used : Path(java.nio.file.Path) Archive(org.jreleaser.model.Archive) TreeSet(java.util.TreeSet) AssemblerProcessingException(org.jreleaser.model.assembler.spi.AssemblerProcessingException) SemVer(org.jreleaser.util.SemVer) Artifact(org.jreleaser.model.Artifact)

Aggregations

SemVer (org.jreleaser.util.SemVer)8 Path (java.nio.file.Path)4 LinkedHashMap (java.util.LinkedHashMap)2 Artifact (org.jreleaser.model.Artifact)2 Jpackage (org.jreleaser.model.Jpackage)2 AssemblerProcessingException (org.jreleaser.model.assembler.spi.AssemblerProcessingException)2 ArrayList (java.util.ArrayList)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 Pattern (java.util.regex.Pattern)1 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)1 RB (org.jreleaser.bundle.RB)1 Active (org.jreleaser.model.Active)1 Archive (org.jreleaser.model.Archive)1 JReleaserContext (org.jreleaser.model.JReleaserContext)1 Jlink (org.jreleaser.model.Jlink)1 Project (org.jreleaser.model.Project)1 TemplateValidator.validateTemplate (org.jreleaser.model.validation.TemplateValidator.validateTemplate)1