Add libraries support (#12)

Closes #11
This commit is contained in:
56738 2021-07-16 15:52:00 +02:00 committed by GitHub
parent 5e1f0bc577
commit 973756cc6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 56 additions and 5 deletions

View file

@ -27,6 +27,12 @@ plugins {
id 'net.minecrell.plugin-yml.bukkit' version '0.4.0' id 'net.minecrell.plugin-yml.bukkit' version '0.4.0'
} }
dependencies {
// Downloaded from Maven Central when the plugin is loaded
library 'com.google.code.gson:gson:2.8.7' // All platforms
bukkitLibrary 'com.google.code.gson:gson:2.8.7' // Bukkit only
}
bukkit { bukkit {
// Default values can be overridden if needed // Default values can be overridden if needed
// name = 'TestPlugin' // name = 'TestPlugin'
@ -85,6 +91,13 @@ plugins {
id("net.minecrell.plugin-yml.bukkit") version "0.4.0" id("net.minecrell.plugin-yml.bukkit") version "0.4.0"
} }
dependencies {
// Downloaded from Maven Central when the plugin is loaded
library(kotlin("stdlib")) // All platforms
library("com.google.code.gson", "gson", "2.8.7") // All platforms
bukkitLibrary("com.google.code.gson", "gson", "2.8.7") // Bukkit only
}
bukkit { bukkit {
// Default values can be overridden if needed // Default values can be overridden if needed
// name = "TestPlugin" // name = "TestPlugin"
@ -145,6 +158,12 @@ plugins {
id 'net.minecrell.plugin-yml.bungee' version '0.4.0' id 'net.minecrell.plugin-yml.bungee' version '0.4.0'
} }
dependencies {
// Downloaded from Maven Central when the plugin is loaded
library 'com.google.code.gson:gson:2.8.7' // All platforms
bungeeLibrary 'com.google.code.gson:gson:2.8.7' // Bungee only
}
bungee { bungee {
// Default values can be overridden if needed // Default values can be overridden if needed
// name = 'TestPlugin' // name = 'TestPlugin'
@ -170,6 +189,13 @@ plugins {
id("net.minecrell.plugin-yml.bungee") version "0.4.0" id("net.minecrell.plugin-yml.bungee") version "0.4.0"
} }
dependencies {
// Downloaded from Maven Central when the plugin is loaded
library(kotlin("stdlib")) // All platforms
library("com.google.code.gson", "gson", "2.8.7") // All platforms
bungeeLibrary("com.google.code.gson", "gson", "2.8.7") // Bungee only
}
bungee { bungee {
// Default values can be overridden if needed // Default values can be overridden if needed
// name = "TestPlugin" // name = "TestPlugin"

View file

@ -26,6 +26,7 @@ package net.minecrell.pluginyml
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.plugins.JavaPlugin import org.gradle.api.plugins.JavaPlugin
import org.gradle.kotlin.dsl.register import org.gradle.kotlin.dsl.register
import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.SourceSet
@ -37,6 +38,11 @@ abstract class PlatformPlugin<T : PluginDescription>(private val platformName: S
protected abstract fun createExtension(project: Project): T protected abstract fun createExtension(project: Project): T
protected open fun createConfiguration(project: Project): Configuration? {
val library = project.configurations.maybeCreate("library")
return project.configurations.create("${platformName.decapitalize()}Library").extendsFrom(library)
}
final override fun apply(project: Project) { final override fun apply(project: Project) {
project.run { project.run {
val description = createExtension(this) val description = createExtension(this)
@ -46,12 +52,15 @@ abstract class PlatformPlugin<T : PluginDescription>(private val platformName: S
val generatedResourcesDirectory = layout.buildDirectory.dir("generated/plugin-yml/$platformName") val generatedResourcesDirectory = layout.buildDirectory.dir("generated/plugin-yml/$platformName")
// Add library configuration
val libraries = createConfiguration(this)
// Create task // Create task
val generateTask = tasks.register<GeneratePluginDescription>("generate${platformName}PluginDescription") { val generateTask = tasks.register<GeneratePluginDescription>("generate${platformName}PluginDescription") {
fileName.set(this@PlatformPlugin.fileName) fileName.set(this@PlatformPlugin.fileName)
outputDirectory.set(generatedResourcesDirectory) outputDirectory.set(generatedResourcesDirectory)
pluginDescription.set(provider { pluginDescription.set(provider {
setDefaults(project, description) setDefaults(project, libraries, description)
description description
}) })
@ -63,12 +72,15 @@ abstract class PlatformPlugin<T : PluginDescription>(private val platformName: S
plugins.withType<JavaPlugin> { plugins.withType<JavaPlugin> {
extensions.getByType<SourceSetContainer>().named(SourceSet.MAIN_SOURCE_SET_NAME) { extensions.getByType<SourceSetContainer>().named(SourceSet.MAIN_SOURCE_SET_NAME) {
resources.srcDir(generateTask) resources.srcDir(generateTask)
if (libraries != null) {
configurations.getByName(compileClasspathConfigurationName).extendsFrom(libraries)
}
} }
} }
} }
} }
protected abstract fun setDefaults(project: Project, description: T) protected abstract fun setDefaults(project: Project, libraries: Configuration?, description: T)
protected abstract fun validate(description: T) protected abstract fun validate(description: T)
} }

View file

@ -27,6 +27,7 @@ package net.minecrell.pluginyml.bukkit
import net.minecrell.pluginyml.InvalidPluginDescriptionException import net.minecrell.pluginyml.InvalidPluginDescriptionException
import net.minecrell.pluginyml.PlatformPlugin import net.minecrell.pluginyml.PlatformPlugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
class BukkitPlugin : PlatformPlugin<BukkitPluginDescription>("Bukkit", "plugin.yml") { class BukkitPlugin : PlatformPlugin<BukkitPluginDescription>("Bukkit", "plugin.yml") {
@ -36,12 +37,14 @@ class BukkitPlugin : PlatformPlugin<BukkitPluginDescription>("Bukkit", "plugin.y
override fun createExtension(project: Project) = BukkitPluginDescription(project) override fun createExtension(project: Project) = BukkitPluginDescription(project)
override fun setDefaults(project: Project, description: BukkitPluginDescription) { override fun setDefaults(project: Project, libraries: Configuration?, description: BukkitPluginDescription) {
description.name = description.name ?: project.name description.name = description.name ?: project.name
description.version = description.version ?: project.version.toString() description.version = description.version ?: project.version.toString()
description.description = description.description ?: project.description description.description = description.description ?: project.description
description.website = description.website ?: project.findProperty("url")?.toString() description.website = description.website ?: project.findProperty("url")?.toString()
description.author = description.author ?: project.findProperty("author")?.toString() description.author = description.author ?: project.findProperty("author")?.toString()
description.libraries = description.libraries ?: libraries!!.resolvedConfiguration.firstLevelModuleDependencies
.map { it.module.id.toString() }
} }
override fun validate(description: BukkitPluginDescription) { override fun validate(description: BukkitPluginDescription) {

View file

@ -52,6 +52,7 @@ class BukkitPluginDescription(project: Project) : PluginDescription {
@Input @Optional var prefix: String? = null @Input @Optional var prefix: String? = null
@Input @Optional @JsonProperty("default-permission") var defaultPermission: Permission.Default? = null @Input @Optional @JsonProperty("default-permission") var defaultPermission: Permission.Default? = null
@Input @Optional var provides: List<String>? = null @Input @Optional var provides: List<String>? = null
@Input @Optional var libraries: List<String>? = null
@Nested val commands: NamedDomainObjectContainer<Command> = project.container(Command::class.java) @Nested val commands: NamedDomainObjectContainer<Command> = project.container(Command::class.java)
@Nested val permissions: NamedDomainObjectContainer<Permission> = project.container(Permission::class.java) @Nested val permissions: NamedDomainObjectContainer<Permission> = project.container(Permission::class.java)

View file

@ -27,16 +27,19 @@ package net.minecrell.pluginyml.bungee
import net.minecrell.pluginyml.InvalidPluginDescriptionException import net.minecrell.pluginyml.InvalidPluginDescriptionException
import net.minecrell.pluginyml.PlatformPlugin import net.minecrell.pluginyml.PlatformPlugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
class BungeePlugin : PlatformPlugin<BungeePluginDescription>("Bungee", "bungee.yml") { class BungeePlugin : PlatformPlugin<BungeePluginDescription>("Bungee", "bungee.yml") {
override fun createExtension(project: Project) = BungeePluginDescription() override fun createExtension(project: Project) = BungeePluginDescription()
override fun setDefaults(project: Project, description: BungeePluginDescription) { override fun setDefaults(project: Project, libraries: Configuration?, description: BungeePluginDescription) {
description.name = description.name ?: project.name description.name = description.name ?: project.name
description.version = description.version ?: project.version.toString() description.version = description.version ?: project.version.toString()
description.description = description.description ?: project.description description.description = description.description ?: project.description
description.author = description.author ?: project.findProperty("author")?.toString() description.author = description.author ?: project.findProperty("author")?.toString()
description.libraries = description.libraries ?: libraries!!.resolvedConfiguration.firstLevelModuleDependencies
.map { it.module.id.toString() }
} }
override fun validate(description: BungeePluginDescription) { override fun validate(description: BungeePluginDescription) {

View file

@ -36,4 +36,5 @@ class BungeePluginDescription : PluginDescription {
@Input @Optional var depends: Set<String>? = null @Input @Optional var depends: Set<String>? = null
@Input @Optional var softDepends: Set<String>? = null @Input @Optional var softDepends: Set<String>? = null
@Input @Optional var description: String? = null @Input @Optional var description: String? = null
@Input @Optional var libraries: List<String>? = null
} }

View file

@ -27,11 +27,16 @@ package net.minecrell.pluginyml.nukkit
import net.minecrell.pluginyml.InvalidPluginDescriptionException import net.minecrell.pluginyml.InvalidPluginDescriptionException
import net.minecrell.pluginyml.PlatformPlugin import net.minecrell.pluginyml.PlatformPlugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
class NukkitPlugin : PlatformPlugin<NukkitPluginDescription>("Nukkit", "nukkit.yml") { class NukkitPlugin : PlatformPlugin<NukkitPluginDescription>("Nukkit", "nukkit.yml") {
override fun createExtension(project: Project) = NukkitPluginDescription(project) override fun createExtension(project: Project) = NukkitPluginDescription(project)
override fun setDefaults(project: Project, description: NukkitPluginDescription) { override fun createConfiguration(project: Project): Configuration? {
return null
}
override fun setDefaults(project: Project, libraries: Configuration?, description: NukkitPluginDescription) {
description.name = description.name ?: project.name description.name = description.name ?: project.name
description.version = description.version ?: project.version.toString() description.version = description.version ?: project.version.toString()
description.description = description.description ?: project.description description.description = description.description ?: project.description