cstamas opened a new pull request, #2371:
URL: https://github.com/apache/maven-resolver/pull/2371

   Filter sources (`groupId` and `prefixes`) keep per-repository state in 
session data (loaded rules, rule file paths, recorded rules, prefixes, 
layouts). Until now that state was keyed by `RemoteRepository` instances 
"normalized" with `RemoteRepository#toBareRemoteRepository()`. This PR keys it 
by the strings `RepositoryKeyFunction` produces instead.
   
   ### Why `toBareRemoteRepository()` was a bad idea for keys
   
   `RemoteRepository#equals` covers every property: id, URL, content type, 
release/snapshot policies, proxy, authentication, mirrored repositories, 
repository manager flag, blocked flag and intent. The repository system changes 
several of these as a repository moves through a session:
   
   - `newResolutionRepositories()` sets the intent, proxy, authentication and 
mirrors.
   - `DefaultRemoteRepositoryManager` merges the policies of mirrored 
repositories into the mirror, applies the session's global update and checksum 
policies, and clamps checksum policies.
   
   `toBareRemoteRepository()` resets only some of these: intent, proxy, auth, 
mirrored repos and the repository-manager flag. **Policies and the blocked flag 
are kept.** So the "same" repository, as seen by user code, by the manager, or 
merged with different mirrored repositories, can still produce different "bare" 
instances that are not equal. For the filters this means one logical repository 
ends up as several cache entries in one session:
   
   - rules or prefixes are loaded more than once,
   - recorded `groupId` rules are split across entries. On save, each entry is 
appended to the same rule file as its own `# Recorded entries` section.
   
   Adding more fields to "bare" would not fix the root problem. Filter state 
does not belong to a `RemoteRepository` instance. It belongs to the **input 
files** the filter reads, and `repositoryKeys()` already chooses those through 
`RepositoryKeyFunction`. `toBareRemoteRepository()` also has no correct result 
for mirrors: it returns the mirror without its mirrored repositories but with 
their merged-in policies.
   
   ### The proper way: `RepositoryKeyFunction`
   
   `RepositoryKeyFunction` is the configurable, documented way to say when two 
repositories are the same in a given context. Filter sources already use it 
(`trackingRepositoryKeyFunction` and `systemRepositoryKeyFunction` in 
`repositoryKeys()`) to find the user-provided rule and prefix files. Using the 
same keys for the cache makes the cache match its source by construction: 
repositories that select the same files share the same cached state, and 
repositories that select different files never do.
   
   ### What changed
   
   - **`RemoteRepositoryFilterSourceSupport`**: replaced 
`normalizeRemoteRepository()` (which returned `toBareRemoteRepository()`) with 
`repositoryCacheKey()`, which joins `repositoryKeys()` into one string. This is 
an internal impl package, and Maven and MIMA have no callers.
   - **`GroupIdRemoteRepositoryFilterSource`**: the `rules`, `ruleFiles` and 
`recordedRules` session maps are now keyed by `String`. `loadRepositoryRules` 
now receives the original repository instead of the map key.
   - **`PrefixesRemoteRepositoryFilterSource`**: the `prefixes` and `layouts` 
session maps are now keyed by `String`. The layout key also adds the repository 
content type, because the layout depends on it and repository keys do not 
include it.
   - **`RemoteRepository` javadoc**: the class and `Intent` docs now point to 
`RepositoryKeyFunction` for key use. `toBareRemoteRepository()` stays (public 
API since 2.0.14) and is not deprecated. Its javadoc no longer says it is 
usable as a key, and it now warns against using it with mirror repositories.
   - **Test**: 
`RemoteRepositoryFilterSourceTestSupport#sameStateForSystemManagedChanges` 
checks both filters. It changes the snapshot policy, proxy and intent, the way 
the repository system would, and asserts that the filter still applies the same 
rules.
   
   ---
   
   To make clear that you license your contribution under
   the [Apache License Version 2.0, January 
2004](https://www.apache.org/licenses/LICENSE-2.0)
   check one of the following:
   
   - [x] I hereby declare this contribution to be licensed under the [Apache 
License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
   - [ ] I hereby declare that I have filed an [Apache Individual Contributor 
License Agreement](https://www.apache.org/licenses/icla.pdf).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to