Search in sources :

Example 1 with ToolException

use of org.jreleaser.sdk.tool.ToolException in project jreleaser by jreleaser.

the class NativeImageAssemblerProcessor method upx.

private void upx(Path image) throws AssemblerProcessingException {
    Upx upx = new Upx(context, assembler.getUpx().getVersion());
    try {
        if (!upx.setup()) {
            context.getLogger().warn(RB.$("tool_unavailable", "upx"));
            return;
        }
    } catch (ToolException e) {
        throw new AssemblerProcessingException(e.getMessage(), e);
    }
    List<String> args = new ArrayList<>(assembler.getUpx().getArgs());
    args.add(image.getFileName().toString());
    context.getLogger().info("upx {}", image.getFileName().toString());
    try {
        upx.compress(image.getParent(), args);
    } catch (CommandException e) {
        throw new AssemblerProcessingException(RB.$("ERROR_unexpected_error"), e);
    }
}
Also used : AssemblerProcessingException(org.jreleaser.model.assembler.spi.AssemblerProcessingException) ArrayList(java.util.ArrayList) ToolException(org.jreleaser.sdk.tool.ToolException) CommandException(org.jreleaser.util.command.CommandException) Upx(org.jreleaser.sdk.tool.Upx)

Example 2 with ToolException

use of org.jreleaser.sdk.tool.ToolException in project jreleaser by jreleaser.

the class Signer method cosignSign.

private static void cosignSign(JReleaserContext context) throws SigningException {
    Signing signing = context.getModel().getSigning();
    Cosign cosign = new Cosign(context, signing.getCosign().getVersion());
    try {
        if (!cosign.setup()) {
            context.getLogger().warn(RB.$("tool_unavailable", "cosign"));
            return;
        }
    } catch (ToolException e) {
        throw new SigningException(e.getMessage(), e);
    }
    String privateKey = signing.getCosign().getResolvedPrivateKeyFile();
    String publicKey = signing.getCosign().getResolvedPublicKeyFile();
    Path privateKeyFile = isNotBlank(privateKey) ? context.getBasedir().resolve(privateKey) : null;
    Path publicKeyFile = isNotBlank(publicKey) ? context.getBasedir().resolve(publicKey) : null;
    byte[] password = (signing.getResolvedCosignPassword() + System.lineSeparator()).getBytes();
    boolean forceSign = false;
    if (null == privateKeyFile) {
        privateKeyFile = signing.getCosign().getResolvedPrivateKeyFilePath(context);
        publicKeyFile = privateKeyFile.resolveSibling("cosign.pub");
        if (!Files.exists(privateKeyFile)) {
            privateKeyFile = cosign.generateKeyPair(password);
            forceSign = true;
        }
    }
    Path thePublicKeyFile = publicKeyFile;
    List<FilePair> files = collectArtifacts(context, forceSign, pair -> isValid(context, cosign, thePublicKeyFile, pair));
    if (files.isEmpty()) {
        context.getLogger().info(RB.$("signing.no.match"));
        return;
    }
    files = files.stream().filter(FilePair::isInvalid).collect(Collectors.toList());
    if (files.isEmpty()) {
        context.getLogger().info(RB.$("signing.up.to.date"));
        return;
    }
    if (!cosign.checkPassword(privateKeyFile, password)) {
        context.getLogger().warn(RB.$("WARN_cosign_password_does_not_match", "cosign"));
        return;
    }
    sign(context, files, cosign, privateKeyFile, password);
    verify(context, files, cosign, publicKeyFile);
}
Also used : Path(java.nio.file.Path) Signing(org.jreleaser.model.Signing) SigningException(org.jreleaser.util.signing.SigningException) ToolException(org.jreleaser.sdk.tool.ToolException) Cosign(org.jreleaser.sdk.tool.Cosign)

Aggregations

ToolException (org.jreleaser.sdk.tool.ToolException)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Signing (org.jreleaser.model.Signing)1 AssemblerProcessingException (org.jreleaser.model.assembler.spi.AssemblerProcessingException)1 Cosign (org.jreleaser.sdk.tool.Cosign)1 Upx (org.jreleaser.sdk.tool.Upx)1 CommandException (org.jreleaser.util.command.CommandException)1 SigningException (org.jreleaser.util.signing.SigningException)1