-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
125 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import com.fasterxml.jackson.core.JsonFactory | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory | ||
import com.fasterxml.jackson.module.kotlin.readValue | ||
import com.fasterxml.jackson.module.kotlin.registerKotlinModule | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.provider.MapProperty | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.* | ||
import java.io.File | ||
|
||
enum class PluginDescriptorFormat { | ||
YAML, JSON | ||
} | ||
|
||
abstract class PluginDescriptorTask : DefaultTask() { | ||
|
||
@get:Input | ||
@get:Optional | ||
abstract val descriptor: Property<String> | ||
|
||
@get:InputFile | ||
@get:Optional | ||
abstract val descriptorFile: RegularFileProperty | ||
|
||
@get:Input | ||
abstract val content: MapProperty<String, Any> | ||
|
||
@get:Input | ||
@get:Optional | ||
abstract val format: Property<PluginDescriptorFormat> | ||
|
||
@get:Input | ||
@get:Optional | ||
abstract val append: Property<Boolean> | ||
|
||
init { | ||
project.tasks.getByName("processResources") { | ||
finalizedBy(this@PluginDescriptorTask) | ||
} | ||
} | ||
|
||
@TaskAction | ||
fun writeFile() { | ||
val mapper = constructMapper() | ||
mapper.registerKotlinModule() | ||
val file = extractDescriptorFile() | ||
val fileContent = LinkedHashMap<String, Any>() | ||
if (append.getOrElse(false)) { | ||
fileContent.putAll(mapper.readValue<Map<String, Any>>(file)) | ||
} | ||
fileContent.putAll(content.get()) | ||
mapper.writeValue( | ||
file, | ||
fileContent, | ||
) | ||
} | ||
|
||
private fun constructMapper(): ObjectMapper { | ||
@Suppress("WHEN_ENUM_CAN_BE_NULL_IN_JAVA") | ||
return ObjectMapper(when(format.getOrElse(PluginDescriptorFormat.YAML)) { | ||
PluginDescriptorFormat.JSON -> JsonFactory() | ||
PluginDescriptorFormat.YAML -> YAMLFactory() | ||
}) | ||
} | ||
|
||
private fun extractDescriptorFile(): File { | ||
var file: File? = descriptorFile.map { it.asFile }.orNull | ||
if (file == null) { | ||
val sourceSets: SourceSetContainer = project.extensions.getByName("sourceSets") as SourceSetContainer | ||
file = sourceSets.getByName("main").output.resourcesDir!!.resolve(descriptor.get()) | ||
} | ||
return file | ||
} | ||
} |
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,20 +1,28 @@ | ||
import kr.entree.spigradle.kotlin.bungeecord | ||
|
||
plugins { | ||
id("java-shadow") | ||
alias(libs.plugins.spigradle.bungee) | ||
} | ||
|
||
bungee { | ||
name = "MapModCompanion" | ||
author = "turikhay" | ||
debug { | ||
jvmArgs = listOf("-Xmx256m", "-Dnet.md_5.bungee.console-log-level=ALL") | ||
repositories { | ||
maven { | ||
name = "Sonatype" | ||
url = uri("https://oss.sonatype.org/content/repositories/snapshots/") | ||
} | ||
} | ||
|
||
tasks { | ||
val writeBungeeYml by creating(PluginDescriptorTask::class) { | ||
descriptor = "bungee.yml" | ||
content.putAll(mapOf( | ||
"name" to "MapModCompanion", | ||
"version" to project.version, | ||
"author" to "turikhay", | ||
"main" to "com.turikhay.mc.mapmodcompanion.bungee.MapModCompanion" | ||
)) | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(project(":common")) | ||
implementation(libs.bstats.bungeecord) | ||
compileOnly(bungeecord()) | ||
compileOnly("net.md-5:bungeecord-api:1.19-R0.1-SNAPSHOT") | ||
} |
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