Skip to content

Commit

Permalink
[checksum] Finer control for uploading checksums
Browse files Browse the repository at this point in the history
- Only upload matching checksum files. Fixes #290
- artifact/distribution provide individual checksum hint. Resolves #293
  • Loading branch information
aalmiray committed Jul 16, 2021
1 parent 54dc902 commit 65ab5a5
Showing 1 changed file with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
import java.util.List;

import static java.util.Objects.requireNonNull;
import static org.jreleaser.util.StringUtils.isTrue;

/**
* @author Andres Almiray
* @since 0.1.0
*/
public abstract class AbstractReleaserBuilder<R extends Releaser> implements ReleaserBuilder<R> {
private static final String INDIVIDUAL_CHECKSUM = "individualChecksum";
protected final List<Path> assets = new ArrayList<>();
protected JReleaserContext context;

Expand Down Expand Up @@ -78,7 +80,7 @@ public ReleaserBuilder<R> configureWith(JReleaserContext context) {
for (Artifact artifact : Artifacts.resolveFiles(context)) {
Path path = artifact.getEffectivePath(context);
addReleaseAsset(path);
if (uploadIndividualChecksums) {
if (isIndividual(context, artifact)) {
for (Algorithm algorithm : context.getModel().getChecksum().getAlgorithms()) {
addReleaseAsset(context.getChecksumsDirectory()
.resolve(path.getFileName() + "." + algorithm.formatted()));
Expand All @@ -88,10 +90,15 @@ public ReleaserBuilder<R> configureWith(JReleaserContext context) {

for (Distribution distribution : context.getModel().getActiveDistributions()) {
for (Artifact artifact : distribution.getArtifacts()) {
addReleaseAsset(artifact.getEffectivePath(context, distribution));
}
if (uploadIndividualChecksums) {
addReleaseAssets(context.getChecksumsDirectory().resolve(distribution.getName()));
Path path = artifact.getEffectivePath(context, distribution);
addReleaseAsset(path);
if (isIndividual(context, distribution, artifact)) {
for (Algorithm algorithm : context.getModel().getChecksum().getAlgorithms()) {
addReleaseAsset(context.getChecksumsDirectory()
.resolve(distribution.getName())
.resolve(path.getFileName() + "." + algorithm.formatted()));
}
}
}
}

Expand All @@ -109,4 +116,21 @@ public ReleaserBuilder<R> configureWith(JReleaserContext context) {

return this;
}

private boolean isIndividual(JReleaserContext context, Artifact artifact) {
if (artifact.getExtraProperties().containsKey(INDIVIDUAL_CHECKSUM)) {
return isTrue(artifact.getExtraProperties().get(INDIVIDUAL_CHECKSUM));
}
return context.getModel().getChecksum().isIndividual();
}

private boolean isIndividual(JReleaserContext context, Distribution distribution, Artifact artifact) {
if (artifact.getExtraProperties().containsKey(INDIVIDUAL_CHECKSUM)) {
return isTrue(artifact.getExtraProperties().get(INDIVIDUAL_CHECKSUM));
}
if (distribution.getExtraProperties().containsKey(INDIVIDUAL_CHECKSUM)) {
return isTrue(distribution.getExtraProperties().get(INDIVIDUAL_CHECKSUM));
}
return context.getModel().getChecksum().isIndividual();
}
}

0 comments on commit 65ab5a5

Please sign in to comment.