This is an automated email from the ASF dual-hosted git repository.

cstamas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git


The following commit(s) were added to refs/heads/master by this push:
     new 9e552940d Fix #1304: respect updatePolicy=never on composite metadata 
checks (#2261)
9e552940d is described below

commit 9e552940dc1b6603834bd750442ce793d9b0e303
Author: Arturo Bernal <[email protected]>
AuthorDate: Wed Nov 4 19:10:33 2026 +0100

    Fix #1304: respect updatePolicy=never on composite metadata checks (#2261)
    
    Fixes #1304.
    
    When a repository has updatePolicy=never for releases but no explicit 
snapshot policy (which defaults to daily), resolving metadata of nature 
RELEASE_OR_SNAPSHOT (version ranges, LATEST/RELEASE) merged the release and 
snapshot update policies into one effective policy by picking whichever had the 
shorter interval. "never" always lost to "daily", so every build re-fetched 
maven-metadata.xml for any version-ranged dependency regardless of the 
configured policy.
    
    DefaultRemoteRepositoryManager.merge() already has this exact pattern for 
checksum policies (since 2.0.23): the stronger of the two wins by default, with 
a config flag to opt back into the old "weakest wins" merge. This applies the 
same fix to the artifact and metadata update policies, via a new 
UpdatePolicyAnalyzer.getStrongerUpdatePolicy() counterpart to the existing 
getEffectiveUpdatePolicy().
    
    Testing: updated testGetPolicy to assert the correct ("never") outcome, 
which fails against the unfixed merge logic, and added three more tests 
mirroring the existing checksum-policy coverage (stronger-wins default, legacy 
opt-in flag, session override). Ran the full maven-resolver-impl test suite 
plus checkstyle/spotless, all green.
    
    No backport: maven-resolver-1.9.x has a single update policy shared by both 
natures (no release/snapshot split), so this merge doesn't exist there.
    
    ---
    
    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)
    - [x] I hereby declare that I have filed an [Apache Individual Contributor 
License Agreement](https://www.apache.org/licenses/icla.pdf).
---
 .../eclipse/aether/impl/UpdatePolicyAnalyzer.java  | 11 ++++
 .../impl/DefaultRemoteRepositoryManager.java       | 35 ++++++++++++
 .../internal/impl/DefaultUpdatePolicyAnalyzer.java |  6 +++
 .../impl/DefaultRemoteRepositoryManagerTest.java   | 63 ++++++++++++++++++++++
 .../impl/DefaultUpdatePolicyAnalyzerTest.java      | 20 +++++++
 5 files changed, 135 insertions(+)

diff --git 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/UpdatePolicyAnalyzer.java
 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/UpdatePolicyAnalyzer.java
index ce17a1e91..39b307c21 100644
--- 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/UpdatePolicyAnalyzer.java
+++ 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/UpdatePolicyAnalyzer.java
@@ -39,6 +39,17 @@ public interface UpdatePolicyAnalyzer {
      */
     String getEffectiveUpdatePolicy(RepositorySystemSession session, String 
policy1, String policy2);
 
+    /**
+     * Returns the policy with the longer update interval, i.e. the one that 
checks for updates least often.
+     *
+     * @param session The repository system session during which the request 
is made, must not be {@code null}.
+     * @param policy1 A policy to compare, may be {@code null}.
+     * @param policy2 A policy to compare, may be {@code null}.
+     * @return The policy with the longer update interval.
+     * @since 2.0.25
+     */
+    String getStrongerUpdatePolicy(RepositorySystemSession session, String 
policy1, String policy2);
+
     /**
      * Determines whether the specified modification timestamp satisfies the 
freshness constraint expressed by the given
      * update policy.
diff --git 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRemoteRepositoryManager.java
 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRemoteRepositoryManager.java
index 18adb4fb9..17cd7c09c 100644
--- 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRemoteRepositoryManager.java
+++ 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRemoteRepositoryManager.java
@@ -356,6 +356,25 @@ public class DefaultRemoteRepositoryManager implements 
RemoteRepositoryManager {
 
     public static final boolean DEFAULT_NATURE_MERGE_WEAKEST_CHECKSUM_POLICY = 
false;
 
+    /**
+     * Flag indicating whether the merge of a repository's release and 
snapshot update policies (used when a single
+     * effective policy has to serve both natures, most notably for metadata 
of nature RELEASE_OR_SNAPSHOT such as
+     * {@code maven-metadata.xml} version lists) may pick the policy with the 
<em>shorter</em> update interval of the
+     * two, which was the legacy behavior. When disabled (the default), the 
policy with the longer update interval
+     * wins, so enabling snapshots on a repository configured with {@code 
updatePolicy=never} for releases no longer
+     * silently forces metadata updates that the operator configured to never 
happen (or vice versa). An explicit
+     * update policy set on the session takes precedence over either behavior, 
as before.
+     *
+     * @since 2.0.25
+     * @configurationSource {@link 
RepositorySystemSession#getConfigProperties()}
+     * @configurationType {@link java.lang.Boolean}
+     * @configurationDefaultValue {@link 
#DEFAULT_NATURE_MERGE_WEAKEST_UPDATE_POLICY}
+     */
+    public static final String CONFIG_PROP_NATURE_MERGE_WEAKEST_UPDATE_POLICY =
+            "aether.remoteRepositoryManager.natureMergeWeakestUpdatePolicy";
+
+    public static final boolean DEFAULT_NATURE_MERGE_WEAKEST_UPDATE_POLICY = 
false;
+
     @Override
     public RepositoryPolicy getPolicy(
             RepositorySystemSession session, RemoteRepository repository, 
boolean releases, boolean snapshots) {
@@ -429,10 +448,21 @@ public class DefaultRemoteRepositoryManager implements 
RemoteRepositoryManager {
                         session, policy1.getChecksumPolicy(), 
policy2.getChecksumPolicy());
             }
 
+            boolean mergeWeakestUpdatePolicy = ConfigUtils.getBoolean(
+                    session,
+                    DEFAULT_NATURE_MERGE_WEAKEST_UPDATE_POLICY,
+                    CONFIG_PROP_NATURE_MERGE_WEAKEST_UPDATE_POLICY);
+
             String artifactUpdates = session.getArtifactUpdatePolicy();
             //noinspection StatementWithEmptyBody
             if (globalPolicy && artifactUpdates != null && 
!artifactUpdates.isEmpty()) {
                 // use global override
+            } else if (globalPolicy && !mergeWeakestUpdatePolicy) {
+                // merging the release and snapshot policies of a single 
repository into one effective policy
+                // (e.g. for metadata of nature RELEASE_OR_SNAPSHOT): the 
result must not be more eager than what
+                // the operator configured for either nature, so the policy 
with the longer update interval wins
+                artifactUpdates = updatePolicyAnalyzer.getStrongerUpdatePolicy(
+                        session, policy1.getArtifactUpdatePolicy(), 
policy2.getArtifactUpdatePolicy());
             } else {
                 artifactUpdates = 
updatePolicyAnalyzer.getEffectiveUpdatePolicy(
                         session, policy1.getArtifactUpdatePolicy(), 
policy2.getArtifactUpdatePolicy());
@@ -440,6 +470,11 @@ public class DefaultRemoteRepositoryManager implements 
RemoteRepositoryManager {
             String metadataUpdates = session.getMetadataUpdatePolicy();
             if (globalPolicy && metadataUpdates != null && 
!metadataUpdates.isEmpty()) {
                 // use global override
+            } else if (globalPolicy && !mergeWeakestUpdatePolicy) {
+                // same reasoning as above, for metadata update policy; this 
is the composite RELEASE_OR_SNAPSHOT
+                // case that version-range and LATEST/RELEASE metadata 
requests go through
+                metadataUpdates = updatePolicyAnalyzer.getStrongerUpdatePolicy(
+                        session, policy1.getMetadataUpdatePolicy(), 
policy2.getMetadataUpdatePolicy());
             } else {
                 metadataUpdates = 
updatePolicyAnalyzer.getEffectiveUpdatePolicy(
                         session, policy1.getMetadataUpdatePolicy(), 
policy2.getMetadataUpdatePolicy());
diff --git 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultUpdatePolicyAnalyzer.java
 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultUpdatePolicyAnalyzer.java
index 774bc0530..8c5a5e6d4 100644
--- 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultUpdatePolicyAnalyzer.java
+++ 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultUpdatePolicyAnalyzer.java
@@ -45,6 +45,12 @@ public class DefaultUpdatePolicyAnalyzer implements 
UpdatePolicyAnalyzer {
         return ordinalOfUpdatePolicy(policy1) < ordinalOfUpdatePolicy(policy2) 
? policy1 : policy2;
     }
 
+    @Override
+    public String getStrongerUpdatePolicy(RepositorySystemSession session, 
String policy1, String policy2) {
+        requireNonNull(session, "session cannot be null");
+        return ordinalOfUpdatePolicy(policy1) > ordinalOfUpdatePolicy(policy2) 
? policy1 : policy2;
+    }
+
     private int ordinalOfUpdatePolicy(String policy) {
         if (RepositoryPolicy.UPDATE_POLICY_DAILY.equals(policy)) {
             return 1440;
diff --git 
a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultRemoteRepositoryManagerTest.java
 
b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultRemoteRepositoryManagerTest.java
index 344790cc0..13bd5bcdc 100644
--- 
a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultRemoteRepositoryManagerTest.java
+++ 
b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultRemoteRepositoryManagerTest.java
@@ -92,6 +92,9 @@ public class DefaultRemoteRepositoryManagerTest {
 
     @Test
     void testGetPolicy() {
+        // MRESOLVER-634: a repository with updatePolicy=never for releases 
and the (default) always for
+        // snapshots must keep honoring "never" once release and snapshot 
policies are merged into one
+        // effective policy for metadata of nature RELEASE_OR_SNAPSHOT, e.g. 
for version-range requests.
         RepositoryPolicy snapshotPolicy = new RepositoryPolicy(
                 true, RepositoryPolicy.UPDATE_POLICY_ALWAYS, 
RepositoryPolicy.CHECKSUM_POLICY_IGNORE);
         RepositoryPolicy releasePolicy =
@@ -105,10 +108,65 @@ public class DefaultRemoteRepositoryManagerTest {
         RepositoryPolicy effectivePolicy = manager.getPolicy(session, repo, 
true, true);
         assertTrue(effectivePolicy.isEnabled());
         assertEquals(RepositoryPolicy.CHECKSUM_POLICY_FAIL, 
effectivePolicy.getChecksumPolicy());
+        assertEquals(RepositoryPolicy.UPDATE_POLICY_NEVER, 
effectivePolicy.getArtifactUpdatePolicy());
+        assertEquals(RepositoryPolicy.UPDATE_POLICY_NEVER, 
effectivePolicy.getMetadataUpdatePolicy());
+    }
+
+    @Test
+    void testGetPolicy_NatureMergePicksStrongerUpdatePolicy() {
+        RepositoryPolicy snapshotPolicy =
+                new RepositoryPolicy(true, 
RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
+        RepositoryPolicy releasePolicy = new RepositoryPolicy(
+                true, RepositoryPolicy.UPDATE_POLICY_INTERVAL + ":10080", 
RepositoryPolicy.CHECKSUM_POLICY_FAIL);
+
+        RemoteRepository repo = new RemoteRepository.Builder("id", "type", 
"http://localhost";)
+                .setSnapshotPolicy(snapshotPolicy)
+                .setReleasePolicy(releasePolicy)
+                .build();
+
+        RepositoryPolicy effectivePolicy = manager.getPolicy(session, repo, 
true, true);
+        assertEquals(RepositoryPolicy.UPDATE_POLICY_INTERVAL + ":10080", 
effectivePolicy.getArtifactUpdatePolicy());
+        assertEquals(RepositoryPolicy.UPDATE_POLICY_INTERVAL + ":10080", 
effectivePolicy.getMetadataUpdatePolicy());
+    }
+
+    @Test
+    void testGetPolicy_LegacyWeakestUpdatePolicyNatureMerge() {
+        RepositoryPolicy snapshotPolicy = new RepositoryPolicy(
+                true, RepositoryPolicy.UPDATE_POLICY_ALWAYS, 
RepositoryPolicy.CHECKSUM_POLICY_FAIL);
+        RepositoryPolicy releasePolicy =
+                new RepositoryPolicy(true, 
RepositoryPolicy.UPDATE_POLICY_NEVER, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
+
+        RemoteRepository repo = new RemoteRepository.Builder("id", "type", 
"http://localhost";)
+                .setSnapshotPolicy(snapshotPolicy)
+                .setReleasePolicy(releasePolicy)
+                .build();
+
+        
session.setConfigProperty(DefaultRemoteRepositoryManager.CONFIG_PROP_NATURE_MERGE_WEAKEST_UPDATE_POLICY,
 true);
+
+        RepositoryPolicy effectivePolicy = manager.getPolicy(session, repo, 
true, true);
         assertEquals(RepositoryPolicy.UPDATE_POLICY_ALWAYS, 
effectivePolicy.getArtifactUpdatePolicy());
         assertEquals(RepositoryPolicy.UPDATE_POLICY_ALWAYS, 
effectivePolicy.getMetadataUpdatePolicy());
     }
 
+    @Test
+    void testGetPolicy_SessionUpdatePolicyOverridesNatureMerge() {
+        RepositoryPolicy snapshotPolicy = new RepositoryPolicy(
+                true, RepositoryPolicy.UPDATE_POLICY_ALWAYS, 
RepositoryPolicy.CHECKSUM_POLICY_FAIL);
+        RepositoryPolicy releasePolicy =
+                new RepositoryPolicy(true, 
RepositoryPolicy.UPDATE_POLICY_NEVER, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
+
+        RemoteRepository repo = new RemoteRepository.Builder("id", "type", 
"http://localhost";)
+                .setSnapshotPolicy(snapshotPolicy)
+                .setReleasePolicy(releasePolicy)
+                .build();
+
+        session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_DAILY);
+
+        RepositoryPolicy effectivePolicy = manager.getPolicy(session, repo, 
true, true);
+        assertEquals(RepositoryPolicy.UPDATE_POLICY_DAILY, 
effectivePolicy.getArtifactUpdatePolicy());
+        assertEquals(RepositoryPolicy.UPDATE_POLICY_DAILY, 
effectivePolicy.getMetadataUpdatePolicy());
+    }
+
     @Test
     void testGetPolicy_NatureMergePicksStrongerChecksumPolicy() {
         RepositoryPolicy snapshotPolicy = new RepositoryPolicy(
@@ -725,6 +783,11 @@ public class DefaultRemoteRepositoryManagerTest {
             return ordinalOfUpdatePolicy(policy1) < 
ordinalOfUpdatePolicy(policy2) ? policy1 : policy2;
         }
 
+        public String getStrongerUpdatePolicy(RepositorySystemSession session, 
String policy1, String policy2) {
+            requireNonNull(session, "session cannot be null");
+            return ordinalOfUpdatePolicy(policy1) > 
ordinalOfUpdatePolicy(policy2) ? policy1 : policy2;
+        }
+
         private int ordinalOfUpdatePolicy(String policy) {
             if (RepositoryPolicy.UPDATE_POLICY_DAILY.equals(policy)) {
                 return 1440;
diff --git 
a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultUpdatePolicyAnalyzerTest.java
 
b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultUpdatePolicyAnalyzerTest.java
index f09a81d8a..a16d03b7d 100644
--- 
a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultUpdatePolicyAnalyzerTest.java
+++ 
b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultUpdatePolicyAnalyzerTest.java
@@ -117,4 +117,24 @@ public class DefaultUpdatePolicyAnalyzerTest {
                 analyzer.getEffectiveUpdatePolicy(
                         session, UPDATE_POLICY_INTERVAL + ":100", 
UPDATE_POLICY_INTERVAL + ":60"));
     }
+
+    @Test
+    void testStrongerUpdatePolicy() {
+        assertEquals(
+                UPDATE_POLICY_DAILY,
+                analyzer.getStrongerUpdatePolicy(session, 
UPDATE_POLICY_ALWAYS, UPDATE_POLICY_DAILY));
+        assertEquals(
+                UPDATE_POLICY_NEVER,
+                analyzer.getStrongerUpdatePolicy(session, 
UPDATE_POLICY_ALWAYS, UPDATE_POLICY_NEVER));
+        assertEquals(
+                UPDATE_POLICY_NEVER,
+                analyzer.getStrongerUpdatePolicy(session, UPDATE_POLICY_DAILY, 
UPDATE_POLICY_NEVER));
+        assertEquals(
+                UPDATE_POLICY_DAILY,
+                analyzer.getStrongerUpdatePolicy(session, UPDATE_POLICY_DAILY, 
UPDATE_POLICY_INTERVAL + ":60"));
+        assertEquals(
+                UPDATE_POLICY_INTERVAL + ":100",
+                analyzer.getStrongerUpdatePolicy(
+                        session, UPDATE_POLICY_INTERVAL + ":100", 
UPDATE_POLICY_INTERVAL + ":60"));
+    }
 }

Reply via email to