update PluginEntry and PluginManifest

This commit is contained in:
C10udburst 2022-08-08 11:54:17 +02:00
parent 2b98fcdfde
commit 07c70ccfbd
6 changed files with 60 additions and 22 deletions

View file

@ -12,6 +12,9 @@ abstract class CloudstreamExtension @Inject constructor(project: Project) {
var apkinfo: ApkInfo? = null var apkinfo: ApkInfo? = null
internal set internal set
var repository: Repo? = null
internal set
fun overrideUrlPrefix(url: String) { fun overrideUrlPrefix(url: String) {
if (apkinfo == null) { if (apkinfo == null) {
apkinfo = ApkInfo(this, "pre-release") apkinfo = ApkInfo(this, "pre-release")
@ -19,12 +22,15 @@ abstract class CloudstreamExtension @Inject constructor(project: Project) {
apkinfo!!.urlPrefix = url apkinfo!!.urlPrefix = url
} }
fun setRepo(user: String, repo: String) {
repository = Repo(user, repo)
}
internal var pluginClassName: String? = null internal var pluginClassName: String? = null
val repositoryUrl: Property<String> = project.objects.property(String::class.java)
val description: Property<String> = project.objects.property(String::class.java) val description: Property<String> = project.objects.property(String::class.java)
val authors: ListProperty<String> = project.objects.listProperty(String::class.java) val authors: ListProperty<String> = project.objects.listProperty(String::class.java)
val isAdult: Property<Boolean> = project.objects.property(Boolean::class.java) val adult: Property<Boolean> = project.objects.property(Boolean::class.java)
val status: Property<Int> = project.objects.property(Int::class.java) val status: Property<Int> = project.objects.property(Int::class.java)
} }
@ -35,6 +41,15 @@ class ApkInfo(extension: CloudstreamExtension, release: String) {
val jarFile = cache.resolve("cloudstream.jar") val jarFile = cache.resolve("cloudstream.jar")
} }
class Repo(val user: String, val repo: String) {
val url: String
get() = "https://github.com/${user}/${repo}"
fun getRawLink(filename: String, branch: String): String {
return "https://raw.githubusercontent.com/${user}/${repo}/${branch}/${filename}"
}
}
fun ExtensionContainer.getCloudstream(): CloudstreamExtension { fun ExtensionContainer.getCloudstream(): CloudstreamExtension {
return getByName("cloudstream") as CloudstreamExtension return getByName("cloudstream") as CloudstreamExtension
} }

View file

@ -2,30 +2,45 @@ package com.lagradost.cloudstream3.gradle
import org.gradle.api.Project import org.gradle.api.Project
import com.lagradost.cloudstream3.gradle.getCloudstream import com.lagradost.cloudstream3.gradle.getCloudstream
import com.lagradost.cloudstream3.gradle.entities.PluginManifest import com.lagradost.cloudstream3.gradle.entities.*
import groovy.json.JsonBuilder import groovy.json.JsonBuilder
fun Project.makeManifest(skipClass: Boolean): PluginManifest { fun Project.makeManifest(): PluginManifest {
val extension = this.extensions.getCloudstream() val extension = this.extensions.getCloudstream()
require(this.version != "unspecified") { require(this.version != "unspecified") {
"No version is set" "No version is set"
} }
if (!skipClass) {
require(extension.pluginClassName != null) { require(extension.pluginClassName != null) {
"No plugin class found, make sure your plugin class is annotated with @CloudstreamPlugin" "No plugin class found, make sure your plugin class is annotated with @CloudstreamPlugin"
} }
}
return PluginManifest( return PluginManifest(
pluginClassName = extension.pluginClassName, pluginClassName = extension.pluginClassName,
name = this.name, name = this.name,
version = this.version.toString(), pluginVersion = this.version.toString()
authors = extension.authors.getOrElse(listOf()), )
repositoryUrl = extension.repositoryUrl.orNull, }
description = extension.description.orNull,
isAdult = extension.isAdult.getOrElse(false), fun Project.makePluginEntry(): PluginEntry {
status = extension.status.getOrElse(3) val extension = this.extensions.getCloudstream()
require(this.version != "unspecified") {
"No version is set"
}
val repo = extension.repository
return PluginEntry(
url = (if (repo == null) "" else repo.getRawLink("${this.name}.cs3", "builds")),
status = extension.status.getOrElse(3),
version = this.version.toString(),
name = this.name,
internalName = this.name,
authors = extension.authors.getOrElse(listOf()),
description = extension.description.orNull,
repositoryUrl = (if (repo == null) null else repo.url),
isAdult = extension.adult.getOrElse(false)
) )
} }

View file

@ -0,0 +1,13 @@
package com.lagradost.cloudstream3.gradle.entities
data class PluginEntry(
val url: String,
val status: Int,
val version: String,
val name: String,
val internalName: String,
val authors: List<String>,
val description: String?,
val repositoryUrl: String?,
val isAdult: Boolean,
)

View file

@ -3,10 +3,5 @@ package com.lagradost.cloudstream3.gradle.entities
data class PluginManifest( data class PluginManifest(
val pluginClassName: String?, val pluginClassName: String?,
val name: String, val name: String,
val version: String, val pluginVersion: String
val authors: List<String>,
val repositoryUrl: String?,
val description: String?,
val isAdult: Boolean,
val status: Int
) )

View file

@ -1,8 +1,8 @@
package com.lagradost.cloudstream3.gradle.tasks package com.lagradost.cloudstream3.gradle.tasks
import com.lagradost.cloudstream3.gradle.findCloudstream import com.lagradost.cloudstream3.gradle.findCloudstream
import com.lagradost.cloudstream3.gradle.makeManifest import com.lagradost.cloudstream3.gradle.makePluginEntry
import com.lagradost.cloudstream3.gradle.entities.PluginManifest import com.lagradost.cloudstream3.gradle.entities.PluginEntry
import groovy.json.JsonBuilder import groovy.json.JsonBuilder
import groovy.json.JsonGenerator import groovy.json.JsonGenerator
import org.gradle.api.DefaultTask import org.gradle.api.DefaultTask
@ -17,12 +17,12 @@ abstract class MakePluginsJsonTask : DefaultTask() {
@TaskAction @TaskAction
fun makePluginsJson() { fun makePluginsJson() {
val lst = LinkedList<PluginManifest>() val lst = LinkedList<PluginEntry>()
for (subproject in project.allprojects) { for (subproject in project.allprojects) {
val cloudstream = subproject.extensions.findCloudstream() ?: continue val cloudstream = subproject.extensions.findCloudstream() ?: continue
lst.add(subproject.makeManifest(true)) lst.add(subproject.makePluginEntry())
} }
outputFile.asFile.get().writeText( outputFile.asFile.get().writeText(

View file

@ -70,7 +70,7 @@ fun registerTasks(project: Project) {
} }
manifestFile.writeText( manifestFile.writeText(
JsonBuilder(project.makeManifest(false), JsonBuilder(project.makeManifest(),
JsonGenerator.Options() JsonGenerator.Options()
.excludeNulls() .excludeNulls()
.build() .build()