Search in sources :

Example 1 with KEY_BREW_DEPENDENCIES

use of org.jreleaser.util.Constants.KEY_BREW_DEPENDENCIES in project jreleaser by jreleaser.

the class BrewPackagerProcessor method fillPackagerProperties.

@Override
protected void fillPackagerProperties(Map<String, Object> props, Distribution distribution) throws PackagerProcessingException {
    GitService gitService = context.getModel().getRelease().getGitService();
    props.put(KEY_BREW_FORMULA_NAME, packager.getResolvedFormulaName(props));
    props.put(KEY_HOMEBREW_TAP_REPO_URL, gitService.getResolvedRepoUrl(context.getModel(), packager.getTap().getOwner(), packager.getTap().getResolvedName()));
    props.put(KEY_HOMEBREW_TAP_REPO_CLONE_URL, gitService.getResolvedRepoCloneUrl(context.getModel(), packager.getTap().getOwner(), packager.getTap().getResolvedName()));
    props.put(KEY_BREW_HAS_LIVECHECK, packager.hasLivecheck());
    if (packager.hasLivecheck()) {
        props.put(KEY_BREW_LIVECHECK, packager.getLivecheck().stream().map(line -> resolveTemplate(line, props)).map(MustacheUtils::passThrough).collect(Collectors.toList()));
    }
    Brew.Cask cask = packager.getCask();
    if (cask.isEnabled()) {
        boolean hasPkg = isNotBlank(cask.getPkgName());
        boolean hasApp = isNotBlank(cask.getAppName());
        props.put(KEY_BREW_CASK_NAME, cask.getResolvedCaskName(props));
        props.put(KEY_BREW_CASK_DISPLAY_NAME, cask.getResolvedDisplayName(props));
        props.put(KEY_BREW_CASK_HAS_UNINSTALL, !cask.getUninstallItems().isEmpty());
        props.put(KEY_BREW_CASK_HAS_PKG, hasPkg);
        if (hasPkg) {
            props.put(KEY_BREW_CASK_PKG, cask.getResolvedPkgName(props));
        }
        props.put(KEY_BREW_CASK_HAS_APP, hasApp);
        if (hasApp) {
            props.put(KEY_BREW_CASK_APP, cask.getResolvedAppName(props));
        }
        props.put(KEY_BREW_CASK_UNINSTALL, cask.getUninstallItems());
        props.put(KEY_BREW_CASK_HAS_ZAP, !cask.getZapItems().isEmpty());
        props.put(KEY_BREW_CASK_ZAP, cask.getZapItems());
        String appcast = cask.getResolvedAppcast(props);
        props.put(KEY_BREW_CASK_HAS_APPCAST, isNotBlank(appcast));
        props.put(KEY_BREW_CASK_APPCAST, appcast);
        if (!hasApp && !hasPkg) {
            for (Artifact artifact : collectArtifacts(distribution)) {
                if (artifact.getPath().endsWith(ZIP.extension())) {
                    props.put(KEY_DISTRIBUTION_URL, resolveArtifactUrl(props, distribution, artifact));
                    props.put(KEY_BREW_CASK_HAS_BINARY, true);
                    break;
                }
            }
        }
    } else if (packager.isMultiPlatform()) {
        List<String> multiPlatforms = new ArrayList<>();
        for (Artifact artifact : collectArtifacts(distribution)) {
            if (!artifact.getPath().endsWith(ZIP.extension()) || isBlank(artifact.getPlatform()))
                continue;
            String template = null;
            String artifactUrl = resolveArtifactUrl(props, distribution, artifact);
            if (PlatformUtils.isMac(artifact.getPlatform())) {
                if (PlatformUtils.isArm(artifact.getPlatform())) {
                    template = TPL_MAC_ARM;
                } else {
                    template = TPL_MAC_INTEL;
                }
            } else if (PlatformUtils.isLinux(artifact.getPlatform())) {
                if (PlatformUtils.isArm(artifact.getPlatform())) {
                    template = TPL_LINUX_ARM;
                } else {
                    template = TPL_LINUX_INTEL;
                }
            }
            if (isNotBlank(template)) {
                Map<String, Object> newProps = new LinkedHashMap<>(props);
                newProps.put(KEY_DISTRIBUTION_URL, artifactUrl);
                newProps.put(KEY_DISTRIBUTION_CHECKSUM_SHA_256, artifact.getHash(Algorithm.SHA_256));
                multiPlatforms.add(resolveTemplate(template, newProps));
            }
        }
        if (multiPlatforms.isEmpty()) {
            throw new PackagerProcessingException(org.jreleaser.bundle.RB.$("ERROR_brew_multiplatform_artifacts"));
        }
        props.put(KEY_BREW_MULTIPLATFORM, passThrough(String.join(System.lineSeparator() + "  ", multiPlatforms)));
    } else if ((distribution.getType() == Distribution.DistributionType.JAVA_BINARY || distribution.getType() == Distribution.DistributionType.SINGLE_JAR) && !isTrue(packager.getExtraProperties().get(SKIP_JAVA))) {
        packager.addDependency("openjdk@" + props.get(KEY_DISTRIBUTION_JAVA_VERSION));
    }
    props.put(KEY_BREW_DEPENDENCIES, packager.getDependenciesAsList().stream().map(dependency -> passThrough(dependency.toString())).collect(Collectors.toList()));
}
Also used : TemplateUtils.trimTplExtension(org.jreleaser.templates.TemplateUtils.trimTplExtension) MustacheUtils.passThrough(org.jreleaser.util.MustacheUtils.passThrough) KEY_BREW_MULTIPLATFORM(org.jreleaser.util.Constants.KEY_BREW_MULTIPLATFORM) Artifact(org.jreleaser.model.Artifact) KEY_BREW_FORMULA_NAME(org.jreleaser.util.Constants.KEY_BREW_FORMULA_NAME) StringUtils.isTrue(org.jreleaser.util.StringUtils.isTrue) KEY_DISTRIBUTION_URL(org.jreleaser.util.Constants.KEY_DISTRIBUTION_URL) KEY_BREW_CASK_HAS_PKG(org.jreleaser.util.Constants.KEY_BREW_CASK_HAS_PKG) PackagerProcessingException(org.jreleaser.model.packager.spi.PackagerProcessingException) KEY_BREW_CASK_APPCAST(org.jreleaser.util.Constants.KEY_BREW_CASK_APPCAST) KEY_BREW_DEPENDENCIES(org.jreleaser.util.Constants.KEY_BREW_DEPENDENCIES) StringUtils.isBlank(org.jreleaser.util.StringUtils.isBlank) StringUtils.isNotBlank(org.jreleaser.util.StringUtils.isNotBlank) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) KEY_BREW_CASK_UNINSTALL(org.jreleaser.util.Constants.KEY_BREW_CASK_UNINSTALL) KEY_BREW_CASK_HAS_BINARY(org.jreleaser.util.Constants.KEY_BREW_CASK_HAS_BINARY) KEY_BREW_CASK_DISPLAY_NAME(org.jreleaser.util.Constants.KEY_BREW_CASK_DISPLAY_NAME) KEY_BREW_HAS_LIVECHECK(org.jreleaser.util.Constants.KEY_BREW_HAS_LIVECHECK) ZIP(org.jreleaser.util.FileType.ZIP) Map(java.util.Map) JReleaserContext(org.jreleaser.model.JReleaserContext) Distribution(org.jreleaser.model.Distribution) Path(java.nio.file.Path) KEY_BREW_LIVECHECK(org.jreleaser.util.Constants.KEY_BREW_LIVECHECK) KEY_BREW_CASK_PKG(org.jreleaser.util.Constants.KEY_BREW_CASK_PKG) Templates.resolveTemplate(org.jreleaser.util.Templates.resolveTemplate) KEY_DISTRIBUTION_JAVA_VERSION(org.jreleaser.util.Constants.KEY_DISTRIBUTION_JAVA_VERSION) Algorithm(org.jreleaser.util.Algorithm) KEY_BREW_CASK_HAS_ZAP(org.jreleaser.util.Constants.KEY_BREW_CASK_HAS_ZAP) Brew(org.jreleaser.model.Brew) KEY_BREW_CASK_APP(org.jreleaser.util.Constants.KEY_BREW_CASK_APP) KEY_BREW_CASK_HAS_APPCAST(org.jreleaser.util.Constants.KEY_BREW_CASK_HAS_APPCAST) PlatformUtils(org.jreleaser.util.PlatformUtils) Collectors(java.util.stream.Collectors) Project(org.jreleaser.model.Project) KEY_HOMEBREW_TAP_REPO_URL(org.jreleaser.util.Constants.KEY_HOMEBREW_TAP_REPO_URL) List(java.util.List) KEY_BREW_CASK_ZAP(org.jreleaser.util.Constants.KEY_BREW_CASK_ZAP) MustacheUtils(org.jreleaser.util.MustacheUtils) GitService(org.jreleaser.model.GitService) KEY_BREW_CASK_HAS_UNINSTALL(org.jreleaser.util.Constants.KEY_BREW_CASK_HAS_UNINSTALL) KEY_BREW_CASK_HAS_APP(org.jreleaser.util.Constants.KEY_BREW_CASK_HAS_APP) KEY_HOMEBREW_TAP_REPO_CLONE_URL(org.jreleaser.util.Constants.KEY_HOMEBREW_TAP_REPO_CLONE_URL) Artifacts(org.jreleaser.model.util.Artifacts) KEY_BREW_CASK_NAME(org.jreleaser.util.Constants.KEY_BREW_CASK_NAME) MustacheUtils(org.jreleaser.util.MustacheUtils) Artifact(org.jreleaser.model.Artifact) GitService(org.jreleaser.model.GitService) PackagerProcessingException(org.jreleaser.model.packager.spi.PackagerProcessingException) ArrayList(java.util.ArrayList) List(java.util.List) Brew(org.jreleaser.model.Brew) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Artifact (org.jreleaser.model.Artifact)1 Brew (org.jreleaser.model.Brew)1 Distribution (org.jreleaser.model.Distribution)1 GitService (org.jreleaser.model.GitService)1 JReleaserContext (org.jreleaser.model.JReleaserContext)1 Project (org.jreleaser.model.Project)1 PackagerProcessingException (org.jreleaser.model.packager.spi.PackagerProcessingException)1 Artifacts (org.jreleaser.model.util.Artifacts)1 TemplateUtils.trimTplExtension (org.jreleaser.templates.TemplateUtils.trimTplExtension)1 Algorithm (org.jreleaser.util.Algorithm)1 KEY_BREW_CASK_APP (org.jreleaser.util.Constants.KEY_BREW_CASK_APP)1 KEY_BREW_CASK_APPCAST (org.jreleaser.util.Constants.KEY_BREW_CASK_APPCAST)1 KEY_BREW_CASK_DISPLAY_NAME (org.jreleaser.util.Constants.KEY_BREW_CASK_DISPLAY_NAME)1 KEY_BREW_CASK_HAS_APP (org.jreleaser.util.Constants.KEY_BREW_CASK_HAS_APP)1