Search in sources :

Example 1 with AnnounceException

use of org.jreleaser.model.announcer.spi.AnnounceException in project jreleaser by jreleaser.

the class ArticleAnnouncer method prepareFiles.

private void prepareFiles(Path prepareDirectory) throws AnnounceException {
    Path templateDirectory = context.getBasedir().resolve(article.getTemplateDirectory());
    try {
        FileUtils.deleteFiles(prepareDirectory);
        Files.createDirectories(prepareDirectory);
    } catch (IOException e) {
        context.getLogger().trace(e);
        throw new AnnounceException(RB.$("ERROR_unexpected_article_announcer", context.relativizeToBasedir(templateDirectory)), e);
    }
    context.getLogger().debug(RB.$("announcer.article.resolve.templates"));
    Map<String, Object> props = context.fullProps();
    props.put(Constants.KEY_CHANGELOG, passThrough(context.getChangelog()));
    context.getModel().getRelease().getGitService().fillProps(props, context.getModel());
    props.putAll(article.getResolvedExtraProperties());
    try {
        for (Artifact file : article.getFiles()) {
            Path input = file.getResolvedPath(context, templateDirectory, true);
            Path output = file.getResolvedTransform(context, prepareDirectory);
            if (null == output) {
                output = file.getResolvedPath(context, prepareDirectory, false);
            }
            Reader reader = Files.newBufferedReader(input);
            context.getLogger().debug(RB.$("announcer.article.eval.template"), context.relativizeToBasedir(input));
            String content = applyTemplate(reader, props);
            context.getLogger().debug(RB.$("announcer.article.write.template"), context.relativizeToBasedir(input));
            writeFile(content, output);
        }
    } catch (JReleaserException e) {
        context.getLogger().warn(e.getMessage());
        context.getLogger().trace(e);
        throw new AnnounceException(RB.$("ERROR_unexpected_template_resolution", context.relativizeToBasedir(templateDirectory)), e);
    } catch (IOException e) {
        context.getLogger().trace(e);
        throw new AnnounceException(RB.$("ERROR_unexpected_template_resolution", context.relativizeToBasedir(templateDirectory)), e);
    }
}
Also used : Path(java.nio.file.Path) AnnounceException(org.jreleaser.model.announcer.spi.AnnounceException) Reader(java.io.Reader) IOException(java.io.IOException) Artifact(org.jreleaser.model.Artifact) JReleaserException(org.jreleaser.util.JReleaserException)

Example 2 with AnnounceException

use of org.jreleaser.model.announcer.spi.AnnounceException in project jreleaser by jreleaser.

the class ArticleAnnouncer method writeFile.

private void writeFile(String content, Path outputFile) throws AnnounceException {
    try {
        createDirectoriesWithFullAccess(outputFile.getParent());
        Files.write(outputFile, content.getBytes(), CREATE, WRITE, TRUNCATE_EXISTING);
    } catch (IOException e) {
        throw new AnnounceException(RB.$("ERROR_unexpected_error_writing_file", outputFile.toAbsolutePath()), e);
    }
}
Also used : AnnounceException(org.jreleaser.model.announcer.spi.AnnounceException) IOException(java.io.IOException)

Example 3 with AnnounceException

use of org.jreleaser.model.announcer.spi.AnnounceException in project jreleaser by jreleaser.

the class ClientUtils method webhook.

public static void webhook(JReleaserLogger logger, String webhookUrl, int connectTimeout, int readTimeout, Object message) throws AnnounceException {
    if (message instanceof String) {
        webhook(logger, webhookUrl, connectTimeout, readTimeout, (String) message);
    }
    try {
        ObjectMapper objectMapper = new ObjectMapper();
        webhook(logger, webhookUrl, connectTimeout, readTimeout, objectMapper.writeValueAsString(message));
    } catch (JsonProcessingException e) {
        throw new AnnounceException(e);
    }
}
Also used : AnnounceException(org.jreleaser.model.announcer.spi.AnnounceException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with AnnounceException

use of org.jreleaser.model.announcer.spi.AnnounceException in project jreleaser by jreleaser.

the class MailAnnouncer method announce.

@Override
public void announce() throws AnnounceException {
    Mail mail = context.getModel().getAnnounce().getMail();
    String message = "";
    if (isNotBlank(mail.getMessage())) {
        message = mail.getResolvedMessage(context);
    } else {
        Map<String, Object> props = new LinkedHashMap<>();
        props.put(Constants.KEY_CHANGELOG, MustacheUtils.passThrough(context.getChangelog()));
        context.getModel().getRelease().getGitService().fillProps(props, context.getModel());
        message = mail.getResolvedMessageTemplate(context, props);
    }
    String subject = mail.getResolvedSubject(context);
    context.getLogger().info("subject: {}", subject);
    context.getLogger().debug("message: {}", message);
    try {
        MessageMailCommand.builder(context.getLogger()).dryrun(context.isDryrun()).transport(mail.getTransport()).host(mail.getHost()).port(mail.getPort()).auth(mail.isAuth()).username(mail.getUsername()).password(context.isDryrun() ? "**UNDEFINED**" : mail.getResolvedPassword()).from(mail.getFrom()).to(mail.getTo()).cc(mail.getCc()).bcc(mail.getBcc()).subject(subject).message(message).mimeType(mail.getMimeType()).build().execute();
    } catch (MailException e) {
        context.getLogger().trace(e);
        throw new AnnounceException(e);
    }
}
Also used : AnnounceException(org.jreleaser.model.announcer.spi.AnnounceException) Mail(org.jreleaser.model.Mail) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with AnnounceException

use of org.jreleaser.model.announcer.spi.AnnounceException 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

AnnounceException (org.jreleaser.model.announcer.spi.AnnounceException)15 LinkedHashMap (java.util.LinkedHashMap)8 IOException (java.io.IOException)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Reader (java.io.Reader)2 Path (java.nio.file.Path)2 Distribution (org.jreleaser.model.Distribution)2 JReleaserException (org.jreleaser.util.JReleaserException)2 InputStreamReader (java.io.InputStreamReader)1 OutputStream (java.io.OutputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 CommitCommand (org.eclipse.jgit.api.CommitCommand)1 Git (org.eclipse.jgit.api.Git)1 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)1 RB (org.jreleaser.bundle.RB)1