From e363e9ba97f98fb7dba57f8f32734af76c4a4b48 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 29 Jun 2023 20:32:04 +0200 Subject: [PATCH 1/5] [MRESOLVER-377] Introduce metadataUpdatePolicy Split the policies applied in case of data and metadata application. --- https://issues.apache.org/jira/browse/MRESOLVER-377 --- ...ractForwardingRepositorySystemSession.java | 5 +++ .../DefaultRepositorySystemSession.java | 24 +++++++++++ .../aether/RepositorySystemSession.java | 14 ++++++- .../aether/repository/RepositoryPolicy.java | 32 ++++++++++++++- .../org/eclipse/aether/impl/UpdateCheck.java | 34 +++++++++++++-- .../impl/DefaultArtifactResolver.java | 1 + .../impl/DefaultMetadataResolver.java | 2 + .../impl/DefaultRemoteRepositoryManager.java | 41 +++++++++++++++---- .../impl/DefaultUpdateCheckManager.java | 10 +++-- .../impl/DefaultUpdateCheckManagerTest.java | 6 +++ 10 files changed, 151 insertions(+), 18 deletions(-) diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/AbstractForwardingRepositorySystemSession.java b/maven-resolver-api/src/main/java/org/eclipse/aether/AbstractForwardingRepositorySystemSession.java index a1a2083e1..4583b065c 100644 --- a/maven-resolver-api/src/main/java/org/eclipse/aether/AbstractForwardingRepositorySystemSession.java +++ b/maven-resolver-api/src/main/java/org/eclipse/aether/AbstractForwardingRepositorySystemSession.java @@ -87,6 +87,11 @@ public String getUpdatePolicy() { return getSession().getUpdatePolicy(); } + @Override + public String getMetadataUpdatePolicy() { + return getSession().getMetadataUpdatePolicy(); + } + @Override public LocalRepository getLocalRepository() { return getSession().getLocalRepository(); diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/DefaultRepositorySystemSession.java b/maven-resolver-api/src/main/java/org/eclipse/aether/DefaultRepositorySystemSession.java index a6e24fd57..978ae5cdb 100644 --- a/maven-resolver-api/src/main/java/org/eclipse/aether/DefaultRepositorySystemSession.java +++ b/maven-resolver-api/src/main/java/org/eclipse/aether/DefaultRepositorySystemSession.java @@ -73,6 +73,8 @@ public final class DefaultRepositorySystemSession implements RepositorySystemSes private String updatePolicy; + private String metadataUpdatePolicy; + private LocalRepositoryManager localRepositoryManager; private FileTransformerManager fileTransformerManager; @@ -154,6 +156,7 @@ public DefaultRepositorySystemSession(RepositorySystemSession session) { setArtifactDescriptorPolicy(session.getArtifactDescriptorPolicy()); setChecksumPolicy(session.getChecksumPolicy()); setUpdatePolicy(session.getUpdatePolicy()); + setMetadataUpdatePolicy(session.getMetadataUpdatePolicy()); setLocalRepositoryManager(session.getLocalRepositoryManager()); setWorkspaceReader(session.getWorkspaceReader()); setRepositoryListener(session.getRepositoryListener()); @@ -293,6 +296,27 @@ public DefaultRepositorySystemSession setUpdatePolicy(String updatePolicy) { return this; } + @Override + public String getMetadataUpdatePolicy() { + return metadataUpdatePolicy; + } + + /** + * Sets the global metadata update policy. If set, the global update policy overrides the update policies of the remote + * repositories being used for resolution. + * + * @param metadataUpdatePolicy The global update policy, may be {@code null}/empty to apply the per-repository policies. + * @return This session for chaining, never {@code null}. + * @see RepositoryPolicy#UPDATE_POLICY_ALWAYS + * @see RepositoryPolicy#UPDATE_POLICY_DAILY + * @see RepositoryPolicy#UPDATE_POLICY_NEVER + */ + public DefaultRepositorySystemSession setMetadataUpdatePolicy(String metadataUpdatePolicy) { + verifyStateForMutation(); + this.metadataUpdatePolicy = metadataUpdatePolicy; + return this; + } + @Override public LocalRepository getLocalRepository() { LocalRepositoryManager lrm = getLocalRepositoryManager(); diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java index 31e99cd70..581161119 100644 --- a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java +++ b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystemSession.java @@ -94,7 +94,7 @@ public interface RepositorySystemSession { String getChecksumPolicy(); /** - * Gets the global update policy. If set, the global update policy overrides the update policies of the remote + * Gets the global data update policy. If set, the global update policy overrides the update policies of the remote * repositories being used for resolution. * * @return The global update policy or {@code null}/empty if not set and the per-repository policies apply. @@ -104,6 +104,18 @@ public interface RepositorySystemSession { */ String getUpdatePolicy(); + /** + * Gets the global metadata update policy. If set, the global update policy overrides the update policies of the remote + * repositories being used for resolution. + * + * @return The global update policy or {@code null}/empty if not set and the per-repository policies apply. + * @see RepositoryPolicy#UPDATE_POLICY_ALWAYS + * @see RepositoryPolicy#UPDATE_POLICY_DAILY + * @see RepositoryPolicy#UPDATE_POLICY_NEVER + * @since TBD + */ + String getMetadataUpdatePolicy(); + /** * Gets the local repository used during this session. This is a convenience method for * {@link LocalRepositoryManager#getRepository()}. diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RepositoryPolicy.java b/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RepositoryPolicy.java index 14f44d44d..af593033b 100644 --- a/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RepositoryPolicy.java +++ b/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RepositoryPolicy.java @@ -62,13 +62,25 @@ public final class RepositoryPolicy { private final String updatePolicy; + private final String metadataUpdatePolicy; + private final String checksumPolicy; /** * Creates a new policy with checksum warnings and daily update checks. */ public RepositoryPolicy() { - this(true, UPDATE_POLICY_DAILY, CHECKSUM_POLICY_WARN); + this(true, UPDATE_POLICY_DAILY, UPDATE_POLICY_DAILY, CHECKSUM_POLICY_WARN); + } + + /** + * Legacy constructor that handles update policy and metadata update policy same (as before). + * + * @deprecated Use any other constructor. + */ + @Deprecated + public RepositoryPolicy(boolean enabled, String updatePolicy, String checksumPolicy) { + this(enabled, updatePolicy, updatePolicy, checksumPolicy); } /** @@ -77,11 +89,16 @@ public RepositoryPolicy() { * @param enabled A flag whether the associated repository should be accessed or not. * @param updatePolicy The update interval after which locally cached data from the repository is considered stale * and should be refetched, may be {@code null}. + * @param metadataUpdatePolicy The update interval after which locally cached metadata from the repository is considered stale + * and should be refetched, may be {@code null}. * @param checksumPolicy The way checksum verification should be handled, may be {@code null}. + * + * @since TBD */ - public RepositoryPolicy(boolean enabled, String updatePolicy, String checksumPolicy) { + public RepositoryPolicy(boolean enabled, String updatePolicy, String metadataUpdatePolicy, String checksumPolicy) { this.enabled = enabled; this.updatePolicy = (updatePolicy != null) ? updatePolicy : ""; + this.metadataUpdatePolicy = (metadataUpdatePolicy != null) ? metadataUpdatePolicy : ""; this.checksumPolicy = (checksumPolicy != null) ? checksumPolicy : ""; } @@ -103,6 +120,16 @@ public String getUpdatePolicy() { return updatePolicy; } + /** + * Gets the update policy for locally cached metadata from the repository. + * + * @return The update policy, never {@code null}. + * @since TBD + */ + public String getMetadataUpdatePolicy() { + return metadataUpdatePolicy; + } + /** * Gets the policy for checksum validation. * @@ -118,6 +145,7 @@ public String toString() { buffer.append("enabled=").append(isEnabled()); buffer.append(", checksums=").append(getChecksumPolicy()); buffer.append(", updates=").append(getUpdatePolicy()); + buffer.append(", metadataUpdates=").append(getMetadataUpdatePolicy()); return buffer.toString(); } diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/UpdateCheck.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/UpdateCheck.java index f689c12fe..f5a2454e9 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/UpdateCheck.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/impl/UpdateCheck.java @@ -43,6 +43,8 @@ public final class UpdateCheck { private String policy; + private String metadataPolicy; + private RemoteRepository repository; private RemoteRepository authoritativeRepository; @@ -147,19 +149,30 @@ public UpdateCheck setFileValid(boolean fileValid) { } /** - * Gets the policy to use for the check. + * Gets the policy to use for the data check. * - * @return The policy to use for the check. + * @return The policy to use for the data check. * @see org.eclipse.aether.repository.RepositoryPolicy */ public String getPolicy() { return policy; } + /** + * Gets the policy to use for the metadata check. + * + * @return The policy to use for the metadata check. + * @see org.eclipse.aether.repository.RepositoryPolicy + * @since TBD + */ + public String getMetadataPolicy() { + return metadataPolicy; + } + /** * Sets the policy to use for the check. * - * @param policy The policy to use for the check, may be {@code null}. + * @param policy The policy to use for the data check, may be {@code null}. * @return This object for chaining. * @see org.eclipse.aether.repository.RepositoryPolicy */ @@ -168,6 +181,19 @@ public UpdateCheck setPolicy(String policy) { return this; } + /** + * Sets the policy to use for the check. + * + * @param metadataPolicy The policy to use for the metadata check, may be {@code null}. + * @return This object for chaining. + * @see org.eclipse.aether.repository.RepositoryPolicy + * @since TBD + */ + public UpdateCheck setMetadataPolicy(String metadataPolicy) { + this.metadataPolicy = metadataPolicy; + return this; + } + /** * Gets the repository from which a potential update/download will performed. * @@ -256,6 +282,6 @@ public UpdateCheck setException(E exception) { @Override public String toString() { - return getPolicy() + ": " + getFile() + " < " + getRepository(); + return getPolicy() + "/" + getMetadataPolicy() + ": " + getFile() + " < " + getRepository(); } } diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultArtifactResolver.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultArtifactResolver.java index 252e1821b..f9ed96da7 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultArtifactResolver.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultArtifactResolver.java @@ -567,6 +567,7 @@ private List gatherDownloads(RepositorySystemSession session, check.setFileValid(false); check.setRepository(group.repository); check.setPolicy(policy.getUpdatePolicy()); + check.setMetadataPolicy(policy.getMetadataUpdatePolicy()); item.updateCheck = check; updateCheckManager.checkArtifact(session, check); if (!check.isRequired()) { diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultMetadataResolver.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultMetadataResolver.java index 1d938b942..aecf04af8 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultMetadataResolver.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultMetadataResolver.java @@ -290,6 +290,8 @@ private List resolve( check.setAuthoritativeRepository(repo); check.setPolicy( getPolicy(session, repo, metadata.getNature()).getUpdatePolicy()); + check.setMetadataPolicy( + getPolicy(session, repo, metadata.getNature()).getMetadataUpdatePolicy()); if (lrmResult.isStale()) { checks.add(check); 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 9a297555c..547414cea 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 @@ -255,25 +255,41 @@ private RepositoryPolicy merge( if (policy2 == null) { if (globalPolicy) { - policy = merge(policy1, session.getUpdatePolicy(), session.getChecksumPolicy()); + policy = merge( + policy1, + session.getUpdatePolicy(), + session.getMetadataUpdatePolicy(), + session.getChecksumPolicy()); } else { policy = policy1; } } else if (policy1 == null) { if (globalPolicy) { - policy = merge(policy2, session.getUpdatePolicy(), session.getChecksumPolicy()); + policy = merge( + policy2, + session.getUpdatePolicy(), + session.getMetadataUpdatePolicy(), + session.getChecksumPolicy()); } else { policy = policy2; } } else if (!policy2.isEnabled()) { if (globalPolicy) { - policy = merge(policy1, session.getUpdatePolicy(), session.getChecksumPolicy()); + policy = merge( + policy1, + session.getUpdatePolicy(), + session.getMetadataUpdatePolicy(), + session.getChecksumPolicy()); } else { policy = policy1; } } else if (!policy1.isEnabled()) { if (globalPolicy) { - policy = merge(policy2, session.getUpdatePolicy(), session.getChecksumPolicy()); + policy = merge( + policy2, + session.getUpdatePolicy(), + session.getMetadataUpdatePolicy(), + session.getChecksumPolicy()); } else { policy = policy2; } @@ -295,24 +311,35 @@ private RepositoryPolicy merge( updates = updatePolicyAnalyzer.getEffectiveUpdatePolicy( session, policy1.getUpdatePolicy(), policy2.getUpdatePolicy()); } + String metadataUpdates = session.getMetadataUpdatePolicy(); + if (globalPolicy && metadataUpdates != null && !metadataUpdates.isEmpty()) { + // use global override + } else { + metadataUpdates = updatePolicyAnalyzer.getEffectiveUpdatePolicy( + session, policy1.getMetadataUpdatePolicy(), policy2.getMetadataUpdatePolicy()); + } - policy = new RepositoryPolicy(true, updates, checksums); + policy = new RepositoryPolicy(true, updates, metadataUpdates, checksums); } return policy; } - private RepositoryPolicy merge(RepositoryPolicy policy, String updates, String checksums) { + private RepositoryPolicy merge(RepositoryPolicy policy, String updates, String metadataUpdates, String checksums) { if (policy != null) { if (updates == null || updates.isEmpty()) { updates = policy.getUpdatePolicy(); } + if (metadataUpdates == null || metadataUpdates.isEmpty()) { + metadataUpdates = policy.getMetadataUpdatePolicy(); + } if (checksums == null || checksums.isEmpty()) { checksums = policy.getChecksumPolicy(); } if (!policy.getUpdatePolicy().equals(updates) + || !policy.getMetadataUpdatePolicy().equals(metadataUpdates) || !policy.getChecksumPolicy().equals(checksums)) { - policy = new RepositoryPolicy(policy.isEnabled(), updates, checksums); + policy = new RepositoryPolicy(policy.isEnabled(), updates, metadataUpdates, checksums); } } return policy; diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultUpdateCheckManager.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultUpdateCheckManager.java index 367bc2b2c..a7d40a1eb 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultUpdateCheckManager.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultUpdateCheckManager.java @@ -134,8 +134,9 @@ public DefaultUpdateCheckManager setUpdatePolicyAnalyzer(UpdatePolicyAnalyzer up public void checkArtifact(RepositorySystemSession session, UpdateCheck check) { requireNonNull(session, "session cannot be null"); requireNonNull(check, "check cannot be null"); + final String updatePolicy = check.getPolicy(); if (check.getLocalLastUpdated() != 0 - && !isUpdatedRequired(session, check.getLocalLastUpdated(), check.getPolicy())) { + && !isUpdatedRequired(session, check.getLocalLastUpdated(), updatePolicy)) { LOGGER.debug("Skipped remote request for {}, locally installed artifact up-to-date", check.getItem()); check.setRequired(false); @@ -185,7 +186,7 @@ public void checkArtifact(RepositorySystemSession session, UpdateCheck check) { requireNonNull(session, "session cannot be null"); requireNonNull(check, "check cannot be null"); + final String updatePolicy = check.getMetadataPolicy(); if (check.getLocalLastUpdated() != 0 - && !isUpdatedRequired(session, check.getLocalLastUpdated(), check.getPolicy())) { + && !isUpdatedRequired(session, check.getLocalLastUpdated(), updatePolicy)) { LOGGER.debug("Skipped remote request for {} locally installed metadata up-to-date", check.getItem()); check.setRequired(false); @@ -290,7 +292,7 @@ public void checkMetadata(RepositorySystemSession session, UpdateCheck newMetadataCheck() { check.setRepository(repository); check.setAuthoritativeRepository(repository); check.setPolicy(RepositoryPolicy.UPDATE_POLICY_INTERVAL + ":10"); + check.setMetadataPolicy(RepositoryPolicy.UPDATE_POLICY_INTERVAL + ":10"); return check; } @@ -298,6 +299,7 @@ public void testCheckMetadataErrorFromRepoCachingDisabled() { public void testCheckMetadataAtMostOnceDuringSessionEvenIfUpdatePolicyAlways() { UpdateCheck check = newMetadataCheck(); check.setPolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS); + check.setMetadataPolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS); // first check manager.checkMetadata(session, check); @@ -314,6 +316,7 @@ public void testCheckMetadataAtMostOnceDuringSessionEvenIfUpdatePolicyAlways() { public void testCheckMetadataSessionStateModes() { UpdateCheck check = newMetadataCheck(); check.setPolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS); + check.setMetadataPolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS); manager.touchMetadata(session, check); session.setConfigProperty(DefaultUpdateCheckManager.CONFIG_PROP_SESSION_STATE, "bypass"); @@ -338,6 +341,7 @@ public void testCheckMetadataSessionStateModes() { public void testCheckMetadataAtMostOnceDuringSessionEvenIfUpdatePolicyAlways_InvalidFile() { UpdateCheck check = newMetadataCheck(); check.setPolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS); + check.setMetadataPolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS); check.setFileValid(false); // first check @@ -364,6 +368,7 @@ public void testCheckMetadataAtMostOnceDuringSessionEvenIfUpdatePolicyAlways_Inv public void testCheckMetadataAtMostOnceDuringSessionEvenIfUpdatePolicyAlways_DifferentRepoIdSameUrl() { UpdateCheck check = newMetadataCheck(); check.setPolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS); + check.setMetadataPolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS); check.setFileValid(false); // first check @@ -427,6 +432,7 @@ public void testCheckMetadataWhenLocallyDeletedEvenIfTimestampUpToDate() { public void testCheckMetadataNotWhenUpdatePolicyIsNeverAndTimestampIsUnavailable() { UpdateCheck check = newMetadataCheck(); check.setPolicy(RepositoryPolicy.UPDATE_POLICY_NEVER); + check.setMetadataPolicy(RepositoryPolicy.UPDATE_POLICY_NEVER); session.setResolutionErrorPolicy(new SimpleResolutionErrorPolicy(true, false)); manager.checkMetadata(session, check); From 07df406fbc8fdb4d36d5f964a2f157a4c904532b Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 29 Jun 2023 20:43:13 +0200 Subject: [PATCH 2/5] Tidy up --- .../java/org/eclipse/aether/DefaultRepositorySystemSession.java | 1 + .../java/org/eclipse/aether/repository/RepositoryPolicy.java | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/DefaultRepositorySystemSession.java b/maven-resolver-api/src/main/java/org/eclipse/aether/DefaultRepositorySystemSession.java index 978ae5cdb..9738d9a07 100644 --- a/maven-resolver-api/src/main/java/org/eclipse/aether/DefaultRepositorySystemSession.java +++ b/maven-resolver-api/src/main/java/org/eclipse/aether/DefaultRepositorySystemSession.java @@ -310,6 +310,7 @@ public String getMetadataUpdatePolicy() { * @see RepositoryPolicy#UPDATE_POLICY_ALWAYS * @see RepositoryPolicy#UPDATE_POLICY_DAILY * @see RepositoryPolicy#UPDATE_POLICY_NEVER + * @since TBD */ public DefaultRepositorySystemSession setMetadataUpdatePolicy(String metadataUpdatePolicy) { verifyStateForMutation(); diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RepositoryPolicy.java b/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RepositoryPolicy.java index af593033b..59193af8a 100644 --- a/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RepositoryPolicy.java +++ b/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RepositoryPolicy.java @@ -92,7 +92,6 @@ public RepositoryPolicy(boolean enabled, String updatePolicy, String checksumPol * @param metadataUpdatePolicy The update interval after which locally cached metadata from the repository is considered stale * and should be refetched, may be {@code null}. * @param checksumPolicy The way checksum verification should be handled, may be {@code null}. - * * @since TBD */ public RepositoryPolicy(boolean enabled, String updatePolicy, String metadataUpdatePolicy, String checksumPolicy) { From c4a4bb4cec60820aecaf0c0c1374867a60022248 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Fri, 13 Oct 2023 17:31:00 +0200 Subject: [PATCH 3/5] Simplify --- .../aether/internal/impl/DefaultMetadataResolver.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultMetadataResolver.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultMetadataResolver.java index fee2efe2e..b26de1d8d 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultMetadataResolver.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultMetadataResolver.java @@ -282,6 +282,8 @@ private List resolve( List> checks = new ArrayList<>(); Exception exception = null; for (RemoteRepository repo : repositories) { + RepositoryPolicy policy = getPolicy(session, repo, metadata.getNature()); + UpdateCheck check = new UpdateCheck<>(); check.setLocalLastUpdated((localLastUpdate != null) ? localLastUpdate : 0); check.setItem(metadata); @@ -294,10 +296,8 @@ private List resolve( check.setFile(checkFile); check.setRepository(repository); check.setAuthoritativeRepository(repo); - check.setPolicy( - getPolicy(session, repo, metadata.getNature()).getUpdatePolicy()); - check.setMetadataPolicy( - getPolicy(session, repo, metadata.getNature()).getMetadataUpdatePolicy()); + check.setPolicy(policy.getUpdatePolicy()); + check.setMetadataPolicy(policy.getMetadataUpdatePolicy()); if (lrmResult.isStale()) { checks.add(check); From 4040bac8b8cd28a8fd3ef0e3d63667f2be79895a Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Fri, 13 Oct 2023 17:41:59 +0200 Subject: [PATCH 4/5] Do not deprecate ctor Instead, make javadoc clear this ctor enables "old" behaviour, as maybe that is some wants. Also, migrated code will not get deprecation warnings like this, as using this ctor is really "legal" in a sense, is still okay to use it IF this is what you want. --- .../org/eclipse/aether/repository/RepositoryPolicy.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RepositoryPolicy.java b/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RepositoryPolicy.java index 59193af8a..7a7bbd0a4 100644 --- a/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RepositoryPolicy.java +++ b/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RepositoryPolicy.java @@ -74,11 +74,9 @@ public RepositoryPolicy() { } /** - * Legacy constructor that handles update policy and metadata update policy same (as before). - * - * @deprecated Use any other constructor. + * Creates a new policy with the specified settings (uses same update policy for data and metadata, retains old + * resolver behaviour). */ - @Deprecated public RepositoryPolicy(boolean enabled, String updatePolicy, String checksumPolicy) { this(enabled, updatePolicy, updatePolicy, checksumPolicy); } From d854af699752a990444a8ee9b3d1a60e31d351c1 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Fri, 13 Oct 2023 17:45:40 +0200 Subject: [PATCH 5/5] Get rid of ancient constructs --- .../aether/repository/RepositoryPolicy.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RepositoryPolicy.java b/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RepositoryPolicy.java index 7a7bbd0a4..6adf28bf6 100644 --- a/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RepositoryPolicy.java +++ b/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RepositoryPolicy.java @@ -86,9 +86,9 @@ public RepositoryPolicy(boolean enabled, String updatePolicy, String checksumPol * * @param enabled A flag whether the associated repository should be accessed or not. * @param updatePolicy The update interval after which locally cached data from the repository is considered stale - * and should be refetched, may be {@code null}. + * and should be re-fetched, may be {@code null}. * @param metadataUpdatePolicy The update interval after which locally cached metadata from the repository is considered stale - * and should be refetched, may be {@code null}. + * and should be re-fetched, may be {@code null}. * @param checksumPolicy The way checksum verification should be handled, may be {@code null}. * @since TBD */ @@ -138,12 +138,10 @@ public String getChecksumPolicy() { @Override public String toString() { - StringBuilder buffer = new StringBuilder(256); - buffer.append("enabled=").append(isEnabled()); - buffer.append(", checksums=").append(getChecksumPolicy()); - buffer.append(", updates=").append(getUpdatePolicy()); - buffer.append(", metadataUpdates=").append(getMetadataUpdatePolicy()); - return buffer.toString(); + return "enabled=" + isEnabled() + + ", checksums=" + getChecksumPolicy() + + ", updates=" + getUpdatePolicy() + + ", metadataUpdates=" + getMetadataUpdatePolicy(); } @Override