mirror of https://github.com/apache/maven.git
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.
This commit is contained in:
parent
986f59683e
commit
a55accd518
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue