diff --git a/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamExtension.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamExtension.kt index e1824591..860f66bb 100644 --- a/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamExtension.kt +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamExtension.kt @@ -80,7 +80,10 @@ abstract class CloudstreamExtension @Inject constructor(project: Project) { internal var pluginClassName: String? = null internal var fileSize: Long? = null + internal var fileHash: String? = null + internal var jarFileSize: Long? = null + internal var jarHash: String? = null var requiresResources = false var description: String? = null diff --git a/src/main/kotlin/com/lagradost/cloudstream3/gradle/Utils.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/Utils.kt index 68ddfb2e..7f5636f2 100644 --- a/src/main/kotlin/com/lagradost/cloudstream3/gradle/Utils.kt +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/Utils.kt @@ -2,6 +2,8 @@ package com.lagradost.cloudstream3.gradle import org.gradle.api.Project import com.lagradost.cloudstream3.gradle.entities.* +import java.io.File +import java.security.MessageDigest fun Project.makeManifest(): PluginManifest { val extension = this.extensions.getCloudstream() @@ -23,6 +25,20 @@ fun Project.makeManifest(): PluginManifest { ) } +fun sha256(file: File): String { + val digest = MessageDigest.getInstance("SHA-256") + + file.inputStream().use { fis -> + val buffer = ByteArray(8192) + var read = fis.read(buffer) + while (read != -1) { + digest.update(buffer, 0, read) + read = fis.read(buffer) + } + } + return "sha256-" + digest.digest().joinToString("") { "%02x".format(it) } +} + fun Project.makePluginEntry(): PluginEntry { val extension = this.extensions.getCloudstream() @@ -51,5 +67,7 @@ fun Project.makePluginEntry(): PluginEntry { jarUrl = ( if (repo == null || extension.jarFileSize == null) null else repo.getRawLink("${this.name}.jar", extension.buildBranch) ), + jarHash = extension.jarHash, + fileHash = extension.fileHash ) } \ No newline at end of file diff --git a/src/main/kotlin/com/lagradost/cloudstream3/gradle/entities/PluginEntry.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/entities/PluginEntry.kt index dddc9b91..83569d84 100644 --- a/src/main/kotlin/com/lagradost/cloudstream3/gradle/entities/PluginEntry.kt +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/entities/PluginEntry.kt @@ -14,8 +14,10 @@ data class PluginEntry( val tvTypes: List?, val iconUrl: String?, val apiVersion: Int, + val fileHash: String?, // For cross-platform val jarFileSize: Long?, - val jarUrl: String? + val jarUrl: String?, + val jarHash: String? ) \ No newline at end of file diff --git a/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/CompilePluginJarTask.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/CompilePluginJarTask.kt index 6ea804c0..56bc63ce 100644 --- a/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/CompilePluginJarTask.kt +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/CompilePluginJarTask.kt @@ -1,5 +1,6 @@ package com.lagradost.cloudstream3.gradle.tasks +import com.lagradost.cloudstream3.gradle.sha256 import org.gradle.api.DefaultTask import org.gradle.api.file.RegularFileProperty import org.gradle.api.provider.Property @@ -23,6 +24,9 @@ abstract class CompilePluginJarTask : DefaultTask() { @get:Internal abstract val jarFileSize: Property + @get:Internal + abstract val jarHash: Property + @get:InputFile abstract val jarInputFile: RegularFileProperty @@ -45,6 +49,8 @@ abstract class CompilePluginJarTask : DefaultTask() { jarFile.copyTo(targetFile, overwrite = true) jarFileSize.set(jarFile.length()) + + jarHash.set(sha256(jarFile)) logger.lifecycle("Made Cloudstream cross-platform package at ${targetFile.absolutePath}") } } diff --git a/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/Tasks.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/Tasks.kt index e3d59e7e..5bfb3615 100644 --- a/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/Tasks.kt +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/Tasks.kt @@ -6,6 +6,7 @@ import com.lagradost.cloudstream3.gradle.findCloudstream import com.lagradost.cloudstream3.gradle.getCloudstream import com.lagradost.cloudstream3.gradle.makeManifest import com.lagradost.cloudstream3.gradle.makePluginEntry +import com.lagradost.cloudstream3.gradle.sha256 import groovy.json.JsonBuilder import groovy.json.JsonGenerator import org.gradle.api.Project @@ -105,10 +106,12 @@ fun registerTasks(project: Project) { task.jarInputFile.fileProvider(jarTask.map { it.outputs.files.singleFile }) task.targetJarFile.set(project.layout.buildDirectory.file("${project.name}.jar")) task.jarFileSize.set(extension.jarFileSize) - + task.jarHash.set(extension.jarHash) + task.doLast { extension.pluginClassName = task.pluginClassName.orNull extension.jarFileSize = task.jarFileSize.orNull + extension.jarHash = task.jarHash.orNull } } @@ -164,6 +167,7 @@ fun registerTasks(project: Project) { it.doLast { task -> extension.fileSize = task.outputs.files.singleFile.length() + extension.fileHash = sha256(task.outputs.files.singleFile) task.logger.lifecycle("Made Cloudstream package at ${task.outputs.files.singleFile}") } }