mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
169 lines
5.5 KiB
Groovy
169 lines
5.5 KiB
Groovy
import com.moandjiezana.toml.Toml
|
|
import org.apollo.build.tasks.KotlinScriptCompileTask
|
|
|
|
import java.nio.file.Paths
|
|
|
|
def PLUGIN_VERIFICATION_GROUP = "plugin-verification"
|
|
def PLUGIN_BUILD_GROUP = "plugin-build"
|
|
|
|
buildscript {
|
|
repositories {
|
|
mavenCentral()
|
|
}
|
|
|
|
dependencies {
|
|
classpath group: 'com.moandjiezana.toml', name: 'toml4j', version: '0.7.1'
|
|
}
|
|
}
|
|
|
|
task testPlugins {
|
|
group = "plugin-verification"
|
|
|
|
doLast {
|
|
println("Finished executing plugin tests")
|
|
}
|
|
}
|
|
|
|
check.dependsOn testPlugins
|
|
|
|
class PluginBuildData {
|
|
PluginBuildData(String normalizedName, SourceSet mainSources, SourceSet testSources,
|
|
FileCollection scriptFiles, List<String> dependencyNames) {
|
|
this.normalizedName = normalizedName
|
|
this.mainSources = mainSources
|
|
this.testSources = testSources
|
|
this.scriptFiles = scriptFiles
|
|
this.dependencyNames = dependencyNames
|
|
}
|
|
|
|
String normalizedName
|
|
SourceSet mainSources
|
|
SourceSet testSources
|
|
FileCollection scriptFiles
|
|
List<String> dependencyNames
|
|
}
|
|
|
|
Map<String, PluginBuildData> pluginMap = new HashMap<>()
|
|
|
|
def configurePluginDependencies(SourceSet mainSources, SourceSet testSources,
|
|
List<PluginBuildData> pluginDependencies) {
|
|
|
|
def testConfiguration = testSources.compileConfigurationName
|
|
def mainConfiguration = mainSources.compileConfigurationName
|
|
|
|
// Add this plugin as a runtime dependency to the main game project
|
|
dependencies.add(configurations.runtime.name, mainSources.output)
|
|
|
|
pluginDependencies.each {
|
|
dependencies.add(mainConfiguration, it.mainSources.output)
|
|
dependencies.add(testConfiguration, it.testSources.output)
|
|
}
|
|
|
|
dependencies.add(mainConfiguration, configurations.compile)
|
|
dependencies.add(mainConfiguration, sourceSets.main.output)
|
|
|
|
dependencies.add(testConfiguration, mainSources.output)
|
|
dependencies.add(testConfiguration, configurations.testCompile)
|
|
dependencies.add(testConfiguration, sourceSets.test.output)
|
|
}
|
|
|
|
def configurePluginTasks(String name, SourceSet mainSources, SourceSet testSources,
|
|
FileCollection scriptFiles, List<PluginBuildData> pluginDependencies) {
|
|
def taskName = name.split("_").collect { it.capitalize() }.join("")
|
|
|
|
def testsTask = task("test${taskName}", type: Test) {
|
|
group = "plugin-verification"
|
|
|
|
testClassesDir = testSources.output.classesDir
|
|
classpath = testSources.runtimeClasspath + mainSources.runtimeClasspath
|
|
|
|
binResultsDir = file("$buildDir/plugin-test-results/binary/$name")
|
|
|
|
reports {
|
|
html.destination = "$buildDir/reports/plugin-tests/$name"
|
|
junitXml.destination = "$buildDir/plugin-tests/$name"
|
|
}
|
|
|
|
testLogging {
|
|
events "passed", "skipped", "failed"
|
|
}
|
|
}
|
|
|
|
testPlugins.dependsOn testsTask
|
|
|
|
if (!scriptFiles.empty) {
|
|
def compileScriptsTask = task("compile${taskName}Scripts", type: KotlinScriptCompileTask) {
|
|
group = "plugin-compile"
|
|
|
|
def outputDir = mainSources.output.classesDir
|
|
|
|
inputs.files scriptFiles
|
|
outputsDir = outputDir
|
|
|
|
compileClasspath = sourceSets.main.compileClasspath +
|
|
sourceSets.main.runtimeClasspath +
|
|
mainSources.compileClasspath +
|
|
mainSources.runtimeClasspath
|
|
|
|
scriptDefinitionClass = "org.apollo.game.plugin.kotlin.KotlinPluginScript"
|
|
mustRunAfter tasks[mainSources.classesTaskName]
|
|
}
|
|
|
|
testPlugins.dependsOn compileScriptsTask
|
|
tasks[mainSources.classesTaskName].finalizedBy compileScriptsTask
|
|
}
|
|
}
|
|
|
|
def pluginTree = fileTree(dir: "$pluginsDir")
|
|
def pluginDefinitions = pluginTree.matching {
|
|
include '**/meta.toml'
|
|
}
|
|
|
|
pluginDefinitions.each { file ->
|
|
def meta = new Toml()
|
|
meta.read(file.absoluteFile)
|
|
|
|
def pluginFolder = Paths.get(file.parentFile.absolutePath)
|
|
def name = meta.getString("name", pluginFolder.getFileName().toString())
|
|
def normalizedName = name.replaceAll("[^a-zA-Z0-9_]", '_').toLowerCase()
|
|
def displayNameArray = normalizedName.split("_").collect { it.capitalize() }.join("").toCharArray()
|
|
displayNameArray[0] = displayNameArray[0].toLowerCase()
|
|
|
|
def sourceSetName = new String(displayNameArray)
|
|
|
|
def packageName = meta.getString("package", "org.apollo.game.plugin")
|
|
def authors = meta.getList("authors", new ArrayList())
|
|
def dependencies = meta.getList("dependencies", new ArrayList())
|
|
|
|
def scripts = fileTree(file.parentFile) {
|
|
include '**/*.plugin.kts'
|
|
exclude '*.kt'
|
|
}
|
|
|
|
def srcsDir = meta.getString("config.src", "src/")
|
|
def testDir = meta.getString("config.test", "test/")
|
|
|
|
def mainSources = sourceSets.create("${sourceSetName}Main") {
|
|
kotlin {
|
|
srcDir pluginFolder.resolve(srcsDir).toString()
|
|
exclude '*.kts'
|
|
}
|
|
}
|
|
|
|
def testSources = sourceSets.create("${sourceSetName}Test") {
|
|
kotlin {
|
|
srcDir pluginFolder.resolve(testDir).toString()
|
|
}
|
|
}
|
|
|
|
def pluginData = new PluginBuildData(normalizedName, mainSources, testSources, scripts, dependencies)
|
|
pluginMap.put(normalizedName, pluginData)
|
|
}
|
|
|
|
pluginMap.values().each {
|
|
def dependencies = it.dependencyNames.collect { name -> pluginMap.get(name) }
|
|
|
|
configurePluginDependencies(it.mainSources, it.testSources, dependencies)
|
|
configurePluginTasks(it.normalizedName, it.mainSources, it.testSources, it.scriptFiles, dependencies)
|
|
}
|