Search in sources :

Example 26 with JReleaserException

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);
    }
}
Also used : IOException(java.io.IOException) JReleaserException(org.jreleaser.util.JReleaserException)

Example 27 with JReleaserException

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);
    }
}
Also used : IOException(java.io.IOException) JReleaserException(org.jreleaser.util.JReleaserException)

Example 28 with JReleaserException

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)));
    }
}
Also used : Path(java.nio.file.Path) Reader(java.io.Reader) IOException(java.io.IOException) JReleaserException(org.jreleaser.util.JReleaserException)

Example 29 with JReleaserException

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)));
    }
}
Also used : Path(java.nio.file.Path) Reader(java.io.Reader) IOException(java.io.IOException) JReleaserException(org.jreleaser.util.JReleaserException)

Example 30 with JReleaserException

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)));
    }
}
Also used : Path(java.nio.file.Path) Reader(java.io.Reader) IOException(java.io.IOException) JReleaserException(org.jreleaser.util.JReleaserException)

Aggregations

JReleaserException (org.jreleaser.util.JReleaserException)31 IOException (java.io.IOException)23 Path (java.nio.file.Path)22 Reader (java.io.Reader)15 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 Artifact (org.jreleaser.model.Artifact)3 PrintWriter (java.io.PrintWriter)2 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)2 FileSystem (java.nio.file.FileSystem)2 PathMatcher (java.nio.file.PathMatcher)2 Map (java.util.Map)2 Scanner (java.util.Scanner)2 JReleaserModel (org.jreleaser.model.JReleaserModel)2 ResolvedType (com.fasterxml.classmate.ResolvedType)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)1 Option (com.github.victools.jsonschema.generator.Option)1 OptionPreset (com.github.victools.jsonschema.generator.OptionPreset)1 SchemaGenerationContext (com.github.victools.jsonschema.generator.SchemaGenerationContext)1