Hot Reloading plugin

This commit is contained in:
Stef Tervelde
2025-07-17 15:49:40 +02:00
parent 0c674adc54
commit fdc43dc7d2
9 changed files with 99 additions and 25 deletions

View File

@@ -527,7 +527,7 @@ afterEvaluate {
tasks.named("prepareAppResources").configure {
dependsOn("includeProcessingResources")
// Make sure all libraries are bundled in the maven repository distributed with the app
dependsOn(listOf("core","java:preprocessor", "java:gradle").map { project(":$it").tasks.named("publishAllPublicationsToAppRepository") })
dependsOn(listOf("core","java:preprocessor", "java:gradle", "java:gradle:hotreload").map { project(":$it").tasks.named("publishAllPublicationsToAppRepository") })
}
tasks.named("createDistributable").configure {
finalizedBy("setExecutablePermissions")

View File

@@ -25,6 +25,7 @@ import processing.app.Messages
import processing.app.Platform
import processing.app.Platform.getContentFile
import processing.app.Platform.getSettingsFolder
import processing.app.Settings
import processing.app.Sketch
import processing.app.gradle.Log.Companion.startLogServer
import processing.app.ui.Editor
@@ -32,6 +33,7 @@ import processing.app.ui.EditorStatus
import java.nio.file.Path
import kotlin.io.path.deleteIfExists
import kotlin.io.path.writeText
import kotlin.text.split
/*
* The gradle job runs the gradle tasks and manages the gradle connection
@@ -166,11 +168,44 @@ class GradleJob(
.split("\n")
.joinToString("\n") { "// $it" }
val enabledPlugins = mutableListOf(GradlePlugin(
"Processing Java",
"The Processing Java mode for Gradle",
null,
"org.processing.java",
getVersionName()
))
val propertiesFile = sketchFolder.resolve(Sketch.PROPERTIES_NAME)
if(propertiesFile.exists()){
val sketchSettings = Settings(propertiesFile)
// Grab the installed plugins
val plugins = GradlePlugin.plugins
// Grab the enabled plugins
val pluginSetting = (sketchSettings.get(GradlePlugin.PROPERTIES_KEY) ?: "")
.split(",")
.map { it.trim() }
.filter{ it.isNotEmpty() }
// Link plugins in the settings to their installed counterparts
enabledPlugins.addAll(
pluginSetting
.mapNotNull { id ->
plugins.find { plugin -> plugin.id == id
}
}
)
}
val pluginList = enabledPlugins
.joinToString("\n ") { "id(\"${it.id}\") version \"${it.version}\"" }
val configuration = """
plugins{
id("org.processing.java") version "${getVersionName()}"
#plugins
}
""".trimIndent()
""".trimIndent().replace("#plugins", pluginList)
val content = "${header}\n${instructions}\n\n${configuration}"
buildGradle.writeText(content)
}

View File

@@ -13,7 +13,7 @@ data class GradlePlugin(
companion object{
const val PROPERTIES_KEY = "sketch.plugins"
val plugins = mutableStateListOf<GradlePlugin>(
GradlePlugin("Hot Reload (experimental)", "Automatically apply changes in your sketch upon saving", null, "org.processing.java.hotreload", Base.getVersionName()),
GradlePlugin("Hot Reload", "Automatically apply changes in your sketch upon saving", null, "org.processing.java.hotreload", Base.getVersionName()),
GradlePlugin("Android","Run your sketch on an Android device", null, "org.processing.android", Base.getVersionName()),
)
}

View File

@@ -325,7 +325,7 @@ gradle.instructions = About this file: \nProcessing creates this file when you r
gradle.using_gradle = Building sketch using the new build system. (See settings to switch to the legacy build system.)
gradle.using_eclipse = Building sketch using the legacy build system. (See settings to switch to the new build system.)
gradle.settings = Settings
gradle.settings.plugins = Plugins
gradle.settings.plugins = Plugins (experimental)
# ---------------------------------------
# Toolbars

View File

@@ -24,7 +24,7 @@ dependencies{
// TODO: CI/CD for publishing the plugin to the Gradle Plugin Portal
gradlePlugin{
plugins{
create("processing"){
create("processing.java"){
id = "org.processing.java"
implementationClass = "org.processing.java.gradle.ProcessingPlugin"
}

View File

@@ -0,0 +1,33 @@
plugins {
`java-gradle-plugin`
kotlin("jvm") version libs.versions.kotlin
alias(libs.plugins.gradlePublish)
}
repositories {
mavenCentral()
}
dependencies{
implementation("org.jetbrains.compose.hot-reload:hot-reload-gradle-plugin:1.0.0-beta03")
}
gradlePlugin{
plugins{
create("processing.java.hotreload"){
id = "org.processing.java.hotreload"
implementationClass = "org.processing.java.gradle.ProcessingHotReloadPlugin"
}
}
}
publishing{
repositories{
mavenLocal()
maven {
name = "App"
url = uri(project(":app").layout.buildDirectory.dir("resources-bundled/common/repository").get().asFile.absolutePath)
}
}
}

View File

@@ -0,0 +1,24 @@
package org.processing.java.gradle
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.GradleBuild
import org.jetbrains.compose.reload.gradle.ComposeHotReloadPlugin
import org.jetbrains.compose.reload.gradle.ComposeHotRun
class ProcessingHotReloadPlugin: Plugin<Project> {
override fun apply(project: Project) {
project.plugins.apply(ComposeHotReloadPlugin::class.java)
project.repositories.google()
project.afterEvaluate {
project.tasks.named("hotRun", ComposeHotRun::class.java){ task ->
task.isAutoReloadEnabled.set(true)
}
project.tasks.named("run").configure { task ->
task.dependsOn("hotRun")
}
}
}
}

View File

@@ -59,25 +59,6 @@ class ProcessingPlugin @Inject constructor(private val objectFactory: ObjectFact
// Add the compose plugin to wrap the sketch in an executable
project.plugins.apply("org.jetbrains.compose")
val propertiesFile = project.layout.projectDirectory.file("sketch.properties")
if (propertiesFile.asFile.exists()) {
val properties = Properties()
properties.load(propertiesFile.asFile.inputStream())
val pluginsSetting = properties.getProperty("sketch.plugins")
if (pluginsSetting != null && pluginsSetting.isNotEmpty()) {
val plugins = pluginsSetting.split(",").map { it.trim() }
plugins.forEach { pluginId ->
// Apply the plugin to the project, equivalent of
// plugins {
// id("org.processing.java.hotreload")
// }
project.plugins.apply(pluginId)
}
}
}
// Add the Processing core library (within Processing from the internal maven repo and outside from the internet), equivalent of
// dependencies {
// implementation("org.processing:core:4.3.4")

View File

@@ -6,6 +6,7 @@ include(
"java",
"java:preprocessor",
"java:gradle",
"java:gradle:hotreload",
"java:libraries:dxf",
"java:libraries:io",
"java:libraries:net",