@@ -9,6 +9,7 @@ import org.gradle.tooling.BuildLauncher
99import org.gradle.tooling.GradleConnector
1010import org.gradle.tooling.ProjectConnection
1111import processing.app.Base
12+ import processing.app.Language
1213import processing.app.Messages
1314import processing.app.Platform
1415import processing.app.gradle.helpers.ActionGradleJob
@@ -25,8 +26,11 @@ import kotlin.io.path.writeText
2526// TODO: PoC new debugger/tweak mode
2627// TODO: Allow for plugins to skip gradle entirely
2728// TODO: Improve background building
29+
2830// The gradle service runs the gradle tasks and manages the gradle connection
2931// It will create the necessary build files for gradle to run
32+ // Then it will kick off a new GradleJob to run the tasks
33+ // GradleJob manages the gradle build and connects the debugger
3034class GradleService (val editor : Editor ) {
3135 val folder: File get() = editor.sketch.folder
3236 val active = mutableStateOf(true )
@@ -194,21 +198,41 @@ class GradleService(val editor: Editor) {
194198
195199
196200 val buildGradle = folder.resolve(" build.gradle.kts" )
197- // TODO: Manage script if the comment exists
198- if (! buildGradle.exists()) {
199- Messages .log(" build.gradle.kts not found in ${folder} , creating one" )
201+ val generate = buildGradle.let {
202+ if (! it.exists()) return @let true
203+
204+ val contents = it.readText()
205+ if (! contents.contains(" @processing-auto-generated" )) return @let false
206+
207+ val version = contents.substringAfter(" version=" ).substringBefore(" \n " )
208+ if (version != Base .getVersionName()) return @let true
209+
210+ val mode = contents.substringAfter(" mode=" ).substringBefore(" " )
211+ if (editor.mode.title != mode) return @let true
212+
213+ return @let Base .DEBUG
214+ }
215+ if (generate) {
216+ Messages .log(" build.gradle.kts not found or outdated in ${folder} , creating one" )
217+ val header = """
218+ // @processing-auto-generated mode=${editor.mode.title} version=${Base .getVersionName()}
219+ //
220+ """ .trimIndent()
221+
222+ val instructions = Language .text(" gradle.instructions" )
223+ .split(" \n " )
224+ .joinToString(" \n " ) { " // $it " }
225+
226+ // TODO: Move the current configuration to java mode
200227 // TODO: Allow for other plugins to be registered
201228 // TODO: Allow for the whole configuration to be overridden
202- // TODO: Move this to java mode
203229 // TODO: Define new plugin / mode schema
204- val content = """
205- // Managed by: Processing ${Base .getVersionName()} ${editor.mode.title}
206- // If you delete this comment Processing will no longer update the build scripts
207-
208- plugins{
209- id("org.processing.gradle") version "${Base .getVersionName()} "
210- }
211- """ .trimIndent()
230+ val configuration = """
231+ plugins{
232+ id("org.processing.gradle") version "${Base .getVersionName()} "
233+ }
234+ """ .trimIndent()
235+ val content = " ${header} \n ${instructions} \n ${configuration} "
212236 buildGradle.writeText(content)
213237 }
214238 val settingsGradle = folder.resolve(" settings.gradle.kts" )
0 commit comments