Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

XWIKI-7502: Replace notion of Container's ApplicationContext with the…

… notion of Environment
  • Loading branch information...
commit b245d86bea602940589a66a4f0a5545cb3b112e1 1 parent 700cf1d
Vincent Massol authored February 08, 2012

Showing 54 changed files with 385 additions and 298 deletions. Show diff stats Hide diff stats

  1. 6  xwiki-platform-core/xwiki-platform-cache/xwiki-platform-cache-infinispan/pom.xml
  2. 18  ...iki-platform-cache-infinispan/src/main/java/org/xwiki/cache/infinispan/internal/InfinispanCacheFactory.java
  3. 12  ...rm-cache/xwiki-platform-cache-infinispan/src/test/java/org/xwiki/cache/infinispan/InfinispanConfigTest.java
  4. 6  xwiki-platform-core/xwiki-platform-configuration/xwiki-platform-configuration-default/pom.xml
  5. 19  ...atform-configuration-default/src/main/java/org/xwiki/configuration/internal/CommonsConfigurationSource.java
  6. 30  ...onfiguration-default/src/main/java/org/xwiki/configuration/internal/XWikiPropertiesConfigurationSource.java
  7. 33  ...guration-default/src/test/java/org/xwiki/configuration/internal/XWikiPropertiesConfigurationSourceTest.java
  8. 2  ...m-containers/xwiki-platform-container-api/src/main/java/org/xwiki/container/AbstractApplicationContext.java
  9. 5  ...-platform-containers/xwiki-platform-container-api/src/main/java/org/xwiki/container/ApplicationContext.java
  10. 2  ...m-containers/xwiki-platform-container-api/src/main/java/org/xwiki/container/ApplicationContextListener.java
  11. 4  ...iners/xwiki-platform-container-api/src/main/java/org/xwiki/container/ApplicationContextListenerManager.java
  12. 8  ...ore/xwiki-platform-containers/xwiki-platform-container-api/src/main/java/org/xwiki/container/Container.java
  13. 2  ...form-container-api/src/main/java/org/xwiki/container/internal/DefaultApplicationContextListenerManager.java
  14. 13  ...rm-containers/xwiki-platform-container-api/src/main/java/org/xwiki/container/internal/DefaultContainer.java
  15. 4  ...s/xwiki-platform-container-portlet/src/main/java/org/xwiki/container/portlet/PortletApplicationContext.java
  16. 4  ...xwiki-platform-container-portlet/src/main/java/org/xwiki/container/portlet/PortletContainerInitializer.java
  17. 4  ...ontainer-portlet/src/main/java/org/xwiki/container/portlet/internal/DefaultPortletContainerInitializer.java
  18. 5  xwiki-platform-core/xwiki-platform-containers/xwiki-platform-container-servlet/pom.xml
  19. 4  ...s/xwiki-platform-container-servlet/src/main/java/org/xwiki/container/servlet/ServletApplicationContext.java
  20. 6  ...xwiki-platform-container-servlet/src/main/java/org/xwiki/container/servlet/ServletContainerInitializer.java
  21. 21  ...xwiki-platform-container-servlet/src/main/java/org/xwiki/container/servlet/XWikiServletContextListener.java
  22. 4  ...ontainer-servlet/src/main/java/org/xwiki/container/servlet/internal/DefaultServletContainerInitializer.java
  23. 72  ...rm-container-servlet/src/main/java/org/xwiki/container/servlet/internal/LegacyEnvironmentConfiguration.java
  24. 3  ...-core/xwiki-platform-containers/xwiki-platform-container-servlet/src/main/resources/META-INF/components.txt
  25. 4  xwiki-platform-core/xwiki-platform-extension/xwiki-platform-extension-api/pom.xml
  26. 8  ...platform-extension-api/src/main/java/org/xwiki/extension/internal/DefaultExtensionManagerConfiguration.java
  27. 2  ...-extension-api/src/main/java/org/xwiki/extension/repository/internal/DefaultExtensionRepositoryManager.java
  28. 4  ...form-extension-api/src/test/java/org/xwiki/extension/internal/DefaultExtensionManagerConfigurationTest.java
  29. 2  ...ion/xwiki-platform-extension-api/src/test/java/org/xwiki/extension/job/internal/DefaultJobProgressTest.java
  30. 2  ...latform-extension-api/src/test/java/org/xwiki/extension/repository/DefaultLocalExtensionRepositoryTest.java
  31. 2  ...nsion/xwiki-platform-extension-api/src/test/java/org/xwiki/extension/test/AbstractExtensionHandlerTest.java
  32. 11  ...-platform-extension/xwiki-platform-extension-api/src/test/java/org/xwiki/extension/test/RepositoryUtil.java
  33. 2  ...ers/xwiki-platform-extension-handler-xar/src/test/java/org/xwiki/extension/xar/XarExtensionHandlerTest.java
  34. 7  ...platform-extension/xwiki-platform-extension-repositories/xwiki-platform-extension-repository-aether/pom.xml
  35. 11  .../src/main/java/org/xwiki/extension/repository/aether/internal/configuration/DefaultAetherConfiguration.java
  36. 2  ...aether/src/test/java/org/xwiki/extension/repository/aether/internal/AetherDefaultRepositoryManagerTest.java
  37. 4  xwiki-platform-core/xwiki-platform-observation/xwiki-platform-observation-remote/pom.xml
  38. 40  ...m-observation-remote/src/main/java/org/xwiki/observation/remote/internal/jgroups/JGroupsNetworkAdapter.java
  39. 13  xwiki-platform-core/xwiki-platform-office/xwiki-platform-office-viewer/pom.xml
  40. 10  ...ffice/xwiki-platform-office-viewer/src/main/java/org/xwiki/office/viewer/internal/AbstractOfficeViewer.java
  41. 21  ...ce/xwiki-platform-office-viewer/src/test/java/org/xwiki/office/viewer/internal/DefaultOfficeViewerTest.java
  42. 27  xwiki-platform-core/xwiki-platform-oldcore/pom.xml
  43. 7  xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/pdf/impl/PdfExportImpl.java
  44. 8  xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/web/TempResourceAction.java
  45. 17  ...platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/test/AbstractBridgedComponentTestCase.java
  46. 15  ...orm-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/test/AbstractBridgedXWikiComponentTestCase.java
  47. 61  xwiki-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/test/TestApplicationContext.java
  48. 41  xwiki-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/web/TempResourceActionTest.java
  49. 11  xwiki-platform-core/xwiki-platform-velocity/xwiki-platform-velocity-webapp/pom.xml
  50. 22  ...orm-velocity/xwiki-platform-velocity-webapp/src/main/java/org/xwiki/velocity/XWikiWebappResourceLoader.java
  51. 8  ...velocity/xwiki-platform-velocity-webapp/src/test/java/org/xwiki/velocity/XWikiWebappResourceLoaderTest.java
  52. 14  xwiki-platform-tools/xwiki-platform-tool-configuration-resources/src/main/resources/xwiki.properties.vm
  53. 10  xwiki-platform-tools/xwiki-platform-tool-packager-plugin/pom.xml
  54. 10  ...orm-tools/xwiki-platform-tool-packager-plugin/src/main/java/com/xpn/xwiki/tool/backup/AbstractPackager.java
6  xwiki-platform-core/xwiki-platform-cache/xwiki-platform-cache-infinispan/pom.xml
@@ -38,9 +38,9 @@
38 38
       <version>${project.version}</version>
39 39
     </dependency>
40 40
     <dependency>
41  
-      <groupId>org.xwiki.platform</groupId>
42  
-      <artifactId>xwiki-platform-container-api</artifactId>
43  
-      <version>${project.version}</version>
  41
+      <groupId>org.xwiki.commons</groupId>
  42
+      <artifactId>xwiki-commons-environment-api</artifactId>
  43
+      <version>${commons.version}</version>
44 44
     </dependency>
45 45
     <dependency>
46 46
       <groupId>commons-io</groupId>
18  ...-platform-cache-infinispan/src/main/java/org/xwiki/cache/infinispan/internal/InfinispanCacheFactory.java
@@ -44,8 +44,7 @@
44 44
 import org.xwiki.component.manager.ComponentManager;
45 45
 import org.xwiki.component.phase.Initializable;
46 46
 import org.xwiki.component.phase.InitializationException;
47  
-import org.xwiki.container.ApplicationContext;
48  
-import org.xwiki.container.Container;
  47
+import org.xwiki.environment.Environment;
49 48
 
50 49
 /**
51 50
  * Implements {@link org.xwiki.cache.CacheFactory} based on Infinispan.
@@ -76,9 +75,9 @@
76 75
     private ComponentManager componentManager;
77 76
 
78 77
     /**
79  
-     * Optional container used to access configuration files.
  78
+     * Optional Environment used to access configuration files.
80 79
      */
81  
-    private Container container;
  80
+    private Environment environment;
82 81
 
83 82
     /**
84 83
      * Used to create Infinispan caches.
@@ -99,9 +98,9 @@ public void initialize() throws InitializationException
99 98
         // environments when there's no container.
100 99
 
101 100
         try {
102  
-            this.container = this.componentManager.lookup(Container.class);
  101
+            this.environment = this.componentManager.lookup(Environment.class);
103 102
         } catch (ComponentLookupException e) {
104  
-            this.logger.debug("Can't find any Container", e);
  103
+            this.logger.debug("Can't find any Environment", e);
105 104
         }
106 105
 
107 106
         InputStream configurationStream = getConfigurationFileAsStream();
@@ -150,11 +149,8 @@ private InputStream getConfigurationFileAsStream()
150 149
     {
151 150
         InputStream is = null;
152 151
 
153  
-        if (this.container != null) {
154  
-            ApplicationContext applicationContext = this.container.getApplicationContext();
155  
-            if (applicationContext != null) {
156  
-                is = applicationContext.getResourceAsStream(DEFAULT_CONFIGURATION_FILE);
157  
-            }
  152
+        if (this.environment != null) {
  153
+            is = this.environment.getResourceAsStream(DEFAULT_CONFIGURATION_FILE);
158 154
         }
159 155
 
160 156
         return is;
12  ...cache/xwiki-platform-cache-infinispan/src/test/java/org/xwiki/cache/infinispan/InfinispanConfigTest.java
@@ -22,8 +22,7 @@
22 22
 import org.jmock.Expectations;
23 23
 import org.junit.Test;
24 24
 import org.xwiki.cache.tests.AbstractTestCache;
25  
-import org.xwiki.container.ApplicationContext;
26  
-import org.xwiki.container.Container;
  25
+import org.xwiki.environment.Environment;
27 26
 
28 27
 /**
29 28
  * Verify that defining an Infinispan config file is taken into account.
@@ -42,13 +41,10 @@ public InfinispanConfigTest()
42 41
     public void testConfig() throws Exception
43 42
     {
44 43
         // We register a mock Container to verify that getCacheFactory() below will call
45  
-        // Container#getApplicationContext() which will mean that the configuration file is read.
46  
-        final Container mockContainer = registerMockComponent(Container.class);
47  
-        final ApplicationContext mockApplicationContext = getMockery().mock(ApplicationContext.class);
  44
+        // Environment#getResourceAsStream() which will mean that the configuration file is read.
  45
+        final Environment environment = registerMockComponent(Environment.class);
48 46
         getMockery().checking(new Expectations() {{
49  
-            oneOf(mockContainer).getApplicationContext();
50  
-            will(returnValue(mockApplicationContext));
51  
-            oneOf(mockApplicationContext).getResourceAsStream("/WEB-INF/cache/infinispan/config.xml");
  47
+            oneOf(environment).getResourceAsStream("/WEB-INF/cache/infinispan/config.xml");
52 48
             will(returnValue(null));
53 49
         }});
54 50
 
6  xwiki-platform-core/xwiki-platform-configuration/xwiki-platform-configuration-default/pom.xml
@@ -40,9 +40,9 @@
40 40
       <version>${commons.version}</version>
41 41
     </dependency>
42 42
     <dependency>
43  
-      <groupId>org.xwiki.platform</groupId>
44  
-      <artifactId>xwiki-platform-container-api</artifactId>
45  
-      <version>${project.version}</version>
  43
+      <groupId>org.xwiki.commons</groupId>
  44
+      <artifactId>xwiki-commons-environment-api</artifactId>
  45
+      <version>${commons.version}</version>
46 46
     </dependency>
47 47
     <dependency>
48 48
       <groupId>org.xwiki.platform</groupId>
19  ...orm-configuration-default/src/main/java/org/xwiki/configuration/internal/CommonsConfigurationSource.java
@@ -48,6 +48,11 @@
48 48
     @Inject
49 49
     private ConverterManager converterManager;
50 50
 
  51
+    protected Configuration getConfiguration()
  52
+    {
  53
+        return this.configuration;
  54
+    }
  55
+
51 56
     protected void setConfiguration(Configuration configuration)
52 57
     {
53 58
         this.configuration = configuration;
@@ -75,7 +80,7 @@ protected void setConfiguration(Configuration configuration)
75 80
     @SuppressWarnings("unchecked")
76 81
     public <T> T getProperty(String key)
77 82
     {
78  
-        return (T) this.configuration.getProperty(key);
  83
+        return (T) getConfiguration().getProperty(key);
79 84
     }
80 85
 
81 86
     @Override
@@ -86,11 +91,11 @@ protected void setConfiguration(Configuration configuration)
86 91
 
87 92
         try {
88 93
             if (String.class.getName().equals(valueClass.getName())) {
89  
-                result = (T) this.configuration.getString(key);
  94
+                result = (T) getConfiguration().getString(key);
90 95
             } else if (List.class.isAssignableFrom(valueClass)) {
91  
-                result = (T) this.configuration.getList(key);
  96
+                result = (T) getConfiguration().getList(key);
92 97
             } else if (Properties.class.isAssignableFrom(valueClass)) {
93  
-                result = (T) this.configuration.getProperties(key);
  98
+                result = (T) getConfiguration().getProperties(key);
94 99
             } else if (null != getProperty(key)) {
95 100
                 result = (T) this.converterManager.convert(valueClass, getProperty(key));
96 101
             }
@@ -109,7 +114,7 @@ protected void setConfiguration(Configuration configuration)
109 114
     public List<String> getKeys()
110 115
     {
111 116
         List<String> keysList = new ArrayList<String>();
112  
-        Iterator<String> keys = (Iterator<String>) this.configuration.getKeys();
  117
+        Iterator<String> keys = (Iterator<String>) getConfiguration().getKeys();
113 118
         while (keys.hasNext()) {
114 119
             keysList.add(keys.next());
115 120
         }
@@ -120,12 +125,12 @@ protected void setConfiguration(Configuration configuration)
120 125
     @Override
121 126
     public boolean containsKey(String key)
122 127
     {
123  
-        return this.configuration.containsKey(key);
  128
+        return getConfiguration().containsKey(key);
124 129
     }
125 130
 
126 131
     @Override
127 132
     public boolean isEmpty()
128 133
     {
129  
-        return this.configuration.isEmpty();
  134
+        return getConfiguration().isEmpty();
130 135
     }
131 136
 }
30  ...iguration-default/src/main/java/org/xwiki/configuration/internal/XWikiPropertiesConfigurationSource.java
@@ -31,7 +31,7 @@
31 31
 import org.xwiki.component.annotation.Component;
32 32
 import org.xwiki.component.phase.Initializable;
33 33
 import org.xwiki.component.phase.InitializationException;
34  
-import org.xwiki.container.Container;
  34
+import org.xwiki.environment.Environment;
35 35
 
36 36
 /**
37 37
  * Looks for configuration data in {@code /WEB-INF/xwiki.properties}.
@@ -47,10 +47,10 @@
47 47
     private static final String XWIKI_PROPERTIES_FILE = "/WEB-INF/xwiki.properties";
48 48
 
49 49
     /**
50  
-     * Injected by the Component Manager.
  50
+     * the Environment from where to get the XWiki properties file.
51 51
      */
52 52
     @Inject
53  
-    private Container container;
  53
+    private Environment environment;
54 54
 
55 55
     /**
56 56
      * The logger to log.
@@ -63,27 +63,27 @@ public void initialize() throws InitializationException
63 63
     {
64 64
         // Register the Commons Properties Configuration, looking for a xwiki.properties file
65 65
         // in the XWiki path somewhere.
66  
-        URL xwikiPropertiesUrl;
  66
+        URL xwikiPropertiesUrl = null;
67 67
         try {
68  
-            xwikiPropertiesUrl = this.container.getApplicationContext().getResource(XWIKI_PROPERTIES_FILE);
  68
+            xwikiPropertiesUrl = this.environment.getResource(XWIKI_PROPERTIES_FILE);
69 69
             if (xwikiPropertiesUrl != null) {
70 70
                 setConfiguration(new PropertiesConfiguration(xwikiPropertiesUrl));
71  
-            } else if (this.logger.isDebugEnabled()) {
  71
+            } else {
72 72
                 // We use a debug logging level here since we consider it's ok that there's no XWIKI_PROPERTIES_FILE
73 73
                 // available, in which case default values are used.
74  
-                this.logger.debug("No configuration file [" + XWIKI_PROPERTIES_FILE + "] found. "
75  
-                    + "Using default configuration values.");
76  
-
77  
-                // Use a default Commons Configuration implementation since we couldn't use a Properties configuration.
78  
-                setConfiguration(new BaseConfiguration());
  74
+                this.logger.debug("No configuration file [{}] found. Using default configuration values.",
  75
+                    XWIKI_PROPERTIES_FILE);
79 76
             }
80 77
         } catch (Exception e) {
81  
-            // Note: if we cannot read the configuration file for any reasonwe log a warning but continue since XWiki
  78
+            // Note: if we cannot read the configuration file for any reason we log a warning but continue since XWiki
82 79
             // will use default values for all configurable elements.
83  
-            this.logger.warn("Failed to load configuration file [" + XWIKI_PROPERTIES_FILE
84  
-                + "]. Using default configuration values. " + " Internal error [" + e.getMessage() + "]");
  80
+            this.logger.warn("Failed to load configuration file [{}]. Using default configuration values. "
  81
+                + "Internal error [{}]", XWIKI_PROPERTIES_FILE, e.getMessage());
  82
+        }
85 83
 
86  
-            // Use a default Commons Configuration implementation since we couldn't use a Properties configuration.
  84
+        // If no Commons Properties Configuration has been set, use a default empty Commons Configuration
  85
+        // implementation.
  86
+        if (xwikiPropertiesUrl == null) {
87 87
             setConfiguration(new BaseConfiguration());
88 88
         }
89 89
     }
33  ...ation-default/src/test/java/org/xwiki/configuration/internal/XWikiPropertiesConfigurationSourceTest.java
@@ -24,8 +24,7 @@
24 24
 import org.junit.Test;
25 25
 import org.slf4j.Logger;
26 26
 import org.xwiki.component.util.ReflectionUtils;
27  
-import org.xwiki.container.ApplicationContext;
28  
-import org.xwiki.container.Container;
  27
+import org.xwiki.environment.Environment;
29 28
 import org.xwiki.test.AbstractComponentTestCase;
30 29
 
31 30
 /**
@@ -46,46 +45,32 @@ public void setUp() throws Exception
46 45
     {
47 46
         super.setUp();
48 47
 
49  
-        final ApplicationContext appContext = getMockery().mock(ApplicationContext.class);
  48
+        final Environment environment = getMockery().mock(Environment.class);
50 49
         getMockery().checking(new Expectations() {{
51  
-            oneOf(appContext).getResource("/WEB-INF/xwiki.properties");
  50
+            oneOf(environment).getResource("/WEB-INF/xwiki.properties");
52 51
             will(returnValue(null));
53 52
         }});
54 53
 
55  
-        Container container = getComponentManager().lookup(Container.class);
56  
-        container.setApplicationContext(appContext);
57  
-
58 54
         // Set a mock Logger to capture all log outputs and perform verifications
59 55
         this.logger = getMockery().mock(Logger.class);
60 56
 
61 57
         this.source = new XWikiPropertiesConfigurationSource();
62  
-        ReflectionUtils.setFieldValue(this.source, "container", container);
  58
+        ReflectionUtils.setFieldValue(this.source, "environment", environment);
63 59
         ReflectionUtils.setFieldValue(this.source, "logger", this.logger);
64 60
     }
65 61
 
66 62
     @Test
67  
-    public void testInitializeWhenNoPropertiesFileAndDebugEnabled() throws Exception
  63
+    public void testInitializeWhenNoPropertiesFile() throws Exception
68 64
     {
69 65
         getMockery().checking(new Expectations() {{
70  
-            oneOf(logger).isDebugEnabled();
71  
-            will(returnValue(true));
72 66
             // This is the test
73  
-            oneOf(logger).debug("No configuration file [/WEB-INF/xwiki.properties] found. "
74  
-                + "Using default configuration values.");
  67
+            oneOf(logger).debug("No configuration file [{}] found. Using default configuration values.",
  68
+                "/WEB-INF/xwiki.properties");
75 69
         }});
76 70
 
77 71
         this.source.initialize();
78  
-    }
79  
-
80  
-    @Test
81  
-    public void testInitializeWhenNoPropertiesFileAndDebugNotEnabled() throws Exception
82  
-    {
83  
-        getMockery().checking(new Expectations() {{
84  
-            oneOf(logger).isDebugEnabled();
85  
-            will(returnValue(false));
86  
-            // This is the test. It shows nothing is logged when the properties file is not available.
87  
-        }});
88 72
 
89  
-        this.source.initialize();
  73
+        // Verifies that we can get a property from the source (i.e. that it's correctly initialized)
  74
+        this.source.getProperty("key");
90 75
     }
91 76
 }
2  ...ontainers/xwiki-platform-container-api/src/main/java/org/xwiki/container/AbstractApplicationContext.java
@@ -31,7 +31,9 @@
31 31
  * Base class for {@link ApplicationContext} implementations.
32 32
  * 
33 33
  * @version $Id$
  34
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
34 35
  */
  36
+@Deprecated
35 37
 public abstract class AbstractApplicationContext implements ApplicationContext
36 38
 {
37 39
     /**
5  ...atform-containers/xwiki-platform-container-api/src/main/java/org/xwiki/container/ApplicationContext.java
@@ -24,6 +24,11 @@
24 24
 import java.net.MalformedURLException;
25 25
 import java.net.URL;
26 26
 
  27
+/**
  28
+ * @version $Id$
  29
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
  30
+ */
  31
+@Deprecated
27 32
 public interface ApplicationContext
28 33
 {
29 34
     InputStream getResourceAsStream(String resourceName);
2  ...ontainers/xwiki-platform-container-api/src/main/java/org/xwiki/container/ApplicationContextListener.java
@@ -27,8 +27,10 @@
27 27
  * 
28 28
  * @version $Id$
29 29
  * @since 1.9M2
  30
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
30 31
  */
31 32
 @ComponentRole
  33
+@Deprecated
32 34
 public interface ApplicationContextListener
33 35
 {
34 36
     /**
4  ...rs/xwiki-platform-container-api/src/main/java/org/xwiki/container/ApplicationContextListenerManager.java
@@ -26,8 +26,10 @@
26 26
  * 
27 27
  * @version $Id$
28 28
  * @since 1.9M2
  29
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
29 30
  */
30 31
 @ComponentRole
  32
+@Deprecated
31 33
 public interface ApplicationContextListenerManager
32 34
 {
33 35
     /**
@@ -35,6 +37,7 @@
35 37
      * 
36 38
      * @param applicationContext the {@link ApplicationContext}.
37 39
      */
  40
+    @Deprecated
38 41
     void initializeApplicationContext(ApplicationContext applicationContext);
39 42
     
40 43
     /**
@@ -42,5 +45,6 @@
42 45
      * 
43 46
      * @param applicationContext the {@link ApplicationContext}.
44 47
      */
  48
+    @Deprecated
45 49
     void destroyApplicationContext(ApplicationContext applicationContext);
46 50
 }
8  .../xwiki-platform-containers/xwiki-platform-container-api/src/main/java/org/xwiki/container/Container.java
@@ -24,8 +24,16 @@
24 24
 @ComponentRole
25 25
 public interface Container
26 26
 {
  27
+    /**
  28
+     * @deprecated starting with 3.5M1, use the notion of Environment instead
  29
+     */
  30
+    @Deprecated
27 31
     ApplicationContext getApplicationContext();
28 32
 
  33
+    /**
  34
+     * @deprecated starting with 3.5M1, use the notion of Environment instead
  35
+     */
  36
+    @Deprecated
29 37
     void setApplicationContext(ApplicationContext context);
30 38
     
31 39
     Request getRequest();
2  ...m-container-api/src/main/java/org/xwiki/container/internal/DefaultApplicationContextListenerManager.java
@@ -37,9 +37,11 @@
37 37
  * 
38 38
  * @version $Id$
39 39
  * @since 1.9M2
  40
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
40 41
  */
41 42
 @Component
42 43
 @Singleton
  44
+@Deprecated
43 45
 public class DefaultApplicationContextListenerManager implements ApplicationContextListenerManager
44 46
 {
45 47
     /**
13  ...containers/xwiki-platform-container-api/src/main/java/org/xwiki/container/internal/DefaultContainer.java
@@ -37,11 +37,20 @@
37 37
 @Component
38 38
 public class DefaultContainer implements Container
39 39
 {
  40
+    /**
  41
+     * @deprecated starting with 3.5M1, use the notion of Environment instead
  42
+     */
  43
+    @Deprecated
40 44
     private ApplicationContext applicationContext;
  45
+
41 46
     private ThreadLocal<Stack<Request>> request = new ThreadLocal<Stack<Request>>();
42 47
     private ThreadLocal<Stack<Response>> response = new ThreadLocal<Stack<Response>>();
43 48
     private ThreadLocal<Stack<Session>> session = new ThreadLocal<Stack<Session>>();
44 49
 
  50
+    /**
  51
+     * @deprecated starting with 3.5M1, use the notion of Environment instead
  52
+     */
  53
+    @Deprecated
45 54
     public ApplicationContext getApplicationContext()
46 55
     {
47 56
         return this.applicationContext;
@@ -125,6 +134,10 @@ public void popSession()
125 134
         }
126 135
     }
127 136
 
  137
+    /**
  138
+     * @deprecated starting with 3.5M1, use the notion of Environment instead
  139
+     */
  140
+    @Deprecated
128 141
     public void setApplicationContext(ApplicationContext context)
129 142
     {
130 143
         this.applicationContext = context;
4  ...wiki-platform-container-portlet/src/main/java/org/xwiki/container/portlet/PortletApplicationContext.java
@@ -29,6 +29,10 @@
29 29
 import org.xwiki.component.manager.ComponentManager;
30 30
 import org.xwiki.container.AbstractApplicationContext;
31 31
 
  32
+/**
  33
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
  34
+ */
  35
+@Deprecated
32 36
 public class PortletApplicationContext extends AbstractApplicationContext
33 37
 {
34 38
     private PortletContext portletContext;
4  ...ki-platform-container-portlet/src/main/java/org/xwiki/container/portlet/PortletContainerInitializer.java
@@ -33,5 +33,9 @@ void initializeRequest(javax.portlet.PortletRequest request, Object xwikiContext
33 33
 
34 34
     void initializeSession(javax.portlet.PortletRequest request);
35 35
 
  36
+    /**
  37
+     * @deprecated starting with 3.5M1, use the notion of Environment instead
  38
+     */
  39
+    @Deprecated
36 40
     void initializeApplicationContext(PortletContext servletContext);
37 41
 }
4  ...ainer-portlet/src/main/java/org/xwiki/container/portlet/internal/DefaultPortletContainerInitializer.java
@@ -63,6 +63,10 @@
63 63
     @Inject
64 64
     private ComponentManager componentManager;
65 65
 
  66
+    /**
  67
+     * @deprecated starting with 3.5M1, use the notion of Environment instead
  68
+     */
  69
+    @Deprecated
66 70
     @Override
67 71
     public void initializeApplicationContext(PortletContext portletContext)
68 72
     {
5  xwiki-platform-core/xwiki-platform-containers/xwiki-platform-container-servlet/pom.xml
@@ -50,6 +50,11 @@
50 50
       <version>${commons.version}</version>
51 51
     </dependency>
52 52
     <dependency>
  53
+      <groupId>org.xwiki.commons</groupId>
  54
+      <artifactId>xwiki-commons-environment-servlet</artifactId>
  55
+      <version>${commons.version}</version>
  56
+    </dependency>
  57
+    <dependency>
53 58
       <groupId>org.xwiki.platform</groupId>
54 59
       <artifactId>xwiki-platform-action</artifactId>
55 60
       <version>${project.version}</version>
4  ...wiki-platform-container-servlet/src/main/java/org/xwiki/container/servlet/ServletApplicationContext.java
@@ -31,6 +31,10 @@
31 31
 import org.xwiki.component.manager.ComponentManager;
32 32
 import org.xwiki.container.AbstractApplicationContext;
33 33
 
  34
+/**
  35
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
  36
+ */
  37
+@Deprecated
34 38
 public class ServletApplicationContext extends AbstractApplicationContext
35 39
 {
36 40
     /**
6  ...ki-platform-container-servlet/src/main/java/org/xwiki/container/servlet/ServletContainerInitializer.java
@@ -37,6 +37,10 @@ void initializeRequest(HttpServletRequest request)
37 37
     void initializeResponse(HttpServletResponse response);
38 38
     
39 39
     void initializeSession(HttpServletRequest request);
40  
-    
  40
+
  41
+    /**
  42
+     * @deprecated starting with 3.5M1, use the notion of Environment instead
  43
+     */
  44
+    @Deprecated
41 45
     void initializeApplicationContext(ServletContext servletContext);
42 46
 }
21  ...ki-platform-container-servlet/src/main/java/org/xwiki/container/servlet/XWikiServletContextListener.java
@@ -28,6 +28,8 @@
28 28
 import org.xwiki.component.manager.ComponentManager;
29 29
 import org.xwiki.container.ApplicationContextListenerManager;
30 30
 import org.xwiki.container.Container;
  31
+import org.xwiki.environment.Environment;
  32
+import org.xwiki.environment.internal.ServletEnvironment;
31 33
 import org.xwiki.observation.ObservationManager;
32 34
 import org.xwiki.observation.event.ApplicationStartedEvent;
33 35
 import org.xwiki.observation.event.ApplicationStoppedEvent;
@@ -57,7 +59,20 @@ public void contextInitialized(ServletContextEvent servletContextEvent)
57 59
         StackingComponentEventManager eventManager = new StackingComponentEventManager();
58 60
         this.componentManager.setComponentEventManager(eventManager);
59 61
 
60  
-        // Initializes XWiki's Container with the Servlet Context.
  62
+        // Initialize the Environment
  63
+        try {
  64
+            ServletEnvironment servletEnvironment =
  65
+                (ServletEnvironment) this.componentManager.lookup(Environment.class);
  66
+            servletEnvironment.setServletContext(servletContextEvent.getServletContext());
  67
+        } catch (ComponentLookupException e) {
  68
+            throw new RuntimeException("Failed to initialize the Servlet Environment", e);
  69
+        }
  70
+
  71
+        // Initializes the Application Context.
  72
+        // Even though the notion of ApplicationContext has been deprecated in favor of the notion of Environment we
  73
+        // still keep this initialization for backward-compatibility.
  74
+        // TODO: Add an Observation Even that we send when the Environment is initialized so that we can move the code
  75
+        // below in an Event Listener and move it to the legacy module.
61 76
         try {
62 77
             ServletContainerInitializer containerInitializer =
63 78
                 this.componentManager.lookup(ServletContainerInitializer.class);
@@ -106,6 +121,10 @@ public void contextDestroyed(ServletContextEvent sce)
106 121
             // TODO: Log a warning
107 122
         }
108 123
 
  124
+        // Even though the notion of ApplicationContext has been deprecated in favor of the notion of Environment we
  125
+        // still keep this destruction for backward-compatibility.
  126
+        // TODO: Add an Observation Even that we send when the Environment is destroyed so that we can move the code
  127
+        // below in an Event Listener and move it to the legacy module.
109 128
         try {
110 129
             ApplicationContextListenerManager applicationContextListenerManager =
111 130
                 this.componentManager.lookup(ApplicationContextListenerManager.class);
4  ...ainer-servlet/src/main/java/org/xwiki/container/servlet/internal/DefaultServletContainerInitializer.java
@@ -80,6 +80,10 @@
80 80
     @Inject
81 81
     private Logger logger;
82 82
 
  83
+    /**
  84
+     * @deprecated starting with 3.5M1, use the notion of Environment instead
  85
+     */
  86
+    @Deprecated
83 87
     @Override
84 88
     public void initializeApplicationContext(ServletContext servletContext)
85 89
     {
72  ...container-servlet/src/main/java/org/xwiki/container/servlet/internal/LegacyEnvironmentConfiguration.java
... ...
@@ -0,0 +1,72 @@
  1
+/*
  2
+ * See the NOTICE file distributed with this work for additional
  3
+ * information regarding copyright ownership.
  4
+ *
  5
+ * This is free software; you can redistribute it and/or modify it
  6
+ * under the terms of the GNU Lesser General Public License as
  7
+ * published by the Free Software Foundation; either version 2.1 of
  8
+ * the License, or (at your option) any later version.
  9
+ *
  10
+ * This software is distributed in the hope that it will be useful,
  11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13
+ * Lesser General Public License for more details.
  14
+ *
  15
+ * You should have received a copy of the GNU Lesser General Public
  16
+ * License along with this software; if not, write to the Free
  17
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  18
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  19
+ */
  20
+package org.xwiki.container.servlet.internal;
  21
+
  22
+import java.io.File;
  23
+
  24
+import javax.inject.Inject;
  25
+import javax.inject.Singleton;
  26
+
  27
+import org.slf4j.Logger;
  28
+import org.xwiki.component.annotation.Component;
  29
+import org.xwiki.environment.internal.DefaultEnvironmentConfiguration;
  30
+
  31
+/**
  32
+ * Overrides the {@link DefaultEnvironmentConfiguration} component in order to take into account the deprecated
  33
+ * permanent directory configuration property "container.persistentDirectory" and use it if the newer
  34
+ * "environment.permanentDirectory" property isn't set.
  35
+ *
  36
+ * @version $Id$
  37
+ * @since 3.5M1
  38
+ * @deprecated starting with 3.5M1 use the "environment.permanentDirectory" property instead
  39
+ */
  40
+@Component
  41
+@Singleton
  42
+@Deprecated
  43
+public class LegacyEnvironmentConfiguration extends DefaultEnvironmentConfiguration
  44
+{
  45
+    /**
  46
+     * The name of the property for configuring the permanent directory.
  47
+     */
  48
+    private static final String PROPERTY_DEPRECATED_PERMANENTDIRECTORY = "container.persistentDirectory";
  49
+
  50
+    /**
  51
+     * The logger to log.
  52
+     */
  53
+    @Inject
  54
+    private Logger logger;
  55
+
  56
+    @Override
  57
+    public File getPermanentDirectory()
  58
+    {
  59
+        File directory = super.getPermanentDirectory();
  60
+        if (directory == null) {
  61
+            // Fallback to the old deprecated permanent directory configuration property
  62
+            directory = initializeDirectory(
  63
+                getConfigurationSource().getProperty(PROPERTY_DEPRECATED_PERMANENTDIRECTORY, String.class));
  64
+            // Display a warning to the user so that he upgrades
  65
+            if (directory != null) {
  66
+                this.logger.warn("You're using the deprecated [{}] configuration property. You should instead use the "
  67
+                    + "newer [{}] one", PROPERTY_DEPRECATED_PERMANENTDIRECTORY, "environment.permanentDirectory");
  68
+            }
  69
+        }
  70
+        return directory;
  71
+    }
  72
+}
3  ...re/xwiki-platform-containers/xwiki-platform-container-servlet/src/main/resources/META-INF/components.txt
... ...
@@ -1 +1,2 @@
1  
-org.xwiki.container.servlet.internal.DefaultServletContainerInitializer
  1
+org.xwiki.container.servlet.internal.DefaultServletContainerInitializer
  2
+900:org.xwiki.container.servlet.internal.LegacyEnvironmentConfiguration
4  xwiki-platform-core/xwiki-platform-extension/xwiki-platform-extension-api/pom.xml
@@ -70,8 +70,8 @@
70 70
       <version>${rendering.version}</version>
71 71
     </dependency>
72 72
     <dependency>
73  
-      <groupId>org.xwiki.platform</groupId>
74  
-      <artifactId>xwiki-platform-container-api</artifactId>
  73
+      <groupId>org.xwiki.commons</groupId>
  74
+      <artifactId>xwiki-commons-environment-api</artifactId>
75 75
       <version>${project.version}</version>
76 76
     </dependency>
77 77
     <dependency>
8  ...tform-extension-api/src/main/java/org/xwiki/extension/internal/DefaultExtensionManagerConfiguration.java
@@ -37,7 +37,7 @@
37 37
 import org.slf4j.Logger;
38 38
 import org.xwiki.component.annotation.Component;
39 39
 import org.xwiki.configuration.ConfigurationSource;
40  
-import org.xwiki.container.Container;
  40
+import org.xwiki.environment.Environment;
41 41
 import org.xwiki.extension.ExtensionManagerConfiguration;
42 42
 import org.xwiki.extension.repository.ExtensionRepositoryId;
43 43
 
@@ -67,10 +67,10 @@
67 67
     private Logger logger;
68 68
 
69 69
     /**
70  
-     * Used to get work directory.
  70
+     * Used to get permanent directory.
71 71
      */
72 72
     @Inject
73  
-    private Container container;
  73
+    private Environment environment;
74 74
 
75 75
     /**
76 76
      * The configuration.
@@ -91,7 +91,7 @@
91 91
      */
92 92
     public File getHome()
93 93
     {
94  
-        return new File(this.container.getApplicationContext().getPermanentDirectory(), "extension/");
  94
+        return new File(this.environment.getPermanentDirectory(), "extension/");
95 95
     }
96 96
 
97 97
     @Override
2  ...tension-api/src/main/java/org/xwiki/extension/repository/internal/DefaultExtensionRepositoryManager.java
@@ -112,7 +112,7 @@ public ExtensionRepository addRepository(ExtensionRepositoryId repositoryId) thr
112 112
 
113 113
             addRepository(repository);
114 114
         } catch (ComponentLookupException e) {
115  
-            throw new ExtensionRepositoryException("Unsupported repository type[" + repositoryId.getType() + "]", e);
  115
+            throw new ExtensionRepositoryException("Unsupported repository type [" + repositoryId.getType() + "]", e);
116 116
         }
117 117
 
118 118
         return repository;
4  ...m-extension-api/src/test/java/org/xwiki/extension/internal/DefaultExtensionManagerConfigurationTest.java
@@ -26,6 +26,7 @@
26 26
 import junit.framework.Assert;
27 27
 
28 28
 import org.junit.Test;
  29
+import org.xwiki.environment.Environment;
29 30
 import org.xwiki.extension.ExtensionManagerConfiguration;
30 31
 import org.xwiki.extension.repository.ExtensionRepositoryId;
31 32
 import org.xwiki.test.AbstractComponentTestCase;
@@ -39,6 +40,9 @@ public void setUp() throws Exception
39 40
     {
40 41
         super.setUp();
41 42
 
  43
+        // Register a Mocked Environment since we need to provide one.
  44
+        registerMockComponent(Environment.class);
  45
+        
42 46
         this.configuration = getComponentManager().lookup(ExtensionManagerConfiguration.class);
43 47
     }
44 48
 
2  .../xwiki-platform-extension-api/src/test/java/org/xwiki/extension/job/internal/DefaultJobProgressTest.java
@@ -43,7 +43,7 @@ public void setUp() throws Exception
43 43
         super.setUp();
44 44
         this.repositoryUtil =
45 45
             new RepositoryUtil(getClass().getSimpleName(), getConfigurationSource(), getComponentManager());
46  
-        this.repositoryUtil.setup();
  46
+        this.repositoryUtil.setup(getMockery());
47 47
 
48 48
         this.observation = getComponentManager().lookup(ObservationManager.class);
49 49
         this.progress = new DefaultJobProgress("id");
2  ...form-extension-api/src/test/java/org/xwiki/extension/repository/DefaultLocalExtensionRepositoryTest.java
@@ -58,7 +58,7 @@ public void setUp() throws Exception
58 58
 
59 59
         this.repositoryUtil =
60 60
             new RepositoryUtil(getClass().getSimpleName(), getConfigurationSource(), getComponentManager());
61  
-        this.repositoryUtil.setup();
  61
+        this.repositoryUtil.setup(getMockery());
62 62
 
63 63
         // lookup
64 64
 
2  ...on/xwiki-platform-extension-api/src/test/java/org/xwiki/extension/test/AbstractExtensionHandlerTest.java
@@ -54,7 +54,7 @@ public void setUp() throws Exception
54 54
 
55 55
         this.repositoryUtil =
56 56
             new RepositoryUtil(getClass().getSimpleName(), getConfigurationSource(), getComponentManager());
57  
-        this.repositoryUtil.setup();
  57
+        this.repositoryUtil.setup(getMockery());
58 58
 
59 59
         // lookup
60 60
 
11  ...atform-extension/xwiki-platform-extension-api/src/test/java/org/xwiki/extension/test/RepositoryUtil.java
@@ -28,6 +28,7 @@
28 28
 import java.util.regex.Pattern;
29 29
 
30 30
 import org.apache.commons.io.FileUtils;
  31
+import org.jmock.Mockery;
31 32
 import org.reflections.Reflections;
32 33
 import org.reflections.scanners.ResourcesScanner;
33 34
 import org.reflections.util.ClasspathHelper;
@@ -35,7 +36,9 @@
35 36
 import org.reflections.util.FilterBuilder;
36 37
 import org.xwiki.component.annotation.ComponentAnnotationLoader;
37 38
 import org.xwiki.component.descriptor.ComponentDescriptor;
  39
+import org.xwiki.component.descriptor.DefaultComponentDescriptor;
38 40
 import org.xwiki.component.manager.ComponentManager;
  41
+import org.xwiki.environment.Environment;
39 42
 import org.xwiki.extension.handler.ExtensionInitializer;
40 43
 import org.xwiki.extension.repository.CoreExtensionRepository;
41 44
 import org.xwiki.extension.repository.ExtensionRepositoryId;
@@ -123,10 +126,16 @@ public String getRemoteRepositoryId()
123 126
         return MAVENREPOSITORY_ID;
124 127
     }
125 128
 
126  
-    public void setup() throws Exception
  129
+    public void setup(Mockery mockery) throws Exception
127 130
     {
128 131
         clean();
129 132
 
  133
+        // Mock Environment
  134
+        Environment environment = mockery.mock(Environment.class);
  135
+        DefaultComponentDescriptor<Environment> dcd = new DefaultComponentDescriptor<Environment>();
  136
+        dcd.setRole(Environment.class);
  137
+        this.componentManager.registerComponent(dcd, environment);
  138
+
130 139
         // disable default configuration
131 140
         // TODO: probably mean that this default configuration should not be at this level
132 141