Search in sources :

Example 1 with Checksum

use of org.jreleaser.model.Checksum in project jreleaser by jreleaser.

the class AbstractReleaserBuilder method configureWith.

@Override
public ReleaserBuilder<R> configureWith(JReleaserContext context) {
    this.context = context;
    GitService service = context.getModel().getRelease().getGitService();
    if (!service.resolveUploadAssetsEnabled(context.getModel().getProject())) {
        return this;
    }
    List<Asset> assets = new ArrayList<>();
    Checksum checksum = context.getModel().getChecksum();
    if (service.isFiles()) {
        for (Artifact artifact : Artifacts.resolveFiles(context)) {
            if (!artifact.isActive() || artifact.extraPropertyIsTrue(KEY_SKIP_RELEASE))
                continue;
            Path path = artifact.getEffectivePath(context);
            assets.add(Asset.file(Artifact.of(path, artifact.getExtraProperties())));
            if (service.isChecksums() && isIndividual(context, artifact) && !artifact.extraPropertyIsTrue(KEY_SKIP_CHECKSUM)) {
                for (Algorithm algorithm : checksum.getAlgorithms()) {
                    assets.add(Asset.checksum(Artifact.of(context.getChecksumsDirectory().resolve(path.getFileName() + "." + algorithm.formatted()))));
                }
            }
        }
    }
    if (service.isArtifacts()) {
        for (Distribution distribution : context.getModel().getActiveDistributions()) {
            if (distribution.extraPropertyIsTrue(KEY_SKIP_RELEASE)) {
                continue;
            }
            for (Artifact artifact : distribution.getArtifacts()) {
                if (!artifact.isActive() || artifact.extraPropertyIsTrue(KEY_SKIP_RELEASE))
                    continue;
                Path path = artifact.getEffectivePath(context, distribution);
                assets.add(Asset.file(Artifact.of(path, artifact.getExtraProperties()), distribution));
                if (service.isChecksums() && isIndividual(context, distribution, artifact)) {
                    for (Algorithm algorithm : checksum.getAlgorithms()) {
                        assets.add(Asset.checksum(Artifact.of(context.getChecksumsDirectory().resolve(distribution.getName()).resolve(path.getFileName() + "." + algorithm.formatted()))));
                    }
                }
            }
        }
    }
    if (service.isChecksums()) {
        for (Algorithm algorithm : checksum.getAlgorithms()) {
            Path checksums = context.getChecksumsDirectory().resolve(checksum.getResolvedName(context, algorithm));
            if (Files.exists(checksums)) {
                assets.add(Asset.checksum(Artifact.of(checksums)));
            }
        }
    }
    Signing signing = context.getModel().getSigning();
    if (signing.isEnabled() && service.isSignatures()) {
        boolean signaturesAdded = false;
        List<Asset> assetsCopy = new ArrayList<>(assets);
        for (Asset asset : assetsCopy) {
            if (asset.getArtifact().extraPropertyIsTrue(KEY_SKIP_SIGNING) || asset.getArtifact().extraPropertyIsTrue(KEY_SKIP_RELEASE_SIGNATURES))
                continue;
            Path signature = context.getSignaturesDirectory().resolve(asset.getFilename() + (signing.getSignatureExtension()));
            if (Files.exists(signature)) {
                assets.add(Asset.signature(Artifact.of(signature)));
                signaturesAdded = true;
            }
        }
        if (signaturesAdded && signing.getMode() == Signing.Mode.COSIGN) {
            Path publicKeyFile = signing.getCosign().getResolvedPublicKeyFilePath(context);
            assets.add(Asset.signature(Artifact.of(publicKeyFile)));
        }
    }
    assets.forEach(this::addReleaseAsset);
    return this;
}
Also used : Path(java.nio.file.Path) Signing(org.jreleaser.model.Signing) Checksum(org.jreleaser.model.Checksum) GitService(org.jreleaser.model.GitService) Distribution(org.jreleaser.model.Distribution) ArrayList(java.util.ArrayList) Algorithm(org.jreleaser.util.Algorithm) Artifact(org.jreleaser.model.Artifact)

Example 2 with Checksum

use of org.jreleaser.model.Checksum in project jreleaser by jreleaser.

the class AbstractArtifactUploader method collectArtifacts.

protected List<Artifact> collectArtifacts() {
    List<Artifact> artifacts = new ArrayList<>();
    List<String> keys = getUploader().resolveSkipKeys();
    Checksum checksum = context.getModel().getChecksum();
    boolean uploadChecksums = getUploader().isChecksums() && !(getUploader() instanceof Artifactory);
    if (getUploader().isFiles()) {
        for (Artifact artifact : Artifacts.resolveFiles(context)) {
            if (!artifact.isActive())
                continue;
            Path path = artifact.getEffectivePath(context);
            if (isSkip(artifact, keys))
                continue;
            if (Files.exists(path) && 0 != path.toFile().length()) {
                artifacts.add(artifact);
                if (uploadChecksums && isIndividual(context, artifact) && !artifact.extraPropertyIsTrue(KEY_SKIP_CHECKSUM)) {
                    for (Algorithm algorithm : checksum.getAlgorithms()) {
                        artifacts.add(Artifact.of(context.getChecksumsDirectory().resolve(path.getFileName() + "." + algorithm.formatted())));
                    }
                }
            }
        }
    }
    if (getUploader().isArtifacts()) {
        for (Distribution distribution : context.getModel().getActiveDistributions()) {
            if (isSkip(distribution, keys))
                continue;
            for (Artifact artifact : distribution.getArtifacts()) {
                if (!artifact.isActive())
                    continue;
                Path path = artifact.getEffectivePath(context, distribution);
                if (isSkip(artifact, keys))
                    continue;
                if (Files.exists(path) && 0 != path.toFile().length()) {
                    String platform = artifact.getPlatform();
                    String platformReplaced = distribution.getPlatform().applyReplacements(platform);
                    if (isNotBlank(platformReplaced)) {
                        artifact.getExtraProperties().put("platformReplaced", platformReplaced);
                    }
                    artifacts.add(artifact);
                    if (uploadChecksums && isIndividual(context, distribution, artifact)) {
                        for (Algorithm algorithm : checksum.getAlgorithms()) {
                            artifacts.add(Artifact.of(context.getChecksumsDirectory().resolve(distribution.getName()).resolve(path.getFileName() + "." + algorithm.formatted())));
                        }
                    }
                }
            }
        }
    }
    if (uploadChecksums) {
        for (Algorithm algorithm : checksum.getAlgorithms()) {
            Path checksums = context.getChecksumsDirectory().resolve(checksum.getResolvedName(context, algorithm));
            if (Files.exists(checksums)) {
                artifacts.add(Artifact.of(checksums));
            }
        }
    }
    Signing signing = context.getModel().getSigning();
    if (getUploader().isSignatures() && signing.isEnabled()) {
        String extension = signing.getSignatureExtension();
        List<Artifact> signatures = new ArrayList<>();
        for (Artifact artifact : artifacts) {
            if (artifact.extraPropertyIsTrue(KEY_SKIP_SIGNING))
                continue;
            Path signaturePath = context.getSignaturesDirectory().resolve(artifact.getEffectivePath(context).getFileName() + extension);
            if (Files.exists(signaturePath) && 0 != signaturePath.toFile().length()) {
                signatures.add(Artifact.of(signaturePath, artifact.getExtraProperties()));
            }
        }
        if (!signatures.isEmpty() && signing.getMode() == Signing.Mode.COSIGN) {
            Path publicKeyFile = signing.getCosign().getResolvedPublicKeyFilePath(context);
            signatures.add(Artifact.of(publicKeyFile));
        }
        artifacts.addAll(signatures);
    }
    return artifacts;
}
Also used : Path(java.nio.file.Path) Signing(org.jreleaser.model.Signing) Checksum(org.jreleaser.model.Checksum) Distribution(org.jreleaser.model.Distribution) ArrayList(java.util.ArrayList) Artifactory(org.jreleaser.model.Artifactory) Algorithm(org.jreleaser.util.Algorithm) Artifact(org.jreleaser.model.Artifact)

Example 3 with Checksum

use of org.jreleaser.model.Checksum in project jreleaser by jreleaser.

the class ChecksumValidator method validateChecksum.

public static void validateChecksum(JReleaserContext context, JReleaserContext.Mode mode, Errors errors) {
    context.getLogger().debug("checksum");
    Checksum checksum = context.getModel().getChecksum();
    if (!checksum.isIndividualSet()) {
        checksum.setIndividual(false);
    }
    if (isBlank(checksum.getName())) {
        checksum.setName("checksums.txt");
    }
    checksum.getAlgorithms().add(Algorithm.SHA_256);
}
Also used : Checksum(org.jreleaser.model.Checksum)

Aggregations

Checksum (org.jreleaser.model.Checksum)3 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 Artifact (org.jreleaser.model.Artifact)2 Distribution (org.jreleaser.model.Distribution)2 Signing (org.jreleaser.model.Signing)2 Algorithm (org.jreleaser.util.Algorithm)2 Artifactory (org.jreleaser.model.Artifactory)1 GitService (org.jreleaser.model.GitService)1