@@ -6,7 +6,6 @@ import com.sun.jdi.Bootstrap
66import com.sun.jdi.VirtualMachine
77import com.sun.jdi.connect.AttachingConnector
88import kotlinx.coroutines.*
9- import org.gradle.internal.logging.events.OutputEvent
109import org.gradle.tooling.BuildLauncher
1110import org.gradle.tooling.GradleConnector
1211import org.gradle.tooling.ProjectConnection
@@ -26,11 +25,14 @@ import javax.swing.event.DocumentListener
2625import kotlin.io.path.writeText
2726
2827// TODO: Remove dependency on editor
28+ // TODO: Move to jobs system
29+ // TODO: Improve progress tracking
2930class GradleService (val editor : Editor ) {
31+ val active = mutableStateOf(true )
3032 val availableTasks = mutableStateListOf<String >()
3133 val finishedTasks = mutableStateListOf<String >()
3234 val running = mutableStateOf(false )
33- var vm: VirtualMachine ? = null
35+ var vm = mutableStateOf< VirtualMachine ?>( null )
3436 val debugPort = (30000 .. 60000 ).random()
3537 val problems = mutableStateListOf<ProblemEvent >()
3638
@@ -43,6 +45,14 @@ class GradleService(val editor: Editor) {
4345
4446 val folder: File get() = editor.sketch.folder
4547
48+ // Hooks for java to check if the Gradle service is running
49+ fun getEnabled (): Boolean {
50+ return active.value
51+ }
52+ fun setEnabled (active : Boolean ) {
53+ this .active.value = active
54+ }
55+
4656 fun prepare (){
4757 Messages .log(" Preparing sketch" )
4858 if (preparing) return
@@ -164,9 +174,9 @@ class GradleService(val editor: Editor) {
164174 ? : return @ProgressListener
165175 val args = connector.defaultArguments()
166176 args[" port" ]?.setValue(debugPort.toString())
167- val vm = connector.attach(args)
168- this @GradleService.vm = vm
169- Messages .log(" Attached to VM: ${vm .name()} " )
177+ val sketch = connector.attach(args)
178+ vm.value = sketch
179+ Messages .log(" Attached to VM: ${sketch .name()} " )
170180 })
171181 return this
172182 }
@@ -182,7 +192,7 @@ class GradleService(val editor: Editor) {
182192 finishedTasks.add(name)
183193 }
184194 if (event is DefaultSingleProblemEvent ){
185- Messages .log( " " )
195+ problems.add(event )
186196 }
187197 })
188198 return this
0 commit comments