-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* paper-plugin.yml requires api-version * Exclude empty maps from plugin ymls * Add VelocityPluginJson factory
- Loading branch information
Showing
9 changed files
with
152 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
package xyz.jpenilla.resourcefactory | ||
|
||
import org.gradle.api.NamedDomainObjectContainer | ||
import org.gradle.api.provider.ListProperty | ||
import org.gradle.api.provider.MapProperty | ||
|
||
fun <T> ListProperty<T>.nullIfEmpty(): List<T>? = if (get().isEmpty()) null else get().toList() | ||
|
||
fun <A, B> MapProperty<A, B>.nullIfEmpty(): Map<A, B>? = if (get().isEmpty()) null else get().toMap() | ||
|
||
fun <A> NamedDomainObjectContainer<A>.nullIfEmpty(): Map<String, A>? = if (isEmpty()) null else asMap.toMap() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
plugin/src/main/kotlin/xyz/jpenilla/resourcefactory/velocity/VelocityPluginJson.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package xyz.jpenilla.resourcefactory.velocity | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.api.model.ObjectFactory | ||
import org.gradle.api.provider.ListProperty | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.Nested | ||
import org.gradle.api.tasks.Optional | ||
import org.gradle.kotlin.dsl.listProperty | ||
import org.gradle.kotlin.dsl.newInstance | ||
import org.gradle.kotlin.dsl.property | ||
import org.spongepowered.configurate.gson.GsonConfigurationLoader | ||
import org.spongepowered.configurate.objectmapping.ConfigSerializable | ||
import xyz.jpenilla.resourcefactory.ConfigurateSingleFileResourceFactory | ||
import xyz.jpenilla.resourcefactory.ResourceFactory | ||
import xyz.jpenilla.resourcefactory.nullIfEmpty | ||
import java.nio.file.Path | ||
|
||
fun Project.velocityPluginJson(op: VelocityPluginJson.() -> Unit = {}): VelocityPluginJson { | ||
val yml = VelocityPluginJson(objects) | ||
yml.copyProjectMeta(this) | ||
yml.op() | ||
return yml | ||
} | ||
|
||
class VelocityPluginJson constructor( | ||
@Transient | ||
private val objects: ObjectFactory | ||
) : ConfigurateSingleFileResourceFactory.ObjectMapper.ValueProvider { | ||
|
||
@get:Input | ||
val id: Property<String> = objects.property() | ||
|
||
@get:Input | ||
@get:Optional | ||
val name: Property<String> = objects.property() | ||
|
||
@get:Input | ||
@get:Optional | ||
val version: Property<String> = objects.property() | ||
|
||
@get:Input | ||
@get:Optional | ||
val description: Property<String> = objects.property() | ||
|
||
@get:Input | ||
@get:Optional | ||
val url: Property<String> = objects.property() | ||
|
||
@get:Input | ||
val authors: ListProperty<String> = objects.listProperty() | ||
|
||
@get:Nested | ||
val dependencies: ListProperty<Dependency> = objects.listProperty() | ||
|
||
fun dependency(id: String, optional: Boolean) = dependencies.add(Dependency(id, optional)) | ||
|
||
@get:Input | ||
val main: Property<String> = objects.property() | ||
|
||
override fun asConfigSerializable(): Any { | ||
return Serializable(this) | ||
} | ||
|
||
fun copyProjectMeta(project: Project) { | ||
id.convention(project.name) | ||
name.convention(project.name) | ||
description.convention(project.description) | ||
version.convention(project.version as String?) | ||
} | ||
|
||
fun resourceFactory(): ResourceFactory { | ||
val factory = objects.newInstance( | ||
ConfigurateSingleFileResourceFactory.ObjectMapper::class, | ||
{ path: Path -> | ||
GsonConfigurationLoader.builder() | ||
.path(path) | ||
.build() | ||
} | ||
) | ||
factory.path.set("velocity-plugin.json") | ||
factory.value.set(this) | ||
return factory | ||
} | ||
|
||
@ConfigSerializable | ||
class Dependency( | ||
@get:Input | ||
val id: String, | ||
@get:Input | ||
val optional: Boolean | ||
) | ||
|
||
@ConfigSerializable | ||
class Serializable(json: VelocityPluginJson) { | ||
val id = json.id.get() | ||
val name = json.name.orNull | ||
val version = json.version.orNull | ||
val description = json.description.orNull | ||
val url = json.url.orNull | ||
val dependencies = json.dependencies.nullIfEmpty() | ||
val main = json.main.get() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters