Skip to content

Commit

Permalink
META-INF/forge.xml is the marker file for ClassPath URL Scanning, not…
Browse files Browse the repository at this point in the history
… Beans.xml - this is probably bad, but for now it helps debug
  • Loading branch information
lincolnthree committed Nov 8, 2012
1 parent e35ac2e commit 8eb841a
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 68 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans />
<forge />
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,14 @@ protected void handle(String name, URL url, List<String> discoveredClasses, List
String className = filenameToClassname(name);
try
{
// resourceLoader.classForName(className);
resourceLoader.classForName(className);
discoveredClasses.add(className);
}
catch (Exception e)
{
log.warn(
"Not loading Bean definition from class: ["
+ className + "] because of underlying class loading error " +
"(probably the Bean was not actually defined in the addon module.)",
e);
log.warn("Not loading Bean definition from class: ["
+ className + "] because of underlying class loading error. " +
"Class found in [" + resourceLoader + "] but could not be loaded.)", e);
}
}
else if (name.endsWith("beans.xml"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,76 +18,92 @@

/**
* Scan the classloader
*
*
* @author Thomas Heute
* @author Gavin King
* @author Norman Richards
* @author Pete Muir
* @author Peter Royle
*/
public class ModularURLScanner {
public class ModularURLScanner
{

private static final Logger log = LoggerFactory.getLogger(ModularURLScanner.class);
private final String[] resources;
private final ResourceLoader resourceLoader;
private final Bootstrap bootstrap;
private static final Logger log = LoggerFactory.getLogger(ModularURLScanner.class);
private final String[] resources;
private final ResourceLoader resourceLoader;
private final Bootstrap bootstrap;

public ModularURLScanner(ResourceLoader resourceLoader, Bootstrap bootstrap, String... resources) {
this.resources = resources;
this.resourceLoader = resourceLoader;
this.bootstrap = bootstrap;
}
public ModularURLScanner(ResourceLoader resourceLoader, Bootstrap bootstrap, String... resources)
{
this.resources = resources;
this.resourceLoader = resourceLoader;
this.bootstrap = bootstrap;
}

public BeanDeploymentArchive scan() {
List<String> discoveredClasses = new ArrayList<String>();
List<URL> discoveredBeanXmlUrls = new ArrayList<URL>();
Collection<String> paths = new ArrayList<String>();
for (String resourceName : resources) {
// grab all the URLs for this resource
Collection<URL> urlEnum = resourceLoader.getResources(resourceName);
for (URL url : urlEnum) {
public BeanDeploymentArchive scan()
{
List<String> discoveredClasses = new ArrayList<String>();
List<URL> discoveredBeanXmlUrls = new ArrayList<URL>();
Collection<String> paths = new ArrayList<String>();
for (String resourceName : resources)
{
// grab all the URLs for this resource
Collection<URL> urlEnum = resourceLoader.getResources(resourceName);
for (URL url : urlEnum)
{

String urlPath = url.toExternalForm();
String urlPath = url.toExternalForm();

// determin resource type (eg: jar, file, bundle)
String urlType = "file";
int colonIndex = urlPath.indexOf(":");
if (colonIndex != -1) {
urlType = urlPath.substring(0, colonIndex);
}
// determin resource type (eg: jar, file, bundle)
String urlType = "file";
int colonIndex = urlPath.indexOf(":");
if (colonIndex != -1)
{
urlType = urlPath.substring(0, colonIndex);
}

// Extra built-in support for simple file-based resources
if ("file".equals(urlType) || "jar".equals(urlType)) {
// switch to using getPath() instead of toExternalForm()
urlPath = url.getPath();
// Extra built-in support for simple file-based resources
if ("file".equals(urlType) || "jar".equals(urlType))
{
// switch to using getPath() instead of toExternalForm()
urlPath = url.getPath();

if (urlPath.indexOf('!') > 0) {
urlPath = urlPath.substring(0, urlPath.indexOf('!'));
} else {
// hack for /META-INF/beans.xml
File dirOrArchive = new File(urlPath);
if ((resourceName != null) && (resourceName.lastIndexOf('/') > 0)) {
dirOrArchive = dirOrArchive.getParentFile();
}
urlPath = dirOrArchive.getParent();
}
}
if (urlPath.indexOf('!') > 0)
{
urlPath = urlPath.substring(0, urlPath.indexOf('!'));
}
else
{
// hack for /META-INF/beans.xml
File dirOrArchive = new File(urlPath);
if ((resourceName != null) && (resourceName.lastIndexOf('/') > 0))
{
dirOrArchive = dirOrArchive.getParentFile();
}
urlPath = dirOrArchive.getParent();
}
}

try {
urlPath = URLDecoder.decode(urlPath, "UTF-8");
} catch (UnsupportedEncodingException ex) {
throw new ClasspathScanningException("Error decoding URL using UTF-8");
}
try
{
urlPath = URLDecoder.decode(urlPath, "UTF-8");
}
catch (UnsupportedEncodingException ex)
{
throw new ClasspathScanningException("Error decoding URL using UTF-8");
}

log.debug("URL Type: " + urlType);
log.debug("URL Type: " + urlType);

paths.add(urlPath);
}
File file = new File("").getAbsoluteFile();
if (!urlPath.contains(file.getAbsolutePath()))
paths.add(urlPath);
}

ModularFileSystemURLHandler handler = new ModularFileSystemURLHandler(resourceLoader);
handler.handle(paths, discoveredClasses, discoveredBeanXmlUrls);
}
return new ImmutableBeanDeploymentArchive("classpath", discoveredClasses, bootstrap.parse(discoveredBeanXmlUrls));
}
ModularFileSystemURLHandler handler = new ModularFileSystemURLHandler(resourceLoader);
handler.handle(paths, discoveredClasses, discoveredBeanXmlUrls);
}
return new ImmutableBeanDeploymentArchive("classpath", discoveredClasses, bootstrap.parse(discoveredBeanXmlUrls));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public ModularWeldDeployment(Module module, Bootstrap bootstrap)
super(bootstrap);

ModuleResourceLoader resourceLoader = new ModuleResourceLoader(module);
this.beanDeploymentArchive = new ModularURLScanner(resourceLoader, bootstrap, RESOURCES).scan();
this.beanDeploymentArchive = new ModularURLScanner(resourceLoader, bootstrap,
new String[] { "META-INF/forge.xml" }).scan();
this.beanDeploymentArchive.getServices().add(ResourceLoader.class, resourceLoader);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jboss.forge.container.modules;

import org.jboss.modules.Module;
import org.jboss.modules.ModuleClassLoader;
import org.jboss.weld.resources.spi.ResourceLoader;
import org.jboss.weld.resources.spi.ResourceLoadingException;

Expand All @@ -21,18 +22,25 @@
*/
public class ModuleResourceLoader implements ResourceLoader
{
@Override
public String toString()
{
return "ModuleResourceLoader [module=" + module + "]";
}

private final Module module;

/**
* Additional classes that have been added to the bean archive by the container or by a portable extension
*/
private final Map<String, Class<?>> classes;
private ModuleClassLoader classLoader;

public ModuleResourceLoader(Module module)
{
this.module = module;
this.classes = new ConcurrentHashMap<String, Class<?>>();
this.classLoader = module.getClassLoader();
}

/**
Expand All @@ -49,7 +57,7 @@ public Class<?> classForName(String name)
{
return classes.get(name);
}
final Class<?> clazz = module.getClassLoader().loadClass(name);
final Class<?> clazz = classLoader.loadClass(name);
classes.put(name, clazz);
return clazz;
}
Expand Down Expand Up @@ -114,7 +122,7 @@ public Collection<URL> getResources(String name)
@Override
public void cleanup()
{
// nop
// noop
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class WeldClasspathSpec extends BaseModuleSpecProvider

static
{
paths.add("META-INF");
// paths.add("META-INF");
paths.add("META-INF/services");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Set;

import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.Annotated;
import javax.enterprise.inject.spi.AnnotatedMember;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.Extension;
Expand Down Expand Up @@ -41,7 +42,8 @@ public void processRemotes(@Observes ProcessAnnotatedType<?> event)

public void processRemoteInjectionPoint(@Observes ProcessInjectionPoint<?, ?> event)
{
if (event.getInjectionPoint().getAnnotated().isAnnotationPresent(Service.class))
Annotated annotated = event.getInjectionPoint().getAnnotated();
if (annotated.isAnnotationPresent(Service.class))
event.setInjectionPoint(new RemoteInjectionPoint(event.getInjectionPoint()));
}

Expand Down
2 changes: 2 additions & 0 deletions plugin-container/src/main/resources/META-INF/forge.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<forge />

0 comments on commit 8eb841a

Please sign in to comment.