mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Remove plugins.gradle and factor into common extension
This commit is contained in:
@@ -14,6 +14,7 @@ subprojects {
|
|||||||
repositories {
|
repositories {
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
maven { url "https://repo.maven.apache.org/maven2" }
|
maven { url "https://repo.maven.apache.org/maven2" }
|
||||||
|
maven { url "https://dl.bintray.com/kotlin/kotlinx/" }
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
apply plugin: 'kotlin'
|
apply plugin: 'kotlin'
|
||||||
|
apply plugin: 'groovy'
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
apply from: '../properties.gradle'
|
apply from: '../properties.gradle'
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package org.apollo.build.plugin
|
||||||
|
|
||||||
|
import org.gradle.api.Plugin
|
||||||
|
import org.gradle.api.Project
|
||||||
|
|
||||||
|
class ApolloPlugin implements Plugin<Project> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void apply(Project project) {
|
||||||
|
project.extensions.create('apolloPlugin', ApolloPluginExtension, project)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
package org.apollo.build.plugin
|
||||||
|
|
||||||
|
import org.apollo.build.plugin.tasks.ApolloScriptCompileTask
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.file.FileTree
|
||||||
|
|
||||||
|
class ApolloPluginExtension {
|
||||||
|
private Project project
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of this plugin (defaults to the project name).
|
||||||
|
*/
|
||||||
|
String name
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The package that plugin scripts (.kts files) will be packaged under for this plugin.
|
||||||
|
*/
|
||||||
|
String packageName = "org.apollo.game.plugins"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An optional description of this plugin.
|
||||||
|
*/
|
||||||
|
String description = "Empty description"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of other {@link ApolloPlugin}s that this plugin depends on.
|
||||||
|
*/
|
||||||
|
List<String> dependencies = []
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of others who contributed to this plugin.
|
||||||
|
*/
|
||||||
|
List<String> authors = []
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The directory that library files and script files are found under.
|
||||||
|
*/
|
||||||
|
final String srcDir = "src/"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The directory that tests are found under.
|
||||||
|
*/
|
||||||
|
final String testDir = "test/"
|
||||||
|
|
||||||
|
ApolloPluginExtension(Project project) {
|
||||||
|
this.project = project
|
||||||
|
this.name = project.name
|
||||||
|
|
||||||
|
init()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup the {@link Project} with the correct dependencies and tasks required to build the plugin
|
||||||
|
* and its scripts.
|
||||||
|
*/
|
||||||
|
def init() {
|
||||||
|
def gameProject = project.findProject(":game")
|
||||||
|
def pluginTestingProject = project.findProject(':game:plugin-testing')
|
||||||
|
|
||||||
|
project.plugins.apply('kotlin')
|
||||||
|
project.sourceSets {
|
||||||
|
main {
|
||||||
|
kotlin {
|
||||||
|
srcDir this.srcDir
|
||||||
|
exclude '*.kts'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test {
|
||||||
|
kotlin {
|
||||||
|
srcDir this.testDir
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
project.dependencies.add('compile', gameProject)
|
||||||
|
project.dependencies.add('testCompile', pluginTestingProject.sourceSets.test.output)
|
||||||
|
|
||||||
|
dependencies.each {
|
||||||
|
project.dependencies.add('compile', project.findProject(":game:plugin:$it"))
|
||||||
|
}
|
||||||
|
|
||||||
|
project.tasks.create('compileScripts', ApolloScriptCompileTask) {
|
||||||
|
def mainSources = project.sourceSets.main
|
||||||
|
def outputDir = mainSources.output.classesDir
|
||||||
|
|
||||||
|
FileTree filtered = project.fileTree(srcDir).matching {
|
||||||
|
include '*.kts'
|
||||||
|
}
|
||||||
|
|
||||||
|
inputs.files filtered.files
|
||||||
|
outputsDir = outputDir
|
||||||
|
|
||||||
|
compileClasspath = mainSources.compileClasspath +
|
||||||
|
mainSources.runtimeClasspath
|
||||||
|
|
||||||
|
scriptDefinitionClass = "org.apollo.game.plugin.kotlin.KotlinPluginScript"
|
||||||
|
mustRunAfter project.tasks['classes']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+61
@@ -0,0 +1,61 @@
|
|||||||
|
package org.apollo.build.plugin.compiler
|
||||||
|
|
||||||
|
import kotlin.jvm.JvmClassMappingKt
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
import kotlin.reflect.full.KClasses
|
||||||
|
import kotlin.reflect.jvm.internal.KClassImpl
|
||||||
|
import kotlin.script.templates.ScriptTemplateDefinition
|
||||||
|
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||||
|
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||||
|
import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot
|
||||||
|
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||||
|
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||||
|
import org.jetbrains.kotlin.script.KotlinScriptDefinitionFromAnnotatedTemplate
|
||||||
|
|
||||||
|
import java.lang.management.ManagementFactory
|
||||||
|
|
||||||
|
class KotlinCompilerConfigurationFactory {
|
||||||
|
|
||||||
|
static CompilerConfiguration create(String scriptDefinitionClassName, Collection<File> classpath, MessageCollector messageCollector) {
|
||||||
|
def parentClassLoader = (URLClassLoader) Thread.currentThread().contextClassLoader
|
||||||
|
if (parentClassLoader == null) {
|
||||||
|
throw new RuntimeException("Unable to find current classloader")
|
||||||
|
}
|
||||||
|
|
||||||
|
URL[] classpathUrls = parentClassLoader.getURLs()
|
||||||
|
|
||||||
|
for (classpathUrl in classpathUrls) {
|
||||||
|
try {
|
||||||
|
classpath.add(new File(classpathUrl.toURI()))
|
||||||
|
} catch (ex) {
|
||||||
|
throw new RuntimeException("URL returned by ClassLoader is invalid", ex)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
def runtimeBean = ManagementFactory.getRuntimeMXBean()
|
||||||
|
if (!runtimeBean.bootClassPathSupported) {
|
||||||
|
println("Warning! Boot class path is not supported, must be supplied on the command line")
|
||||||
|
} else {
|
||||||
|
def bootClasspath = runtimeBean.bootClassPath
|
||||||
|
classpath.addAll(bootClasspath.split(File.pathSeparatorChar.toString()).collect { new File(it) })
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def classLoader = new URLClassLoader(classpath.collect { it.toURL() }.toArray(new URL[classpath.size()]))
|
||||||
|
def configuration = new CompilerConfiguration()
|
||||||
|
def scriptDefinitionClass = classLoader.loadClass(scriptDefinitionClassName)
|
||||||
|
def classpathFiles = classpath.collect { it }
|
||||||
|
|
||||||
|
def scriptDefinition = new KotlinScriptDefinitionFromAnnotatedTemplate(JvmClassMappingKt.getKotlinClass(scriptDefinitionClass),
|
||||||
|
null, null, null, classpathFiles)
|
||||||
|
|
||||||
|
configuration.add(JVMConfigurationKeys.SCRIPT_DEFINITIONS, scriptDefinition)
|
||||||
|
configuration.put(JVMConfigurationKeys.CONTENT_ROOTS, classpath.collect { new JvmClasspathRoot(it) })
|
||||||
|
configuration.put(JVMConfigurationKeys.RETAIN_OUTPUT_IN_MEMORY, true)
|
||||||
|
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector)
|
||||||
|
configuration.copy()
|
||||||
|
|
||||||
|
return configuration
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package org.apollo.build.plugin.compiler
|
||||||
|
|
||||||
|
import java.nio.file.Path
|
||||||
|
|
||||||
|
class KotlinScriptBinary {
|
||||||
|
final String fullyQualifiedName
|
||||||
|
final Path output
|
||||||
|
|
||||||
|
KotlinScriptBinary(String fullyQualifiedName, Path output) {
|
||||||
|
this.output = output
|
||||||
|
this.fullyQualifiedName = fullyQualifiedName
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package org.apollo.build.plugin.compiler
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||||
|
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||||
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||||
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler
|
||||||
|
import org.jetbrains.kotlin.com.intellij.openapi.util.Disposer
|
||||||
|
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||||
|
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||||
|
import org.jetbrains.kotlin.config.KotlinSourceRoot
|
||||||
|
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.nio.file.Path
|
||||||
|
import java.nio.file.StandardOpenOption
|
||||||
|
|
||||||
|
class KotlinScriptCompiler {
|
||||||
|
private String scriptDefinitionClass
|
||||||
|
private Collection<File> classpath
|
||||||
|
private MessageCollector messageCollector
|
||||||
|
|
||||||
|
KotlinScriptCompiler(String scriptDefinitionClass, Collection<File> classpath, MessageCollector messageCollector) {
|
||||||
|
this.scriptDefinitionClass = scriptDefinitionClass
|
||||||
|
this.classpath = classpath
|
||||||
|
this.messageCollector = messageCollector
|
||||||
|
}
|
||||||
|
|
||||||
|
KotlinScriptBinary compile(Path input, Path output) {
|
||||||
|
def compilerConfiguration = KotlinCompilerConfigurationFactory.create(
|
||||||
|
scriptDefinitionClass,
|
||||||
|
classpath,
|
||||||
|
messageCollector
|
||||||
|
)
|
||||||
|
|
||||||
|
def rootDisposable = Disposer.newDisposable()
|
||||||
|
def configuration = compilerConfiguration.copy()
|
||||||
|
|
||||||
|
output.toFile().mkdirs()
|
||||||
|
|
||||||
|
configuration.put(CommonConfigurationKeys.MODULE_NAME, input.toString())
|
||||||
|
configuration.add(JVMConfigurationKeys.CONTENT_ROOTS, new KotlinSourceRoot(input.toAbsolutePath().toString()))
|
||||||
|
|
||||||
|
def configFiles = EnvironmentConfigFiles.JVM_CONFIG_FILES
|
||||||
|
def environment = KotlinCoreEnvironment.createForProduction(rootDisposable, configuration, configFiles)
|
||||||
|
|
||||||
|
try {
|
||||||
|
def generationState = KotlinToJVMBytecodeCompiler.INSTANCE.analyzeAndGenerate(environment)
|
||||||
|
if (generationState == null) {
|
||||||
|
throw new KotlinScriptCompilerException("Failed to generate bytecode for kotlin script")
|
||||||
|
}
|
||||||
|
|
||||||
|
def sourceFiles = environment.getSourceFiles()
|
||||||
|
def script = sourceFiles[0].script
|
||||||
|
if (script == null) {
|
||||||
|
throw new KotlinScriptCompilerException("Main source file is not a script")
|
||||||
|
}
|
||||||
|
|
||||||
|
def scriptFilePath = script.fqName.asString().replace('.', '/') + ".class"
|
||||||
|
def scriptFileClass = generationState.factory.get(scriptFilePath)
|
||||||
|
|
||||||
|
if (scriptFileClass == null) {
|
||||||
|
throw new KotlinScriptCompilerException("Unable to find compiled plugin class file $scriptFilePath")
|
||||||
|
}
|
||||||
|
|
||||||
|
generationState.factory.asList().forEach {
|
||||||
|
Files.write(output.resolve(it.relativePath), it.asByteArray(), StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING)
|
||||||
|
}
|
||||||
|
|
||||||
|
return new KotlinScriptBinary(script.fqName.asString(), output.resolve(scriptFileClass.relativePath))
|
||||||
|
} catch (ex) {
|
||||||
|
throw new KotlinScriptCompilerException("Compilation failed", ex)
|
||||||
|
} finally {
|
||||||
|
Disposer.dispose(rootDisposable)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package org.apollo.build.plugin.compiler
|
||||||
|
|
||||||
|
class KotlinScriptCompilerException extends Exception {
|
||||||
|
KotlinScriptCompilerException(String message) {
|
||||||
|
super(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
KotlinScriptCompilerException(String message, Throwable cause) {
|
||||||
|
super(message, cause)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package org.apollo.build.plugin.tasks
|
||||||
|
|
||||||
|
import org.apollo.build.plugin.compiler.KotlinScriptCompiler
|
||||||
|
import org.gradle.api.DefaultTask
|
||||||
|
import org.gradle.api.file.FileCollection
|
||||||
|
import org.gradle.api.tasks.Input
|
||||||
|
import org.gradle.api.tasks.TaskAction
|
||||||
|
import org.gradle.api.tasks.incremental.IncrementalTaskInputs
|
||||||
|
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
|
||||||
|
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
|
||||||
|
|
||||||
|
class ApolloScriptCompileTask extends DefaultTask {
|
||||||
|
File outputsDir
|
||||||
|
|
||||||
|
@Input
|
||||||
|
FileCollection compileClasspath
|
||||||
|
|
||||||
|
@Input
|
||||||
|
String scriptDefinitionClass
|
||||||
|
|
||||||
|
@TaskAction
|
||||||
|
def execute(IncrementalTaskInputs inputs) {
|
||||||
|
if (scriptDefinitionClass == null) {
|
||||||
|
throw new Exception("No script definition class given")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (compileClasspath == null) {
|
||||||
|
throw new Exception("No compile classpath given")
|
||||||
|
}
|
||||||
|
|
||||||
|
def classpath = compileClasspath.files
|
||||||
|
def messageCollector = new PrintingMessageCollector(System.err, MessageRenderer.PLAIN_RELATIVE_PATHS, true);
|
||||||
|
def compiler = new KotlinScriptCompiler(scriptDefinitionClass, classpath, messageCollector)
|
||||||
|
|
||||||
|
inputs.outOfDate {
|
||||||
|
removeBinariesFor(it.file)
|
||||||
|
compiler.compile(it.file.toPath(), outputsDir.toPath())
|
||||||
|
}
|
||||||
|
|
||||||
|
inputs.removed {
|
||||||
|
removeBinariesFor(it.file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def removeBinariesFor(File file) {
|
||||||
|
def normalizedFilename = file.name.replace("[^A-Z_]", "_")
|
||||||
|
def normalizedPrefix = normalizedFilename.subSequence(0, normalizedFilename.lastIndexOf('.'))
|
||||||
|
|
||||||
|
FileFilter filter = {
|
||||||
|
it.name.startsWith(normalizedPrefix)
|
||||||
|
}
|
||||||
|
|
||||||
|
def binaries = outputsDir.listFiles FileFilter { dir, name -> name.startsWith(normalizedPrefix) }
|
||||||
|
|
||||||
|
binaries.forEach {
|
||||||
|
it.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,128 +0,0 @@
|
|||||||
package org.apollo.build.compile
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
|
||||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler
|
|
||||||
import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot
|
|
||||||
import org.jetbrains.kotlin.codegen.CompilationException
|
|
||||||
import org.jetbrains.kotlin.com.intellij.openapi.util.Disposer
|
|
||||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
|
||||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
|
||||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
|
||||||
import org.jetbrains.kotlin.config.addKotlinSourceRoot
|
|
||||||
import org.jetbrains.kotlin.script.KotlinScriptDefinitionFromAnnotatedTemplate
|
|
||||||
import java.io.File
|
|
||||||
import java.lang.management.ManagementFactory
|
|
||||||
import java.net.URISyntaxException
|
|
||||||
import java.net.URLClassLoader
|
|
||||||
import java.nio.file.Files
|
|
||||||
import java.nio.file.Path
|
|
||||||
import java.nio.file.StandardOpenOption
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
|
|
||||||
data class KotlinCompilerResult(val fqName: String, val outputPath: Path)
|
|
||||||
|
|
||||||
class KotlinScriptCompiler {
|
|
||||||
|
|
||||||
val classpath: List<File>
|
|
||||||
val messageCollector: MessageCollector
|
|
||||||
val compilerConfiguration: CompilerConfiguration
|
|
||||||
|
|
||||||
constructor(scriptDefinitionClassName: String, classpath: Collection<File>, messageCollector: MessageCollector) {
|
|
||||||
this.classpath = classpath + currentClasspath()
|
|
||||||
this.messageCollector = messageCollector
|
|
||||||
this.compilerConfiguration = createCompilerConfiguration(scriptDefinitionClassName)
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
fun currentClasspath(): List<File> {
|
|
||||||
val classLoader = Thread.currentThread().contextClassLoader as? URLClassLoader ?:
|
|
||||||
throw RuntimeException("Unable to resolve classpath for current ClassLoader")
|
|
||||||
|
|
||||||
val classpathUrls = classLoader.urLs
|
|
||||||
val classpath = ArrayList<File>()
|
|
||||||
|
|
||||||
for (classpathUrl in classpathUrls) {
|
|
||||||
try {
|
|
||||||
classpath.add(File(classpathUrl.toURI()))
|
|
||||||
} catch (e: URISyntaxException) {
|
|
||||||
throw RuntimeException("URL returned by ClassLoader is invalid")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
val runtimeBean = ManagementFactory.getRuntimeMXBean()
|
|
||||||
if (!runtimeBean.isBootClassPathSupported) {
|
|
||||||
println("Warning! Boot class path is not supported, must be supplied on the command line")
|
|
||||||
} else {
|
|
||||||
val bootClasspath = runtimeBean.bootClassPath
|
|
||||||
classpath.addAll(bootClasspath.split(File.pathSeparatorChar).map { File(it) })
|
|
||||||
}
|
|
||||||
|
|
||||||
return classpath
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createCompilerConfiguration(scriptDefinitionClassName: String): CompilerConfiguration {
|
|
||||||
val classLoader = URLClassLoader(classpath.map { it.toURL() }.toTypedArray())
|
|
||||||
val configuration = CompilerConfiguration()
|
|
||||||
val scriptDefinitionClass = classLoader.loadClass(scriptDefinitionClassName)
|
|
||||||
val scriptDefinition = KotlinScriptDefinitionFromAnnotatedTemplate(scriptDefinitionClass.kotlin)
|
|
||||||
|
|
||||||
configuration.add(JVMConfigurationKeys.SCRIPT_DEFINITIONS, scriptDefinition)
|
|
||||||
configuration.put(JVMConfigurationKeys.CONTENT_ROOTS, classpath.map { JvmClasspathRoot(it) })
|
|
||||||
configuration.put(JVMConfigurationKeys.RETAIN_OUTPUT_IN_MEMORY, true)
|
|
||||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector)
|
|
||||||
configuration.copy()
|
|
||||||
|
|
||||||
return configuration
|
|
||||||
}
|
|
||||||
|
|
||||||
@Throws(KotlinPluginCompilerException::class)
|
|
||||||
fun compile(inputPath: Path, outputPath: Path): KotlinCompilerResult {
|
|
||||||
val rootDisposable = Disposer.newDisposable()
|
|
||||||
val configuration = compilerConfiguration.copy()
|
|
||||||
|
|
||||||
configuration.put(CommonConfigurationKeys.MODULE_NAME, inputPath.toString())
|
|
||||||
configuration.addKotlinSourceRoot(inputPath.toAbsolutePath().toString())
|
|
||||||
|
|
||||||
val configFiles = EnvironmentConfigFiles.JVM_CONFIG_FILES
|
|
||||||
val environment = KotlinCoreEnvironment.createForProduction(rootDisposable, configuration, configFiles)
|
|
||||||
|
|
||||||
try {
|
|
||||||
val generationState = KotlinToJVMBytecodeCompiler.analyzeAndGenerate(environment)
|
|
||||||
if (generationState == null) {
|
|
||||||
throw KotlinPluginCompilerException("Failed to generate bytecode for kotlin script")
|
|
||||||
}
|
|
||||||
|
|
||||||
val sourceFiles = environment.getSourceFiles()
|
|
||||||
val script = sourceFiles[0].script ?: throw KotlinPluginCompilerException("Main script file isnt a script")
|
|
||||||
|
|
||||||
val scriptFilePath = script.fqName.asString().replace('.', '/') + ".class"
|
|
||||||
val scriptFileClass = generationState.factory.get(scriptFilePath)
|
|
||||||
|
|
||||||
if (scriptFileClass == null) {
|
|
||||||
throw KotlinPluginCompilerException("Unable to find compiled plugin class file $scriptFilePath")
|
|
||||||
}
|
|
||||||
|
|
||||||
generationState.factory.asList().forEach {
|
|
||||||
Files.write(outputPath.resolve(it.relativePath), it.asByteArray(), StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING)
|
|
||||||
}
|
|
||||||
|
|
||||||
return KotlinCompilerResult(script.fqName.asString(), outputPath.resolve(scriptFileClass.relativePath))
|
|
||||||
} catch (e: CompilationException) {
|
|
||||||
throw KotlinPluginCompilerException("Compilation failed", e)
|
|
||||||
} finally {
|
|
||||||
Disposer.dispose(rootDisposable)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class KotlinPluginCompilerException(message: String, cause: Throwable? = null) : Exception(message, cause) {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
package org.apollo.build.tasks
|
|
||||||
|
|
||||||
import org.apollo.build.compile.KotlinScriptCompiler
|
|
||||||
import org.gradle.api.DefaultTask
|
|
||||||
import org.gradle.api.file.FileCollection
|
|
||||||
import org.gradle.api.tasks.Input
|
|
||||||
import org.gradle.api.tasks.OutputDirectory
|
|
||||||
import org.gradle.api.tasks.TaskAction
|
|
||||||
import org.gradle.api.tasks.incremental.IncrementalTaskInputs
|
|
||||||
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
|
|
||||||
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
open class KotlinScriptCompileTask : DefaultTask() {
|
|
||||||
@OutputDirectory
|
|
||||||
var outputsDir: File? = null
|
|
||||||
|
|
||||||
@Input
|
|
||||||
var compileClasspath: FileCollection? = null
|
|
||||||
|
|
||||||
@Input
|
|
||||||
var scriptDefinitionClass: String? = null
|
|
||||||
|
|
||||||
@TaskAction
|
|
||||||
fun execute(inputs: IncrementalTaskInputs) {
|
|
||||||
if (scriptDefinitionClass == null) {
|
|
||||||
throw Exception("No script definition class given")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (compileClasspath == null) {
|
|
||||||
throw Exception("No compile classpath given")
|
|
||||||
}
|
|
||||||
|
|
||||||
val classpath = compileClasspath!!.files
|
|
||||||
val messageCollector = PrintingMessageCollector(System.err, MessageRenderer.PLAIN_RELATIVE_PATHS, true);
|
|
||||||
val compiler = KotlinScriptCompiler(scriptDefinitionClass!!, classpath, messageCollector)
|
|
||||||
|
|
||||||
inputs.outOfDate {
|
|
||||||
removeBinariesFor(it.file)
|
|
||||||
compiler.compile(it.file.toPath(), outputsDir!!.toPath())
|
|
||||||
}
|
|
||||||
|
|
||||||
inputs.removed {
|
|
||||||
removeBinariesFor(it.file)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun removeBinariesFor(file: File) {
|
|
||||||
val normalizedFilename = file.name.replace("[^A-Z_]", "_")
|
|
||||||
val normalizedPrefix = normalizedFilename.subSequence(0, normalizedFilename.lastIndexOf('.'))
|
|
||||||
|
|
||||||
val binaries = outputsDir!!.listFiles { dir, name -> name.startsWith(normalizedPrefix) }
|
|
||||||
|
|
||||||
binaries.forEach {
|
|
||||||
it.delete()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
implementation-class=org.apollo.build.plugin.ApolloPlugin
|
||||||
+6
-11
@@ -6,15 +6,11 @@ buildscript {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
|
classpath group: 'org.jetbrains.kotlin', name: 'kotlin-gradle-plugin', version: "$kotlinVersion"
|
||||||
classpath group: 'com.moandjiezana.toml', name: 'toml4j', version: '0.7.1'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ext.pluginsDir = "$projectDir/src/plugins"
|
|
||||||
|
|
||||||
apply plugin: 'kotlin'
|
apply plugin: 'kotlin'
|
||||||
apply from: 'plugins.gradle'
|
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
@@ -24,12 +20,6 @@ sourceSets {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
|
||||||
maven {
|
|
||||||
url { 'https://dl.bintray.com/kotlin/kotlinx/' }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(':cache')
|
compile project(':cache')
|
||||||
compile project(':net')
|
compile project(':net')
|
||||||
@@ -41,6 +31,11 @@ dependencies {
|
|||||||
compile group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-jdk8', version: '0.16'
|
compile group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-jdk8', version: '0.16'
|
||||||
compile group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '0.16'
|
compile group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '0.16'
|
||||||
|
|
||||||
|
project(":game:plugin").subprojects.each { plugin ->
|
||||||
|
println(plugin)
|
||||||
|
runtime plugin
|
||||||
|
}
|
||||||
|
|
||||||
testCompile group: 'org.assertj', name: 'assertj-core', version: '3.8.0'
|
testCompile group: 'org.assertj', name: 'assertj-core', version: '3.8.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
apply plugin: 'kotlin'
|
||||||
|
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile project(':game')
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
apolloPlugin {
|
||||||
|
name = "Banking"
|
||||||
|
packageName = "org.apollo.game.plugin.banking"
|
||||||
|
authors = [
|
||||||
|
"Major",
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
import com.moandjiezana.toml.Toml
|
||||||
|
|
||||||
|
import java.nio.file.Paths
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
classpath group: 'com.moandjiezana.toml', name: 'toml4j', version: '0.7.1'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
subprojects {
|
||||||
|
if (it.buildFile.exists()) {
|
||||||
|
apply plugin: 'apollo-plugin'
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
maven {
|
||||||
|
url { 'https://dl.bintray.com/kotlin/kotlinx/' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task("convertPluginTomlToGradle") {
|
||||||
|
def pluginTree = fileTree(dir: "${project.rootDir}/game/src/plugins/")
|
||||||
|
def pluginDefinitions = pluginTree.matching {
|
||||||
|
include "**/*.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 description = meta.getString("description", "")
|
||||||
|
def packageName = meta.getString("package", "org.apollo.game.plugin")
|
||||||
|
def authors = meta.getList("authors", new ArrayList())
|
||||||
|
def dependencies = meta.getList("dependencies", new ArrayList())
|
||||||
|
|
||||||
|
def buildFile = new File(pluginFolder.toFile(), 'build.gradle')
|
||||||
|
buildFile.withWriter('UTF-8') { writer ->
|
||||||
|
writer.write("apolloPlugin {\n")
|
||||||
|
writer.write(" name = \"$normalizedName\"\n")
|
||||||
|
|
||||||
|
if (packageName != "org.apollo.game.plugin") {
|
||||||
|
writer.write(" packageName = \"$packageName\"\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (description.length() > 0) {
|
||||||
|
writer.write(" description = \"$description\"\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (authors.size > 0) {
|
||||||
|
writer.write(" authors = [\n")
|
||||||
|
authors.each { writer.write(" \"$it\",\n") }
|
||||||
|
writer.write(" ]\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dependencies.size > 0) {
|
||||||
|
writer.write(" dependencies = [\n")
|
||||||
|
dependencies.each { writer.write(" \"$it\",\n") }
|
||||||
|
writer.write(" ]\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.write("}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
apolloPlugin {
|
||||||
|
name = "private-messaging"
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
apolloPlugin {
|
||||||
|
name = "Chat commands"
|
||||||
|
packageName = "org.apollo.game.plugin.cmd"
|
||||||
|
authors = [
|
||||||
|
"Graham",
|
||||||
|
"Major",
|
||||||
|
"lare96",
|
||||||
|
"cubeee",
|
||||||
|
]
|
||||||
|
dependencies = [
|
||||||
|
"util:command",
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
apolloPlugin {
|
||||||
|
name = "consumables"
|
||||||
|
packageName = "org.apollo.game.plugin.consumables"
|
||||||
|
authors = [
|
||||||
|
"Gary Tierney",
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
apolloPlugin {
|
||||||
|
name = "training-dummy"
|
||||||
|
packageName = "org.apollo.game.plugin.entity"
|
||||||
|
authors = [
|
||||||
|
"Gary Tierney",
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
apolloPlugin {
|
||||||
|
name = "emote-tab"
|
||||||
|
packageName = "org.apollo.game.plugin.widget"
|
||||||
|
authors = [
|
||||||
|
"Gary Tierney",
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
apolloPlugin {
|
||||||
|
name = "following"
|
||||||
|
packageName = "org.apollo.game.plugin.entity"
|
||||||
|
authors = [
|
||||||
|
"Gary Tierney",
|
||||||
|
]
|
||||||
|
dependencies = [
|
||||||
|
"walkto",
|
||||||
|
"command_utilities",
|
||||||
|
"player_action",
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
apolloPlugin {
|
||||||
|
name = "player_action"
|
||||||
|
packageName = "org.apollo.game.plugin.entity"
|
||||||
|
authors = [
|
||||||
|
"Gary Tierney",
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
apolloPlugin {
|
||||||
|
name = "spawning"
|
||||||
|
packageName = "org.apollo.game.plugin.entity"
|
||||||
|
authors = [
|
||||||
|
"Gary Tierney",
|
||||||
|
]
|
||||||
|
dependencies = [
|
||||||
|
"entity_lookup",
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
apolloPlugin {
|
||||||
|
name = "walkto"
|
||||||
|
packageName = "org.apollo.plugin.entity.walkto"
|
||||||
|
authors = [
|
||||||
|
"Gary Tierney",
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
apolloPlugin {
|
||||||
|
name = "al-kharid npc spawns"
|
||||||
|
packageName = "org.apollo.game.plugin.locations"
|
||||||
|
authors = [
|
||||||
|
"Jesse W",
|
||||||
|
]
|
||||||
|
dependencies = [
|
||||||
|
"spawning",
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
apolloPlugin {
|
||||||
|
name = "edgeville npc spawns"
|
||||||
|
packageName = "org.apollo.game.plugin.locations"
|
||||||
|
authors = [
|
||||||
|
"Jesse W",
|
||||||
|
]
|
||||||
|
dependencies = [
|
||||||
|
"spawning",
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
apolloPlugin {
|
||||||
|
name = "falador npc spawns"
|
||||||
|
packageName = "org.apollo.game.plugin.locations"
|
||||||
|
authors = [
|
||||||
|
"Jesse W",
|
||||||
|
]
|
||||||
|
dependencies = [
|
||||||
|
"spawning",
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
apolloPlugin {
|
||||||
|
name = "lumbridge npc spawns"
|
||||||
|
packageName = "org.apollo.game.plugin.locations"
|
||||||
|
authors = [
|
||||||
|
"Gary Tierney",
|
||||||
|
]
|
||||||
|
dependencies = [
|
||||||
|
"spawning",
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
apolloPlugin {
|
||||||
|
name = "tutorial island npc spawns"
|
||||||
|
packageName = "org.apollo.game.plugin.locations"
|
||||||
|
authors = [
|
||||||
|
"Jesse W",
|
||||||
|
]
|
||||||
|
dependencies = [
|
||||||
|
"spawning",
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
apolloPlugin {
|
||||||
|
name = "varrock npc spawns"
|
||||||
|
packageName = "org.apollo.game.plugin.locations"
|
||||||
|
authors = [
|
||||||
|
"Jesse W",
|
||||||
|
]
|
||||||
|
dependencies = [
|
||||||
|
"spawning",
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
apolloPlugin {
|
||||||
|
name = "logout"
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
apolloPlugin {
|
||||||
|
name = "run"
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
apolloPlugin {
|
||||||
|
name = "command utilities"
|
||||||
|
packageName = "org.apollo.game.plugins.util"
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
apolloPlugin {
|
||||||
|
name = "entity lookup"
|
||||||
|
packageName = "org.apollo.game.plugins.util"
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user