From dc196c66cb5dca53913ab351b68aa4fb3bd35206 Mon Sep 17 00:00:00 2001 From: C10udburst <18114966+C10udburst@users.noreply.github.com> Date: Thu, 4 Aug 2022 13:30:09 +0200 Subject: [PATCH] update plugin to be usable maybe --- .github/workflows/ci.yml | 14 +-- .vscode/settings.json | 3 + build.gradle.kts | 8 +- .../gradle/CloudstreamExtension.kt | 10 +- .../gradle/CloudstreamPlugin.kt | 6 +- .../gradle/DownloadUtils.kt | 2 +- .../configuration/ApkConfigurationProvider.kt | 13 +-- .../gradle/configuration/Configurations.kt | 2 +- .../configuration/IConfigurationProvider.kt | 2 +- .../gradle/entities/PluginManifest.kt | 6 ++ .../gradle/tasks/CleanCacheTask.kt | 26 ++++++ .../gradle/tasks/CompileDexTask.kt | 6 +- .../gradle/tasks/GenSourcesTask.kt | 4 +- .../cloudstream3/gradle/tasks/Tasks.kt | 91 +++++++++++++++++++ .../com/lagradost/gradle/tasks/Tasks.kt | 67 -------------- 15 files changed, 160 insertions(+), 100 deletions(-) create mode 100644 .vscode/settings.json rename src/main/kotlin/com/lagradost/{ => cloudstream3}/gradle/CloudstreamExtension.kt (81%) rename src/main/kotlin/com/lagradost/{ => cloudstream3}/gradle/CloudstreamPlugin.kt (64%) rename src/main/kotlin/com/lagradost/{ => cloudstream3}/gradle/DownloadUtils.kt (98%) rename src/main/kotlin/com/lagradost/{ => cloudstream3}/gradle/configuration/ApkConfigurationProvider.kt (76%) rename src/main/kotlin/com/lagradost/{ => cloudstream3}/gradle/configuration/Configurations.kt (93%) rename src/main/kotlin/com/lagradost/{ => cloudstream3}/gradle/configuration/IConfigurationProvider.kt (76%) create mode 100644 src/main/kotlin/com/lagradost/cloudstream3/gradle/entities/PluginManifest.kt create mode 100644 src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/CleanCacheTask.kt rename src/main/kotlin/com/lagradost/{ => cloudstream3}/gradle/tasks/CompileDexTask.kt (96%) rename src/main/kotlin/com/lagradost/{ => cloudstream3}/gradle/tasks/GenSourcesTask.kt (92%) create mode 100644 src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/Tasks.kt delete mode 100644 src/main/kotlin/com/lagradost/gradle/tasks/Tasks.kt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 166b4fc..6f125a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 }} \ No newline at end of file + # - 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 }} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c5f3f6b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "interactive" +} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index eecb2d7..588e1aa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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" } } } diff --git a/src/main/kotlin/com/lagradost/gradle/CloudstreamExtension.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamExtension.kt similarity index 81% rename from src/main/kotlin/com/lagradost/gradle/CloudstreamExtension.kt rename to src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamExtension.kt index 5ebc99c..e64e92a 100644 --- a/src/main/kotlin/com/lagradost/gradle/CloudstreamExtension.kt +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamExtension.kt @@ -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") } diff --git a/src/main/kotlin/com/lagradost/gradle/CloudstreamPlugin.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamPlugin.kt similarity index 64% rename from src/main/kotlin/com/lagradost/gradle/CloudstreamPlugin.kt rename to src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamPlugin.kt index 744c2a5..8196f37 100644 --- a/src/main/kotlin/com/lagradost/gradle/CloudstreamPlugin.kt +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamPlugin.kt @@ -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 { override fun apply(project: Project) { diff --git a/src/main/kotlin/com/lagradost/gradle/DownloadUtils.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/DownloadUtils.kt similarity index 98% rename from src/main/kotlin/com/lagradost/gradle/DownloadUtils.kt rename to src/main/kotlin/com/lagradost/cloudstream3/gradle/DownloadUtils.kt index b93221a..451cfd3 100644 --- a/src/main/kotlin/com/lagradost/gradle/DownloadUtils.kt +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/DownloadUtils.kt @@ -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 diff --git a/src/main/kotlin/com/lagradost/gradle/configuration/ApkConfigurationProvider.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/configuration/ApkConfigurationProvider.kt similarity index 76% rename from src/main/kotlin/com/lagradost/gradle/configuration/ApkConfigurationProvider.kt rename to src/main/kotlin/com/lagradost/cloudstream3/gradle/configuration/ApkConfigurationProvider.kt index 269b877..a39eff7 100644 --- a/src/main/kotlin/com/lagradost/gradle/configuration/ApkConfigurationProvider.kt +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/configuration/ApkConfigurationProvider.kt @@ -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() diff --git a/src/main/kotlin/com/lagradost/gradle/configuration/Configurations.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/configuration/Configurations.kt similarity index 93% rename from src/main/kotlin/com/lagradost/gradle/configuration/Configurations.kt rename to src/main/kotlin/com/lagradost/cloudstream3/gradle/configuration/Configurations.kt index 8f3b11a..4a90c28 100644 --- a/src/main/kotlin/com/lagradost/gradle/configuration/Configurations.kt +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/configuration/Configurations.kt @@ -1,4 +1,4 @@ -package com.lagradost.gradle.configuration +package com.lagradost.cloudstream3.gradle.configuration import org.gradle.api.Project diff --git a/src/main/kotlin/com/lagradost/gradle/configuration/IConfigurationProvider.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/configuration/IConfigurationProvider.kt similarity index 76% rename from src/main/kotlin/com/lagradost/gradle/configuration/IConfigurationProvider.kt rename to src/main/kotlin/com/lagradost/cloudstream3/gradle/configuration/IConfigurationProvider.kt index e91dac9..affa869 100644 --- a/src/main/kotlin/com/lagradost/gradle/configuration/IConfigurationProvider.kt +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/configuration/IConfigurationProvider.kt @@ -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 diff --git a/src/main/kotlin/com/lagradost/cloudstream3/gradle/entities/PluginManifest.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/entities/PluginManifest.kt new file mode 100644 index 0000000..119108e --- /dev/null +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/entities/PluginManifest.kt @@ -0,0 +1,6 @@ +package com.lagradost.cloudstream3.gradle.entities + +data class PluginManifest( + val pluginClassName: String, + val name: String +) \ No newline at end of file diff --git a/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/CleanCacheTask.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/CleanCacheTask.kt new file mode 100644 index 0000000..717085b --- /dev/null +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/CleanCacheTask.kt @@ -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() + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lagradost/gradle/tasks/CompileDexTask.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/CompileDexTask.kt similarity index 96% rename from src/main/kotlin/com/lagradost/gradle/tasks/CompileDexTask.kt rename to src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/CompileDexTask.kt index a308d3e..c63df34 100644 --- a/src/main/kotlin/com/lagradost/gradle/tasks/CompileDexTask.kt +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/CompileDexTask.kt @@ -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) { diff --git a/src/main/kotlin/com/lagradost/gradle/tasks/GenSourcesTask.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/GenSourcesTask.kt similarity index 92% rename from src/main/kotlin/com/lagradost/gradle/tasks/GenSourcesTask.kt rename to src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/GenSourcesTask.kt index 5a38a08..5e186c2 100644 --- a/src/main/kotlin/com/lagradost/gradle/tasks/GenSourcesTask.kt +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/GenSourcesTask.kt @@ -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 diff --git a/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/Tasks.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/Tasks.kt new file mode 100644 index 0000000..f89de9c --- /dev/null +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/tasks/Tasks.kt @@ -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 + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lagradost/gradle/tasks/Tasks.kt b/src/main/kotlin/com/lagradost/gradle/tasks/Tasks.kt deleted file mode 100644 index 2010516..0000000 --- a/src/main/kotlin/com/lagradost/gradle/tasks/Tasks.kt +++ /dev/null @@ -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 } - } - } -} \ No newline at end of file