mirror of
https://github.com/plexusorg/plugin-yml.git
synced 2024-12-22 16:25:06 +00:00
parent
5e1f0bc577
commit
973756cc6b
7 changed files with 56 additions and 5 deletions
26
README.md
26
README.md
|
@ -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"
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue