Update Kotlin to 1.4.20.

This moves us off the third-party implementation of the Kotlin
scripting because the project is not yet compatible with 1.4. Doesn't
appear we really needed it for much anyway.

Test: ./gradlew build
Bug: None
Change-Id: Ib1349b2588fa571026d8263eb94e2a2d98715b25
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index e3439a9..54e392b 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -4,6 +4,22 @@
     <option name="WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN" value="true" />
     <option name="SOFT_MARGINS" value="80" />
     <JetCodeStyleSettings>
+      <option name="PACKAGES_TO_USE_STAR_IMPORTS">
+        <value>
+          <package name="java.util" alias="false" withSubpackages="false" />
+          <package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
+          <package name="io.ktor" alias="false" withSubpackages="true" />
+        </value>
+      </option>
+      <option name="PACKAGES_IMPORT_LAYOUT">
+        <value>
+          <package name="" alias="false" withSubpackages="true" />
+          <package name="java" alias="false" withSubpackages="true" />
+          <package name="javax" alias="false" withSubpackages="true" />
+          <package name="kotlin" alias="false" withSubpackages="true" />
+          <package name="" alias="true" withSubpackages="true" />
+        </value>
+      </option>
       <option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" />
       <option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="2147483647" />
       <option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index 347b2d7..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="ProjectModuleManager">
-    <modules>
-      <module fileurl="file://$PROJECT_DIR$/.idea/ndkports.iml" filepath="$PROJECT_DIR$/.idea/ndkports.iml" />
-    </modules>
-  </component>
-</project>
\ No newline at end of file
diff --git a/.idea/ndkports.iml b/.idea/ndkports.iml
index d6ebd48..78b2cc5 100644
--- a/.idea/ndkports.iml
+++ b/.idea/ndkports.iml
@@ -1,9 +1,2 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<module type="JAVA_MODULE" version="4">
-  <component name="NewModuleRootManager" inherit-compiler-output="true">
-    <exclude-output />
-    <content url="file://$MODULE_DIR$" />
-    <orderEntry type="inheritedJdk" />
-    <orderEntry type="sourceFolder" forTests="false" />
-  </component>
-</module>
\ No newline at end of file
+<module type="JAVA_MODULE" version="4" />
\ No newline at end of file
diff --git a/build.gradle.kts b/build.gradle.kts
index a00d626..86fe519 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,7 +1,9 @@
 import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
 
+val kotlinVersion = "1.4.20"
+
 plugins {
-    kotlin("jvm") version "1.3.72"
+    kotlin("jvm") version "1.4.20"
     application
 }
 
@@ -16,13 +18,20 @@
 }
 
 dependencies {
-    implementation(kotlin("stdlib", "1.3.72"))
-    implementation(kotlin("reflect", "1.3.72"))
+    implementation(kotlin("stdlib", kotlinVersion))
+    implementation(kotlin("reflect", kotlinVersion))
+
+    // JSR223 support.
+    implementation(kotlin("script-runtime", kotlinVersion))
+    implementation(kotlin("script-util", kotlinVersion))
+    implementation(kotlin("compiler-embeddable", kotlinVersion))
+    implementation(kotlin("scripting-compiler-embeddable", kotlinVersion))
+    implementation("net.java.dev.jna:jna:5.6.0")
+    runtime(kotlin("scripting-compiler-embeddable", kotlinVersion))
 
     implementation("com.google.prefab:api:1.0.0")
 
     implementation("com.github.ajalt:clikt:2.2.0")
-    implementation("de.swirtz:ktsRunner:0.0.7")
     implementation("org.apache.maven:maven-core:3.6.2")
     implementation("org.redundent:kotlin-xml-builder:1.5.3")
 
diff --git a/src/main/kotlin/com/android/ndkports/Cli.kt b/src/main/kotlin/com/android/ndkports/Cli.kt
index e2a5879..597500b 100644
--- a/src/main/kotlin/com/android/ndkports/Cli.kt
+++ b/src/main/kotlin/com/android/ndkports/Cli.kt
@@ -26,10 +26,10 @@
 import com.github.ajalt.clikt.parameters.options.option
 import com.github.ajalt.clikt.parameters.options.required
 import com.github.ajalt.clikt.parameters.types.file
-import de.swirtz.ktsrunner.objectloader.KtsObjectLoader
 import java.io.File
 import java.io.FileNotFoundException
 import java.lang.RuntimeException
+import javax.script.ScriptEngineManager
 import kotlin.system.exitProcess
 
 class Cli : CliktCommand(help = "ndkports") {
@@ -67,7 +67,9 @@
             }
         }
 
-        return KtsObjectLoader().load(portFile.reader())
+        val engine = ScriptEngineManager().getEngineByExtension("kts")
+            ?: throw RuntimeException("Could not get kts scripting engine")
+        return engine.eval(portFile.readText()) as Port
     }
 
     override fun run() {
diff --git a/src/main/kotlin/com/android/ndkports/PrefabPackageBuilder.kt b/src/main/kotlin/com/android/ndkports/PrefabPackageBuilder.kt
index 1a58f5a..90ef57c 100644
--- a/src/main/kotlin/com/android/ndkports/PrefabPackageBuilder.kt
+++ b/src/main/kotlin/com/android/ndkports/PrefabPackageBuilder.kt
@@ -20,6 +20,7 @@
 import com.google.prefab.api.ModuleMetadataV1
 import com.google.prefab.api.PackageMetadataV1
 import kotlinx.serialization.json.Json
+import kotlinx.serialization.json.JsonConfiguration
 import kotlinx.serialization.stringify
 import org.apache.maven.model.Dependency
 import org.apache.maven.model.Developer
@@ -110,7 +111,7 @@
 
     private fun makePackageMetadata() {
         prefabDirectory.resolve("prefab.json").writeText(
-            Json.stringify(
+            Json(JsonConfiguration.Stable).stringify(
                 PackageMetadataV1(
                     port.name,
                     schemaVersion = 1,
@@ -123,7 +124,7 @@
 
     private fun makeModuleMetadata(module: Module, moduleDirectory: File) {
         moduleDirectory.resolve("module.json").writeText(
-            Json.stringify(
+            Json(JsonConfiguration.Stable).stringify(
                 ModuleMetadataV1(
                     exportLibraries = module.dependencies
                 )
@@ -147,7 +148,7 @@
         }
 
         installDirectory.resolve("abi.json").writeText(
-            Json.stringify(
+            Json(JsonConfiguration.Stable).stringify(
                 AndroidAbiMetadata(
                     abi = abi.abiName,
                     api = api,
diff --git a/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory b/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory
new file mode 100644
index 0000000..f8f5900
--- /dev/null
+++ b/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory
@@ -0,0 +1 @@
+org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngineFactory
\ No newline at end of file