in hot-reload-gradle-plugin/src/main/kotlin/org/jetbrains/compose/reload/gradle/hotSnapshotTask.kt [86:126]
fun execute(inputs: InputChanges) {
val classpathSnapshotFile = classpathSnapshotFile.get().asFile.toPath()
val pendingRequestFile = pendingRequestFile.get().asFile.toPath()
if (!inputs.isIncremental) {
logger.info("Non-incremental run: Taking classpath snapshot")
classpathSnapshotFile.writeClasspathSnapshot(ClasspathSnapshot(classpath))
pendingRequestFile.deleteIfExists()
return
}
logger.info("Incremental run: Reloading classes")
val snapshot = if (classpathSnapshotFile.exists()) classpathSnapshotFile.readClasspathSnapshot()
else ClasspathSnapshot(classpath)
try {
val changedFiles = if (pendingRequestFile.exists()) {
pendingRequestFile.readObject<ReloadClassesRequest>().changedClassFiles.toMutableMap()
} else mutableMapOf()
inputs.getFileChanges(classpath).forEach { change ->
if (change.file.extension == "jar") {
changedFiles += resolveChangedJar(snapshot, change)
} else {
changedFiles += resolveChangedFile(change)
}
}
pendingRequestFile.createParentDirectories()
.writeObject(ReloadClassesRequest(changedFiles))
classpathSnapshotFile
.createParentDirectories()
.writeClasspathSnapshot(snapshot)
} catch (t: Throwable) {
/* We're in trouble; How shall we handle the snapshot? Let's try to take a new one? */
logger.error("Failed to reload classes", t)
runCatching { classpathSnapshotFile.deleteIfExists() }
throw t
}
}