diff --git a/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamExtension.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamExtension.kt index f5ca43b..a8b5653 100644 --- a/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamExtension.kt +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamExtension.kt @@ -12,6 +12,9 @@ abstract class CloudstreamExtension @Inject constructor(project: Project) { var apkinfo: ApkInfo? = null internal set + var repository: Repo? = null + internal set + fun overrideUrlPrefix(url: String) { if (apkinfo == null) { apkinfo = ApkInfo(this, "pre-release") @@ -19,12 +22,15 @@ abstract class CloudstreamExtension @Inject constructor(project: Project) { apkinfo!!.urlPrefix = url } + fun setRepo(user: String, repo: String) { + repository = Repo(user, repo) + } + internal var pluginClassName: String? = null - val repositoryUrl: Property = project.objects.property(String::class.java) val description: Property = project.objects.property(String::class.java) val authors: ListProperty = project.objects.listProperty(String::class.java) - val isAdult: Property = project.objects.property(Boolean::class.java) + val adult: Property = project.objects.property(Boolean::class.java) val status: Property = project.objects.property(Int::class.java) } @@ -35,6 +41,15 @@ class ApkInfo(extension: CloudstreamExtension, release: String) { 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 { return getByName("cloudstream") as CloudstreamExtension } diff --git a/src/main/kotlin/com/lagradost/cloudstream3/gradle/Utils.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/Utils.kt index b772683..6fdb7e3 100644 --- a/src/main/kotlin/com/lagradost/cloudstream3/gradle/Utils.kt +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/Utils.kt @@ -2,30 +2,45 @@ package com.lagradost.cloudstream3.gradle import org.gradle.api.Project import com.lagradost.cloudstream3.gradle.getCloudstream -import com.lagradost.cloudstream3.gradle.entities.PluginManifest +import com.lagradost.cloudstream3.gradle.entities.* import groovy.json.JsonBuilder -fun Project.makeManifest(skipClass: Boolean): PluginManifest { +fun Project.makeManifest(): PluginManifest { val extension = this.extensions.getCloudstream() require(this.version != "unspecified") { "No version is set" } - if (!skipClass) { - require(extension.pluginClassName != null) { - "No plugin class found, make sure your plugin class is annotated with @CloudstreamPlugin" - } + require(extension.pluginClassName != null) { + "No plugin class found, make sure your plugin class is annotated with @CloudstreamPlugin" } return PluginManifest( pluginClassName = extension.pluginClassName, name = this.name, + pluginVersion = this.version.toString() + ) +} + +fun Project.makePluginEntry(): PluginEntry { + 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()), - repositoryUrl = extension.repositoryUrl.orNull, description = extension.description.orNull, - isAdult = extension.isAdult.getOrElse(false), - status = extension.status.getOrElse(3) + repositoryUrl = (if (repo == null) null else repo.url), + isAdult = extension.adult.getOrElse(false) ) } \ 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 new file mode 100644 index 0000000..459267b --- /dev/null +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/entities/PluginEntry.kt @@ -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, + val description: String?, + val repositoryUrl: String?, + val isAdult: Boolean, +) \ No newline at end of file diff --git a/src/main/kotlin/com/lagradost/cloudstream3/gradle/entities/PluginManifest.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/entities/PluginManifest.kt index 3b1ad54..f4a05c5 100644 --- a/src/main/kotlin/com/lagradost/cloudstream3/gradle/entities/PluginManifest.kt +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/entities/PluginManifest.kt @@ -3,10 +3,5 @@ package com.lagradost.cloudstream3.gradle.entities data class PluginManifest( val pluginClassName: String?, val name: String, - val version: String, - val authors: List, - val repositoryUrl: String?, - val description: String?, - val isAdult: Boolean, - val status: Int + val pluginVersion: String ) \ No newline at end of file diff --git a/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/MakePluginsJsonTask.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/MakePluginsJsonTask.kt index 41ded0e..635deb2 100644 --- a/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/MakePluginsJsonTask.kt +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/MakePluginsJsonTask.kt @@ -1,8 +1,8 @@ package com.lagradost.cloudstream3.gradle.tasks import com.lagradost.cloudstream3.gradle.findCloudstream -import com.lagradost.cloudstream3.gradle.makeManifest -import com.lagradost.cloudstream3.gradle.entities.PluginManifest +import com.lagradost.cloudstream3.gradle.makePluginEntry +import com.lagradost.cloudstream3.gradle.entities.PluginEntry import groovy.json.JsonBuilder import groovy.json.JsonGenerator import org.gradle.api.DefaultTask @@ -17,12 +17,12 @@ abstract class MakePluginsJsonTask : DefaultTask() { @TaskAction fun makePluginsJson() { - val lst = LinkedList() + val lst = LinkedList() for (subproject in project.allprojects) { val cloudstream = subproject.extensions.findCloudstream() ?: continue - lst.add(subproject.makeManifest(true)) + lst.add(subproject.makePluginEntry()) } outputFile.asFile.get().writeText( 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 bacd76f..fd69a23 100644 --- a/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/Tasks.kt +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/Tasks.kt @@ -70,7 +70,7 @@ fun registerTasks(project: Project) { } manifestFile.writeText( - JsonBuilder(project.makeManifest(false), + JsonBuilder(project.makeManifest(), JsonGenerator.Options() .excludeNulls() .build()