Skip to content

Commit

Permalink
WELD-2134 log actions from extensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
tremes authored and mkouba committed Apr 14, 2016
1 parent e627977 commit 8c765e2
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 12 deletions.
Expand Up @@ -17,6 +17,7 @@
package org.jboss.weld.bootstrap.events;

import org.jboss.weld.exceptions.DefinitionException;
import org.jboss.weld.logging.BootstrapLogger;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.util.Preconditions;

Expand All @@ -35,6 +36,7 @@ public void addDefinitionError(Throwable t) {
Preconditions.checkArgumentNotNull(t, "Throwable t");
checkWithinObserverNotification();
getErrors().add(t);
BootstrapLogger.LOG.addDefinitionErrorCalled(getReceiver(), t);
}

@Override
Expand Down
Expand Up @@ -44,6 +44,7 @@
import org.jboss.weld.bootstrap.ContextHolder;
import org.jboss.weld.bootstrap.spi.Deployment;
import org.jboss.weld.logging.BeanLogger;
import org.jboss.weld.logging.BootstrapLogger;
import org.jboss.weld.logging.ContextLogger;
import org.jboss.weld.logging.InterceptorLogger;
import org.jboss.weld.logging.MetadataLogger;
Expand Down Expand Up @@ -80,6 +81,7 @@ public void addBean(Bean<?> bean) {
ExternalBeanAttributesFactory.validateBeanAttributes(bean, getBeanManager());
validateBean(bean);
additionalBeans.add(bean);
BootstrapLogger.LOG.addBeanCalled(getReceiver(), bean);
}

protected <T> void processBean(Bean<T> bean) {
Expand Down Expand Up @@ -153,6 +155,7 @@ public void addContext(Context context) {
throw ContextLogger.LOG.cannotRegisterContext(scope, context);
}
getBeanManager().addContext(context);
BootstrapLogger.LOG.addContext(getReceiver(), context);
}

@Override
Expand All @@ -161,6 +164,7 @@ public void addObserverMethod(ObserverMethod<?> observerMethod) {
Preconditions.checkArgumentNotNull(observerMethod, "observerMethod");
validateObserverMethod(observerMethod, getBeanManager());
additionalObservers.add(observerMethod);
BootstrapLogger.LOG.addObserverMethodCalled(getReceiver(), observerMethod);
}

@Override
Expand Down
Expand Up @@ -32,12 +32,14 @@
import org.jboss.weld.bootstrap.ContextHolder;
import org.jboss.weld.bootstrap.enablement.GlobalEnablementBuilder;
import org.jboss.weld.bootstrap.spi.Deployment;
import org.jboss.weld.logging.BootstrapLogger;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.resources.ClassTransformer;

public class AfterTypeDiscoveryImpl extends AbstractAnnotatedTypeRegisteringEvent implements AfterTypeDiscovery {

public static void fire(BeanManagerImpl beanManager, Deployment deployment, BeanDeploymentArchiveMapping bdaMapping, Collection<ContextHolder<? extends Context>> contexts) {
public static void fire(BeanManagerImpl beanManager, Deployment deployment, BeanDeploymentArchiveMapping bdaMapping,
Collection<ContextHolder<? extends Context>> contexts) {
new AfterTypeDiscoveryImpl(beanManager, bdaMapping, deployment, contexts).fire();
}

Expand All @@ -46,7 +48,8 @@ public static void fire(BeanManagerImpl beanManager, Deployment deployment, Bean
private final ClassTransformer transformer;
private final SlimAnnotatedTypeStore store;

protected AfterTypeDiscoveryImpl(BeanManagerImpl beanManager, BeanDeploymentArchiveMapping bdaMapping, Deployment deployment, Collection<ContextHolder<? extends Context>> contexts) {
protected AfterTypeDiscoveryImpl(BeanManagerImpl beanManager, BeanDeploymentArchiveMapping bdaMapping, Deployment deployment,
Collection<ContextHolder<? extends Context>> contexts) {
super(beanManager, AfterTypeDiscovery.class, bdaMapping, deployment, contexts);
this.builder = beanManager.getServices().get(GlobalEnablementBuilder.class);
this.events = beanManager.getServices().get(ContainerLifecycleEvents.class);
Expand Down Expand Up @@ -76,6 +79,7 @@ public List<Class<?>> getDecorators() {
public void addAnnotatedType(AnnotatedType<?> type, String id) {
checkWithinObserverNotification();
addSyntheticAnnotatedType(type, id);
BootstrapLogger.LOG.addAnnotatedTypeCalled(getReceiver(), type);
}

@Override
Expand All @@ -88,7 +92,7 @@ protected void storeSyntheticAnnotatedType(BeanDeployment deployment, AnnotatedT
if (event == null) {
deployment.getBeanDeployer().getEnvironment().addAnnotatedType(annotatedTypeContext);
store.put(annotatedType);
} else if (event.isVeto()) {
} else if (event.isVeto()) {
return;
} else {
annotatedType = event.getResultingAnnotatedType();
Expand Down
Expand Up @@ -55,6 +55,7 @@ public void addQualifier(Class<? extends Annotation> bindingType) {
getTypeStore().add(bindingType, QualifierLiteral.INSTANCE);
getBeanManager().getServices().get(ClassTransformer.class).clearAnnotationData(bindingType);
getBeanManager().getServices().get(MetaAnnotationStore.class).clearAnnotationData(bindingType);
BootstrapLogger.LOG.addQualifierCalled(getReceiver(), bindingType);
}

@Override
Expand All @@ -67,6 +68,7 @@ public void addInterceptorBinding(Class<? extends Annotation> bindingType, Annot
}
getBeanManager().getServices().get(ClassTransformer.class).clearAnnotationData(bindingType);
getBeanManager().getServices().get(MetaAnnotationStore.class).clearAnnotationData(bindingType);
BootstrapLogger.LOG.addInterceptorBindingCalled(getReceiver(), bindingType);
}

@Override
Expand All @@ -82,6 +84,7 @@ public void addScope(Class<? extends Annotation> scopeType, boolean normal, bool
getBeanManager().getServices().get(ClassTransformer.class).clearAnnotationData(scopeType);
getBeanManager().getServices().get(MetaAnnotationStore.class).clearAnnotationData(scopeType);
getBeanManager().getServices().get(ReflectionCache.class).cleanup();
BootstrapLogger.LOG.addScopeCalled(getReceiver(), scopeType);
}

@Override
Expand All @@ -94,30 +97,35 @@ public void addStereotype(Class<? extends Annotation> stereotype, Annotation...
}
getBeanManager().getServices().get(ClassTransformer.class).clearAnnotationData(stereotype);
getBeanManager().getServices().get(MetaAnnotationStore.class).clearAnnotationData(stereotype);
BootstrapLogger.LOG.addStereoTypeCalled(getReceiver(), stereotype);
}

@Override
public void addAnnotatedType(AnnotatedType<?> source) {
checkWithinObserverNotification();
addAnnotatedType(source, null);
BootstrapLogger.LOG.addAnnotatedTypeCalledInBBD(getReceiver(), source);
}

@Override
public void addAnnotatedType(AnnotatedType<?> type, String id) {
checkWithinObserverNotification();
addSyntheticAnnotatedType(type, id);
BootstrapLogger.LOG.addAnnotatedTypeCalledInBBD(getReceiver(), type);
}

@Override
public void addQualifier(AnnotatedType<? extends Annotation> qualifier) {
checkWithinObserverNotification();
addSyntheticAnnotation(qualifier, QualifierLiteral.INSTANCE);
BootstrapLogger.LOG.addQualifierCalled(getReceiver(), qualifier);
}

@Override
public void addInterceptorBinding(AnnotatedType<? extends Annotation> bindingType) {
checkWithinObserverNotification();
addSyntheticAnnotation(bindingType, InterceptorBindingTypeLiteral.INSTANCE);
BootstrapLogger.LOG.addInterceptorBindingCalled(getReceiver(), bindingType);
}

private <A extends Annotation> void addSyntheticAnnotation(AnnotatedType<A> annotation, Annotation requiredMetaAnnotation) {
Expand Down
Expand Up @@ -59,6 +59,7 @@ public AnnotatedType<X> getAnnotatedType() {

/**
* Call this method after all observer methods of this event have been invoked to get the final value of this {@link AnnotatedType}.
*
* @return
*/
public SlimAnnotatedType<X> getResultingAnnotatedType() {
Expand All @@ -83,6 +84,7 @@ public void setAnnotatedType(AnnotatedType<X> type) {
throw BootstrapLogger.LOG.annotatedTypeJavaClassMismatch(this.annotatedType.getJavaClass(), type.getJavaClass());
}
AnnotatedTypeValidator.validateAnnotatedType(type);
BootstrapLogger.LOG.setAnnotatedTypeCalled(getReceiver(), annotatedType, type);
this.annotatedType = type;
}

Expand Down
Expand Up @@ -22,6 +22,7 @@
import javax.enterprise.inject.spi.BeanAttributes;
import javax.enterprise.inject.spi.ProcessBeanAttributes;

import org.jboss.weld.logging.BootstrapLogger;
import org.jboss.weld.manager.BeanManagerImpl;

/**
Expand Down Expand Up @@ -70,6 +71,7 @@ public BeanAttributes<T> getBeanAttributesInternal() {
@Override
public void setBeanAttributes(BeanAttributes<T> beanAttributes) {
checkWithinObserverNotification();
BootstrapLogger.LOG.setBeanAttributesCalled(getReceiver(), attributes, beanAttributes);
attributes = beanAttributes;
dirty = true;
}
Expand Down
Expand Up @@ -17,12 +17,12 @@
package org.jboss.weld.bootstrap.events;

import org.jboss.weld.bean.AbstractClassBean;
import org.jboss.weld.logging.BootstrapLogger;
import org.jboss.weld.manager.BeanManagerImpl;

import javax.enterprise.inject.spi.InjectionTarget;
import javax.enterprise.inject.spi.ProcessInjectionTarget;


public class ProcessBeanInjectionTarget<X> extends AbstractProcessInjectionTarget<X> implements ProcessInjectionTarget<X> {

private final AbstractClassBean<X> classBean;
Expand All @@ -39,6 +39,7 @@ public InjectionTarget<X> getInjectionTarget() {

public void setInjectionTarget(InjectionTarget<X> injectionTarget) {
checkWithinObserverNotification();
BootstrapLogger.LOG.setInjectionTargetCalled(getReceiver(), getInjectionTarget(), injectionTarget);
classBean.setProducer(injectionTarget);
}

Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.jboss.weld.injection.attributes.ForwardingFieldInjectionPointAttributes;
import org.jboss.weld.injection.attributes.ForwardingParameterInjectionPointAttributes;
import org.jboss.weld.injection.attributes.ParameterInjectionPointAttributes;
import org.jboss.weld.logging.BootstrapLogger;
import org.jboss.weld.manager.BeanManagerImpl;

/**
Expand Down Expand Up @@ -75,6 +76,7 @@ InjectionPoint getInjectionPointInternal() {
@Override
public void setInjectionPoint(InjectionPoint injectionPoint) {
checkWithinObserverNotification();
BootstrapLogger.LOG.setInjectionPointCalled(getReceiver(), ip, injectionPoint);
ip = injectionPoint;
dirty = true;
}
Expand Down
Expand Up @@ -17,6 +17,7 @@
package org.jboss.weld.bootstrap.events;

import org.jboss.weld.bean.AbstractProducerBean;
import org.jboss.weld.logging.BootstrapLogger;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.util.reflection.Reflections;

Expand All @@ -26,7 +27,6 @@
import java.lang.reflect.Member;
import java.lang.reflect.Type;


public class ProcessProducerImpl<T, X> extends AbstractDefinitionContainerEvent implements ProcessProducer<T, X> {

protected static <T, X> void fire(BeanManagerImpl beanManager, AbstractProducerBean<T, X, Member> bean) {
Expand All @@ -40,7 +40,7 @@ protected static <T, X> void fire(BeanManagerImpl beanManager, AbstractProducerB
private AbstractProducerBean<T, X, ?> bean;

private ProcessProducerImpl(BeanManagerImpl beanManager, AnnotatedMember<T> annotatedMember, AbstractProducerBean<T, X, ?> bean) {
super(beanManager, ProcessProducer.class, new Type[]{bean.getAnnotated().getDeclaringType().getBaseType(), bean.getAnnotated().getBaseType()});
super(beanManager, ProcessProducer.class, new Type[] { bean.getAnnotated().getDeclaringType().getBaseType(), bean.getAnnotated().getBaseType() });
this.bean = bean;
this.annotatedMember = annotatedMember;
}
Expand All @@ -57,6 +57,7 @@ public Producer<X> getProducer() {

public void setProducer(Producer<X> producer) {
checkWithinObserverNotification();
BootstrapLogger.LOG.setProducerCalled(getReceiver(), getProducer(), producer);
this.bean.setProducer(producer);
}

Expand Down
Expand Up @@ -16,13 +16,13 @@
*/
package org.jboss.weld.bootstrap.events;

import org.jboss.weld.logging.BootstrapLogger;
import org.jboss.weld.manager.BeanManagerImpl;

import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.InjectionTarget;
import javax.enterprise.inject.spi.ProcessInjectionTarget;


public class ProcessSimpleInjectionTarget<X> extends AbstractProcessInjectionTarget<X> implements ProcessInjectionTarget<X> {

private InjectionTarget<X> injectionTarget;
Expand All @@ -44,6 +44,7 @@ InjectionTarget<X> getInjectionTargetInternal() {

public void setInjectionTarget(InjectionTarget<X> injectionTarget) {
checkWithinObserverNotification();
BootstrapLogger.LOG.setInjectionTargetCalled(getReceiver(), getInjectionTarget(), injectionTarget);
this.injectionTarget = injectionTarget;
}

Expand Down
71 changes: 66 additions & 5 deletions impl/src/main/java/org/jboss/weld/logging/BootstrapLogger.java
Expand Up @@ -35,7 +35,7 @@

/**
* Log messages for bootstrap
*
* <p>
* Message Ids: 000100 - 000199
*/
@MessageLogger(projectCode = WELD_PROJECT_CODE)
Expand Down Expand Up @@ -159,7 +159,7 @@ public interface BootstrapLogger extends WeldLogger {
void errorWhileLoadingClass(Object param1, Object param2);

@LogMessage(level = Logger.Level.WARN)
@Message(id = 139, value = "Ignoring portable extension class {0} because of underlying class loading error: Type {1} not found. Enable DEBUG logging level to see the full error." , format = Format.MESSAGE_FORMAT)
@Message(id = 139, value = "Ignoring portable extension class {0} because of underlying class loading error: Type {1} not found. Enable DEBUG logging level to see the full error.", format = Format.MESSAGE_FORMAT)
void ignoringExtensionClassDueToLoadingError(String className, String missingDependency);

@Message(id = 140, value = "Calling Bootstrap method after container has already been initialized. For correct order, see CDI11Bootstrap's documentation.")
Expand All @@ -174,15 +174,15 @@ public interface BootstrapLogger extends WeldLogger {
void exceptionLoadingAnnotatedType(String message);

@LogMessage(level = Logger.Level.TRACE)
@Message(id = Message.NONE , value = "No PAT observers resolved for {0}. Skipping.", format = Format.MESSAGE_FORMAT)
@Message(id = Message.NONE, value = "No PAT observers resolved for {0}. Skipping.", format = Format.MESSAGE_FORMAT)
void patSkipped(SlimAnnotatedType<?> type);

@LogMessage(level = Logger.Level.TRACE)
@Message(id = Message.NONE , value = "Sending PAT using the default event resolver: {0}", format = Format.MESSAGE_FORMAT)
@Message(id = Message.NONE, value = "Sending PAT using the default event resolver: {0}", format = Format.MESSAGE_FORMAT)
void patDefaultResolver(SlimAnnotatedType<?> type);

@LogMessage(level = Logger.Level.TRACE)
@Message(id = Message.NONE , value = "Sending PAT using the fast event resolver: {0}", format = Format.MESSAGE_FORMAT)
@Message(id = Message.NONE, value = "Sending PAT using the fast event resolver: {0}", format = Format.MESSAGE_FORMAT)
void patFastResolver(SlimAnnotatedType<?> type);

@Message(id = 143, value = "Container lifecycle event method invoked outside of extension observer method invocation.")
Expand All @@ -200,4 +200,65 @@ public interface BootstrapLogger extends WeldLogger {
@LogMessage(level = Level.WARN)
@Message(id = 147, value = "Decorator {0} declares inappropriate constructor therefore will not available as a managed bean!", format = Format.MESSAGE_FORMAT)
void decoratorWithNonCdiConstructor(String clazzName);

@LogMessage(level = Logger.Level.DEBUG)
@Message(id = 148, value = "ProcessAnnotatedType.setAnnotatedType() called by {0}: {1} replaced by {2}", format = Format.MESSAGE_FORMAT)
void setAnnotatedTypeCalled(Object extensionName, Object original, Object newer);

@LogMessage(level = Logger.Level.DEBUG)
@Message(id = 149, value = "ProcessBeanAttributes.setBeanAttributes() called by {0}: {1} replaced by {2}", format = Format.MESSAGE_FORMAT)
void setBeanAttributesCalled(Object extensionName, Object original, Object newer);

@LogMessage(level = Logger.Level.DEBUG)
@Message(id = 150, value = "ProcessInjectionPoint.setInjectionPoint() called by {0}: {1} replaced by {2}", format = Format.MESSAGE_FORMAT)
void setInjectionPointCalled(Object extensionName, Object original, Object newer);

@LogMessage(level = Logger.Level.DEBUG)
@Message(id = 151, value = "ProcessInjectionTarget.setInjectionTarget() called by {0}: {1} replaced by {2}", format = Format.MESSAGE_FORMAT)
void setInjectionTargetCalled(Object extensionName, Object original, Object newer);

@LogMessage(level = Logger.Level.DEBUG)
@Message(id = 152, value = "ProcessProducer.setProducer() called by {0}: {1} replaced by {2}", format = Format.MESSAGE_FORMAT)
void setProducerCalled(Object extensionName, Object original, Object newer);

@LogMessage(level = Logger.Level.DEBUG)
@Message(id = 153, value = "AfterTypeDiscovery.addAnnotatedType() called by {0} for {1}", format = Format.MESSAGE_FORMAT)
void addAnnotatedTypeCalled(Object extensionName, Object type);

@LogMessage(level = Logger.Level.DEBUG)
@Message(id = 154, value = "AfterBeanDiscovery.addBean() called by {0} for {1}", format = Format.MESSAGE_FORMAT)
void addBeanCalled(Object extensionName, Object type);

@LogMessage(level = Logger.Level.DEBUG)
@Message(id = 155, value = "AfterBeanDiscovery.addObserverMethod() called by {0} for {1}", format = Format.MESSAGE_FORMAT)
void addObserverMethodCalled(Object extensionName, Object type);

@LogMessage(level = Logger.Level.DEBUG)
@Message(id = 156, value = "AfterBeanDiscovery.addContext() called by {0} for {1}", format = Format.MESSAGE_FORMAT)
void addContext(Object extensionName, Object type);

@LogMessage(level = Logger.Level.DEBUG)
@Message(id = 157, value = "AfterBeanDiscovery.addDefinitionError() called by {0} for {1}", format = Format.MESSAGE_FORMAT)
void addDefinitionErrorCalled(Object extensionName, Object type);

@LogMessage(level = Logger.Level.DEBUG)
@Message(id = 158, value = "BeforeBeanDiscovery.addQualifier() called by {0} for {1}", format = Format.MESSAGE_FORMAT)
void addQualifierCalled(Object extensionName, Object type);

@LogMessage(level = Logger.Level.DEBUG)
@Message(id = 159, value = "BeforeBeanDiscovery.addScope() called by {0} for {1}", format = Format.MESSAGE_FORMAT)
void addScopeCalled(Object extensionName, Object type);

@LogMessage(level = Logger.Level.DEBUG)
@Message(id = 160, value = "BeforeBeanDiscovery.addStereoType() called by {0} for {1}", format = Format.MESSAGE_FORMAT)
void addStereoTypeCalled(Object extensionName, Object type);

@LogMessage(level = Logger.Level.DEBUG)
@Message(id = 161, value = "BeforeBeanDiscovery.addInterceptorBindingCalled() called by {0} for {1}", format = Format.MESSAGE_FORMAT)
void addInterceptorBindingCalled(Object extensionName, Object type);

@LogMessage(level = Logger.Level.DEBUG)
@Message(id = 162, value = "BeforeBeanDiscovery.addAnnotatedType() called by {0} for {1}", format = Format.MESSAGE_FORMAT)
void addAnnotatedTypeCalledInBBD(Object extensionName, Object type);

}

0 comments on commit 8c765e2

Please sign in to comment.