Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/main/kotlin/com/lagradost/cloudstream3/gradle/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()

Expand Down Expand Up @@ -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
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ data class PluginEntry(
val tvTypes: List<String>?,
val iconUrl: String?,
val apiVersion: Int,
val fileHash: String?,

// For cross-platform
val jarFileSize: Long?,
val jarUrl: String?
val jarUrl: String?,
val jarHash: String?
)
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,6 +24,9 @@ abstract class CompilePluginJarTask : DefaultTask() {
@get:Internal
abstract val jarFileSize: Property<Long?>

@get:Internal
abstract val jarHash: Property<String?>

@get:InputFile
abstract val jarInputFile: RegularFileProperty

Expand All @@ -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}")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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}")
}
}
Expand Down
Loading