Skip to content

Commit

Permalink
WELD-1622: Weld SE Logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Matej Briskar authored and jharting committed Mar 24, 2014
1 parent 6532e72 commit fc15303
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 25 deletions.
11 changes: 11 additions & 0 deletions environments/se/core/pom.xml
Expand Up @@ -57,6 +57,17 @@
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-processor</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.weld</groupId>
Expand Down
Expand Up @@ -46,6 +46,7 @@
import org.jboss.weld.environment.se.discovery.url.WeldSEResourceLoader;
import org.jboss.weld.environment.se.discovery.url.WeldSEUrlDeployment;
import org.jboss.weld.environment.se.events.ContainerInitialized;
import org.jboss.weld.environment.se.logging.WeldSELogger;
import org.jboss.weld.environment.se.util.SEReflections;
import org.jboss.weld.literal.InitializedLiteral;
import org.jboss.weld.metadata.MetadataImpl;
Expand Down Expand Up @@ -112,16 +113,16 @@ public WeldContainer initialize() {
ResourceLoader resourceLoader = new WeldSEResourceLoader();
// check for beans.xml
if (resourceLoader.getResource(WeldSEUrlDeployment.BEANS_XML) == null) {
throw new IllegalStateException("Missing beans.xml file in META-INF!");
throw WeldSELogger.LOG.missingBeansXml();
}

final CDI11Bootstrap bootstrap;
try {
bootstrap = (CDI11Bootstrap) resourceLoader.classForName(BOOTSTRAP_IMPL_CLASS_NAME).newInstance();
} catch (InstantiationException ex) {
throw new IllegalStateException(ERROR_LOADING_WELD_BOOTSTRAP_EXC_MESSAGE, ex);
throw WeldSELogger.LOG.errorLoadingWeld();
} catch (IllegalAccessException ex) {
throw new IllegalStateException(ERROR_LOADING_WELD_BOOTSTRAP_EXC_MESSAGE, ex);
throw WeldSELogger.LOG.errorLoadingWeld();
}

Deployment deployment = createDeployment(resourceLoader, bootstrap);
Expand Down Expand Up @@ -254,7 +255,7 @@ private WeldSEBeanDeploymentArchive mergeToOne(CDI11Bootstrap bootstrap, Collect
protected <T> T getInstanceByType(BeanManager manager, Class<T> type, Annotation... bindings) {
final Bean<?> bean = manager.resolve(manager.getBeans(type, bindings));
if (bean == null) {
throw new UnsatisfiedResolutionException("Unable to resolve a bean for " + type + " with bindings " + Arrays.asList(bindings));
throw WeldSELogger.LOG.unableToResolveBean(type, Arrays.asList(bindings));
}
CreationalContext<?> cc = manager.createCreationalContext(bean);
return type.cast(manager.getReference(bean, type, cc));
Expand Down
Expand Up @@ -16,9 +16,9 @@
import org.jboss.jandex.IndexView;
import org.jboss.jandex.MethodInfo;
import org.jboss.logging.Logger;
import org.jboss.weld.environment.se.logging.WeldSELogger;
import org.jboss.weld.environment.se.util.SEReflections;
import org.jboss.weld.resources.spi.ClassFileInfo;
import org.jboss.weld.resources.spi.ClassFileInfoException;

import com.google.common.cache.LoadingCache;

Expand Down Expand Up @@ -277,7 +277,7 @@ private Class<?> loadClass(String className) {
try {
clazz = classLoader.loadClass(className);
} catch (ClassNotFoundException ex) {
throw new ClassFileInfoException("Unable to load class " + className); // TODO: localize properly
throw WeldSELogger.LOG.unableToLoadClass(className);
}
return clazz;
}
Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.jboss.weld.environment.se.discovery.url.DiscoveryStrategy;
import org.jboss.weld.environment.se.discovery.url.JandexEnabledDiscoveryStrategy;
import org.jboss.weld.environment.se.discovery.url.WeldSEResourceLoader;
import org.jboss.weld.environment.se.logging.WeldSELogger;
import org.jboss.weld.resources.spi.ClassFileInfo;
import org.jboss.weld.resources.spi.ClassFileServices;

Expand Down Expand Up @@ -64,7 +65,7 @@ public Set<String> load(DotName name) throws Exception {
builder.add(annotation.annotationType().getName());
}
} catch (ClassNotFoundException e) {
throw new IllegalStateException(UNABLE_TO_LOAD_ANNOTATION_MESSAGE + name.toString());
throw WeldSELogger.LOG.unableToLoadAnnotation(name.toString());
}
}
return builder.build();
Expand Down
Expand Up @@ -18,6 +18,7 @@

import org.jboss.weld.bootstrap.api.Bootstrap;
import org.jboss.weld.environment.se.discovery.WeldSEBeanDeploymentArchive;
import org.jboss.weld.environment.se.logging.WeldSELogger;
import org.jboss.weld.resources.spi.ResourceLoader;

/**
Expand All @@ -32,7 +33,7 @@ public DefaultDiscoveryStrategy(ResourceLoader resourceLoader, Bootstrap bootstr

@Override
protected WeldSEBeanDeploymentArchive processAnnotatedDiscovery(BeanArchiveBuilder builder) {
throw new IllegalStateException("bean discovery-mode=\"annotated\" support is disabled. Add org.jboss:jandex to the classpath to enable it.");
throw WeldSELogger.LOG.annotatedBeanDiscoveryNotSupported();
}

}
Expand Up @@ -24,6 +24,7 @@
import org.jboss.weld.bootstrap.spi.BeansXml;
import org.jboss.weld.environment.se.discovery.AbstractWeldSEDeployment;
import org.jboss.weld.environment.se.discovery.WeldSEBeanDeploymentArchive;
import org.jboss.weld.environment.se.logging.WeldSELogger;
import org.jboss.weld.resources.spi.ResourceLoader;

/**
Expand Down Expand Up @@ -63,7 +64,7 @@ public Set<WeldSEBeanDeploymentArchive> discoverArchives() {
addToArchives(processNoneDiscovery(builder));
break;
default:
throw new IllegalStateException("beans.xml has undefined bean discovery value:" + beansXml.getBeanDiscoveryMode());
WeldSELogger.LOG.undefinedBeanDiscoveryValue(beansXml.getBeanDiscoveryMode());
}
}
assignVisibility(deploymentArchives);
Expand Down
Expand Up @@ -31,6 +31,7 @@

import org.jboss.logging.Logger;
import org.jboss.weld.bootstrap.api.Bootstrap;
import org.jboss.weld.environment.se.logging.WeldSELogger;

/**
* This class provides file-system orientated scanning
Expand Down Expand Up @@ -71,15 +72,15 @@ public BeanArchiveBuilder handle(String urlPath) {
ZipFile jarFile = (ZipFile) m.invoke(jnlpClassLoader, new URL(urlPath));
urlPath = jarFile.getName();
} catch (MalformedURLException mue) {
log.warn("could not read entries, method JNLPClassLoader#getJarFile(URL) did not return a valid URL", mue);
WeldSELogger.LOG.couldNotReadEntries(urlPath, mue);
} catch (NoSuchMethodException nsme) {
log.warn(UNEXPECTED_CLASSLOADER_MESSAGE, nsme);
WeldSELogger.LOG.unexpectedClassLoader(nsme);
} catch (IllegalArgumentException iarge) {
log.warn(UNEXPECTED_CLASSLOADER_MESSAGE, iarge);
WeldSELogger.LOG.unexpectedClassLoader(iarge);
} catch (InvocationTargetException ite) {
log.warn("JNLPClassLoader#getJarFile(URL) threw exception", ite);
WeldSELogger.LOG.jnlpClassLoaderInternalException(ite);
} catch (Exception iacce) {
log.warn("could not invoke JNLPClassLoader#getJarFile(URL) on context class loader", iacce);
WeldSELogger.LOG.jnlpClassLoaderInvocationException(iacce);
}
}

Expand Down Expand Up @@ -110,7 +111,7 @@ protected void handleArchiveByFile(File file) throws IOException {
}
zip.close();
} catch (ZipException e) {
throw new RuntimeException("Error handling file " + file, e);
throw WeldSELogger.LOG.cannotHandleFile(file, e);
}
}

Expand All @@ -128,7 +129,7 @@ protected void handleDirectory(File dir, String path) {
try {
addToDiscovered(newPath, child.toURI().toURL());
} catch (MalformedURLException e) {
log.errorv("Error loading file {0}", newPath);
WeldSELogger.LOG.errorLoadingFile(newPath);
}
}
}
Expand All @@ -145,7 +146,7 @@ protected void addToDiscovered(String name, URL url) {
if (discoveredBeansXmlUrl == null) {
discoveredBeansXmlUrl = url;
} else {
throw new IllegalArgumentException("There is more than one beans.xml in the archive");
WeldSELogger.LOG.tooManyBeansXml();
}
}
}
Expand Down
Expand Up @@ -22,8 +22,8 @@

import org.jboss.jandex.Index;
import org.jboss.jandex.Indexer;
import org.jboss.logging.Logger;
import org.jboss.weld.bootstrap.api.Bootstrap;
import org.jboss.weld.environment.se.logging.WeldSELogger;

/**
* An implementation of {@link FileSystemURLHandler} that is filling the {@link BeanArchiveBuilder} also with the jandex index.
Expand All @@ -32,9 +32,6 @@
*/
public class JandexEnabledFileSystemURLHandler extends FileSystemURLHandler {

private static final String UNABLE_TO_OPEN_STREAM_MESSAGE = "Could not open the stream on the url when adding to the jandex index.";
private static final String UNABLE_TO_CLOSE_STREAM_MESSAGE = "Could not close the stream on the url when adding to the jandex index.";
private static final Logger log = Logger.getLogger(JandexEnabledFileSystemURLHandler.class);
private final Indexer indexer = new Indexer();

public JandexEnabledFileSystemURLHandler(Bootstrap bootstrap) {
Expand All @@ -47,14 +44,14 @@ private void addToIndex(URL url) {
fs = url.openStream();
indexer.index(fs);
} catch (IOException ex) {
log.warn(UNABLE_TO_OPEN_STREAM_MESSAGE, ex);
WeldSELogger.LOG.couldNotOpenStreamForURL(url, ex);
} finally {
try {
if (fs != null) {
fs.close();
}
} catch (IOException ex) {
log.warn(UNABLE_TO_CLOSE_STREAM_MESSAGE, ex);
WeldSELogger.LOG.couldNotCloseStreamForURL(url, ex);
}
}
}
Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.jboss.logging.Logger;
import org.jboss.weld.bootstrap.api.Bootstrap;
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.logging.WeldSELogger;
import org.jboss.weld.environment.se.util.SEReflections;
import org.jboss.weld.resources.spi.ResourceLoader;
import org.jboss.weld.util.reflection.Reflections;
Expand Down Expand Up @@ -72,7 +73,7 @@ public Collection<BeanArchiveBuilder> scan() {
try {
urlPath = getUrlPath(resourceName, url);
} catch (URISyntaxException e) {
log.warn("Could not read: " + resourceName, e);
WeldSELogger.LOG.couldNotReadResource(resourceName, e);
continue;
}
final String bdaId = getId(urlPath);
Expand Down
@@ -0,0 +1,100 @@
package org.jboss.weld.environment.se.logging;


import javax.enterprise.inject.UnsatisfiedResolutionException;

import org.jboss.logging.BasicLogger;
import org.jboss.logging.Logger;
import org.jboss.logging.Logger.Level;
import org.jboss.logging.annotations.Cause;
import org.jboss.logging.annotations.LogMessage;
import org.jboss.logging.annotations.Message;
import org.jboss.logging.annotations.Message.Format;
import org.jboss.logging.annotations.MessageLogger;
import org.jboss.weld.resources.spi.ClassFileInfoException;

/**
* A source of localized log/bundle messages and exceptions. Note that this interface extends {@link BasicLogger} so that regular logger methods are available.
*
* @author Matej Briškár
* @author Martin Kouba
*/
@MessageLogger(projectCode = "WELD-SE-")
public interface WeldSELogger extends BasicLogger {

WeldSELogger LOG = Logger.getMessageLogger(WeldSELogger.class, "WELD-SE");

String CATCHING_MARKER = "Catching";
String WELD_PROJECT_CODE = "WELD-SE-";

/**
* Replacement for <code>org.slf4j.ext.XLogger.throwing(Level.DEBUG, e)</code>.
*
* @param throwable
*/
@LogMessage(level = Level.DEBUG)
@Message(id = 1, value = CATCHING_MARKER)
void catchingDebug(@Cause Throwable throwable);

@LogMessage(level = Level.WARN)
@Message(id = 2, value = "Could not read resource with name: {0}", format = Format.MESSAGE_FORMAT)
void couldNotReadResource(Object param1, @Cause Throwable cause);

@LogMessage(level = Level.WARN)
@Message(id = 3, value = "Could not read entries, method JNLPClassLoader#getJarFile(URL) did not return a valid URL for the path {0}", format = Format.MESSAGE_FORMAT)
void couldNotReadEntries(Object param1, @Cause Throwable cause);

@LogMessage(level = Level.WARN)
@Message(id = 4, value = "Could not invoke JNLPClassLoader#getJarFile(URL) on context class loader, expecting Web Start class loader", format = Format.MESSAGE_FORMAT)
void unexpectedClassLoader(@Cause Throwable cause);

@LogMessage(level = Level.WARN)
@Message(id = 5, value = "JNLPClassLoader#getJarFile(URL) threw exception", format = Format.MESSAGE_FORMAT)
void jnlpClassLoaderInternalException(@Cause Throwable cause);

@LogMessage(level = Level.WARN)
@Message(id = 6, value = "Could not invoke JNLPClassLoader#getJarFile(URL) on context class loader", format = Format.MESSAGE_FORMAT)
void jnlpClassLoaderInvocationException(@Cause Throwable cause);

@Message(id = 7, value = "Error handling file {0}", format = Format.MESSAGE_FORMAT)
RuntimeException cannotHandleFile(Object param1, @Cause Throwable cause);

@LogMessage(level = Level.ERROR)
@Message(id = 8, value = "Error loading file {0}", format = Format.MESSAGE_FORMAT)
void errorLoadingFile(Object param1);

@Message(id = 9, value = "There is more than one beans.xml in the archive", format = Format.MESSAGE_FORMAT)
IllegalArgumentException tooManyBeansXml();

@LogMessage(level = Level.WARN)
@Message(id = 10, value = "Could not open the stream on the url {0} when adding to the jandex index.", format = Format.MESSAGE_FORMAT)
void couldNotOpenStreamForURL(Object param1, @Cause Throwable cause);

@LogMessage(level = Level.WARN)
@Message(id = 11, value = "Could not close the stream on the url {0} when adding to the jandex index.", format = Format.MESSAGE_FORMAT)
void couldNotCloseStreamForURL(Object param1, @Cause Throwable cause);

@Message(id = 12, value = "Unable to load class {0}", format = Format.MESSAGE_FORMAT)
ClassFileInfoException unableToLoadClass(Object param1);

@Message(id = 13, value = "beans.xml defines unrecognized bean-discovery-mode value: {0}", format = Format.MESSAGE_FORMAT)
IllegalStateException undefinedBeanDiscoveryValue(Object param1);

@Message(id = 14, value = "bean discovery-mode=\"annotated\" support is disabled. Add org.jboss:jandex to the classpath to enable it.", format = Format.MESSAGE_FORMAT)
IllegalStateException annotatedBeanDiscoveryNotSupported();

@Message(id = 15, value = "Unable to load annotation: {0}", format = Format.MESSAGE_FORMAT)
IllegalStateException unableToLoadAnnotation(Object param1);

@Message(id = 16, value = "Missing beans.xml file in META-INF", format = Format.MESSAGE_FORMAT)
IllegalStateException missingBeansXml();

@Message(id = 17, value = "Error loading Weld bootstrap, check that Weld is on the classpath", format = Format.MESSAGE_FORMAT)
IllegalStateException errorLoadingWeld();

@Message(id = 18, value = "Unable to resolve a bean for {0} with bindings {1}", format = Format.MESSAGE_FORMAT)
UnsatisfiedResolutionException unableToResolveBean(Object param1, Object param2);



}
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -34,7 +34,7 @@
<arquillian.jetty.version>1.0.0.CR2</arquillian.jetty.version>
<arquillian.glassfish.version>1.0.0.CR1</arquillian.glassfish.version>
<atinject.tck.version>1</atinject.tck.version>
<build.config.version>4</build.config.version>
<build.config.version>5</build.config.version>
<cdi.tck-1-1.version>1.1.3.Final</cdi.tck-1-1.version>
<cdi.tck-1-2.version>1.2.0.Beta1</cdi.tck-1-2.version>
<classfilewriter.version>1.0.4.Final</classfilewriter.version>
Expand Down

0 comments on commit fc15303

Please sign in to comment.