@@ -63,7 +63,12 @@ class GradleJob(
6363 private val cancel = GradleConnector .newCancellationTokenSource()
6464
6565
66- // All the configuration for the gradle build
66+ /*
67+ Set up the gradle build launcher with the necessary configuration
68+ This includes setting the working directory, the tasks to run,
69+ and the arguments to pass to gradle.
70+ Create the necessary build files if they do not exist.
71+ */
6772 private fun BuildLauncher.setupGradle (extraArguments : List <String > = listOf()) {
6873 val copy = sketch.isReadOnly || sketch.isUntitled
6974
@@ -195,6 +200,9 @@ class GradleJob(
195200 withCancellationToken(cancel.token())
196201 }
197202
203+ /*
204+ Start the gradle job and run the tasks
205+ */
198206 fun start () {
199207 launchJob {
200208 handleExceptions {
@@ -234,18 +242,26 @@ class GradleJob(
234242 }
235243
236244
237-
245+ /*
246+ Cancel the gradle job and all the jobs that were launched in this scope
247+ */
238248 fun cancel (){
239249 cancel.cancel()
240250 jobs.forEach(Job ::cancel)
241251 }
242252
253+ /*
254+ Add a job to the scope and add it to the list of jobs so we can cancel it later
255+ */
243256 private fun launchJob (block : suspend CoroutineScope .() -> Unit ){
244257 val job = scope.launch { block() }
245258 jobs.add(job)
246259 }
247260
248- // Handle exception thrown by Gradle
261+
262+ /*
263+ Handle exceptions that occur during the build process and inform the user about them
264+ */
249265 private fun handleExceptions (action : () -> Unit ){
250266 try {
251267 action()
@@ -282,7 +298,11 @@ class GradleJob(
282298 }
283299 }
284300
285- // TODO: Move to separate file
301+ // TODO: Move to separate file?
302+ /*
303+ Add a progress listener to the build launcher
304+ to track the progress of the build and update the editor status accordingly
305+ */
286306 private fun BuildLauncher.addStateListener (){
287307 addProgressListener(ProgressListener { event ->
288308 if (event is TaskStartEvent ) {
@@ -328,6 +348,7 @@ class GradleJob(
328348 return @ProgressListener
329349 }
330350 // TODO: Show the error on the location if it is available
351+ // TODO: This functionality should be provided by the mode
331352 /*
332353 We have 6 lines to display the error in the editor.
333354 */
@@ -348,6 +369,11 @@ class GradleJob(
348369 })
349370 }
350371
372+ /*
373+ Start log servers for the standard output and error streams
374+ This allows us to capture the output of Processing and display it in the editor
375+ Whilst keeping the gradle output separate
376+ */
351377 fun BuildLauncher.addLogserver (){
352378 launchJob {
353379 startLogServer(logPort, System .out )
@@ -357,6 +383,10 @@ class GradleJob(
357383 }
358384 }
359385
386+ /*
387+ Connected a debugger to the gradle run task
388+ This allows us to debug the sketch while it is running
389+ */
360390 fun BuildLauncher.addDebugging () {
361391 addProgressListener(ProgressListener { event ->
362392 if (event !is TaskStartEvent ) return @ProgressListener
0 commit comments