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 480fa1bc4 Tone down hard-link fallback log: WARN → INFO, once per 
local repo per session (#2306)
480fa1bc4 is described below

commit 480fa1bc4ab93ce5d62de93a368cf90940bb7874
Author: Guillaume Nodet <[email protected]>
AuthorDate: Mon Nov 16 19:26:30 2026 +0100

    Tone down hard-link fallback log: WARN → INFO, once per local repo per 
session (#2306)
    
    ## Summary
    
    Tone down the hard-link fallback log message introduced in #2198: `WARN` → 
`INFO`,
    exception stack trace demoted to `DEBUG`, and the message is emitted **at 
most once
    per local repository path per session** instead of once per `install()` 
call.
    
    ## Motivation
    
    On setups where the build output tree and `~/.m2` are on different volumes 
(common in
    containers, CI environments with separate mounts, or custom local repo 
paths),
    `Files.createLink` always fails and the installer silently falls back to a 
regular
    copy — which is correct. But the previous `WARN` fired on every install 
invocation,
    producing noise every build when the behaviour is expected and benign.
    
    ## Changes
    
    - **Level** `WARN` → `INFO`. The fallback is not a build problem; `WARN` 
implies
      something is wrong.
    - **Stack trace** moved from `WARN` to `DEBUG`. Useful for diagnosing 
unexpected
      failures, but not needed in normal operation.
    - **Once per local repo per session** using `SessionData` (keyed by local 
repository
      base path), following the same pattern as `DefaultUpdateCheckManager`. 
Subsequent
      install calls within the same build produce no extra output.
    - **Message** includes the local repo path and the property name to opt out:
      `aether.installer.hardLink=false`.
    
    ## Example output (INFO level)
    
    ```
    [INFO] Hard link not supported for local repository at 
/home/user/.m2/repository, falling back to file copy. To suppress this message, 
set 'aether.installer.hardLink=false'.
    ```
    
    ---
    _Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet_
---
 .../aether/internal/impl/DefaultInstaller.java     | 53 +++++++++++++++--
 .../aether/internal/impl/DefaultInstallerTest.java | 67 ++++++++++++++++++++++
 2 files changed, 116 insertions(+), 4 deletions(-)

diff --git 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultInstaller.java
 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultInstaller.java
index 0a02e8289..ca9733ecd 100644
--- 
a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultInstaller.java
+++ 
b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultInstaller.java
@@ -33,8 +33,11 @@ import java.util.IdentityHashMap;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 
 import org.eclipse.aether.ConfigurationProperties;
+import org.eclipse.aether.Keys;
 import org.eclipse.aether.RepositoryEvent;
 import org.eclipse.aether.RepositoryEvent.EventType;
 import org.eclipse.aether.RepositorySystemSession;
@@ -69,6 +72,13 @@ import static java.util.Objects.requireNonNull;
 @Singleton
 @Named
 public class DefaultInstaller implements Installer {
+    private static final Object SESSION_HARDLINK_LOGGED = Keys.of(new Object() 
{
+        @Override
+        public String toString() {
+            return "installer.hardLinkLogged";
+        }
+    });
+
     private final Logger logger = LoggerFactory.getLogger(getClass());
 
     private final PathProcessor pathProcessor;
@@ -177,10 +187,45 @@ public class DefaultInstaller implements Installer {
                 }
             }
             if (linkFailure != null) {
-                logger.warn(
-                        "Hard link not supported, falling back to copy for all 
artifacts: {}",
-                        linkFailure.getMessage(),
-                        linkFailure);
+                Path localRepoBasedir =
+                        
session.getLocalRepositoryManager().getRepository().getBasePath();
+                if (localRepoBasedir == null) {
+                    // No base path (custom or in-memory local repository 
manager) — log without dedup
+                    if (logger.isDebugEnabled()) {
+                        logger.info(
+                                "Hard link not supported for local repository, 
falling back to file copy."
+                                        + " To suppress this message, set 
'{}=false'.",
+                                ConfigurationProperties.INSTALLER_HARD_LINK,
+                                linkFailure);
+                    } else {
+                        logger.info(
+                                "Hard link not supported for local repository, 
falling back to file copy."
+                                        + " To suppress this message, set 
'{}=false'.",
+                                ConfigurationProperties.INSTALLER_HARD_LINK);
+                    }
+                } else {
+                    @SuppressWarnings("unchecked")
+                    Set<Path> logged = (Set<Path>) session.getData()
+                            .computeIfAbsent(
+                                    SESSION_HARDLINK_LOGGED,
+                                    () -> Collections.newSetFromMap(new 
ConcurrentHashMap<Path, Boolean>()));
+                    if (logged.add(localRepoBasedir)) {
+                        if (logger.isDebugEnabled()) {
+                            logger.info(
+                                    "Hard link not supported for local 
repository at {}, falling back to file copy."
+                                            + " To suppress this message, set 
'{}=false'.",
+                                    localRepoBasedir,
+                                    
ConfigurationProperties.INSTALLER_HARD_LINK,
+                                    linkFailure);
+                        } else {
+                            logger.info(
+                                    "Hard link not supported for local 
repository at {}, falling back to file copy."
+                                            + " To suppress this message, set 
'{}=false'.",
+                                    localRepoBasedir,
+                                    
ConfigurationProperties.INSTALLER_HARD_LINK);
+                        }
+                    }
+                }
             }
 
             metadatas = Utils.finishMetadata(metadataGenerators, artifacts);
diff --git 
a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultInstallerTest.java
 
b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultInstallerTest.java
index f840520e2..d4e8fad37 100644
--- 
a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultInstallerTest.java
+++ 
b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultInstallerTest.java
@@ -18,8 +18,11 @@
  */
 package org.eclipse.aether.internal.impl;
 
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
+import java.io.PrintStream;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.Collections;
@@ -47,6 +50,7 @@ import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
 
 public class DefaultInstallerTest {
 
@@ -461,6 +465,69 @@ public class DefaultInstallerTest {
                 1, countingProcessor.copyWithTimestampCount, 
"copyWithTimestamp must be called when hardLink=false");
     }
 
+    @Test
+    void testHardLinkFallbackLoggedOncePerSession() throws Exception {
+        // This test verifies that when hard-link creation fails 
(cross-device), the INFO log message
+        // is emitted exactly once per session even if install is called 
multiple times.
+        // The test is only meaningful when the environment is cross-device 
(copy fallback is triggered);
+        // it skips on same-device filesystems where hard links succeed and no 
message is emitted.
+        CountingPathProcessor countingProcessor = new CountingPathProcessor();
+        installer = new DefaultInstaller(
+                countingProcessor,
+                new StubRepositoryEventDispatcher(),
+                Collections.emptyMap(),
+                Collections.emptyMap(),
+                Collections.emptyMap(),
+                new StubSyncContextFactory());
+
+        // First install — detect if we're on a cross-device filesystem (copy 
fallback triggered),
+        // and assert the message IS emitted on the first occurrence.
+        request.addArtifact(artifact);
+        String log1 = captureStdErr(() -> installer.install(session, request));
+        assumeTrue(
+                countingProcessor.copyWithTimestampCount == 1,
+                "skipped: same-device filesystem — hard link succeeded, no 
fallback log to deduplicate");
+        assertTrue(
+                log1.contains("Hard link not supported"),
+                "hard-link warning must fire on the first cross-device 
install; captured log:\n" + log1);
+
+        // We're on a cross-device filesystem. Capture stderr (slf4j-simple 
logs there) and
+        // install a second artifact in the same session — the dedup set must 
suppress the 2nd log.
+        Artifact artifact2 = new DefaultArtifact("gid", "aid2", "jar", "ver");
+        artifact2 = 
artifact2.setFile(TestFileUtils.createTempFile("artifact2".getBytes(), 1));
+
+        final Artifact artifact2Final = artifact2;
+        InstallRequest request2 = new InstallRequest();
+        request2.addArtifact(artifact2Final);
+        String log2 = captureStdErr(() -> installer.install(session, 
request2));
+
+        // The second install triggered another copy (cross-device), but the 
log must be suppressed
+        assertEquals(2, countingProcessor.copyWithTimestampCount, "second 
install should also copy (cross-device)");
+        assertFalse(
+                log2.contains("Hard link not supported"),
+                "hard-link warning must NOT fire a second time in the same 
session; captured log:\n" + log2);
+    }
+
+    /**
+     * Runs the action while capturing the slf4j-simple output written to 
{@code System.err}.
+     */
+    private static String captureStdErr(ThrowingRunnable action) throws 
Exception {
+        PrintStream original = System.err;
+        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+        try (PrintStream capture = new PrintStream(buffer, true, 
StandardCharsets.UTF_8.name())) {
+            System.setErr(capture);
+            action.run();
+        } finally {
+            System.setErr(original);
+        }
+        return buffer.toString(StandardCharsets.UTF_8.name());
+    }
+
+    @FunctionalInterface
+    private interface ThrowingRunnable {
+        void run() throws Exception;
+    }
+
     /** PathProcessor wrapper that counts copyWithTimestamp invocations. */
     private static class CountingPathProcessor extends PathProcessorSupport {
         int copyWithTimestampCount = 0;

Reply via email to