diff --git a/app/src/processing/app/gradle/Debugger.kt b/app/src/processing/app/gradle/Debugger.kt index aea18ec13..9c93bd824 100644 --- a/app/src/processing/app/gradle/Debugger.kt +++ b/app/src/processing/app/gradle/Debugger.kt @@ -21,6 +21,7 @@ class Debugger { args["port"]?.setValue(port?.toString() ?: "5005") // Try to attach the debugger, retrying if it fails + // TODO: Stop retrying after the job has been cancelled / failed val start = TimeSource.Monotonic.markNow() while (start.elapsedNow() < 10.seconds) { try { diff --git a/app/src/processing/app/gradle/Exceptions.kt b/app/src/processing/app/gradle/Exceptions.kt index c24a6f4dd..c913ef4f8 100644 --- a/app/src/processing/app/gradle/Exceptions.kt +++ b/app/src/processing/app/gradle/Exceptions.kt @@ -56,6 +56,7 @@ class Exceptions (val vm: VirtualMachine, val editor: Editor?) { /* We have 6 lines by default within the editor to display more information about the exception. */ + // TODO: Improve the display and clarity of the exception details val message = """ In Processing code: @@ -91,7 +92,7 @@ class Exceptions (val vm: VirtualMachine, val editor: Editor?) { } // TODO: Map to .pde file again, @see JavaBuild.placeException - // BLOCKED: Because we don't run the JavaBuild code.prepocOffset is empty + // TODO: This functionality should be provided by the mode return this } diff --git a/app/src/processing/app/gradle/GradleJob.kt b/app/src/processing/app/gradle/GradleJob.kt index 135f28de6..006b138f6 100644 --- a/app/src/processing/app/gradle/GradleJob.kt +++ b/app/src/processing/app/gradle/GradleJob.kt @@ -63,7 +63,12 @@ class GradleJob( private val cancel = GradleConnector.newCancellationTokenSource() - // All the configuration for the gradle build + /* + Set up the gradle build launcher with the necessary configuration + This includes setting the working directory, the tasks to run, + and the arguments to pass to gradle. + Create the necessary build files if they do not exist. + */ private fun BuildLauncher.setupGradle(extraArguments: List = listOf()) { val copy = sketch.isReadOnly || sketch.isUntitled @@ -195,6 +200,9 @@ class GradleJob( withCancellationToken(cancel.token()) } + /* + Start the gradle job and run the tasks + */ fun start() { launchJob { handleExceptions { @@ -234,18 +242,26 @@ class GradleJob( } - + /* + Cancel the gradle job and all the jobs that were launched in this scope + */ fun cancel(){ cancel.cancel() jobs.forEach(Job::cancel) } + /* + Add a job to the scope and add it to the list of jobs so we can cancel it later + */ private fun launchJob(block: suspend CoroutineScope.() -> Unit){ val job = scope.launch { block() } jobs.add(job) } - // Handle exception thrown by Gradle + + /* + Handle exceptions that occur during the build process and inform the user about them + */ private fun handleExceptions(action: () -> Unit){ try{ action() @@ -282,7 +298,11 @@ class GradleJob( } } - // TODO: Move to separate file + // TODO: Move to separate file? + /* + Add a progress listener to the build launcher + to track the progress of the build and update the editor status accordingly + */ private fun BuildLauncher.addStateListener(){ addProgressListener(ProgressListener { event -> if(event is TaskStartEvent) { @@ -328,6 +348,7 @@ class GradleJob( return@ProgressListener } // TODO: Show the error on the location if it is available + // TODO: This functionality should be provided by the mode /* We have 6 lines to display the error in the editor. */ @@ -348,6 +369,11 @@ class GradleJob( }) } + /* + Start log servers for the standard output and error streams + This allows us to capture the output of Processing and display it in the editor + Whilst keeping the gradle output separate + */ fun BuildLauncher.addLogserver(){ launchJob { startLogServer(logPort, System.out) @@ -357,6 +383,10 @@ class GradleJob( } } + /* + Connected a debugger to the gradle run task + This allows us to debug the sketch while it is running + */ fun BuildLauncher.addDebugging() { addProgressListener(ProgressListener { event -> if (event !is TaskStartEvent) return@ProgressListener diff --git a/app/src/processing/app/gradle/GradleService.kt b/app/src/processing/app/gradle/GradleService.kt index a921f166e..2739a7519 100644 --- a/app/src/processing/app/gradle/GradleService.kt +++ b/app/src/processing/app/gradle/GradleService.kt @@ -9,17 +9,13 @@ import processing.app.Sketch import processing.app.ui.Editor import kotlin.io.path.createTempDirectory -// TODO: Test offline mode, gradle seems to be included as not needed to be downloaded. -// TODO: Test running examples -// TODO: Report failures to the console -// TODO: Highlight errors in the editor +// TODO: Highlight errors in the editor in the right place // TODO: ---- FUTURE ---- // TODO: Improve progress tracking and show it in the UI // TODO: PoC new debugger/tweak mode -// TODO: Allow for plugins to skip gradle entirely / new modes -// TODO: Add background building // TODO: Track build speed (for analytics?) +// TODO: Bundle Gradle with the app /* * The gradle service runs the gradle tasks and manages the gradle connection diff --git a/app/src/processing/app/gradle/api/Sketch.kt b/app/src/processing/app/gradle/api/Sketch.kt index 04cccbb27..30e6245d1 100644 --- a/app/src/processing/app/gradle/api/Sketch.kt +++ b/app/src/processing/app/gradle/api/Sketch.kt @@ -3,6 +3,7 @@ package processing.app.gradle.api import com.github.ajalt.clikt.command.SuspendingCliktCommand import com.github.ajalt.clikt.core.Context import com.github.ajalt.clikt.core.subcommands +import com.github.ajalt.clikt.parameters.options.default import com.github.ajalt.clikt.parameters.options.option import com.github.ajalt.clikt.parameters.options.required import processing.app.Base @@ -31,6 +32,8 @@ class Sketch : SuspendingCliktCommand("sketch") { val sketch by option("--sketch", help = "The sketch to run") .required() + val mode by option("--mode", help = "The mode to use for running the sketch (only java is supported for now)") + override fun help(context: Context): String { return "Run the Processing sketch." }