From c2b96549a6bee021ab1ee1131c16e8f5a29b3da0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 22 Oct 2025 14:30:42 +0000 Subject: [PATCH 1/5] Initial plan From f333e97a5a96f455d969dbacd557c2bae09c81dc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 22 Oct 2025 14:46:39 +0000 Subject: [PATCH 2/5] Add TeaVM build configuration and initial setup Co-authored-by: Project516 <138796702+Project516@users.noreply.github.com> --- app/build.gradle | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ teavm/index.html | 41 ++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 teavm/index.html diff --git a/app/build.gradle b/app/build.gradle index 53f60ae..17764d4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,3 +1,13 @@ +buildscript { + repositories { + mavenCentral() + } + dependencies { + // TeaVM tooling for JavaScript compilation task + classpath 'org.teavm:teavm-tooling:0.10.2' + } +} + plugins { // Apply the application plugin to add support for building a CLI application in Java. id 'application' @@ -11,9 +21,20 @@ repositories { mavenCentral() } +// Separate configuration for TeaVM compiler (not part of application runtime) +configurations { + teavm +} + dependencies { // This dependency is used by the application. implementation libs.guava + + // TeaVM dependencies for JavaScript compilation (only for build, not runtime) + teavm 'org.teavm:teavm-core:0.10.2' + teavm 'org.teavm:teavm-tooling:0.10.2' + teavm 'org.teavm:teavm-classlib:0.10.2' + teavm 'org.teavm:teavm-jso-apis:0.10.2' } testing { @@ -61,3 +82,53 @@ jar { ) } } + +// TeaVM task for compiling Java GUI to JavaScript +task generateTeaVM { + group = 'build' + description = 'Compiles Java GUI application to JavaScript using TeaVM' + + dependsOn classes + + // Define outputs for up-to-date checking + outputs.dir(layout.buildDirectory.dir('teavm')) + + doLast { + // Create output directory + def outputDir = layout.buildDirectory.dir('teavm').get().asFile + outputDir.mkdirs() + + // Get TeaVM classpath + def teavmClasspath = configurations.teavm.files.collect { it.toURI().toURL() } as URL[] + def appClasspath = (sourceSets.main.runtimeClasspath.files + sourceSets.main.output.classesDirs.files) + .collect { it.toURI().toURL() } as URL[] + + // Combined classloader with TeaVM and application classes + def combinedLoader = new URLClassLoader( + teavmClasspath + appClasspath, + ClassLoader.getSystemClassLoader() + ) + + // Configure TeaVM + def toolingClass = combinedLoader.loadClass('org.teavm.tooling.TeaVMTool') + def targetTypeClass = combinedLoader.loadClass('org.teavm.tooling.TeaVMTargetType') + def tooling = toolingClass.getDeclaredConstructor().newInstance() + + tooling.targetDirectory = outputDir + // Use GUI as main class - TeaVM will compile what it can + tooling.mainClass = 'io.github.project516.NumberGuessingGame.GUI' + + // Application classloader for TeaVM to analyze + def appLoader = new URLClassLoader(appClasspath as URL[], (ClassLoader) null) + tooling.classLoader = appLoader + + // Configuration options + tooling.targetType = targetTypeClass.JAVASCRIPT + tooling.debugInformationGenerated = true + + // Generate JavaScript + tooling.generate() + + println "TeaVM compilation completed. Output: ${outputDir}" + } +} diff --git a/teavm/index.html b/teavm/index.html new file mode 100644 index 0000000..4337d3b --- /dev/null +++ b/teavm/index.html @@ -0,0 +1,41 @@ + + +
+ + +Loading application...
+Compiled with TeaVM
+Loading application...
-Compiled with TeaVM
+