Repository navigation
fix(check): edit plugin.xml inside the build instead of on the UI thread - #1665
joaodinissf wants to merge 1 commit into
Conversation
rubenporras
left a comment
There was a problem hiding this comment.
this looks very wrong on first sight. Are you sure? Are there not other options?
9341722 to
c556fbd
Compare
|
Fair challenge. The first version was a workaround: it stopped the loop, but each save still interrupted the build (N new catalogs cost N+1 builds) and the write stayed in a The loop came from saving plugin.xml from the UI thread while the auto-build runs: the save interrupts the build, Xtext's monitor reports that as cancelled, and we passed the same monitor to PDE, so the save cancelled itself and the build restarted without writing the file. The PR now edits plugin.xml on the build thread, with the same PDE text model and text edits on a private copy of the file. Formatting and comments are kept, nothing interrupts the build, and one build handles any number of catalogs. The description lists what is tested and what is not; it stays a draft while I add a few more tests. Posted by Claude Code on behalf of @joaodinissf. |
CheckExtensionGenerator updated plugin.xml through PDEModelUtility in a syncExec on the UI thread. Saving the file from another thread interrupts a running auto-build. The Xtext builder's monitor reports an interrupted auto-build as canceled, and that monitor was passed to PDE, so the save canceled itself while waiting for the workspace rule. The build ended canceled, kept its deltas and was rescheduled, and the next run did the same: a project with a Check catalog whose extensions were missing or outdated in plugin.xml was rebuilt over and over and never got them, until a full or explicit build wrote the file. PluginXmlEditor now makes the edit on the build thread. It loads PDE's text model of the file from a private copy of the content, applies the changes as text edits, as PDEModelUtility does when no editor is open, and writes the file only if its content changed. Formatting and comments of the untouched parts are kept as before. Nothing is saved from another thread, so the build is not interrupted: one run of the auto-build handles any number of catalogs. An editor that has plugin.xml open sees the write as a change on disk; the build no longer edits the model of an open manifest editor and no longer saves a text editor's unsaved content. CheckExtensionGeneratorAutoBuildTest covers a catalog added to a project with a plugin.xml, a catalog whose extension changes, three catalogs added together, hand-written content, unchanged extensions, Windows line endings, a byte order mark, a text editor with and without unsaved changes, and an open manifest editor. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
c556fbd to
baf2791
Compare
What
The Check builder participant now edits
plugin.xmlinside the build, on the build thread. It no longer goes throughDisplay.syncExecandPDEModelUtility.PluginXmlEditor(package-private,com.avaloq.tools.ddk.check.ui.builder): reads the file into a private document, loads PDE's text model of it (org.eclipse.pde.internal.core.text.plugin.PluginModel), lets the extension helpers change the model, applies the resulting text edits, and writes the file only if its content changed.CheckExtensionGenerator.updateExtensionsandremoveExtensionsuse it for the standardplugin.xml.modifyModeland itssyncExecare gone. The build's monitor is still checked before the edit.CheckExtensionGeneratorAutoBuildTestincom.avaloq.tools.ddk.check.ui.testcovers the edit during an auto-build.This replaces the first version of this PR, which kept the
syncExecand passed PDE aNullProgressMonitor. That stopped the loop described below, but it was a workaround: every save still interrupted the build, so N catalogs needing an edit cost N + 1 runs of the auto-build, and the write stayed on the UI thread.Why
With auto-build on, a Check catalog whose extensions are missing or outdated in the project's
plugin.xmlmakes the project rebuild in a loop, andplugin.xmlnever gets the extensions:PDEModelUtility.modifyModelinDisplay.syncExec. On the UI thread, PDE saves the edited file.Workspace.prepareOperationsees that the file's rule conflicts with the build rule and interrupts the running auto-build.ThreadJob.joinRunchecks the monitor first, so the save throwsOperationCanceledExceptionand nothing is written.The cause is the save from another thread while the build runs. A workspace operation on the build thread itself does not interrupt the build:
AutoBuildJob.interruptignores a request that comes from the build's own thread. That is how the participant already writesMANIFEST.MF, afragment.xml, a plug-in file with a non-standard name and a newplugin.xml.How it works
PDEModelUtility.modifyModeldoes three things when no editor is open: it loads the text model from the file's text buffer, collects the text edits that the model changes produce (XMLTextChangeListener), and applies and commits them.PluginXmlEditordoes the same with a privateDocumentinstead of the shared file buffer, and writes the result withIFile.setContents. The text model and the listener are inorg.eclipse.pde.core, so the edit needs neither the UI thread nor a workbench.Because the edits are the same text edits as before, the parts of
plugin.xmlthat do not change keep their formatting and comments. The file is read and written in its own charset. If the edits leave the content as it was, the file is not written.Behaviour that changes
PDEModelUtilitycommitted the shared text buffer, which saved the user's unsaved text as a side effect. Now the build writes only its own edit; the editor keeps its unsaved text and the user gets the same conflict when saving.plugin.xmlcannot be parsed into the text model, cannot be edited or cannot be encoded in its charset, the edit fails with aCoreException, whichCheckBuilderParticipantlogs. PDE logged and swallowed these.MANIFEST.MFis still updated in that case, as before.How tested
CheckExtensionGeneratorAutoBuildTestruns in the workbench ofcom.avaloq.tools.ddk.check.ui.test, with auto-build on, in a plug-in project that has aplugin.xml. Each test first builds one catalog explicitly, then makes its change and waits for the auto-build: it joins the jobs ofResourcesPlugin.FAMILY_AUTO_BUILDuntil none has been pending for 1 s, for at most 60 s. It asserts that the wait ended before its bound, that the auto-build job ran at most twice, and the content ofplugin.xml.The same test class was run against three versions of the product code: this PR, the first version of this PR (the
NullProgressMonitorworkaround) andmaster. "Runs" is the number of runs of the auto-build job for the change.mastertestAddCatalogtestChangeCatalogtestAddCatalogsTogethertestKeepHandWrittenContenttestUnchangedExtensionsplugin.xmlkeeps its modification stamptestWindowsLineEndingsplugin.xmlhas CRLF line endings, a catalog is added; the file has CRLF onlytestByteOrderMarkplugin.xmlstarts with a byte order mark, a catalog is added; one mark, prolog unchangedtestEditorWithoutChangesplugin.xml, a catalog is added; the editor shows the new extensions and is not dirtytestEditorWithUnsavedChangestestManifestEditorWithoutChangestestUnchangedExtensionspasses everywhere; it guards against an implementation that always writes.Same output as the old path. After each test, the content of
plugin.xmlwas compared between this PR and the workaround, which still edits throughPDEModelUtility. The files are byte-identical in every case, apart from the two intended differences above: the extensions that the old path left in the manifest editor's model, and the unsaved editor text that it saved.Local run on macOS with OpenJDK 21:
./mvnw verify checkstyle:check pmd:pmd pmd:cpd pmd:check pmd:cpd-check spotbugs:check -f ./ddk-parent/pom.xml -pl :ddk-target,:com.avaloq.tools.ddk.check.ui.test -am. All 50 tests of the module pass.No version bump:
com.avaloq.tools.ddk.check.uiis at 17.3.6 onmaster, above the 17.3.5 of the last release.Not tested
removeExtensionsgoes through the samePluginXmlEditor, but no test asserts a removal. I tried two: a catalog that no longer validates and a deleted catalog. In both the extensions stay inplugin.xml, with this PR and with the old path alike (identical files), so this is existing behaviour and outside this change.RegistryBuilderParticipant. DDK'sRegistryBuilderParticipantcatches every exception of a participant, including a cancellation. The edit no longer causes a cancellation, so that path is not reached by it, but a build with several catalogs under the DDK builder was not run.plugin.xmlthat is not UTF-8. The code reads and writes the file's charset and refuses to write a character that charset cannot represent; the tests use UTF-8 only.Alternatives considered
syncExecand pass aNullProgressMonitor(the first version of this PR). It ends the loop but keeps one interrupted run per catalog and the write on the UI thread.plugin.xmland drop its comments.PDEModelUtilitydirectly from the build thread. It looks for open editors through the workbench and, if one has the file open, defers the edit withDisplay.execute, which is asynchronous off the UI thread. The edit would race the build.🤖 Generated with Claude Code