Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add annotation manifest support #4

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion src/main/kotlin/com/aliucord/gradle/AliucordExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import javax.inject.Inject

abstract class AliucordExtension @Inject constructor(project: Project) {
abstract class AliucordExtension @Inject constructor(val project: Project) {
val projectType: Property<ProjectType> =
project.objects.property(ProjectType::class.java).convention(ProjectType.PLUGIN)

Expand Down
18 changes: 18 additions & 0 deletions src/main/kotlin/com/aliucord/gradle/task/CompileDexTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package com.aliucord.gradle.task

import com.aliucord.gradle.AliucordExtension
import com.aliucord.gradle.getAliucord
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.internal.errors.MessageReceiverImpl
Expand Down Expand Up @@ -103,6 +104,8 @@ abstract class CompileDexTask : DefaultTask() {

aliucord.pluginClassName = reader.className.replace('/', '.')
.also { pluginClassFile.asFile.orNull?.writeText(it) }

return PluginAnnotationVisitor(aliucord)
}

return object : AnnotationVisitor(Opcodes.ASM9) {}
Expand All @@ -114,4 +117,19 @@ abstract class CompileDexTask : DefaultTask() {

logger.lifecycle("Compiled dex to ${outputFile.get()}")
}
}


class PluginAnnotationVisitor(private val ext: AliucordExtension) : AnnotationVisitor(Opcodes.ASM9) {
override fun visit(name: String, v: Any) {
if (v is String && v.isNotBlank()) {
when (name) {
"version" -> ext.project.version = v
"description" -> ext.project.description = v
"changelog" -> ext.changelog.set(v.trimIndent())
"changelogMedia" -> ext.changelogMedia.set(v)
}
}
super.visit(name, v)
}
}
6 changes: 3 additions & 3 deletions src/main/kotlin/com/aliucord/gradle/task/Tasks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ fun registerTasks(project: Project) {

it.from(manifestFile)
it.doFirst {
require(project.version != "unspecified") {
"No version is set"
require(project.version != Project.DEFAULT_VERSION) {
"No version is set. Please set the version in either the @AliucordPlugin annotation or the project configuration"
}

if (extension.pluginClassName == null) {
Expand All @@ -87,7 +87,7 @@ fun registerTasks(project: Project) {
}
}

require(extension.pluginClassName != null) {
requireNotNull(extension.pluginClassName) {
"No plugin class found, make sure your plugin class is annotated with @AliucordPlugin"
}

Expand Down