<commit_before>@file:Suppress("UnstableApiUsage", "UNUSED_VARIABLE")

package com.acornui.build.plugins

import com.acornui.toCamelCase
import com.acornui.build.plugins.util.appAssetsWebTasks
import com.acornui.build.plugins.util.applicationResourceTasks
import com.acornui.build.plugins.util.kotlinExt
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.file.CopySpec
import org.gradle.api.tasks.Delete
import org.gradle.api.tasks.JavaExec
import org.gradle.api.tasks.bundling.Jar
import org.gradle.internal.os.OperatingSystem
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationToRunnableFiles
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import java.io.File

@Suppress("unused")
open class AcornUiApplicationPlugin : Plugin<Project> {

	internal val targets = listOf("js", "jvm")

	override fun apply(project: Project) {
		project.pluginManager.apply("org.gradle.idea")
		project.pluginManager.apply("com.acornui.kotlin-mpp")

		project.extensions.create<AcornUiApplicationExtension>("acornui").apply {
			appResources = project.buildDir.resolve("processedResources")
			www = project.buildDir.resolve("www")
			wwwProd = project.buildDir.resolve("wwwProd")
		}
		project.extensions.configure(multiPlatformConfig(project))

		project.applicationResourceTasks(targets, listOf("main"))
		project.appAssetsWebTasks()
		project.runJvmTask()
		project.uberJarTask()

		project.tasks.named<Delete>("clean") {
			doLast {
				delete(project.acornui.www)
				delete(project.acornui.wwwProd)
			}
		}
	}

	private fun multiPlatformConfig(target: Project): KotlinMultiplatformExtension.() -> Unit = {
		js {
			compilations.all {
				kotlinOptions {
					main = "call"
				}
			}
		}

		sourceSets {
			all {
				languageSettings.progressiveMode = true
			}

			val commonMain by getting {
				dependencies {
					implementation("com.acornui:acornui-core")
					implementation("com.acornui:acornui-utils")
				}
			}

			val jvmMain by getting {
				dependencies {
					implementation("com.acornui:acornui-lwjgl-backend")

					val lwjglVersion: String by target.extra
					val lwjglGroup = "org.lwjgl"
					val lwjglName = "lwjgl"

					@Suppress("INACCESSIBLE_TYPE")
					val os = when (OperatingSystem.current()) {
						OperatingSystem.LINUX -> "linux"
						OperatingSystem.MAC_OS -> "macos"
						OperatingSystem.WINDOWS -> "windows"
						else -> throw Exception("Unsupported operating system: ${OperatingSystem.current()}")
					}
					val extensions = arrayOf("glfw", "jemalloc", "opengl", "openal", "stb", "nfd", "tinyfd")
					runtimeOnly("$lwjglGroup:$lwjglName:$lwjglVersion:natives-$os")
					extensions.forEach {
						implementation("$lwjglGroup:$lwjglName-$it:$lwjglVersion")
						runtimeOnly("$lwjglGroup:$lwjglName-$it:$lwjglVersion:natives-$os")
					}
				}
			}

			val jsMain by getting {
				dependencies {
					implementation("com.acornui:acornui-webgl-backend")
				}
			}
		}
	}
}

private fun Project.runJvmTask() {
	val jvmArgs: String? by extra
	tasks.register<JavaExec>("runJvm") {
		dependsOn("jvmProcessResources", "jvmMainClasses")
		group = "application"
		val jvmTarget: KotlinTarget = kotlinExt.targets["jvm"]
		val compilation =
				jvmTarget.compilations["main"] as KotlinCompilationToRunnableFiles<KotlinCommonOptions>
<commit_msg>runJvm dependencies<commit_after>@file:Suppress("UnstableApiUsage", "UNUSED_VARIABLE")

package com.acornui.build.plugins

import com.acornui.toCamelCase
import com.acornui.build.plugins.util.appAssetsWebTasks
import com.acornui.build.plugins.util.applicationResourceTasks
import com.acornui.build.plugins.util.kotlinExt
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.file.CopySpec
import org.gradle.api.tasks.Delete
import org.gradle.api.tasks.JavaExec
import org.gradle.api.tasks.bundling.Jar
import org.gradle.internal.os.OperatingSystem
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationToRunnableFiles
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import java.io.File

@Suppress("unused")
open class AcornUiApplicationPlugin : Plugin<Project> {

	internal val targets = listOf("js", "jvm")

	override fun apply(project: Project) {
		project.pluginManager.apply("org.gradle.idea")
		project.pluginManager.apply("com.acornui.kotlin-mpp")

		project.extensions.create<AcornUiApplicationExtension>("acornui").apply {
			appResources = project.buildDir.resolve("processedResources")
			www = project.buildDir.resolve("www")
			wwwProd = project.buildDir.resolve("wwwProd")
		}
		project.extensions.configure(multiPlatformConfig(project))

		project.applicationResourceTasks(targets, listOf("main"))
		project.appAssetsWebTasks()
		project.runJvmTask()
		project.uberJarTask()

		project.tasks.named<Delete>("clean") {
			doLast {
				delete(project.acornui.www)
				delete(project.acornui.wwwProd)
			}
		}
	}

	private fun multiPlatformConfig(target: Project): KotlinMultiplatformExtension.() -> Unit = {
		js {
			compilations.all {
				kotlinOptions {
					main = "call"
				}
			}
		}

		sourceSets {
			all {
				languageSettings.progressiveMode = true
			}

			val commonMain by getting {
				dependencies {
					implementation("com.acornui:acornui-core")
					implementation("com.acornui:acornui-utils")
				}
			}

			val jvmMain by getting {
				dependencies {
					implementation("com.acornui:acornui-lwjgl-backend")

					val lwjglVersion: String by target.extra
					val lwjglGroup = "org.lwjgl"
					val lwjglName = "lwjgl"

					@Suppress("INACCESSIBLE_TYPE")
					val os = when (OperatingSystem.current()) {
						OperatingSystem.LINUX -> "linux"
						OperatingSystem.MAC_OS -> "macos"
						OperatingSystem.WINDOWS -> "windows"
						else -> throw Exception("Unsupported operating system: ${OperatingSystem.current()}")
					}
					val extensions = arrayOf("glfw", "jemalloc", "opengl", "openal", "stb", "nfd", "tinyfd")
					runtimeOnly("$lwjglGroup:$lwjglName:$lwjglVersion:natives-$os")
					extensions.forEach {
						implementation("$lwjglGroup:$lwjglName-$it:$lwjglVersion")
						runtimeOnly("$lwjglGroup:$lwjglName-$it:$lwjglVersion:natives-$os")
					}
				}
			}

			val jsMain by getting {
				dependencies {
					implementation("com.acornui:acornui-webgl-backend")
				}
			}
		}
	}
}

private fun Project.runJvmTask() {
	val jvmArgs: String? by extra
	tasks.register<JavaExec>("runJvm") {
		dependsOn("jvmAssemble")
		group = "application"
		val jvmTarget: KotlinTarget = kotlinExt.targets["jvm"]
		val compilation =
				jvmTarget.compilations["main"] as KotlinCompilationToRunnableFiles<KotlinCommonOptions>

{'fraction_non_alphanumeric': 0.12185602775368604, 'fraction_numerical': 0.0, 'mean_word_length': 4.486915146708961, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 12, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7397074', 'n_tokens_mistral': 2738, 'n_tokens_neox': 2297, 'n_words': 336}