Repository navigation
ADFA-7287: Stop rewriting unchanged plugin templates at every start - #2310
Open
davidschachterADFA wants to merge 5 commits into
Open
davidschachterADFA wants to merge 5 commits into
davidschachterADFA wants to merge 5 commits into
Conversation
ktlint's output for the whole file, before the ADFA-7287 change to it: tabs, and one parameter per line. It also re-indents the JSON inside the raw strings with tabs. JSON ignores that whitespace, so the templates read the same, but a built .cgt's template.json bytes differ. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
Plugins build and register their .cgt templates in activate(), which runs at every start. CgtTemplateBuilder left each zip entry's time unset, so ZipOutputStream stamped the current time, and both the build and the registration wrote unconditionally. Each start therefore wrote every template twice, with the same contents and a new checksum. - CgtTemplateBuilder gives every entry a fixed time (1980-02-01 00:00 local, Gradle's choice for reproducible archives), builds the zip in memory, and writes the file only when its bytes differ. - IdeTemplateServiceImpl.registerTemplate() copies only when the registered copy is missing or differs, and then skips the template list reload too. It still returns true. Tests: CgtTemplateBuilderTest (4) and IdeTemplateServiceImplRegisterTest (3) pass, as do PluginTemplateCleanupTest and PluginManagerTemplateWiringTest. With the fixed time and the two content checks taken out, the four tests aimed at them fail for the reasons they name, and the three guard tests still pass. :plugin-api:apiCheck passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
Tabs for spaces, and no blank line after the interface's opening brace, before the next commit adds KDoc to it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
- registerTemplate() compares the two files in 8 KB chunks instead of
reading both whole, since a plugin may register a template of any
size. In both comparisons a failed read counts as a difference, so
the write is tried, as it was before.
- CgtTemplateBuilderTest changes one byte of a template without
changing its length, so it pins the byte comparison: with length-only
comparisons the changed-template tests fail.
IdeTemplateServiceImplRegisterTest adds a 20,000-byte template that
differs only in its last byte.
- The time-zone test uses Tokyo and Los Angeles, 17 hours apart in
1980, and its failure message no longer prints both byte arrays.
- KDoc on CgtTemplateBuilder.build() and
IdeTemplateService.registerTemplate() says an identical file is left
untouched and no change is reported.
- The new log line uses {} placeholders.
The template-list reload that registerTemplate() now skips for an
identical copy was a no-op already: nothing calls
PluginManager.setTemplateReloadListener(). The template list rescans
the folder by itself.
Tests: CgtTemplateBuilderTest 4, IdeTemplateServiceImplRegisterTest 4,
PluginTemplateCleanupTest 3, PluginManagerTemplateWiringTest 3, all
pass. :plugin-api:apiCheck passes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
- sameBytes() also checks that the plugin's .cgt has ended, in case it grew after its length was read. Before, a longer .cgt compared equal to a copy that matched its first part. - A comparison that cannot read a file now logs that at debug level before it falls back to writing. Two tests cover that path: a built .cgt and a registered copy that are unreadable, the same length and different in content are written again. With either catch no longer catching IOException, those two tests fail. They skip when the test runs as root, which can read any file. - KDoc: build() promises the same bytes on one device, not everywhere (deflate output depends on the runtime's zlib), and names its IllegalArgumentException. registerTemplate() costs reading both files, not one. Tests: CgtTemplateBuilderTest 5, IdeTemplateServiceImplRegisterTest 5, PluginTemplateCleanupTest 3 and PluginManagerTemplateWiringTest 3 pass, none skipped. :plugin-api:apiCheck passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
davidschachterADFA
marked this pull request as ready for review
November 24, 2026 23:09
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
Contributor
hal-eisen-adfa
approved these changes
Nov 25, 2026
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.
ADFA-7287
Plugins build and register their
.cgttemplates inactivate(), which runs at every start. Each start wrote every template again, and copied it into the templates folder again, with the same contents and a new checksum:CgtTemplateBuilderleft each zip entry's time unset, soZipOutputStreamstamped the current time, and both writes were unconditional. On a Note 20, the JavaScript add-on's three templates (1.7 MB) changed checksum at every start.Change
CgtTemplateBuilder(plugin-api):build()builds the zip in memory and writes the file only when its bytes differ from what is there.IdeTemplateServiceImpl.registerTemplate()(plugin-manager) copies only when the registered copy is missing or differs, comparing the two in 8 KB chunks. When nothing changed it reports no change, and still returnstrue. That skipped report has no effect today: nothing callsPluginManager.setTemplateReloadListener(), so the callback was already a no-op, and the template list rescans the folder by itself.CgtTemplateBuilder.build()andIdeTemplateService.registerTemplate()says an identical file is left untouched.Review by commit. Two commits only reformat with Spotless:
CgtTemplateBuilder.kt(spaces to tabs, one parameter per line) andIdeTemplateService.kt. The first also re-indents the JSON inside the builder's raw strings; JSON ignores that whitespace, but a builttemplate.jsonchanges once.No public API changes:
plugin-api.apiis unchanged, and the plugin API changelog lists capabilities, not this.Sites checked
PluginProjectManager.extractBundledCgtTemplates()also writes into the templates folder unconditionally, but nothing calls it. Left alone.core.cgt(BundledAssetsInstaller,SplitAssetsInstaller) is written when assets install, not at every start. Left alone.cleanupAllTemplates,cleanupPluginTemplates); nothing deletes them at start, so the skip inregisterTemplate()applies on a normal start.cogo-hook-run.shat every activation, on purpose. It lives in addons, not here; the ticket leaves it to its owner.Testing
At the head, 3f153ea:
CgtTemplateBuilderTest(5),IdeTemplateServiceImplRegisterTest(5), and the existingPluginTemplateCleanupTest(3) andPluginManagerTemplateWiringTest(3) pass, none skipped.:plugin-api:apiCheckpasses.IOExceptioncatches removed, the two unreadable-file tests fail. They skip when run as root, which can read any file.template.jsonfiles parse, and all three versions mean the same. The fixed time gave one SHA-256 across all 632 JDK time zones, with no extra zip fields.Not done
🤖 Generated with Claude Code
https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw