You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2007/10/12 16:27:53 UTC

svn commit: r584167 - in /tapestry/tapestry5/trunk/tapestry-ioc/src: main/java/org/apache/tapestry/ioc/IOCUtilities.java site/apt/run.apt test/java/org/apache/tapestry/ioc/RegistryBuilderTest.java

Author: hlship
Date: Fri Oct 12 07:27:46 2007
New Revision: 584167

URL: http://svn.apache.org/viewvc?rev=584167&view=rev
Log:
TAPESTRY-1786: Add JVM system property for adding modules to the IoC container

Modified:
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/IOCUtilities.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/site/apt/run.apt
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/RegistryBuilderTest.java

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/IOCUtilities.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/IOCUtilities.java?rev=584167&r1=584166&r2=584167&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/IOCUtilities.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/IOCUtilities.java Fri Oct 12 07:27:46 2007
@@ -23,6 +23,8 @@
 import java.util.Enumeration;
 import java.util.jar.Manifest;
 
+import org.apache.tapestry.ioc.annotations.SubModule;
+
 /**
  * A collection of utility methods for a couple of different areas, including creating the initial
  * {@link org.apache.tapestry.ioc.Registry}.
@@ -34,10 +36,12 @@
     }
 
     /**
-     * Construct a default registry, including modules identify via the Tapestry-Module-Classes
-     * Manifest entry.
+     * Construct a default Registry, including modules identifed via the Tapestry-Module-Classes
+     * Manifest entry. The registry will have been
+     * {@linkplain Registry#performRegistryStartup() started up} before it is returned.
      * 
-     * @return constructed Registry, after eager loading of services
+     * @return constructed Registry, after startup
+     * @see #addDefaultModules(RegistryBuilder)
      */
     public static Registry buildDefaultRegistry()
     {
@@ -54,10 +58,14 @@
 
     /**
      * Scans the classpath for JAR Manifests that contain the Tapestry-Module-Classes attribute and
-     * adds each corresponding class to the RegistryBuilder.
+     * adds each corresponding class to the RegistryBuilder. In addition, looks for a system
+     * property named "tapestry.modules" and adds all of those modules as well. The tapestry.modules
+     * approach is intended for development.
      * 
      * @param builder
      *            the builder to which modules will be added
+     * @see SubModule
+     * @see RegistryBuilder#add(String)
      */
     public static void addDefaultModules(RegistryBuilder builder)
     {
@@ -71,6 +79,9 @@
 
                 addModulesInManifest(builder, url);
             }
+
+            addModulesInList(builder, System.getProperty("tapestry.modules"));
+
         }
         catch (Exception ex)
         {
@@ -92,7 +103,9 @@
 
             in = null;
 
-            addModulesInManifest(builder, mf);
+            String list = mf.getMainAttributes().getValue(MODULE_BUILDER_MANIFEST_ENTRY_NAME);
+
+            addModulesInList(builder, list);
         }
         finally
         {
@@ -100,10 +113,8 @@
         }
     }
 
-    static void addModulesInManifest(RegistryBuilder builder, Manifest mf)
+    static void addModulesInList(RegistryBuilder builder, String list)
     {
-        String list = mf.getMainAttributes().getValue(MODULE_BUILDER_MANIFEST_ENTRY_NAME);
-
         if (list == null) return;
 
         String[] classnames = list.split(",");

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/site/apt/run.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/site/apt/run.apt?rev=584167&r1=584166&r2=584167&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/site/apt/run.apt (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/site/apt/run.apt Fri Oct 12 07:27:46 2007
@@ -26,7 +26,7 @@
 
 Registry registry = builder.build();
 
-registry.eagerLoadServices();
+registry.performRegistryStartup();
 +---+
 
   You may invoke add() as many times as you wish, or pass as many module classes
@@ -37,7 +37,7 @@
   {{{../apidocs/org/apache/tapestry/ioc/services/TapestryIoCModule.html}Tapestry IoC module}}, plus
   the modules you explicitly list.
   
-  The call to eagerLoadServices() is necessary to ensure that any services marked with the
+  The call to performRegistryStartup() is necessary to ensure that any services marked with the
   {{{../apidocs/org/apache/tapestry/ioc/annotations/EagerLoad.html}EagerLoad}} annotation are, in fact,
   loaded.
   
@@ -48,6 +48,11 @@
   This method builds a Registry using
   {{{module.html#Autoloading modules}autoloading logic}}, where modules to load
   are identified via a JAR Manifest entry.
+  
+  In addition, the JVM system property <<<tapestry.modules>>> (if specified) is a list of additional
+  module classes to load.  This is often used in development, where tests may be executed against
+  the local classes, not JARs, and so there no manifest to read.
+  
   
 Shutting down the Registry
 

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/RegistryBuilderTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/RegistryBuilderTest.java?rev=584167&r1=584166&r2=584167&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/RegistryBuilderTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/RegistryBuilderTest.java Fri Oct 12 07:27:46 2007
@@ -16,7 +16,6 @@
 
 import java.util.Arrays;
 import java.util.List;
-import java.util.jar.Manifest;
 
 import org.apache.tapestry.ioc.test.IOCTestCase;
 import org.testng.annotations.Test;
@@ -50,13 +49,7 @@
         String value = String.format("%s, %s, %s", FredModule.class.getName(), BarneyModule.class
                 .getName(), RegistryBuilderTestModule.class.getName());
 
-        Manifest mf = new Manifest();
-
-        mf.getMainAttributes().putValue(IOCConstants.MODULE_BUILDER_MANIFEST_ENTRY_NAME, value);
-
-        // A package private method. Add in the two modules as if they were listed in the manifest.
-
-        IOCUtilities.addModulesInManifest(builder, mf);
+        IOCUtilities.addModulesInList(builder, value);
 
         Registry registry = builder.build();