Repository navigation
Record the Forge feature pack of a plugin version in the plugin index - #326
jdaugherty wants to merge 4 commits into
Conversation
When the main jar of a version contains META-INF/grails-forge/feature.yml, add a pack property to that version: the format, kind, name, template API, application types and compatibility ranges of the descriptor, read as data with bounds, and the SHA-256 of the jar. A jar whose descriptor cannot be used gets no pack and does not fail the run. Versions already indexed are looked at again only with --rescan-packs.
…r types The indexer held the application types of a Forge feature pack to a list of four, while Grails 9 creates five kinds of application: rest-api-plugin was missing. A pack that declared [web, rest-api-plugin] was refused as a whole, so its version was indexed without a pack and the feature was not offered for web applications either. Since a version already indexed is not looked at again without --rescan-packs, the loss was permanent. The list now has all five types. A name that has the form of a type but is not among them no longer costs the pack its entry: the types are recorded as the descriptor names them and a warning names the unknown one. The Grails command line passes over a type it does not know, so the pack stays offered for the types it is validly for, and a type a later Grails adds does not need a new indexer first. Only a value that cannot be a list of names of types is still refused, with the warning the indexer gives for every descriptor it cannot use. A preset names the one type it is for in applicationType and has no applicationTypes, so the indexer recorded no type for it and the index offered every preset for every type. The type of a preset is now recorded as the one entry of applicationTypes, which is where the command line reads it, and a preset without a type gets no entry. index-plugins-test.groovy tests what is recorded of a pack. It compiles the classes of the indexer without running it, so it reads no plugin file and downloads no plugin.
sbglasius
left a comment
There was a problem hiding this comment.
This is an AI assisted review
Re-reviewed 5e51ab5 (rest-api-plugin, unknown types kept with a warning, preset type recorded under applicationTypes, tests). LGTM.
Nits, non-blocking:
- Error message "names in '$key' what cannot be the name..." reads oddly; "names in '$key' a value that cannot be..." perhaps.
- Keeping unknown types means a typo like
rest-apislands in the index, with only a log line to show for it. Fine given the CLI skips unknown types, just noting it.
matrei
left a comment
There was a problem hiding this comment.
Thanks, this looks good overall. Reading the descriptor as data only, with size and depth limits, and making sure a bad pack never fails the run are both good choices. A few things I noticed:
Feature-name collisions between plugins
pack.name is copied from the jar as it is (L441), and nothing checks whether another plugin already has a pack with that name. New versions arrive through the scheduled "Update Plugin Index" PR, not through the add-a-plugin review that the Trust section relies on. So any plugin that is already listed can ship a release with name: spring-security-core, and the index then has two plugins' packs under one feature name. Could the directory pass collect pack names per coords and warn about (or drop) a pack whose name another plugin already has? At a minimum, the README should ask maintainers to check pack.name in those automated PRs.
A related point: a hand-written pack in a plugin YAML is copied into the index without any check, and --rescan-packs skips versions that already have one. So nothing enforces "Do not write or edit pack by hand".
A broken grails-plugin.xml throws away a valid pack
readPluginArtifact reads the pack first and then calls readGrailsVersion (L567-568). If XmlSlurper throws (malformed XML, or a DOCTYPE, which the default XmlSlurper rejects), the pack is lost. With --rescan-packs this is only logged as "No Forge feature pack read", and in the normal run it aborts the whole run. If readGrailsVersion were wrapped in a try/catch that logs the error and returns null, the pack would be kept, and "one bad jar never fails the run" would also hold for the plugin descriptor.
Early break when the main jar has a pack but no grails-plugin.xml
if (grailsCompatibility || forgePack) break (L339) stops before -plain.jar and .zip are tried. Such a version gets pack but no grailsVersion, and the "Could not find plugin artifact" warning no longer fires. If pack-only versions are intended, what does the CLI do when grailsVersion is missing? Does it go by compatibility.grails alone? If not, it would be safer to break only on grailsCompatibility and still keep the pack from the main jar.
Unknown application types
applicationTypes: [batch-job] is recorded with only a warning (L517). If the CLI skips types it doesn't know, that list becomes empty. Does the CLI treat an empty list like a missing key, meaning "every type"? If it does, that pack would be offered for every application type. It may be worth refusing a pack whose types are all unknown.
Minor:
readForgePackalso runs for-plain.jarand the.zip. It hashes the file and logs warnings about a pack that is then thrown away. A flag onreadPluginArtifactso that the pack is only read for the main jar would avoid this.--rescan-packsdownloads a second time any version that was added earlier in the same run without a pack. Every later rescan also downloads every pack-less version again (about 5,000 jars).extractGrailsVersionFromPluginJaris no longer called, and its Javadoc belongs onreadGrailsVersion, whose body is also indented four spaces too far.
The Grails change this goes with, apache/grails-core#17114, now targets 10.0.x, so the examples and the tests use the range of the Grails 10 line.
…scriptor - The name of a pack belongs to the first plugin that is indexed with it: the pack of another plugin with that name is not recorded, with a warning, and two plugins that have one name in their files already are reported. - A grails-plugin.xml that cannot be read no longer costs the jar its pack, nor fails the run. - A main jar with a pack and no plugin descriptor no longer ends the search for the grailsVersion in the other artifacts, and a pack is not read at all from the plain jar or the zip. - --rescan-packs replaces or removes a pack that is not what the jar has, and does not download again a version the same run added. - extractGrailsVersionFromPluginJar, which nothing called, is removed.
jdaugherty
left a comment
There was a problem hiding this comment.
@matrei thanks for the review. c5d9f63 answers it; the CLI behaviour named below is that of apache/grails-core#17114 (PackCatalog / PackCatalogs in grails-forge-cli).
Feature-name collisions between plugins. The CLI does not pick one of two plugins: when more than one plugin of the catalog has a pack of the name that is usable for the application, it refuses the name ("More than one plugin of the feature catalog has a feature X: name the one that is meant as group:artifact#X or ..."). So a second spring-security-core could not take the name over, but it could take it away from everyone who writes the bare name. The indexer now keeps a name with the first plugin that is indexed with it: before any file is processed it reads the names the plugin files already have, and the pack of a new release of another plugin with such a name is not recorded, with a warning (Ignoring the Forge feature pack of <coords>:<version>: its name ... is that of a pack of <holder>). Two plugins that have one name in their files already are both kept and reported. A feature and a preset can share a name, as the CLI selects them apart. The README has a new section for maintainers that asks to look at each new pack.name in the "Update Plugin Index" pull request, and says how a name is handed over.
A hand-written pack. --rescan-packs now also reads the versions that have a pack, and replaces or removes one that is not what the indexer records of the jar, with a warning; a version whose jar cannot be read is left as it is. The scheduled run does not do this, as it would download every jar with a pack on every run, so the README asks maintainers not to accept such a change and to run --rescan-packs <file> on it. On the side of the CLI a hand-written entry is held to its sha256: a jar with another digest is refused.
A broken grails-plugin.xml. Fixed as you suggest: the descriptor is read in its own try/catch, logged (WARNING: Ignoring the plugin descriptor of <url>: ...) and the version is recorded with its pack and without grailsVersion. That also ends the normal run failing on such a jar.
Early break. The loop now breaks on grailsVersion only, so a main jar with a pack and no plugin descriptor still gets its grailsVersion from -plain.jar or the .zip. Pack-only versions are intended: when a version has no grailsVersion the CLI goes by compatibility.grails alone, and when it has one, both ranges have to allow the Grails version. Such a version is now logged (No grailsVersion found for <coords>:<version>, which is recorded with its Forge feature pack alone).
Unknown application types. Not changed. The CLI does not drop the types it does not know: it keeps the list as it is and offers the pack only for an application whose type is in it, so [batch-job] is offered for no type, not for every type. Only a missing applicationTypes means every type, and an empty list is refused by both the indexer and the CLI. Refusing a pack whose types are all unknown here would cost a pack of a later Grails with a new type its entry until this script learns the type.
Minor:
- The pack is now read for the main jar only (
readPluginArtifact(url, withPack)); nothing of-plain.jaror the.zipis hashed or reported. --rescan-packsno longer downloads again a version the same run added. That a full rescan downloads every version each time is unchanged: it is meant to be run once over the index and after that for single files.extractGrailsVersionFromPluginJaris removed, its Javadoc is onreadGrailsVersion, and the indentation is fixed.
@sbglasius the message now reads "names in '$key' a value that cannot be the name of a type of application". On the typo: agreed, it stays a log line, since the CLI offers the pack for the types it knows and for no other.
Tests: index-plugins-test.groovy now also runs the indexer against a Maven repository on the loopback interface, with a case for each point above (19 tests, all passing with Groovy 5.1.2).
The Grails side of this is the work of apache/grails-core#16348 (one generator: Forge feature packs and the unified CLI, targeted at 10.0.x) and is not merged yet. This PR can be merged prior to that and sets a new format up so the new CLI will work with it.
It changes
index-plugins.groovyandREADME.md, and addsindex-plugins-test.groovy.Why
Grails 10 lets a plugin ship a feature pack in its main jar (
META-INF/grails-forge/feature.yml, packaged by thegrails-pluginGradle plugin fromsrc/main/forge). With it,grails create-app --features <name>can add theplugin to a new application. To find which plugin and version has a feature of a given name, the CLI reads a
catalog, and the catalog it reads is this repository's
grails-plugins-index.json, as it is: the top-level array ofplugins, with the version-level
coordsandmaven-repooverrides,grailsVersion,deprecatedandartifactAvailable. The only thing the index lacks is a record of which versions have a pack.What changes
For a version whose main jar contains
META-INF/grails-forge/feature.yml, the indexer adds one property to thatversion, in the YAML file and therefore in the index:
Nothing else of the format changes. The index stays a top-level array; a consumer that does not know
packis notaffected (the plugin page ignores it).
SafeConstructor, no aliases, anchors or tags, at most256 KiB and 20 levels (the limits Grails itself applies). Nothing of the jar is executed.
grailsVersionis not repeated inpack: the CLI uses the version'sgrailsVersiontogether withcompatibility.grails, and a pack is offeredonly for a Grails that both allow.
sha256is the SHA-256 of the jar the indexer downloaded anyway. The CLI refuses a jar with another digest, sothe entry is tied to one jar. It must not be written or edited by hand.
.jar, not from-plain.jaror a Grails 2.zip.plugin has until the plugin is named with it, so the pack of a release of another plugin with that name is not
recorded, and the indexer logs a warning. A feature and a preset can have the same name.
(
WARNING: Ignoring the Forge feature pack of <url>: ...) and the version is indexed withoutpack, as today.A
grails-plugin.xmlthat cannot be read is logged as well, and the version keeps itspack.grailsVersionand the pack, and the temporary file is deletedafter it is read instead of at JVM exit.
grails-plugin.xmlin the main jar,-plain.jaror.zip) is still indexed whenit has a pack; the CLI then goes by
compatibility.grailsalone.Versions already in the YAML files
The indexer never updates a version that is already present, so existing versions would never get a
pack, and apackwritten by hand would stay. A new flag makespackwhat the jar has on request (added, or replaced or removedwith a warning) and changes nothing else of a version:
It honours a version's own
coordsandmaven-repo, and skips versions withartifactAvailable: false. Over thewhole index it is about 5,000 downloads, so it is meant to be run once, or for single files as plugins adopt packs.
The scheduled workflow is unchanged and does not pass the flag.
Trust
A
packentry makes a feature name resolve to that jar for every user who names this index as a catalog, and apack is code that runs when an application is generated. The review of a pull request that adds a plugin, or that
changes
coordsormaven-repo, therefore decides more than what the plugin page shows, and so does the review ofthe scheduled "Update Plugin Index" pull request when it brings a new
pack: the README says what to look at. The Grails CLI does notread this index by default for that reason; a user has to name it.
What was run
With Groovy 4.0 and SnakeYAML 2.4 from the local Maven cache, against a Maven repository served on the loopback
interface (the script only speaks HTTP, so a
file:repository cannot be used), with jars made of the pack of theplugin-forge-packtest project of grails-core:packwith the jar's SHA-256 (checked against
shasum); the existing one got it only with--rescan-packs;each logged and indexed without
pack, and the run went on; the next version of the same plugin got its pack;The index that run wrote was read by the Grails CLI's catalog reader. Not run: the script against the real
repositories, the GitHub workflows, and
--rescan-packsover the whole index.