diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 865296d13..f02a511cc 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -47,7 +47,7 @@ sourceSets{ compose.desktop { application { - mainClass = "processing.app.ui.Start" + mainClass = "processing.app.ProcessingKt" jvmArgs(*listOf( Pair("processing.version", rootProject.version), @@ -97,6 +97,7 @@ compose.desktop { dependencies { implementation(project(":core")) + runtimeOnly(project(":java")) implementation(libs.flatlaf) @@ -121,6 +122,8 @@ dependencies { testImplementation(libs.mockitoKotlin) testImplementation(libs.junitJupiter) testImplementation(libs.junitJupiterParams) + + implementation("com.github.ajalt.clikt:clikt:5.0.2") } tasks.test { diff --git a/app/src/processing/app/Processing.kt b/app/src/processing/app/Processing.kt new file mode 100644 index 000000000..82f89572d --- /dev/null +++ b/app/src/processing/app/Processing.kt @@ -0,0 +1,70 @@ +package processing.app + +import com.github.ajalt.clikt.command.SuspendingCliktCommand +import com.github.ajalt.clikt.command.main +import com.github.ajalt.clikt.core.Context +import com.github.ajalt.clikt.core.subcommands +import com.github.ajalt.clikt.parameters.options.flag +import com.github.ajalt.clikt.parameters.options.option +import processing.app.ui.Start + +// TODO: Allow Start to run on no args +// TODO: Modify InstallCommander to use the new structure +// TODO: Move dependency to gradle toml +// TODO: Add the options/arguments for Base arguments +class Processing(val args: Array): SuspendingCliktCommand(name = "Processing"){ + override suspend fun run() { + if(currentContext.invokedSubcommand == null){ + Start.main(args) + } + } +} + +suspend fun main(args: Array) = Processing(args) + .subcommands( + LSP(args), + LegacyCLI(args) + ) + .main(args) + + +class LSP(val args: Array): SuspendingCliktCommand("lsp"){ + override fun help(context: Context) = "Start the Processing Language Server" + override suspend fun run(){ + try { + // Indirect invocation since app does not depend on java mode + Class.forName("processing.mode.java.lsp.PdeLanguageServer") + .getMethod("main", Array::class.java) + .invoke(null, *arrayOf(args)) + } catch (e: Exception) { + throw InternalError("Failed to invoke main method", e) + } + } +} + +class LegacyCLI(val args: Array): SuspendingCliktCommand(name = "cli"){ + override fun help(context: Context) = "Legacy processing-java command line interface" + + val help by option("--help").flag() + val build by option("--build").flag() + val run by option("--run").flag() + val present by option("--present").flag() + val sketch: String? by option("--sketch") + val force by option("--force").flag() + val output: String? by option("--output") + val export by option("--export").flag() + val noJava by option("--no-java").flag() + val variant: String? by option("--variant") + + override suspend fun run(){ + val cliArgs = args.filter { it != "cli" }.toTypedArray() + try { + // Indirect invocation since app does not depend on java mode + Class.forName("processing.mode.java.Commander") + .getMethod("main", Array::class.java) + .invoke(null, *arrayOf(cliArgs)) + } catch (e: Exception) { + throw InternalError("Failed to invoke main method", e) + } + } +} \ No newline at end of file diff --git a/core/examples/src/main/java/Basic.java b/core/examples/src/main/java/Basic.java index 379bb4b30..7c5a72cba 100644 --- a/core/examples/src/main/java/Basic.java +++ b/core/examples/src/main/java/Basic.java @@ -1,12 +1,25 @@ import processing.core.PApplet; +import java.io.IOException; + public class Basic extends PApplet { public void settings(){ size(500, 500); + + try { + Runtime.getRuntime().exec("echo Hello World"); + } catch (IOException e) { + throw new RuntimeException(e); + } } public void draw(){ - ellipse(width / 2f, height / 2f, 125f, 125f); + background(255); + fill(0); + ellipse(mouseX, mouseY, 125f, 125f); + println(frameRate); + + } diff --git a/java/src/processing/mode/java/lsp/PdeLanguageServer.java b/java/src/processing/mode/java/lsp/PdeLanguageServer.java index 3d865fcc7..0673b4823 100644 --- a/java/src/processing/mode/java/lsp/PdeLanguageServer.java +++ b/java/src/processing/mode/java/lsp/PdeLanguageServer.java @@ -21,7 +21,7 @@ import org.eclipse.lsp4j.services.LanguageClientAware; import org.eclipse.lsp4j.services.LanguageClient; -class PdeLanguageServer implements LanguageServer, LanguageClientAware { +public class PdeLanguageServer implements LanguageServer, LanguageClientAware { Map adapters = new HashMap<>(); LanguageClient client = null; PdeTextDocumentService textDocumentService = new PdeTextDocumentService(this);