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.git
The following commit(s) were added to refs/heads/master by this push: new a55accd518 CLIng+resident: logging subsystem still needs an update (#1931) a55accd518 is described below commit a55accd5182ff387dda117386b935eed4b0c542c Author: Tamas Cservenak <ta...@cservenak.net> AuthorDate: Thu Nov 21 14:38:51 2024 +0100 CLIng+resident: logging subsystem still needs an update (#1931) As part of capsule creation, capsule logging setup happened as well but it got "stuck" on very first invocation and never updated. --- .../apache/maven/cling/invoker/ContainerCapsule.java | 5 +++++ .../maven/cling/invoker/PlexusContainerCapsule.java | 18 +++++++++++++++--- .../cling/invoker/PlexusContainerCapsuleFactory.java | 10 ++-------- .../invoker/mvn/resident/ResidentMavenInvoker.java | 2 ++ 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/ContainerCapsule.java b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/ContainerCapsule.java index a8c80ed983..9e57961b10 100644 --- a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/ContainerCapsule.java +++ b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/ContainerCapsule.java @@ -28,6 +28,11 @@ import org.apache.maven.api.services.Lookup; * Container capsule. */ public interface ContainerCapsule extends AutoCloseable { + /** + * Updates the existing capsule logging setup. + */ + void updateLogging(LookupContext context); + /** * The {@link Lookup} service backed by container in this capsule. */ diff --git a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/PlexusContainerCapsule.java b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/PlexusContainerCapsule.java index 05d53272d3..ee4ae96b8c 100644 --- a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/PlexusContainerCapsule.java +++ b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/PlexusContainerCapsule.java @@ -22,22 +22,34 @@ import java.util.Optional; import org.apache.maven.api.services.Lookup; import org.apache.maven.internal.impl.DefaultLookup; -import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.DefaultPlexusContainer; import static java.util.Objects.requireNonNull; +import static org.apache.maven.cling.invoker.Utils.toPlexusLoggingLevel; /** * Container capsule backed by Plexus Container. */ public class PlexusContainerCapsule implements ContainerCapsule { private final ClassLoader previousClassLoader; - private final PlexusContainer plexusContainer; + private final DefaultPlexusContainer plexusContainer; private final Lookup lookup; - public PlexusContainerCapsule(ClassLoader previousClassLoader, PlexusContainer plexusContainer) { + public PlexusContainerCapsule( + LookupContext context, ClassLoader previousClassLoader, DefaultPlexusContainer plexusContainer) { this.previousClassLoader = requireNonNull(previousClassLoader, "previousClassLoader"); this.plexusContainer = requireNonNull(plexusContainer, "plexusContainer"); this.lookup = new DefaultLookup(plexusContainer); + updateLogging(context); + } + + @Override + public void updateLogging(LookupContext context) { + plexusContainer.getLoggerManager().setThresholds(toPlexusLoggingLevel(context.loggerLevel)); + org.slf4j.Logger l = context.loggerFactory.getLogger(this.getClass().getName()); + context.logger = (level, message, error) -> l.atLevel(org.slf4j.event.Level.valueOf(level.name())) + .setCause(error) + .log(message); } @Override diff --git a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/PlexusContainerCapsuleFactory.java b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/PlexusContainerCapsuleFactory.java index 14673ef88d..9b4d5a40a1 100644 --- a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/PlexusContainerCapsuleFactory.java +++ b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/PlexusContainerCapsuleFactory.java @@ -73,13 +73,13 @@ public class PlexusContainerCapsuleFactory<C extends LookupContext> implements C public ContainerCapsule createContainerCapsule(LookupInvoker<C> invoker, C context) throws InvokerException { try { return new PlexusContainerCapsule( - Thread.currentThread().getContextClassLoader(), container(invoker, context)); + context, Thread.currentThread().getContextClassLoader(), container(invoker, context)); } catch (Exception e) { throw new InvokerException("Failed to create plexus container capsule", e); } } - protected PlexusContainer container(LookupInvoker<C> invoker, C context) throws Exception { + protected DefaultPlexusContainer container(LookupInvoker<C> invoker, C context) throws Exception { ClassWorld classWorld = invoker.protoLookup.lookup(ClassWorld.class); ClassRealm coreRealm = classWorld.getClassRealm("plexus.core"); List<Path> extClassPath = parseExtClasspath(context); @@ -139,12 +139,6 @@ public class PlexusContainerCapsuleFactory<C extends LookupContext> implements C container.getLoggerManager().setThresholds(toPlexusLoggingLevel(context.loggerLevel)); customizeContainer(context, container); - // refresh logger in case container got customized by spy - org.slf4j.Logger l = context.loggerFactory.getLogger(this.getClass().getName()); - context.logger = (level, message, error) -> l.atLevel(org.slf4j.event.Level.valueOf(level.name())) - .setCause(error) - .log(message); - return container; } diff --git a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/resident/ResidentMavenInvoker.java b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/resident/ResidentMavenInvoker.java index 95132cdcc9..41d57395e7 100644 --- a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/resident/ResidentMavenInvoker.java +++ b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/resident/ResidentMavenInvoker.java @@ -74,6 +74,8 @@ public class ResidentMavenInvoker extends MavenInvoker<ResidentMavenContext> { protected void container(ResidentMavenContext context) throws Exception { if (context.containerCapsule == null) { super.container(context); + } else { + context.containerCapsule.updateLogging(context); } }