use of org.jreleaser.util.JReleaserException in project jreleaser by jreleaser.
the class Checksum method readHash.
private static void readHash(JReleaserContext context, Algorithm algorithm, Artifact artifact, Path artifactPath, Path checksumPath) throws JReleaserException {
if (!Files.exists(artifactPath)) {
throw new JReleaserException(RB.$("ERROR_artifact_does_not_exist", context.relativizeToBasedir(artifactPath)));
}
if (!Files.exists(checksumPath)) {
context.getLogger().debug(RB.$("checksum.not.exist"), context.relativizeToBasedir(checksumPath));
calculateHash(context, artifactPath, checksumPath, algorithm);
} else if (artifactPath.toFile().lastModified() > checksumPath.toFile().lastModified()) {
context.getLogger().debug(RB.$("checksum.file.newer"), context.relativizeToBasedir(artifactPath), context.relativizeToBasedir(checksumPath));
calculateHash(context, artifactPath, checksumPath, algorithm);
}
try {
context.getLogger().debug(RB.$("checksum.reading"), context.relativizeToBasedir(checksumPath));
artifact.setHash(algorithm, new String(Files.readAllBytes(checksumPath)));
} catch (IOException e) {
throw new JReleaserException(RB.$("ERROR_unexpected_error_hash_read", context.relativizeToBasedir(checksumPath)), e);
}
}
use of org.jreleaser.util.JReleaserException in project jreleaser by jreleaser.
the class Checksum method calculateHash.
public static String calculateHash(JReleaserContext context, Path input, Path output, Algorithm algorithm) throws JReleaserException {
try {
context.getLogger().info("{}.{}", context.relativizeToBasedir(input), algorithm.formatted());
String hashcode = ChecksumUtils.checksum(algorithm, Files.readAllBytes(input));
output.toFile().getParentFile().mkdirs();
Files.write(output, hashcode.getBytes());
return hashcode;
} catch (IOException e) {
throw new JReleaserException(RB.$("ERROR_unexpected_error_calculate_checksum", input), e);
}
}
use of org.jreleaser.util.JReleaserException in project jreleaser by jreleaser.
the class Gitter method getResolvedMessageTemplate.
public String getResolvedMessageTemplate(JReleaserContext context, Map<String, Object> extraProps) {
Map<String, Object> props = context.fullProps();
applyTemplates(props, getResolvedExtraProperties());
props.put(KEY_TAG_NAME, context.getModel().getRelease().getGitService().getEffectiveTagName(context.getModel()));
props.putAll(extraProps);
Path templatePath = context.getBasedir().resolve(messageTemplate);
try {
Reader reader = java.nio.file.Files.newBufferedReader(templatePath);
return applyTemplate(reader, props);
} catch (IOException e) {
throw new JReleaserException(RB.$("ERROR_unexpected_error_reading_template", context.relativizeToBasedir(templatePath)));
}
}
use of org.jreleaser.util.JReleaserException in project jreleaser by jreleaser.
the class Mail method getResolvedMessageTemplate.
public String getResolvedMessageTemplate(JReleaserContext context, Map<String, Object> extraProps) {
Map<String, Object> props = context.fullProps();
applyTemplates(props, getResolvedExtraProperties());
props.put(KEY_TAG_NAME, context.getModel().getRelease().getGitService().getEffectiveTagName(context.getModel()));
props.putAll(extraProps);
Path templatePath = context.getBasedir().resolve(messageTemplate);
try {
Reader reader = java.nio.file.Files.newBufferedReader(templatePath);
return applyTemplate(reader, props);
} catch (IOException e) {
throw new JReleaserException(RB.$("ERROR_unexpected_error_reading_template", context.relativizeToBasedir(templatePath)));
}
}
use of org.jreleaser.util.JReleaserException in project jreleaser by jreleaser.
the class Discord method getResolvedMessageTemplate.
public String getResolvedMessageTemplate(JReleaserContext context, Map<String, Object> extraProps) {
Map<String, Object> props = context.fullProps();
applyTemplates(props, getResolvedExtraProperties());
props.put(KEY_TAG_NAME, context.getModel().getRelease().getGitService().getEffectiveTagName(context.getModel()));
props.putAll(extraProps);
Path templatePath = context.getBasedir().resolve(messageTemplate);
try {
Reader reader = java.nio.file.Files.newBufferedReader(templatePath);
return applyTemplate(reader, props);
} catch (IOException e) {
throw new JReleaserException(RB.$("ERROR_unexpected_error_reading_template", context.relativizeToBasedir(templatePath)));
}
}
Aggregations