Skip to content

Commit

Permalink
WELD-2060 Skip irrelevant javax.ejb annotations warnings in SE/Servlet
Browse files Browse the repository at this point in the history
  • Loading branch information
mkouba committed Nov 20, 2015
1 parent 62b7f01 commit c4c9418
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Expand Up @@ -44,7 +44,9 @@ private InterceptionTypeRegistry() {
try {
interceptionAnnotationClasses.put(interceptionType, (Class<? extends Annotation>) InterceptionTypeRegistry.class.getClassLoader().loadClass(interceptionType.annotationClassName()));
} catch (Exception e) {
InterceptorLogger.LOG.interceptorAnnotationClassNotFound(interceptionType.annotationClassName());
if (InterceptionUtils.isAnnotationClassExpected(interceptionType)) {
InterceptorLogger.LOG.interceptorAnnotationClassNotFound(interceptionType.annotationClassName());
}
}
}
INTERCEPTOR_ANNOTATION_CLASSES = Collections.unmodifiableMap(interceptionAnnotationClasses);
Expand Down
Expand Up @@ -19,16 +19,27 @@

import java.util.concurrent.Callable;

import org.jboss.weld.bootstrap.api.Environment;
import org.jboss.weld.bootstrap.api.Environments;
import org.jboss.weld.interceptor.proxy.InterceptorException;
import org.jboss.weld.interceptor.proxy.LifecycleMixin;
import org.jboss.weld.interceptor.spi.model.InterceptionType;
import org.jboss.weld.resources.WeldClassLoaderResourceLoader;
import org.jboss.weld.util.reflection.Reflections;

/**
* @author <a href="mailto:mariusb@redhat.com">Marius Bogoevici</a>
*/
public class InterceptionUtils {

public static final String POST_CONSTRUCT = "lifecycle_mixin_$$_postConstruct";

public static final String PRE_DESTROY = "lifecycle_mixin_$$_preDestroy";

private static final String WELD_SE_CLASS = "org.jboss.weld.environment.se.Weld";

private static final String WELD_SERVLET_CLASS = "org.jboss.weld.environment.servlet.WeldServletLifecycle";

private InterceptionUtils() {
}

Expand Down Expand Up @@ -67,4 +78,25 @@ private static void executePredestroy(Object proxy, Callable callback) {
public static void executePredestroy(Object proxy) {
executePredestroy(proxy, null);
}

static boolean isAnnotationClassExpected(InterceptionType interceptionType) {
if (InterceptionType.POST_ACTIVATE.equals(interceptionType) || InterceptionType.PRE_PASSIVATE.equals(interceptionType)) {
Environment environment = detectEnvironment();
if (environment != null && (Environments.SE.equals(environment) || Environments.SERVLET.equals(environment))) {
return false;
}
}
return true;
}

private static Environment detectEnvironment() {
// We should rather use the environment from WeldStartup but it's not available in the static initializer
Environment environment = null;
if (Reflections.isClassLoadable(WELD_SE_CLASS, WeldClassLoaderResourceLoader.INSTANCE)) {
environment = Environments.SE;
} else if (Reflections.isClassLoadable(WELD_SERVLET_CLASS, WeldClassLoaderResourceLoader.INSTANCE)) {
environment = Environments.SERVLET;
}
return environment;
}
}

0 comments on commit c4c9418

Please sign in to comment.