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);
}
}
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);
}
}
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);
}
}
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);
}
}
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"));
}
}
Aggregations