Skip to content

Commit 1c8581e

Browse files
committed
Move Gradle connection into GradleJob
1 parent d742002 commit 1c8581e

File tree

5 files changed

+13
-61
lines changed

5 files changed

+13
-61
lines changed

app/src/processing/app/gradle/GradleJob.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,15 @@ abstract class GradleJob{
4646

4747
fun start() {
4848
service?.jobs?.add(this)
49-
val connection = service?.connection ?: return
49+
val folder = service?.folder ?: return
5050
scope.launch {
5151
try {
5252
state.value = State.BUILDING
5353

54-
connection.newBuild()
54+
GradleConnector.newConnector()
55+
.forProjectDirectory(folder)
56+
.connect()
57+
.newBuild()
5558
.apply {
5659
configure()
5760
withCancellationToken(cancel.token())

app/src/processing/app/gradle/GradleService.kt

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,18 @@ import javax.swing.event.DocumentListener
2323
import kotlin.io.path.deleteIfExists
2424
import 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(","),

app/src/processing/app/ui/Editor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2280,7 +2280,6 @@ protected void handleOpenInternal(String path) throws EditorException {
22802280
} catch (IOException e) {
22812281
throw new EditorException("Could not create the sketch.", e);
22822282
}
2283-
service.startService();
22842283

22852284
header.rebuild();
22862285
updateTitle();

java/gradle/src/main/kotlin/ProcessingPlugin.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ class ProcessingPlugin @Inject constructor(private val objectFactory: ObjectFact
2828
val debugPort = project.findProperty("processing.debugPort") as String?
2929

3030
val sketchbook = project.findProperty("processing.sketchbook") as String?
31-
?: Preferences.get("sketchbook.path.four")
32-
?: ("${System.getProperty("user.home")}/.processing")
3331

3432
// Apply the Java plugin to the Project
3533
project.plugins.apply(JavaPlugin::class.java)

java/gradle/src/test/kotlin/ProcessingPluginTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import org.junit.Test
66
import org.junit.rules.TemporaryFolder
77

88
class ProcessingPluginTest{
9+
// TODO: Write tests
10+
// TODO: Test on multiple platforms since there is meaningful differences between the platforms
911
@Test
1012
fun testPluginAddsSketchTask(){
1113
val project = ProjectBuilder.builder().build()

0 commit comments

Comments
 (0)