Skip to content

Commit

Permalink
fix generating checksum for non jar files
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyDev05 committed Jan 15, 2025
1 parent 85412d4 commit fbc2045
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "de.crazydev22"
version = "1.0.2"
version = "1.0.3"

repositories {
mavenCentral()
Expand Down
9 changes: 3 additions & 6 deletions src/main/kotlin/de/crazydev22/libbyjar/func/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ internal fun Project.addDependency(ext: LibbyJarExtension) {
dependencies.add(ext.config.get(), "net.byteflux:libby-${ext.type.get()}:${ext.version.get()}")
}

internal fun File.checksum(algorithm: String = "SHA-256", bufferSize: Int = 4096): String {
val md = MessageDigest.getInstance(algorithm)
forEachBlock(bufferSize) { buffer, bytesRead -> md.update(buffer, 0, bytesRead) }
return md.toHex()
internal fun File.checksum(algorithm: String = "SHA-256"): String {
return MessageDigest.getInstance(algorithm).digest(readBytes()).toBase64()
}

internal fun MessageDigest.toHex(): String = digest().toHex()
internal fun ByteArray.toHex() = Base64.getEncoder().encodeToString(this)
internal fun ByteArray.toBase64() = Base64.getEncoder().encodeToString(this)

internal fun File.createDirectory(): File {
if (!exists()) mkdirs()
Expand Down
16 changes: 10 additions & 6 deletions src/main/kotlin/de/crazydev22/libbyjar/task/LibbyJarTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,15 @@ public abstract class LibbyJarTask @Inject constructor(
private fun String.sha256(): String? {
if (!extension.checksum.get() || count { it == ':' } == 3)
return null
return project.configurations
.detachedConfiguration(project.dependencyFactory.create(this))
.setTransitive(false)
.resolve()
.firstOrNull()
?.checksum()

return try {
project.configurations
.detachedConfiguration(project.dependencyFactory.create("$this@jar"))
.setTransitive(false)
.resolve()
.firstOrNull()
?.checksum()
} catch (_: Throwable) { "error" }
}

private fun RepositoryHandler.getMavenRepos() = this.filterIsInstance<MavenArtifactRepository>()
Expand All @@ -131,6 +134,7 @@ public abstract class LibbyJarTask @Inject constructor(
RenderableModuleResult(this.resolutionResult.root).children
.mapNotNull { it.toLibbyDependency() }
.filterNot { it.artifactId.endsWith("-bom") }
.filterNot { it.sha256 == "error" }

protected open fun withShadowTask(
action: ShadowJar.() -> Unit
Expand Down

0 comments on commit fbc2045

Please sign in to comment.