Fix permissions generation when using register("...")

It looks like asMap(...) doesn't return lazily registered values.
Might be a bug, but using .associateBy { it.name } is at least as simple
and does not have that problem.
This commit is contained in:
Minecrell 2021-04-30 11:54:55 +02:00
parent c60658d745
commit 5fff9cf695
2 changed files with 14 additions and 14 deletions

View file

@ -54,10 +54,10 @@ class BukkitPluginDescription(project: Project) : Serializable {
@Transient @JsonIgnore val permissions: NamedDomainObjectContainer<Permission> = project.container(Permission::class.java)
// Java/Jackson serialization for commands and permissions
internal val commandMap: Map<String, Command> = commands.asMap
@JsonProperty("commands") get() = field.toMap() // Return copy
internal val permissionMap: Map<String, Permission> = permissions.asMap
@JsonProperty("permissions") get() = field.toMap() // Return copy
internal val commandMap: Map<String, Command>
@JsonProperty("commands") get() = commands.associateBy { it.name }
internal val permissionMap: Map<String, Permission>
@JsonProperty("permissions") get() = permissions.associateBy { it.name }
// For Groovy DSL
fun commands(closure: Closure<Unit>) = commands.configure(closure)
@ -82,7 +82,7 @@ class BukkitPluginDescription(project: Project) : Serializable {
var children: List<String>?
@JsonIgnore get() = childrenMap?.filterValues { it }?.keys?.toList()
set(value) {
childrenMap = value?.associate { it to true }
childrenMap = value?.associateWith { true }
}
@JsonProperty("children") var childrenMap: Map<String, Boolean>? = null

View file

@ -49,17 +49,17 @@ class NukkitPluginDescription(project: Project) : Serializable {
// DSL provider for commands and permissions (not serialized)
@Transient @JsonIgnore
val commands: NamedDomainObjectContainer<NukkitPluginDescription.Command> = project.container(NukkitPluginDescription.Command::class.java)
val commands: NamedDomainObjectContainer<Command> = project.container(Command::class.java)
@Transient @JsonIgnore
val permissions: NamedDomainObjectContainer<NukkitPluginDescription.Permission> = project.container(NukkitPluginDescription.Permission::class.java) {
val permissions: NamedDomainObjectContainer<Permission> = project.container(Permission::class.java) {
Permission(project, it)
}
// Java/Jackson serialization for commands and permissions
internal val commandMap: Map<String, NukkitPluginDescription.Command> = commands.asMap
@JsonProperty("commands") get() = field.toMap() // Return copy
internal val permissionMap: Map<String, NukkitPluginDescription.Permission> = permissions.asMap
@JsonProperty("permissions") get() = field.toMap() // Return copy
internal val commandMap: Map<String, Command>
@JsonProperty("commands") get() = commands.associateBy { it.name }
internal val permissionMap: Map<String, Permission>
@JsonProperty("permissions") get() = permissions.associateBy { it.name }
// For Groovy DSL
fun commands(closure: Closure<Unit>) = commands.configure(closure)
@ -85,13 +85,13 @@ class NukkitPluginDescription(project: Project) : Serializable {
// DSL provider for recursive children (not serialized)
@Transient @JsonIgnore
val children: NamedDomainObjectContainer<NukkitPluginDescription.Permission> = project.container(NukkitPluginDescription.Permission::class.java) {
val children: NamedDomainObjectContainer<Permission> = project.container(Permission::class.java) {
Permission(project, it)
}
// Java/Jackson serialization for commands and permissions
internal val childrenMap: Map<String, NukkitPluginDescription.Permission> = children.asMap
@JsonProperty("children") get() = field.toMap() // Return copy
internal val childrenMap: Map<String, Permission>
@JsonProperty("children") get() = children.associateBy { it.name }
// For Groovy DSL
fun children(closure: Closure<Unit>) = children.configure(closure)