Author: pete.muir(a)jboss.org
Date: 2008-01-25 07:56:35 -0500 (Fri, 25 Jan 2008)
New Revision: 7232
Added:
trunk/src/jbas5/META-INF/seam-deployment.properties
trunk/src/main/META-INF/seam-deployment.properties
trunk/src/main/org/jboss/seam/bpm/JbpmDeploymentHandler.java
Removed:
trunk/src/jbas5/META-INF/seam-scanner.properties
Modified:
trunk/src/main/org/jboss/seam/deployment/AbstractDeploymentHandler.java
trunk/src/main/org/jboss/seam/deployment/ComponentDeploymentHandler.java
trunk/src/main/org/jboss/seam/deployment/DeploymentHandler.java
trunk/src/main/org/jboss/seam/deployment/DeploymentStrategy.java
trunk/src/main/org/jboss/seam/deployment/GroovyDeploymentHandler.java
trunk/src/main/org/jboss/seam/deployment/HotDeploymentStrategy.java
trunk/src/main/org/jboss/seam/deployment/NamespaceDeploymentHandler.java
trunk/src/main/org/jboss/seam/deployment/StandardDeploymentStrategy.java
trunk/src/main/org/jboss/seam/init/Initialization.java
Log:
JBSEAM-1342
Copied: trunk/src/jbas5/META-INF/seam-deployment.properties (from rev 7222,
trunk/src/jbas5/META-INF/seam-scanner.properties)
===================================================================
--- trunk/src/jbas5/META-INF/seam-deployment.properties (rev 0)
+++ trunk/src/jbas5/META-INF/seam-deployment.properties 2008-01-25 12:56:35 UTC (rev
7232)
@@ -0,0 +1 @@
+org.jboss.seam.deployment.scanners=org.jboss.seam.as5.vfs.VFSScanner
Deleted: trunk/src/jbas5/META-INF/seam-scanner.properties
===================================================================
--- trunk/src/jbas5/META-INF/seam-scanner.properties 2008-01-25 12:54:42 UTC (rev 7231)
+++ trunk/src/jbas5/META-INF/seam-scanner.properties 2008-01-25 12:56:35 UTC (rev 7232)
@@ -1 +0,0 @@
-org.jboss.seam.deployment.scanners=org.jboss.seam.as5.vfs.VFSScanner:org.jboss.seam.deployment.URLScanner
Added: trunk/src/main/META-INF/seam-deployment.properties
===================================================================
Property changes on: trunk/src/main/META-INF/seam-deployment.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/src/main/org/jboss/seam/bpm/JbpmDeploymentHandler.java
===================================================================
--- trunk/src/main/org/jboss/seam/bpm/JbpmDeploymentHandler.java
(rev 0)
+++ trunk/src/main/org/jboss/seam/bpm/JbpmDeploymentHandler.java 2008-01-25 12:56:35 UTC
(rev 7232)
@@ -0,0 +1,46 @@
+package org.jboss.seam.bpm;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.seam.deployment.AbstractDeploymentHandler;
+
+/**
+ * Handles jBPM resources discovered on scan
+ *
+ * TODO Hook this into the Jbpm component
+ *
+ * @author Pete Muir
+ *
+ */
+public class JbpmDeploymentHandler extends AbstractDeploymentHandler
+{
+
+ private List<String> jpdlResources;
+
+ public JbpmDeploymentHandler()
+ {
+ jpdlResources = new ArrayList<String>();
+ }
+
+ public static final String NAME =
"org.jboss.seam.bpm.JbpmDeploymentHandler";
+
+ public String getName()
+ {
+ return NAME;
+ }
+
+ public void handle(String name, ClassLoader classLoader)
+ {
+ if ( name.endsWith(".jpdl.xml") &&
!name.startsWith(".gpd") )
+ {
+ jpdlResources.add(name);
+ }
+ }
+
+ public List<String> getJpdlResources()
+ {
+ return jpdlResources;
+ }
+
+}
Property changes on: trunk/src/main/org/jboss/seam/bpm/JbpmDeploymentHandler.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/src/main/org/jboss/seam/deployment/AbstractDeploymentHandler.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/AbstractDeploymentHandler.java 2008-01-25
12:54:42 UTC (rev 7231)
+++ trunk/src/main/org/jboss/seam/deployment/AbstractDeploymentHandler.java 2008-01-25
12:56:35 UTC (rev 7232)
@@ -93,6 +93,10 @@
}
-
+ @Override
+ public String toString()
+ {
+ return getName();
+ }
}
Modified: trunk/src/main/org/jboss/seam/deployment/ComponentDeploymentHandler.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/ComponentDeploymentHandler.java 2008-01-25
12:54:42 UTC (rev 7231)
+++ trunk/src/main/org/jboss/seam/deployment/ComponentDeploymentHandler.java 2008-01-25
12:56:35 UTC (rev 7232)
@@ -105,4 +105,9 @@
return name.substring( 0, name.lastIndexOf(".class") ) +
".component.xml";
}
+ public String getName()
+ {
+ return NAME;
+ }
+
}
Modified: trunk/src/main/org/jboss/seam/deployment/DeploymentHandler.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/DeploymentHandler.java 2008-01-25 12:54:42
UTC (rev 7231)
+++ trunk/src/main/org/jboss/seam/deployment/DeploymentHandler.java 2008-01-25 12:56:35
UTC (rev 7232)
@@ -17,4 +17,10 @@
* @param classLoader The ClassLoader on which the resource was found
*/
public void handle(String name, ClassLoader classLoader);
+
+ /**
+ * A key used to identify the deployment handler
+ */
+ public String getName();
+
}
Modified: trunk/src/main/org/jboss/seam/deployment/DeploymentStrategy.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/DeploymentStrategy.java 2008-01-25 12:54:42
UTC (rev 7231)
+++ trunk/src/main/org/jboss/seam/deployment/DeploymentStrategy.java 2008-01-25 12:56:35
UTC (rev 7232)
@@ -2,19 +2,22 @@
import static org.jboss.seam.util.Strings.split;
+import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
import java.util.HashMap;
-import java.util.Locale;
+import java.util.List;
import java.util.Map;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
+import java.util.Properties;
import org.jboss.seam.log.LogProvider;
import org.jboss.seam.log.Logging;
/**
- * A {@link DeploymentStrategy} coordinates the deploy of resources for a Seam
+ * A {@link DeploymentStrategy} coordinates the deployment of resources for a Seam
* application.
*
* @author Pete Muir
@@ -29,25 +32,104 @@
private Map<String, DeploymentHandler> deploymentHandlers;
- public DeploymentStrategy()
+ /**
+ * The key under which to list possible scanners. System properties take
+ * precedence over /META-INF/seam-scanner.properties. Entries will be tried
+ * in sequential order until a Scanner can be loaded.
+ *
+ * This can be specified as a System property or in
+ * /META-INF/seam-deployment.properties
+ */
+ public static final String SCANNERS_KEY =
"org.jboss.seam.deployment.scanners";
+
+
+
+ /**
+ * The resource bundle used to control Seam deployment
+ */
+ public static final String RESOURCE_BUNDLE =
"META-INF/seam-deployment.properties";
+
+ // All resource bundles to use, including legacy names
+ private static final String[] RESOURCE_BUNDLES = { RESOURCE_BUNDLE,
"META-INF/seam-scanner.properties" };
+
+ /**
+ * Get a list of possible values for a given key.
+ *
+ * First, System properties are tried, followed by the specified resource
+ * bundle (first in classpath only).
+ *
+ * Colon (:) deliminated lists are split out.
+ *
+ */
+ protected List<String> getPropertyValues(String key)
{
- this.deploymentHandlers = new HashMap<String, DeploymentHandler>();
+ List<String>values = new ArrayList<String>();
+ addPropertyFromSystem(key, values);
+ addPropertyFromResourceBundle(key, values);
+ return values;
}
+ private void addPropertyFromSystem(String key, List<String> values)
+ {
+ addProperty(key, System.getProperty(key), values);
+ }
+
+ private void addPropertyFromResourceBundle(String key, List<String> values)
+ {
+ for (String resourceName : RESOURCE_BUNDLES)
+ {
+ try
+ {
+ // Hard to cache as we have to get it off the correct classloader
+ Enumeration<URL> urlEnum =
getClassLoader().getResources(resourceName);
+ while ( urlEnum.hasMoreElements() )
+ {
+ URL url = urlEnum.nextElement();
+ Properties properties = new Properties();
+ properties.load(url.openStream());
+ addProperty(key, properties.getProperty(key), values);
+ }
+ }
+ catch (IOException e)
+ {
+ // No-op, optional file
+ }
+ }
+ }
+
+ /*
+ * Add the property to the set of properties only if it hasn't already been added
+ */
+ private void addProperty(String key, String value, List<String> values)
+ {
+ if (value != null)
+ {
+ String[] properties = split(value, ":");
+ for (String property : properties)
+ {
+ values.add(property);
+ }
+
+ }
+ }
+
/**
* Do the scan for resources
*
+ * Should only be called by Seam
+ *
*/
public abstract void scan();
/**
* Get the scanner being used
+ *
*/
protected Scanner getScanner()
{
if (scanner == null)
{
- scanner = createScanner();
+ initScanner();
}
return scanner;
}
@@ -65,9 +147,21 @@
*/
public Map<String, DeploymentHandler> getDeploymentHandlers()
{
+ if (deploymentHandlers == null)
+ {
+ initDeploymentHandlers();
+ }
return this.deploymentHandlers;
}
+
+ private void initDeploymentHandlers()
+ {
+ this.deploymentHandlers = new HashMap<String, DeploymentHandler>();
+ addHandlers(getPropertyValues(getDeploymentHandlersKey()));
+ }
+ protected abstract String getDeploymentHandlersKey();
+
/**
* Handle a resource using any registered {@link DeploymentHandler}s
*
@@ -77,78 +171,27 @@
{
for (String key: getDeploymentHandlers().keySet())
{
- DeploymentHandler deploymentHandler = getDeploymentHandlers().get(key);
- deploymentHandler.handle(name, getClassLoader());
+ getDeploymentHandlers().get(key).handle(name, getClassLoader());
}
}
-
- private Scanner createScanner()
+
+ private void initScanner()
{
- Scanner scanner = getScannerFromResource();
- if (scanner == null)
+ List<String> scanners = getPropertyValues(SCANNERS_KEY);
+ for ( String className : scanners )
{
- scanner = getScannerFromSystemProperty();
- }
- if (scanner == null)
- {
- log.debug("Using default URLScanner");
- scanner = new URLScanner(this);
- }
- return scanner;
- }
-
- private Scanner getScannerFromSystemProperty()
- {
- String scanners =
System.getProperty("org.jboss.seam.deployment.scanners");
- if (scanners != null)
- {
- log.debug("Tring to load scanner from system property");
- Scanner scanner = loadScanner(scanners);
+ Scanner scanner = instantiateScanner(className);
if (scanner != null)
{
- log.debug("Using " + scanner.getClass().getName() + "
specified in /META-INF/seam-scanner.properties");
- return scanner;
- }
+ log.debug("Using " + scanner.toString());
+ this.scanner = scanner;
+ return;
+ }
}
- return null;
+ log.debug("Using default URLScanner");
+ this.scanner = new URLScanner(this);
}
- private Scanner getScannerFromResource()
- {
- // Load seam-scanner.properties from the classpath, try to
- // load any scanners specified there
- try
- {
- String scanners = ResourceBundle.getBundle("META-INF/seam-scanner",
Locale.getDefault(),
getClassLoader()).getString("org.jboss.seam.deployment.scanners");
- log.debug("Tring to load scanner from
/META-INF/seam-scanner.properties");
- Scanner scanner = loadScanner(scanners);
- if (scanner != null)
- {
- log.debug("Using " + scanner.getClass().getName() + "
specified in /META-INF/seam-scanner.properties");
- return scanner;
- }
- log.debug("Unable to load any scanner from
/META-INF/seam-scanner.properties");
- }
- catch (MissingResourceException e)
- {
- // no-op
- }
- return null;
- }
-
- private Scanner loadScanner(String scanners)
- {
- for (String className : split(scanners, ":"))
- {
- Scanner scanner = instantiateScanner(className);
- if (scanner != null)
- {
- return scanner;
- }
- }
- return null;
- }
-
private Scanner instantiateScanner(String className)
{
try
@@ -196,4 +239,48 @@
return null;
}
+ private void addHandlers(List<String> handlers)
+ {
+ for (String handler : handlers)
+ {
+ addHandler(handler);
+ }
+ }
+
+ private void addHandler(String className)
+ {
+ DeploymentHandler deploymentHandler = instantiateDeploymentHandler(className);
+ if (deploymentHandler != null)
+ {
+ log.debug("Adding " + deploymentHandler + " as a deployment
handler");
+ deploymentHandlers.put(deploymentHandler.getName(), deploymentHandler);
+ }
+ }
+
+ private DeploymentHandler instantiateDeploymentHandler(String className)
+ {
+ try
+ {
+ Class<DeploymentHandler> clazz = (Class<DeploymentHandler>)
getClassLoader().loadClass(className);
+ return clazz.newInstance();
+ }
+ catch (ClassNotFoundException e)
+ {
+ log.trace("Unable to use " + className + " as a deployment
handler (class not found)", e);
+ }
+ catch (NoClassDefFoundError e)
+ {
+ log.trace("Unable to use " + className + " as a deployment
handler (dependency not found)", e);
+ }
+ catch (InstantiationException e)
+ {
+ log.trace("Unable to instantiate deployment handler " + className,
e);
+ }
+ catch (IllegalAccessException e)
+ {
+ log.trace("Unable to instantiate deployment handler " + className,
e);
+ }
+ return null;
+ }
+
}
Modified: trunk/src/main/org/jboss/seam/deployment/GroovyDeploymentHandler.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/GroovyDeploymentHandler.java 2008-01-25
12:54:42 UTC (rev 7231)
+++ trunk/src/main/org/jboss/seam/deployment/GroovyDeploymentHandler.java 2008-01-25
12:56:35 UTC (rev 7232)
@@ -133,5 +133,10 @@
{
return name.substring(0, name.lastIndexOf(groovyFileExtension)) +
".component.xml";
}
+
+ public String getName()
+ {
+ return NAME;
+ }
}
Modified: trunk/src/main/org/jboss/seam/deployment/HotDeploymentStrategy.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/HotDeploymentStrategy.java 2008-01-25
12:54:42 UTC (rev 7231)
+++ trunk/src/main/org/jboss/seam/deployment/HotDeploymentStrategy.java 2008-01-25
12:56:35 UTC (rev 7232)
@@ -7,6 +7,7 @@
import java.net.URLClassLoader;
import java.util.Set;
+import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.util.Reflections;
/**
@@ -20,8 +21,30 @@
/**
* The default path at which hot deployable Seam components are placed
*/
- public static final String HOT_DEPLOYMENT_DIRECTORY_PATH = "WEB-INF/dev";
+ public static final String DEFAULT_HOT_DEPLOYMENT_DIRECTORY_PATH =
"WEB-INF/dev";
+ /**
+ * The contextual variable name this deployment strategy is made available at
+ * during Seam startup.
+ */
+ public static final String NAME =
"org.jboss.seam.deployment.hotDeploymentStrategy";
+
+ /**
+ * The key under which to list extra hot deployment directories
+ *
+ * This can be specified as a System property or in
+ * /META-INF/seam-deployment.properties
+ */
+ //public static final String HOT_DEPLOY_DIRECTORIES_KEY =
"org.jboss.seam.deployment.hotDeploymentDirectories";
+
+ /**
+ * The key under which to list extra deployment handlers.
+ *
+ * This can be specified as a System property or in
+ * /META-INF/seam-deployment.properties
+ */
+ public static final String HANDLERS_KEY =
"org.jboss.seam.deployment.hotDeploymentHandlers";
+
private ClassLoader hotDeployClassLoader;
private File[] hotDeploymentPaths;
@@ -37,7 +60,7 @@
{
initHotDeployClassLoader(classLoader, hotDeployDirectory);
componentDeploymentHandler = new ComponentDeploymentHandler();
- getDeploymentHandlers().put(ComponentDeploymentHandler.NAME,
componentDeploymentHandler);
+ getDeploymentHandlers().put(ComponentDeploymentHandler.NAME,
componentDeploymentHandler);
}
private void initHotDeployClassLoader(ClassLoader classLoader, File
hotDeployDirectory)
@@ -58,6 +81,12 @@
throw new RuntimeException(mue);
}
}
+
+ @Override
+ protected String getDeploymentHandlersKey()
+ {
+ return HANDLERS_KEY;
+ }
/**
* Get all hot deployable paths
@@ -118,4 +147,14 @@
getScanner().scanDirectories(getHotDeploymentPaths());
}
+
+ public static HotDeploymentStrategy instance()
+ {
+ if (Contexts.getEventContext().isSet(NAME))
+ {
+ return (HotDeploymentStrategy) Contexts.getEventContext().get(NAME);
+ }
+ return null;
+ }
+
}
Modified: trunk/src/main/org/jboss/seam/deployment/NamespaceDeploymentHandler.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/NamespaceDeploymentHandler.java 2008-01-25
12:54:42 UTC (rev 7231)
+++ trunk/src/main/org/jboss/seam/deployment/NamespaceDeploymentHandler.java 2008-01-25
12:56:35 UTC (rev 7232)
@@ -74,5 +74,10 @@
return null;
}
}
+
+ public String getName()
+ {
+ return NAME;
+ }
}
Modified: trunk/src/main/org/jboss/seam/deployment/StandardDeploymentStrategy.java
===================================================================
--- trunk/src/main/org/jboss/seam/deployment/StandardDeploymentStrategy.java 2008-01-25
12:54:42 UTC (rev 7231)
+++ trunk/src/main/org/jboss/seam/deployment/StandardDeploymentStrategy.java 2008-01-25
12:56:35 UTC (rev 7232)
@@ -2,6 +2,8 @@
import java.util.Set;
+import org.jboss.seam.contexts.Contexts;
+
/**
* The standard deployment strategy used with Seam, deploys non-hot-deployable
* Seam components and namespaces
@@ -14,7 +16,24 @@
private ClassLoader classLoader;
+ /**
+ * The files used to identify a Seam archive
+ */
public static final String[] RESOURCE_NAMES = {"seam.properties",
"META-INF/seam.properties", "META-INF/components.xml"};
+
+ /**
+ * The contextual variable name this deployment strategy is made available at
+ * during Seam startup.
+ */
+ public static final String NAME =
"org.jboss.seam.deployment.deploymentStrategy";
+
+ /**
+ * The key under which to list extra deployment handlers.
+ *
+ * This can be specified as a System property or in
+ * /META-INF/seam-deployment.properties
+ */
+ public static final String HANDLERS_KEY =
"org.jboss.seam.deployment.deploymentHandlers";
private ComponentDeploymentHandler componentDeploymentHandler;
private NamespaceDeploymentHandler namespaceDeploymentHandler;
@@ -36,6 +55,12 @@
{
return classLoader;
}
+
+ @Override
+ protected String getDeploymentHandlersKey()
+ {
+ return HANDLERS_KEY;
+ }
/**
* Get all scanned and handled annotated components known to this strategy
@@ -67,4 +92,12 @@
getScanner().scanResources(RESOURCE_NAMES);
}
+ public static StandardDeploymentStrategy instance()
+ {
+ if (Contexts.getEventContext().isSet(NAME))
+ {
+ return (StandardDeploymentStrategy) Contexts.getEventContext().get(NAME);
+ }
+ return null;
+ }
}
Modified: trunk/src/main/org/jboss/seam/init/Initialization.java
===================================================================
--- trunk/src/main/org/jboss/seam/init/Initialization.java 2008-01-25 12:54:42 UTC (rev
7231)
+++ trunk/src/main/org/jboss/seam/init/Initialization.java 2008-01-25 12:56:35 UTC (rev
7232)
@@ -5,6 +5,7 @@
*/
package org.jboss.seam.init;
+
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -75,7 +76,7 @@
private Map<String, EventListenerDescriptor> eventListenerDescriptors = new
HashMap<String, EventListenerDescriptor>();
private Collection<String> globalImports = new ArrayList<String>();
- private StandardDeploymentStrategy deploymentStrategy;
+ private StandardDeploymentStrategy standardDeploymentStrategy;
private HotDeploymentStrategy hotDeploymentStrategy;
private Set<String> nonPropertyAttributes = new HashSet<String>();
@@ -98,8 +99,8 @@
public Initialization create()
{
- deploymentStrategy = new
StandardDeploymentStrategy(Thread.currentThread().getContextClassLoader());
- deploymentStrategy.scan();
+ standardDeploymentStrategy = new
StandardDeploymentStrategy(Thread.currentThread().getContextClassLoader());
+ standardDeploymentStrategy.scan();
addNamespaces();
initComponentsFromXmlDocument("/WEB-INF/components.xml");
initComponentsFromXmlDocument("/WEB-INF/events.xml"); //deprecated
@@ -552,7 +553,7 @@
public Initialization init()
{
log.info("initializing Seam");
- if (deploymentStrategy == null)
+ if (standardDeploymentStrategy == null)
{
throw new IllegalStateException("No deployment strategy!");
}
@@ -573,6 +574,14 @@
init.setHotDeployPaths( hotDeploymentStrategy.getHotDeploymentPaths() );
}
addSpecialComponents(init);
+
+ // Make the deployment strategies available in the contexts. This gives
+ // access to custom deployment handlers for processing custom annotations
+ // etc.
+
+ Contexts.getEventContext().set(StandardDeploymentStrategy.NAME,
standardDeploymentStrategy);
+ Contexts.getEventContext().set(HotDeploymentStrategy.NAME, hotDeploymentStrategy);
+
installComponents(init);
for (String globalImport: globalImports)
@@ -647,10 +656,10 @@
private static File getHotDeployDirectory(ServletContext servletContext)
{
- String path =
servletContext.getRealPath(HotDeploymentStrategy.HOT_DEPLOYMENT_DIRECTORY_PATH);
+ String path =
servletContext.getRealPath(HotDeploymentStrategy.DEFAULT_HOT_DEPLOYMENT_DIRECTORY_PATH);
if (path==null) //WebLogic!
{
- log.debug("Could not find path for " +
HotDeploymentStrategy.HOT_DEPLOYMENT_DIRECTORY_PATH);
+ log.debug("Could not find path for " +
HotDeploymentStrategy.DEFAULT_HOT_DEPLOYMENT_DIRECTORY_PATH);
}
else
{
@@ -684,15 +693,15 @@
private void scanForComponents()
{
- for ( Class<Object> scannedClass:
deploymentStrategy.getScannedComponentClasses() )
+ for ( Class<Object> scannedClass:
standardDeploymentStrategy.getScannedComponentClasses() )
{
installScannedComponentAndRoles(scannedClass);
}
- for ( String name: deploymentStrategy.getScannedComponentResources() )
+ for ( String name: standardDeploymentStrategy.getScannedComponentResources() )
{
- installComponentsFromDescriptor( name, deploymentStrategy.getClassLoader() );
+ installComponentsFromDescriptor( name,
standardDeploymentStrategy.getClassLoader() );
}
}
@@ -783,7 +792,7 @@
private void addNamespaces()
{
- for ( Package pkg : deploymentStrategy.getScannedNamespaces() )
+ for ( Package pkg : standardDeploymentStrategy.getScannedNamespaces() )
{
addNamespace(pkg);
}
@@ -871,7 +880,7 @@
{
try
{
- Reflections.classForName("org.jboss.cache.aop.PojoCache");
+ Reflections.classForName("org.jboss.cache.pojo.PojoCache");
addComponentDescriptor( new ComponentDescriptor(PojoCache.class, true) );
}
catch (ClassNotFoundException e) {}