Search in sources :

Example 1 with MAGIC_SET

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

the class SdkmanAnnouncer method announce.

@Override
public void announce() throws AnnounceException {
    Map<String, Distribution> distributions = context.getModel().getActiveDistributions().stream().filter(d -> d.getSdkman().isEnabled()).filter(d -> !JReleaserCommand.supportsPublish(context.getCommand()) || d.getSdkman().isPublished()).collect(Collectors.toMap(distribution -> {
        Sdkman sdkman = distribution.getSdkman();
        return isNotBlank(sdkman.getCandidate()) ? sdkman.getCandidate().trim() : context.getModel().getProject().getName();
    }, distribution -> distribution));
    Boolean set = (Boolean) context.getModel().getAnnounce().getSdkman().getExtraProperties().remove(MAGIC_SET);
    if (distributions.isEmpty()) {
        if (set == null || !set) {
            announceProject();
        } else {
            context.getLogger().debug(RB.$("announcers.announcer.disabled"));
        }
        return;
    }
    boolean failures = false;
    for (Map.Entry<String, Distribution> e : distributions.entrySet()) {
        String candidate = e.getKey();
        Distribution distribution = e.getValue();
        Sdkman sdkman = distribution.getSdkman();
        Map<String, Object> props = context.fullProps();
        props.putAll(distribution.props());
        String releaseNotesUrl = resolveTemplate(sdkman.getReleaseNotesUrl(), props);
        String command = sdkman.getCommand().name().toLowerCase();
        context.getLogger().info(RB.$("sdkman.release.announce"), command, candidate);
        try {
            AnnounceSdkmanCommand.builder(context.getLogger()).connectTimeout(sdkman.getConnectTimeout()).readTimeout(sdkman.getReadTimeout()).consumerKey(context.isDryrun() ? "**UNDEFINED**" : sdkman.getResolvedConsumerKey()).consumerToken(context.isDryrun() ? "**UNDEFINED**" : sdkman.getResolvedConsumerToken()).candidate(candidate).version(context.getModel().getProject().getVersion()).releaseNotesUrl(releaseNotesUrl).dryrun(context.isDryrun()).build().execute();
        } catch (SdkmanException x) {
            context.getLogger().warn(x.getMessage().trim());
            failures = true;
        }
    }
    if (failures) {
        throw new AnnounceException(RB.$("ERROR_sdkman_announce"));
    }
}
Also used : StringUtils.isTrue(org.jreleaser.util.StringUtils.isTrue) Sdkman(org.jreleaser.model.Sdkman) Collectors(java.util.stream.Collectors) StringUtils.isNotBlank(org.jreleaser.util.StringUtils.isNotBlank) LinkedHashMap(java.util.LinkedHashMap) AnnounceException(org.jreleaser.model.announcer.spi.AnnounceException) Announcer(org.jreleaser.model.announcer.spi.Announcer) JReleaserCommand(org.jreleaser.model.JReleaserCommand) Map(java.util.Map) MAGIC_SET(org.jreleaser.util.Constants.MAGIC_SET) JReleaserContext(org.jreleaser.model.JReleaserContext) SdkmanHelper.collectArtifacts(org.jreleaser.model.util.SdkmanHelper.collectArtifacts) Distribution(org.jreleaser.model.Distribution) RB(org.jreleaser.bundle.RB) Templates.resolveTemplate(org.jreleaser.util.Templates.resolveTemplate) AnnounceException(org.jreleaser.model.announcer.spi.AnnounceException) Sdkman(org.jreleaser.model.Sdkman) Distribution(org.jreleaser.model.Distribution) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 RB (org.jreleaser.bundle.RB)1 Distribution (org.jreleaser.model.Distribution)1 JReleaserCommand (org.jreleaser.model.JReleaserCommand)1 JReleaserContext (org.jreleaser.model.JReleaserContext)1 Sdkman (org.jreleaser.model.Sdkman)1 AnnounceException (org.jreleaser.model.announcer.spi.AnnounceException)1 Announcer (org.jreleaser.model.announcer.spi.Announcer)1 SdkmanHelper.collectArtifacts (org.jreleaser.model.util.SdkmanHelper.collectArtifacts)1 MAGIC_SET (org.jreleaser.util.Constants.MAGIC_SET)1 StringUtils.isNotBlank (org.jreleaser.util.StringUtils.isNotBlank)1 StringUtils.isTrue (org.jreleaser.util.StringUtils.isTrue)1 Templates.resolveTemplate (org.jreleaser.util.Templates.resolveTemplate)1