@@ -23,15 +23,18 @@ import javax.swing.event.DocumentListener
2323import kotlin.io.path.deleteIfExists
2424import kotlin.io.path.writeText
2525
26+ // TODO: Test offline mode, gradle seems to be included as not needed to be downloaded.
27+ // TODO: Test running examples
28+ // TODO: Report failures to the console
29+
30+ // TODO: ---- FUTURE ----
2631// TODO: Remove dependency on editor (editor is not mockable, or move editor away from JFrame)
2732// TODO: Improve progress tracking
2833// TODO: PoC new debugger/tweak mode
2934// TODO: Allow for plugins to skip gradle entirely / new modes
3035// TODO: Improve background building
3136// TODO: Track build speed (for analytics?)
3237
33- // TODO: Support offline mode
34-
3538// The gradle service runs the gradle tasks and manages the gradle connection
3639// It will create the necessary build files for gradle to run
3740// Then it will kick off a new GradleJob to run the tasks
@@ -44,8 +47,6 @@ class GradleService(val editor: Editor) {
4447 val workingDir = kotlin.io.path.createTempDirectory()
4548 val debugPort = (30_000 .. 60_000 ).random()
4649
47- var connection: ProjectConnection ? = null
48-
4950 private val scope = CoroutineScope (Dispatchers .IO )
5051
5152 // Hooks for java to check if the Gradle service is running since mutableStateOf is not accessible in java
@@ -56,57 +57,6 @@ class GradleService(val editor: Editor) {
5657 this .active.value = active
5758 }
5859
59- fun startService (){
60- Messages .log(" Starting Gradle service at $folder " )
61- connection = GradleConnector .newConnector()
62- .forProjectDirectory(folder)
63- .connect()
64- editor.sketch.onFolderChangeListeners.add {
65- connection?.close()
66- connection = GradleConnector .newConnector()
67- .forProjectDirectory(folder)
68- .connect()
69- }
70-
71- startListening()
72- startBuilding()
73- }
74-
75-
76- private fun startBuilding (){
77- scope.launch {
78- val job = BackgroundGradleJob ()
79- job.service = this @GradleService
80- job.configure = {
81- setup()
82- forTasks(" jar" )
83- addArguments(" --continuous" )
84- }
85- job.start()
86- }
87- }
88-
89- private fun startListening (){
90- SwingUtilities .invokeLater {
91- editor.sketch.code.forEach {
92- it.document.addDocumentListener(object : DocumentListener {
93- override fun insertUpdate (e : DocumentEvent ) {
94- setupGradle()
95- }
96-
97- override fun removeUpdate (e : DocumentEvent ) {
98- setupGradle()
99- }
100-
101- override fun changedUpdate (e : DocumentEvent ) {
102- setupGradle()
103- }
104- })
105- }
106-
107- // TODO: Attach listener to new tab created, callback has to be added to the editor
108- }
109- }
11060 // TODO: Add support for present
11161 fun run (){
11262 stopActions()
@@ -136,7 +86,6 @@ class GradleService(val editor: Editor) {
13686
13787 fun stop (){
13888 stopActions()
139- startBuilding()
14089 }
14190
14291 fun stopActions (){
@@ -166,6 +115,7 @@ class GradleService(val editor: Editor) {
166115 " group" to group,
167116 " version" to Base .getVersionName(),
168117 " sketchFolder" to folder.absolutePath,
118+ " sketchbook" to Base .getSketchbookFolder(),
169119 " workingDir" to workingDir.toAbsolutePath().toString(),
170120 " settings" to Platform .getSettingsFolder().absolutePath.toString(),
171121 " unsaved" to unsaved.joinToString(" ," ),
0 commit comments