update plugin to be usable maybe

This commit is contained in:
C10udburst 2022-08-04 13:30:09 +02:00
parent 7cdcd5d29d
commit dc196c66cb
15 changed files with 160 additions and 100 deletions

View file

@ -14,10 +14,10 @@ jobs:
with:
java-version: 11
- name: Build and publish
run: |
chmod +x gradlew
./gradlew :publish -Pversion=${GITHUB_REF##*/}-SNAPSHOT
./gradlew :publish -Pversion=$(git rev-parse --short "$GITHUB_SHA")
env:
GITHUB_TOKEN: ${{ github.token }}
# - name: Build and publish
# run: |
# chmod +x gradlew
# ./gradlew :publish -Pversion=${GITHUB_REF##*/}-SNAPSHOT
# ./gradlew :publish -Pversion=$(git rev-parse --short "$GITHUB_SHA")
# env:
# GITHUB_TOKEN: ${{ github.token }}

3
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
}

View file

@ -4,7 +4,7 @@ plugins {
id("maven-publish")
}
group = "com.lagradost"
group = "com.lagradost.cloudstream3"
java {
sourceCompatibility = JavaVersion.VERSION_11
@ -33,9 +33,9 @@ dependencies {
gradlePlugin {
plugins {
create("com.lagradost.gradle") {
id = "com.lagradost.gradle"
implementationClass = "com.lagradost.gradle.CloudstreamPlugin"
create("com.lagradost.cloudstream3.gradle") {
id = "com.lagradost.cloudstream3.gradle"
implementationClass = "com.lagradost.cloudstream3.gradle.CloudstreamPlugin"
}
}
}

View file

@ -1,4 +1,4 @@
package com.lagradost.gradle
package com.lagradost.cloudstream3.gradle
import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionContainer
@ -8,20 +8,20 @@ import javax.inject.Inject
abstract class CloudstreamExtension @Inject constructor(project: Project) {
val userCache = project.gradle.gradleUserHomeDir.resolve("caches").resolve("cloudstream")
var apkinfo: ApkInfo = ApkInfo(this)
var apkinfo: ApkInfo? = null
internal set
fun overrideUrl(url: String) {
apkinfo.url = url
apkinfo!!.url = url
}
internal var pluginClassName: String? = null
}
class ApkInfo(extension: CloudstreamExtension) {
class ApkInfo(extension: CloudstreamExtension, release: String) {
val cache = extension.userCache.resolve("cloudstream")
var url = "https://github.com/recloudstream/cloudstream/releases/download/pre-release/app-debug.apk"
var url = "https://github.com/recloudstream/cloudstream/releases/download/${release}/app-debug.apk"
val apkFile = cache.resolve("cloudstream.apk")
val jarFile = cache.resolve("cloudstream.jar")
}

View file

@ -1,9 +1,9 @@
package com.lagradost.gradle
package com.lagradost.cloudstream3.gradle
import org.gradle.api.Plugin
import org.gradle.api.Project
import com.lagradost.gradle.tasks.registerTasks
import com.lagradost.gradle.configuration.registerConfigurations
import com.lagradost.cloudstream3.gradle.tasks.registerTasks
import com.lagradost.cloudstream3.gradle.configuration.registerConfigurations
abstract class CloudstreamPlugin : Plugin<Project> {
override fun apply(project: Project) {

View file

@ -1,4 +1,4 @@
package com.lagradost.gradle
package com.lagradost.cloudstream3.gradle
import org.gradle.api.Project
import org.gradle.api.internal.project.ProjectInternal

View file

@ -1,9 +1,9 @@
package com.lagradost.gradle.configuration
package com.lagradost.cloudstream3.gradle.configuration
import com.lagradost.gradle.ApkInfo
import com.lagradost.gradle.createProgressLogger
import com.lagradost.gradle.download
import com.lagradost.gradle.getCloudstream
import com.lagradost.cloudstream3.gradle.ApkInfo
import com.lagradost.cloudstream3.gradle.createProgressLogger
import com.lagradost.cloudstream3.gradle.download
import com.lagradost.cloudstream3.gradle.getCloudstream
import com.googlecode.d2j.dex.Dex2jar
import com.googlecode.d2j.reader.BaseDexFileReader
import com.googlecode.d2j.reader.MultiDexFileReader
@ -21,7 +21,8 @@ class ApkConfigurationProvider : IConfigurationProvider {
override fun provide(project: Project, dependency: Dependency) {
val extension = project.extensions.getCloudstream()
val apkinfo = extension.apkinfo
val apkinfo = ApkInfo(extension, dependency.version ?: "prerelease")
extension.apkinfo = apkinfo
apkinfo.cache.mkdirs()

View file

@ -1,4 +1,4 @@
package com.lagradost.gradle.configuration
package com.lagradost.cloudstream3.gradle.configuration
import org.gradle.api.Project

View file

@ -1,4 +1,4 @@
package com.lagradost.gradle.configuration
package com.lagradost.cloudstream3.gradle.configuration
import org.gradle.api.Project
import org.gradle.api.artifacts.Dependency

View file

@ -0,0 +1,6 @@
package com.lagradost.cloudstream3.gradle.entities
data class PluginManifest(
val pluginClassName: String,
val name: String
)

View file

@ -0,0 +1,26 @@
package com.lagradost.cloudstream3.gradle.tasks
import com.lagradost.cloudstream3.gradle.getCloudstream
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.AbstractCopyTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.options.Option
import se.vidstige.jadb.*
import java.nio.charset.StandardCharsets
abstract class CleanCacheTask : DefaultTask() {
@TaskAction
fun cleanCache() {
val extension = project.extensions.getCloudstream()
val apkinfo = extension.apkinfo
if (apkinfo == null) return;
if (apkinfo.apkFile.exists()) {
apkinfo.apkFile.delete()
}
if (apkinfo.jarFile.exists()) {
apkinfo.jarFile.delete()
}
}
}

View file

@ -1,6 +1,6 @@
package com.lagradost.gradle.tasks
package com.lagradost.cloudstream3.gradle.tasks
import com.lagradost.gradle.getCloudstream
import com.lagradost.cloudstream3.gradle.getCloudstream
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.internal.errors.MessageReceiverImpl
import com.android.build.gradle.options.SyncOptions.ErrorFormatMode
@ -79,7 +79,7 @@ abstract class CompileDexTask : DefaultTask() {
reader.accept(classNode, 0)
for (annotation in classNode.visibleAnnotations.orEmpty() + classNode.invisibleAnnotations.orEmpty()) {
if (annotation.desc == "Lcom/lagradost/annotations/CloudstreamPlugin;") {
if (annotation.desc == "Lcom/lagradost/cloudstream3/plugins/CloudstreamPlugin;") {
val cloudstream = project.extensions.getCloudstream()
require(cloudstream.pluginClassName == null) {

View file

@ -1,6 +1,6 @@
package com.lagradost.gradle.tasks
package com.lagradost.cloudstream3.gradle.tasks
import com.lagradost.gradle.getCloudstream
import com.lagradost.cloudstream3.gradle.getCloudstream
import jadx.api.JadxArgs
import jadx.api.JadxDecompiler
import jadx.api.impl.NoOpCodeCache

View file

@ -0,0 +1,91 @@
package com.lagradost.cloudstream3.gradle.tasks
import com.lagradost.cloudstream3.gradle.getCloudstream
import com.lagradost.cloudstream3.gradle.entities.PluginManifest
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.tasks.ProcessLibraryManifest
import groovy.json.JsonBuilder
import org.gradle.api.Project
import org.gradle.api.tasks.AbstractCopyTask
import org.gradle.api.tasks.bundling.Zip
import org.gradle.api.tasks.compile.AbstractCompile
const val TASK_GROUP = "cloudstream"
fun registerTasks(project: Project) {
val extension = project.extensions.getCloudstream()
val intermediates = project.buildDir.resolve("intermediates")
project.tasks.register("genSources", GenSourcesTask::class.java) {
it.group = TASK_GROUP
}
val pluginClassFile = intermediates.resolve("pluginClass")
val compileDex = project.tasks.register("compileDex", CompileDexTask::class.java) {
it.group = TASK_GROUP
it.pluginClassFile.set(pluginClassFile)
for (name in arrayOf("compileDebugJavaWithJavac", "compileDebugKotlin")) {
val task = project.tasks.findByName(name) as AbstractCompile?
if (task != null) {
it.dependsOn(task)
it.input.from(task.destinationDirectory)
}
}
it.outputFile.set(intermediates.resolve("classes.dex"))
}
project.afterEvaluate {
project.tasks.register("make", Zip::class.java) {
val compileDexTask = compileDex.get()
it.dependsOn(compileDexTask)
val manifestFile = intermediates.resolve("manifest.json")
it.from(manifestFile)
it.doFirst {
require(project.version != "unspecified") {
"No version is set"
}
if (extension.pluginClassName == null) {
if (pluginClassFile.exists()) {
extension.pluginClassName = pluginClassFile.readText()
}
}
require(extension.pluginClassName != null) {
"No plugin class found, make sure your plugin class is annotated with @CloudstreamPlugin"
}
manifestFile.writeText(
JsonBuilder(
PluginManifest(
pluginClassName = extension.pluginClassName!!,
name = project.name
)
).toPrettyString()
)
}
it.from(compileDexTask.outputFile)
val zip = it as Zip
//zip.dependsOn(compileResources.get())
zip.isPreserveFileTimestamps = false
zip.archiveBaseName.set(project.name)
zip.archiveVersion.set("")
zip.destinationDirectory.set(project.buildDir)
it.doLast { task ->
task.logger.lifecycle("Made Cloudstream package at ${task.outputs.files.singleFile}")
}
}
}
project.tasks.register("cleanCache", CleanCacheTask::class.java) {
it.group = TASK_GROUP
}
}

View file

@ -1,67 +0,0 @@
package com.lagradost.gradle.tasks
import com.lagradost.gradle.getCloudstream
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.tasks.ProcessLibraryManifest
import groovy.json.JsonBuilder
import org.gradle.api.Project
import org.gradle.api.tasks.AbstractCopyTask
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.compile.AbstractCompile
const val TASK_GROUP = "cloudstream"
fun registerTasks(project: Project) {
val extension = project.extensions.getCloudstream()
val intermediates = project.buildDir.resolve("intermediates")
project.tasks.register("genSources", GenSourcesTask::class.java) {
it.group = TASK_GROUP
}
val pluginClassFile = intermediates.resolve("pluginClass")
val compileDex = project.tasks.register("compileDex", CompileDexTask::class.java) {
it.group = TASK_GROUP
it.pluginClassFile.set(pluginClassFile)
for (name in arrayOf("compileDebugJavaWithJavac", "compileDebugKotlin")) {
val task = project.tasks.findByName(name) as AbstractCompile?
if (task != null) {
it.dependsOn(task)
it.input.from(task.destinationDirectory)
}
}
it.outputFile.set(intermediates.resolve("classes.dex"))
}
project.afterEvaluate {
project.tasks.register("make", Copy::class.java)
{
val compileDexTask = compileDex.get()
it.dependsOn(compileDexTask)
// it.doFirst {
// require(project.version != "unspecified") {
// "No version is set"
// }
// if (extension.pluginClassName == null) {
// if (pluginClassFile.exists()) {
// extension.pluginClassName = pluginClassFile.readText()
// }
// }
// require(extension.pluginClassName != null) {
// "No plugin class found, make sure your plugin class is annotated with @CloudstreamPlugin"
// }
// }
it.from(compileDexTask.outputFile)
it.into(project.buildDir)
it.rename { return@rename project.name }
}
}
}