cstamas commented on PR #2380:
URL: https://github.com/apache/maven-resolver/pull/2380#issuecomment-7374149676
I pushed 4c2b622f on top of your commit. It keeps the idea of the PR (look
locally before consulting the filter for every repository) and fixes one
regression, narrows the probe to what it can handle, and moves the "is this a
meta version" decision to the component that owns it. Details below.
### 1. Split local repository: the filter could be bypassed
**Setup:** `aether.enhancedLocalRepository.split=true` with
`splitRemoteRepository=true`, a filter that rejects repository `rejected`, and
a copy of the artifact in `cached/rejected-…/` **without** its
`_remote.repositories` file (users often delete these to "fix" builds).
**What happened:** the probe asks the local repository manager with *all*
repositories of the request, including rejected ones.
`EnhancedLocalRepositoryManager` finds the copy in the rejected repository's
directory; as it is untracked, it reports it as available with no repository
(the interop rule for locally installed files). The probe then treated it as
locally installed, skipped the filter, and used it. On master the rejected
repository is not in the lookup, so its directory is never examined and the
artifact is downloaded from the accepted repository.
| | before this commit | master |
|---|---|---|
| file used | `cached/rejected-…/aid-1.0.ext` |
`cached/accepted-…/aid-1.0.ext` |
| downloads | 0 | 1 |
This contradicted the guarantee in the PR description that a copy cached
from a rejected repository is not used.
**Fix:** a probe result with no source repository is accepted only if its
path is the location of locally installed artifacts
(`lrm.getAbsolutePathForLocalArtifact(artifact)`). In a non-split repository
that is the same path as before, so nothing changes there; in a split
repository the untracked copy goes to the regular path, which applies the
filter. The only cost: hits in a `ChainedLocalRepositoryManager` tail also take
the regular path, so they are as fast as on master, not faster.
Test:
`testResolveUntrackedCopyInRejectedRepositoryDirectoryOfSplitLocalRepositoryIsNotUsed`
(fails without the fix).
### 2. Snapshots stay on the regular path
The probe checks the source repository's **release** policy and does not
call `getPath()`, so it has no snapshot normalization and no base-version
tracking (`lrm.add()`). It was only ever correct for non-snapshots, so the call
site now guards it with `!artifact.isSnapshot()`. Without the guard, a locally
cached timestamped snapshot resolved to the timestamped
`gid-aid-1.0-20260101.120000-1.ext` instead of the normalized
`gid-aid-1.0-SNAPSHOT.ext`, and a copy from a repository with snapshots
disabled would have been used.
Test: `testResolveLocalTimestampedSnapshotWithFilterIsNormalized` (fails
without the guard).
### 3. The reuse of the local miss is removed
`notAvailable()` reused the probe's miss so a miss cost one lookup instead
of two. By the benchmark in the description, misses are about 6,300 of 2.5M
lookups (0.25 %), so the saving is negligible. The reuse also had a side effect
in split mode: the miss could carry a path from a rejected repository's
directory into the regular path, where master has none. With the legacy
`aether.artifactResolver.existenceCheckRelabel=true` that path is used for the
existence check and could relabel the rejected repository's file. Removing it
makes the local lookup in the regular path the master code again.
`resolveLocallyBeforeFiltering()` now returns `boolean`. The disabled-policy
test expects two lookups and again checks that the second one gets the filtered
(empty) repository list.
### 4. `VersionResolver#isMetaVersioned(Artifact)`
The previous `isReleaseVersion()` hard-coded `RELEASE` and `LATEST`, which
are Maven's meta versions, not Resolver's: `VersionResolver` is implemented by
the integrating application (Resolver itself has only test stubs). The decision
now lives there, as a default method:
- **Contract:** the caller may skip `resolveVersion()` when it returns
`false`, so an implementation must return `false` only for a version that
`resolveVersion()` returns unchanged, with no repository and without reading
any repository. Returning `true` is always safe; it only costs performance.
Implementations with other meta versions must override it.
- **Default:** `version.endsWith("SNAPSHOT") || RELEASE || LATEST`, which
matches `DefaultVersionResolver` in Maven 3.10.x and Maven 4, so Maven needs no
change. The interface is `@provisional`, and a default method breaks no
implementation.
- Version ranges are not meta versions (they belong to
`VersionRangeResolver`). A range that reaches the artifact resolver takes the
probe, misses, and fails exactly as on master.
The call site now reads: blank version → regular path (master's clear
error); snapshot → regular path (§2); `isMetaVersioned()` → regular path;
otherwise probe.
### Unchanged
The two documented behaviour changes stay as they are: no
`ArtifactFilteredOutException` on a local hit (Maven reads these only on
failure: `MavenInvoker`, `DefaultExceptionHandler`), and no `VersionResolver`
call for a non-meta version that resolves locally. They still need agreement on
dev@.
### Verification
On this branch: `maven-resolver-impl` 684 tests, 0 failures (the branch also
merges cleanly with current master). Both new tests were checked to fail with
their fix removed. Not run: `-Prun-its`, the benchmark.
The PR description still mentions the miss reuse ("a miss still costs one
`LocalRepositoryManager.find()`") and predates `isMetaVersioned()`; it would be
good to update it. Please pull before pushing again.
--
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]