Rework checksums

This commit is contained in:
crschnick 2024-01-03 09:15:53 +00:00
parent 0fef5b0b9a
commit ab8b6d449e
2 changed files with 22 additions and 4 deletions

View file

@ -49,10 +49,18 @@ project.ext {
website = 'https://xpipe.io'
sourceWebsite = 'https://github.com/xpipe-io/xpipe'
authors = 'Christopher Schnick'
artifactChecksums = new HashMap<String, String>()
javafxVersion = '21.0.1'
}
def getArtifactChecksumSha256Hex(String name) {
var file = layout.buildDirectory.file("dist/checksums/artifacts/${name}.sha256")
return file.get().getAsFile().exists() ? file.get().getAsFile().text : "";
}
def getArtifactChecksumSha256Base64(String name) {
return Base64.getEncoder().encodeToString(HexFormat.of().parseHex(getArtifactChecksumSha256Hex(name)))
}
def replaceVariablesInFileAsString(String f, Map<String, String> replacements) {
def fileName = file(f).getName()
def text = file(f).text

16
dist/build.gradle vendored
View file

@ -24,17 +24,27 @@ distZip {
enabled = false;
}
import org.gradle.crypto.checksum.Checksum
import java.util.stream.Collectors
def distDir = layout.buildDirectory.get().dir('dist')
task createChecksums(type: Checksum) {
inputFiles.setFrom(distDir.dir('artifacts').getAsFileTree().files)
outputDirectory.set(layout.buildDirectory.dir("dist/checksums"))
outputDirectory.set(layout.buildDirectory.dir("dist/checksums/artifacts"))
checksumAlgorithm.set(Checksum.Algorithm.SHA256)
doLast {
for (final def file in distDir.dir('checksums').getAsFileTree().files) {
artifactChecksums.put(file.name.lastIndexOf('.').with {it != -1 ? file.name[0..<it] : file.name}, file.text.trim())
def artifactChecksumsSha256Hex = new HashMap<String, String>()
for (final def file in outputDirectory.get().getAsFileTree().files) {
def name = file.name.lastIndexOf('.').with {it != -1 ? file.name[0..<it] : file.name}
artifactChecksumsSha256Hex.put(name, file.text.trim())
}
file(layout.buildDirectory.dir("dist/checksums/sha256sums.txt")).text = artifactChecksumsSha256Hex.entrySet().stream()
.map(e -> e.getValue() + ' ' + e.getKey())
.collect(Collectors.joining('\n'))
}
}