Copilot commented on code in PR #2135:
URL: https://github.com/apache/maven-resolver/pull/2135#discussion_r3993618809


##########
maven-resolver-spi/src/main/java/org/eclipse/aether/spi/remoterepo/RepositoryKeyFunctionFactory.java:
##########
@@ -50,7 +75,30 @@ public interface RepositoryKeyFunctionFactory {
      *                         no configuration lookup happens but the {@code 
defaultValue} is used to create the
      *                         repository key function.
      * @return The repository key function.
+     * @deprecated Use {@link #repositoryKeyFunctionMk(Class, 
RepositorySystemSession, String, String...)} instead.
+     */
+    @Deprecated
+    default RepositoryKeyFunction repositoryKeyFunction(
+            Class<?> owner, RepositorySystemSession session, String 
defaultValue, String configurationKey) {
+        return repositoryKeyFunctionMk(owner, session, defaultValue, 
configurationKey);
+    }
+
+    /**
+     * Method that based on configuration using multiple keys in ordered 
fashion (hence "mk" as multikey) returns the
+     * "repository key function". The returned function will be session cached 
if session is equipped with cache,
+     * otherwise it will be non cached. Method never returns {@code null}. 
Only the {@code configurationKeys} parameter
+     * may be {@code null} in which case no configuration lookup happens and 
the {@code defaultValue} is directly
+     * used instead.
+     *
+     * @param owner The "owner" of key function (used to create cache-key), 
must not be {@code null}.
+     * @param session The repository session, must not be {@code null}.
+     * @param defaultValue The default value of repository key configuration, 
must not be {@code null}.
+     * @param configurationKeys The configuration keys to lookup configuration 
from, may be {@code null}, in which case
+     *                         no configuration lookup happens but the {@code 
defaultValue} is used to create the
+     *                         repository key function.
+     * @return The repository key function.
+     * @since 2.0.23
      */
-    RepositoryKeyFunction repositoryKeyFunction(
-            Class<?> owner, RepositorySystemSession session, String 
defaultValue, String configurationKey);
+    RepositoryKeyFunction repositoryKeyFunctionMk(
+            Class<?> owner, RepositorySystemSession session, String 
defaultValue, String... configurationKeys);

Review Comment:
   This interface was public since 2.0.14 and `repositoryKeyFunction` was its 
sole abstract operation. Making the new `repositoryKeyFunctionMk` method 
abstract while turning the old method into a default adapter breaks existing 
implementors: they fail source compilation, and already-compiled 
implementations reach `AbstractMethodError` when the convenience methods call 
the new method. Preserve a compatibility bridge for the old abstract method 
(and update the built-in implementation) rather than introducing a new required 
method.



##########
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/checksum/SummaryFileTrustedChecksumsSource.java:
##########
@@ -206,17 +203,16 @@ private Map<String, String> doGetTrustedPathChecksums(
         final Path basedir = getBasedir(session, LOCAL_REPO_PREFIX_DIR, 
CONFIG_PROP_BASEDIR, false);
         if (Files.isDirectory(basedir)) {
             final boolean originAware = isOriginAware(session);
-            for (ChecksumAlgorithmFactory checksumAlgorithmFactory : 
checksumAlgorithmFactories) {
-                Path summaryFile = summaryFile(
-                        basedir,
-                        originAware,
-                        repositoryKey(session, artifactRepository),
-                        checksumAlgorithmFactory.getFileExtension());
-                ConcurrentHashMap<String, String> algorithmChecksums =
-                        checksums.computeIfAbsent(summaryFile, f -> 
loadProvidedChecksums(summaryFile));
-                String checksum = algorithmChecksums.get(path);
-                if (checksum != null) {
-                    result.put(checksumAlgorithmFactory.getName(), checksum);
+            for (String repoKey : repositoryKey(session, artifactRepository)) {
+                for (ChecksumAlgorithmFactory checksumAlgorithmFactory : 
checksumAlgorithmFactories) {
+                    Path summaryFile =
+                            summaryFile(basedir, originAware, repoKey, 
checksumAlgorithmFactory.getFileExtension());
+                    ConcurrentHashMap<String, String> algorithmChecksums =
+                            checksums.computeIfAbsent(summaryFile, f -> 
loadProvidedChecksums(summaryFile));
+                    String checksum = algorithmChecksums.get(path);
+                    if (checksum != null) {
+                        result.put(checksumAlgorithmFactory.getName(), 
checksum);

Review Comment:
   Because `repositoryKeys` is ordered from the tracking-specific key to the 
system fallback, a match from this line can later be overwritten by the 
less-specific file when both contain the same path. That defeats the documented 
precedence and can return the wrong trusted checksum; preserve the first match 
with `putIfAbsent` or stop after finding one.



-- 
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