Skip to content

Commit fdc43dc

Browse files
committed
Hot Reloading plugin
1 parent 0c674ad commit fdc43dc

File tree

9 files changed

+99
-25
lines changed

9 files changed

+99
-25
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ afterEvaluate {
527527
tasks.named("prepareAppResources").configure {
528528
dependsOn("includeProcessingResources")
529529
// Make sure all libraries are bundled in the maven repository distributed with the app
530-
dependsOn(listOf("core","java:preprocessor", "java:gradle").map { project(":$it").tasks.named("publishAllPublicationsToAppRepository") })
530+
dependsOn(listOf("core","java:preprocessor", "java:gradle", "java:gradle:hotreload").map { project(":$it").tasks.named("publishAllPublicationsToAppRepository") })
531531
}
532532
tasks.named("createDistributable").configure {
533533
finalizedBy("setExecutablePermissions")

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ import processing.app.Messages
2525
import processing.app.Platform
2626
import processing.app.Platform.getContentFile
2727
import processing.app.Platform.getSettingsFolder
28+
import processing.app.Settings
2829
import processing.app.Sketch
2930
import processing.app.gradle.Log.Companion.startLogServer
3031
import processing.app.ui.Editor
3132
import processing.app.ui.EditorStatus
3233
import java.nio.file.Path
3334
import kotlin.io.path.deleteIfExists
3435
import kotlin.io.path.writeText
36+
import kotlin.text.split
3537

3638
/*
3739
* The gradle job runs the gradle tasks and manages the gradle connection
@@ -166,11 +168,44 @@ class GradleJob(
166168
.split("\n")
167169
.joinToString("\n") { "// $it" }
168170

171+
val enabledPlugins = mutableListOf(GradlePlugin(
172+
"Processing Java",
173+
"The Processing Java mode for Gradle",
174+
null,
175+
"org.processing.java",
176+
getVersionName()
177+
))
178+
val propertiesFile = sketchFolder.resolve(Sketch.PROPERTIES_NAME)
179+
if(propertiesFile.exists()){
180+
val sketchSettings = Settings(propertiesFile)
181+
182+
// Grab the installed plugins
183+
val plugins = GradlePlugin.plugins
184+
185+
// Grab the enabled plugins
186+
val pluginSetting = (sketchSettings.get(GradlePlugin.PROPERTIES_KEY) ?: "")
187+
.split(",")
188+
.map { it.trim() }
189+
.filter{ it.isNotEmpty() }
190+
191+
// Link plugins in the settings to their installed counterparts
192+
enabledPlugins.addAll(
193+
pluginSetting
194+
.mapNotNull { id ->
195+
plugins.find { plugin -> plugin.id == id
196+
}
197+
}
198+
)
199+
}
200+
201+
val pluginList = enabledPlugins
202+
.joinToString("\n ") { "id(\"${it.id}\") version \"${it.version}\"" }
203+
169204
val configuration = """
170205
plugins{
171-
id("org.processing.java") version "${getVersionName()}"
206+
#plugins
172207
}
173-
""".trimIndent()
208+
""".trimIndent().replace("#plugins", pluginList)
174209
val content = "${header}\n${instructions}\n\n${configuration}"
175210
buildGradle.writeText(content)
176211
}

app/src/processing/app/gradle/GradlePlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ data class GradlePlugin(
1313
companion object{
1414
const val PROPERTIES_KEY = "sketch.plugins"
1515
val plugins = mutableStateListOf<GradlePlugin>(
16-
GradlePlugin("Hot Reload (experimental)", "Automatically apply changes in your sketch upon saving", null, "org.processing.java.hotreload", Base.getVersionName()),
16+
GradlePlugin("Hot Reload", "Automatically apply changes in your sketch upon saving", null, "org.processing.java.hotreload", Base.getVersionName()),
1717
GradlePlugin("Android","Run your sketch on an Android device", null, "org.processing.android", Base.getVersionName()),
1818
)
1919
}

build/shared/lib/languages/PDE.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ gradle.instructions = About this file: \nProcessing creates this file when you r
325325
gradle.using_gradle = Building sketch using the new build system. (See settings to switch to the legacy build system.)
326326
gradle.using_eclipse = Building sketch using the legacy build system. (See settings to switch to the new build system.)
327327
gradle.settings = Settings
328-
gradle.settings.plugins = Plugins
328+
gradle.settings.plugins = Plugins (experimental)
329329

330330
# ---------------------------------------
331331
# Toolbars

java/gradle/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dependencies{
2424
// TODO: CI/CD for publishing the plugin to the Gradle Plugin Portal
2525
gradlePlugin{
2626
plugins{
27-
create("processing"){
27+
create("processing.java"){
2828
id = "org.processing.java"
2929
implementationClass = "org.processing.java.gradle.ProcessingPlugin"
3030
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
plugins {
2+
`java-gradle-plugin`
3+
kotlin("jvm") version libs.versions.kotlin
4+
alias(libs.plugins.gradlePublish)
5+
6+
}
7+
8+
9+
repositories {
10+
mavenCentral()
11+
}
12+
13+
dependencies{
14+
implementation("org.jetbrains.compose.hot-reload:hot-reload-gradle-plugin:1.0.0-beta03")
15+
}
16+
17+
gradlePlugin{
18+
plugins{
19+
create("processing.java.hotreload"){
20+
id = "org.processing.java.hotreload"
21+
implementationClass = "org.processing.java.gradle.ProcessingHotReloadPlugin"
22+
}
23+
}
24+
}
25+
publishing{
26+
repositories{
27+
mavenLocal()
28+
maven {
29+
name = "App"
30+
url = uri(project(":app").layout.buildDirectory.dir("resources-bundled/common/repository").get().asFile.absolutePath)
31+
}
32+
}
33+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.processing.java.gradle
2+
3+
import org.gradle.api.Plugin
4+
import org.gradle.api.Project
5+
import org.gradle.api.tasks.GradleBuild
6+
import org.jetbrains.compose.reload.gradle.ComposeHotReloadPlugin
7+
import org.jetbrains.compose.reload.gradle.ComposeHotRun
8+
9+
class ProcessingHotReloadPlugin: Plugin<Project> {
10+
override fun apply(project: Project) {
11+
project.plugins.apply(ComposeHotReloadPlugin::class.java)
12+
13+
project.repositories.google()
14+
15+
project.afterEvaluate {
16+
project.tasks.named("hotRun", ComposeHotRun::class.java){ task ->
17+
task.isAutoReloadEnabled.set(true)
18+
}
19+
project.tasks.named("run").configure { task ->
20+
task.dependsOn("hotRun")
21+
}
22+
}
23+
}
24+
}

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,6 @@ class ProcessingPlugin @Inject constructor(private val objectFactory: ObjectFact
5959
// Add the compose plugin to wrap the sketch in an executable
6060
project.plugins.apply("org.jetbrains.compose")
6161

62-
val propertiesFile = project.layout.projectDirectory.file("sketch.properties")
63-
if (propertiesFile.asFile.exists()) {
64-
val properties = Properties()
65-
properties.load(propertiesFile.asFile.inputStream())
66-
67-
val pluginsSetting = properties.getProperty("sketch.plugins")
68-
if (pluginsSetting != null && pluginsSetting.isNotEmpty()) {
69-
val plugins = pluginsSetting.split(",").map { it.trim() }
70-
71-
plugins.forEach { pluginId ->
72-
// Apply the plugin to the project, equivalent of
73-
// plugins {
74-
// id("org.processing.java.hotreload")
75-
// }
76-
project.plugins.apply(pluginId)
77-
}
78-
}
79-
}
80-
8162
// Add the Processing core library (within Processing from the internal maven repo and outside from the internet), equivalent of
8263
// dependencies {
8364
// implementation("org.processing:core:4.3.4")

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ include(
66
"java",
77
"java:preprocessor",
88
"java:gradle",
9+
"java:gradle:hotreload",
910
"java:libraries:dxf",
1011
"java:libraries:io",
1112
"java:libraries:net",

0 commit comments

Comments
 (0)