Skip to content

Commit

Permalink
WELD-1837: Weld SE does not support empty beans.xml files
Browse files Browse the repository at this point in the history
  • Loading branch information
stefangrossmann authored and jharting committed Jan 14, 2015
1 parent 8abcb4d commit f234c01
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;

import org.jboss.logging.Logger;
import org.jboss.weld.bootstrap.api.Bootstrap;
import org.jboss.weld.bootstrap.spi.BeansXml;
import org.jboss.weld.environment.deployment.WeldBeanDeploymentArchive;
import org.jboss.weld.environment.deployment.discovery.BeanArchiveScanner.ScanResult;
import org.jboss.weld.environment.logging.CommonLogger;
import org.jboss.weld.exceptions.UnsupportedOperationException;
import org.jboss.weld.resources.spi.ClassFileServices;
Expand Down Expand Up @@ -80,14 +80,14 @@ public Set<WeldBeanDeploymentArchive> performDiscovery() {
}

final Collection<BeanArchiveBuilder> beanArchiveBuilders = new ArrayList<BeanArchiveBuilder>();
for (Entry<BeansXml, String> entry : scanner.scan().entrySet()) {
String ref = entry.getValue();
for (ScanResult scanResult : scanner.scan().values()) {
final String ref = scanResult.getBeanArchiveRef();
BeanArchiveBuilder builder = null;
for (BeanArchiveHandler handler : handlers) {
builder = handler.handle(ref);
if (builder != null) {
builder.setId(ref);
builder.setBeansXml(entry.getKey());
builder.setBeansXml(scanResult.getBeansXml());
beanArchiveBuilders.add(builder);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.jboss.weld.environment.deployment.discovery;

import java.net.URL;
import java.util.Map;

import org.jboss.weld.bootstrap.spi.BeansXml;
Expand All @@ -29,12 +30,28 @@
* @author Martin Kouba
*/
public interface BeanArchiveScanner {
public static class ScanResult {
private final String beanArchiveRef;
private final BeansXml beansXml;

public ScanResult(final BeansXml beansXml, final String beanArchiveRef) {
this.beansXml = beansXml;
this.beanArchiveRef = beanArchiveRef;
}

public String getBeanArchiveRef() {
return beanArchiveRef;
}

public BeansXml getBeansXml() {
return beansXml;
}
}

/**
* Scans for bean archives identified by beans.xml files.
*
* @return the map of {@link BeansXml} representations mapped to the bean archive reference (the root path of the bean archive)
* @return the map of {@link ScanResult} representations mapped by url of the beans xml.
*/
Map<BeansXml, String> scan();

Map<URL, ScanResult> scan();
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.jboss.weld.bootstrap.spi.BeansXml;
import org.jboss.weld.environment.deployment.AbstractWeldDeployment;
import org.jboss.weld.environment.deployment.WeldResourceLoader;
import org.jboss.weld.environment.deployment.discovery.BeanArchiveScanner.ScanResult;
import org.jboss.weld.environment.logging.CommonLogger;
import org.jboss.weld.resources.spi.ResourceLoader;

Expand Down Expand Up @@ -66,17 +67,17 @@ public DefaultBeanArchiveScanner(ResourceLoader resourceLoader, Bootstrap bootst
}

@Override
public Map<BeansXml, String> scan() {
Map<BeansXml, String> beansXmlMap = new HashMap<BeansXml, String>();
public Map<URL, ScanResult> scan() {
final Map<URL, ScanResult> beansXmlMap = new HashMap<URL, ScanResult> ();
// META-INF/beans.xml
String[] resources = AbstractWeldDeployment.RESOURCES;
final String[] resources = AbstractWeldDeployment.RESOURCES;

// Find all beans.xml files
for (String resourceName : resources) {
for (URL beansXmlUrl : resourceLoader.getResources(resourceName)) {
BeansXml beansXml = bootstrap.parse(beansXmlUrl);
final BeansXml beansXml = bootstrap.parse(beansXmlUrl);
if (accept(beansXml)) {
beansXmlMap.put(beansXml, getBeanArchiveReference(beansXmlUrl));
beansXmlMap.put(beansXmlUrl, new ScanResult(beansXml, getBeanArchiveReference(beansXmlUrl)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public WebAppBeanArchiveScanner(ResourceLoader resourceLoader, Bootstrap bootstr
}

@Override
public Map<BeansXml, String> scan() {
Map<BeansXml, String> beansXmlMap = super.scan();
public Map<URL, ScanResult> scan() {
Map<URL, ScanResult> beansXmlMap = super.scan();
try {
// WEB-INF/classes
URL beansXmlUrl = null;
Expand All @@ -79,10 +79,10 @@ public Map<BeansXml, String> scan() {
if (accept(beansXml)) {
File webInfClasses = Servlets.getRealFile(servletContext, WEB_INF_CLASSES);
if (webInfClasses != null) {
beansXmlMap.put(beansXml, webInfClasses.getPath());
beansXmlMap.put(beansXmlUrl, new ScanResult(beansXml, webInfClasses.getPath()));
} else {
// The WAR is not extracted to the file system - make use of ServletContext.getResourcePaths()
beansXmlMap.put(beansXml, WEB_INF_CLASSES);
beansXmlMap.put(beansXmlUrl, new ScanResult(beansXml, WEB_INF_CLASSES));
}
}
}
Expand Down

0 comments on commit f234c01

Please sign in to comment.