fix(gettext): coalesce duplicate file changes in incremental msg* tasks#188
Open
vlsi wants to merge 3 commits into
Open
fix(gettext): coalesce duplicate file changes in incremental msg* tasks#188vlsi wants to merge 3 commits into
vlsi wants to merge 3 commits into
Conversation
When poFiles aggregates overlapping providers (e.g. allSource plus feature variants reusing the main source set), Gradle can report the same physical file as both ADDED and REMOVED in a single incremental invocation. The previous loop processed events in order, so msgattrib/msgmerge/msgfmt would write the output and then immediately delete it. Downstream tasks then saw the empty output and dropped their own per-locale outputs, leaving e.g. messages_ru.java missing until --rerun-tasks was used. Introduce coalesceFileChanges() and route the three incremental tasks through it. Per file.absolutePath: ADDED/MODIFIED wins over REMOVED, and a pure-REMOVED event is suppressed when the file is still present in the resolved poFiles snapshot. Non-FILE entries are dropped centrally. Add unit tests covering the eight relevant cases. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…heck Per review feedback. Reorder the predicate so `existing?.changeType` carries its own null-safety instead of relying on smart-cast after an `existing == null` short-circuit (which would make `?.` redundant). Semantics unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…he safe-call Per review feedback. With `existing == null ||` on the left, Kotlin smart-casts `existing` to non-null in the right operand, so the `?.` is no longer needed. Semantics unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Downstream consumers (e.g. pgjdbc's
generateGettextSources) sometimes lost a locale's output: the per-localemessages_<lang>.javawas missing frombuild/gettext/generate_java_resources/po/..., even though<lang>.powas present and unmodified.--rerun-taskspapered it over; the next incremental run reintroduced the loss.Root cause: when
poFilesaggregates overlapping providers (e.g.files(sourceSets.main.get().allSource).filter { …".po" }plus feature variants likeregisterFeature("sspi")/("osgi")reusingsourceSets["main"]), Gradle can report the same physical.pofile as bothADDEDandREMOVEDin one invocation. The task body inMsgAttribTask.run(andMsgMergeTask/MsgFmtTask) iterates events in order, somsgattribwritesoutDir/ru.poand the followingREMOVEDbranch immediately deletes it. The emptyoutDirentry cascades downstream and a locale silently disappears.Trace (
--info):Fix
Introduce
coalesceFileChanges(changes, currentSourceFiles)inFileChangeCoalescing.ktand route the three incremental tasks (MsgAttribTask,MsgMergeTask,MsgFmtTask) through it. Perfile.absolutePath:ADDED/MODIFIEDwins overREMOVED(collapses the spurious pair to a single ADDED/MODIFIED),REMOVEDevent is suppressed when the file is still present in the resolvedpoFiles.filessnapshot.Insertion order is preserved, so the processing order matches the previous behavior.
Tests
Added
FileChangeCoalescingTest(8 unit cases — all green):ADDED → REMOVEDcollapses toADDEDREMOVED → ADDEDcollapses toADDEDMODIFIEDwins overREMOVEDREMOVEDsuppressed when the file is still in the snapshotREMOVEDkept when the file is absent from the snapshotI did not add an end-to-end integration test that wires duplicate providers through a real
GradleRunner:msgattrib/msgmerge/msgfmtwould have to be installed on the test host, and the plugin had no test sources before this PR. The reported regression is purely the duplicate-event handling, which the unit tests cover exactly.Test plan
./gradlew :plugins:gettext-plugin:test --rerun-tasks— 8/8 green./gradlew :plugins:gettext-plugin:build— green./gradlew :postgresql:generateGettextSources --rerun-tasks, delete onemessages_<lang>.java, re-run with--info) and confirm the locale output is regenerated and no spuriousADDED + REMOVEDpair drops it.🤖 Generated with Claude Code