Commits

Anonymous committed 3825610

Changing package load order to have configuration providers first, in order
XW-575

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@1629e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (4)

src/java/com/opensymphony/xwork2/config/ConfigurationManager.java

                 }
             }
             
-            if (packageProviders != null) {
+            if (packageProviders != null && reload) {
                 for (PackageProvider provider : packageProviders) {
                     if (provider.needsReload()) {
                         if (LOG.isInfoEnabled()) {

src/java/com/opensymphony/xwork2/config/impl/DefaultConfiguration.java

         {
             containerProvider.init(this);
             containerProvider.register(builder, props);
-            if (containerProvider instanceof PackageProvider) {
-                builder.factory(PackageProvider.class, containerProvider.toString(), new Factory<PackageProvider>() {
-                    boolean injected = false;
-                    public PackageProvider create(Context context) throws Exception {
-                        if (!injected) {
-                            context.getContainer().inject(containerProvider);
-                            injected = true;
-                        }
-                        return (PackageProvider)containerProvider;
-                    }
-                });
-            }
         }
         props.setConstants(builder);
         
             container = builder.create(false);
             setContext(container);
             objectFactory = container.getInstance(ObjectFactory.class);
+
+            // Process the configuration providers first
+            for (final ContainerProvider containerProvider : providers)
+            {
+                if (containerProvider instanceof PackageProvider) {
+                    container.inject(containerProvider);
+                    ((PackageProvider)containerProvider).loadPackages();
+                    packageProviders.add((PackageProvider)containerProvider);
+                }
+            }
             
+            // Then process any package providers from the plugins
             Set<String> packageProviderNames = container.getInstanceNames(PackageProvider.class);
-            for (String name : packageProviderNames) {
-                PackageProvider provider = container.getInstance(PackageProvider.class, name);
-                
-                // Ensure the init method is only called once in the case of ConfigurationProviders
-                if (!providers.contains(provider)) {
+            if (packageProviderNames != null) {
+                for (String name : packageProviderNames) {
+                    PackageProvider provider = container.getInstance(PackageProvider.class, name);
                     provider.init(this);
+                    provider.loadPackages();
+                    packageProviders.add(provider);
                 }
-                provider.loadPackages();
-                packageProviders.add(provider);
             }
     
             rebuildRuntimeConfiguration();

src/test/com/opensymphony/xwork2/config/ConfigurationManagerTest.java

 
     protected void tearDown() throws Exception {
         configProviderMock.expect("destroy");
+        FileManager.setReloadingConfigs(true);
         super.tearDown();
     }
 }

src/test/com/opensymphony/xwork2/config/ConfigurationTest.java

 import com.opensymphony.xwork2.inject.Scope;
 import com.opensymphony.xwork2.mock.MockInterceptor;
 import com.opensymphony.xwork2.test.StubConfigurationProvider;
+import com.opensymphony.xwork2.util.XWorkTestCaseHelper;
 import com.opensymphony.xwork2.util.location.LocatableProperties;
 
 import java.util.HashMap;
         assertNotNull(configuration.getActionConfig("", MockConfigurationProvider.FOO_ACTION_NAME));
     }
     
-    public void testMultipleContainerProviders() {
+    public void testMultipleContainerProviders() throws Exception {
+        System.out.println("-----");
         Mock mockContainerProvider = new Mock(ContainerProvider.class);
         mockContainerProvider.expect("init", C.ANY_ARGS);
         mockContainerProvider.expect("register", C.ANY_ARGS);
         // check that it has configuration from xml
         assertNotNull(configuration.getActionConfig("/foo/bar", "Bar"));
 
+        System.out.println("-----");
         mockContainerProvider.verify();
     }