Permalink
Browse files

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

… notion of Environment
  • Loading branch information...
1 parent 700cf1d commit b245d86bea602940589a66a4f0a5545cb3b112e1 @vmassol vmassol committed Feb 8, 2012
Showing with 385 additions and 298 deletions.
  1. +3 −3 xwiki-platform-core/xwiki-platform-cache/xwiki-platform-cache-infinispan/pom.xml
  2. +7 −11 ...rm-cache-infinispan/src/main/java/org/xwiki/cache/infinispan/internal/InfinispanCacheFactory.java
  3. +4 −8 ...wiki-platform-cache-infinispan/src/test/java/org/xwiki/cache/infinispan/InfinispanConfigTest.java
  4. +3 −3 xwiki-platform-core/xwiki-platform-configuration/xwiki-platform-configuration-default/pom.xml
  5. +12 −7 ...figuration-default/src/main/java/org/xwiki/configuration/internal/CommonsConfigurationSource.java
  6. +15 −15 ...on-default/src/main/java/org/xwiki/configuration/internal/XWikiPropertiesConfigurationSource.java
  7. +9 −24 ...efault/src/test/java/org/xwiki/configuration/internal/XWikiPropertiesConfigurationSourceTest.java
  8. +2 −0 ...rs/xwiki-platform-container-api/src/main/java/org/xwiki/container/AbstractApplicationContext.java
  9. +5 −0 ...containers/xwiki-platform-container-api/src/main/java/org/xwiki/container/ApplicationContext.java
  10. +2 −0 ...rs/xwiki-platform-container-api/src/main/java/org/xwiki/container/ApplicationContextListener.java
  11. +4 −0 ...i-platform-container-api/src/main/java/org/xwiki/container/ApplicationContextListenerManager.java
  12. +8 −0 ...platform-containers/xwiki-platform-container-api/src/main/java/org/xwiki/container/Container.java
  13. +2 −0 ...iner-api/src/main/java/org/xwiki/container/internal/DefaultApplicationContextListenerManager.java
  14. +13 −0 ...ers/xwiki-platform-container-api/src/main/java/org/xwiki/container/internal/DefaultContainer.java
  15. +4 −0 ...atform-container-portlet/src/main/java/org/xwiki/container/portlet/PortletApplicationContext.java
  16. +4 −0 ...form-container-portlet/src/main/java/org/xwiki/container/portlet/PortletContainerInitializer.java
  17. +4 −0 ...ortlet/src/main/java/org/xwiki/container/portlet/internal/DefaultPortletContainerInitializer.java
  18. +5 −0 xwiki-platform-core/xwiki-platform-containers/xwiki-platform-container-servlet/pom.xml
  19. +4 −0 ...atform-container-servlet/src/main/java/org/xwiki/container/servlet/ServletApplicationContext.java
  20. +5 −1 ...form-container-servlet/src/main/java/org/xwiki/container/servlet/ServletContainerInitializer.java
  21. +20 −1 ...form-container-servlet/src/main/java/org/xwiki/container/servlet/XWikiServletContextListener.java
  22. +4 −0 ...ervlet/src/main/java/org/xwiki/container/servlet/internal/DefaultServletContainerInitializer.java
  23. +72 −0 ...er-servlet/src/main/java/org/xwiki/container/servlet/internal/LegacyEnvironmentConfiguration.java
  24. +2 −1 ...i-platform-containers/xwiki-platform-container-servlet/src/main/resources/META-INF/components.txt
  25. +2 −2 xwiki-platform-core/xwiki-platform-extension/xwiki-platform-extension-api/pom.xml
  26. +4 −4 ...xtension-api/src/main/java/org/xwiki/extension/internal/DefaultExtensionManagerConfiguration.java
  27. +1 −1 ...-api/src/main/java/org/xwiki/extension/repository/internal/DefaultExtensionRepositoryManager.java
  28. +4 −0 ...sion-api/src/test/java/org/xwiki/extension/internal/DefaultExtensionManagerConfigurationTest.java
  29. +1 −1 ...platform-extension-api/src/test/java/org/xwiki/extension/job/internal/DefaultJobProgressTest.java
  30. +1 −1 ...tension-api/src/test/java/org/xwiki/extension/repository/DefaultLocalExtensionRepositoryTest.java
  31. +1 −1 ...i-platform-extension-api/src/test/java/org/xwiki/extension/test/AbstractExtensionHandlerTest.java
  32. +10 −1 ...extension/xwiki-platform-extension-api/src/test/java/org/xwiki/extension/test/RepositoryUtil.java
  33. +1 −1 ...platform-extension-handler-xar/src/test/java/org/xwiki/extension/xar/XarExtensionHandlerTest.java
  34. +5 −2 ...xtension/xwiki-platform-extension-repositories/xwiki-platform-extension-repository-aether/pom.xml
  35. +6 −5 ...java/org/xwiki/extension/repository/aether/internal/configuration/DefaultAetherConfiguration.java
  36. +1 −1 .../test/java/org/xwiki/extension/repository/aether/internal/AetherDefaultRepositoryManagerTest.java
  37. +2 −2 xwiki-platform-core/xwiki-platform-observation/xwiki-platform-observation-remote/pom.xml
  38. +10 −30 ...ion-remote/src/main/java/org/xwiki/observation/remote/internal/jgroups/JGroupsNetworkAdapter.java
  39. +9 −4 xwiki-platform-core/xwiki-platform-office/xwiki-platform-office-viewer/pom.xml
  40. +5 −5 ...i-platform-office-viewer/src/main/java/org/xwiki/office/viewer/internal/AbstractOfficeViewer.java
  41. +3 −18 ...latform-office-viewer/src/test/java/org/xwiki/office/viewer/internal/DefaultOfficeViewerTest.java
  42. +16 −11 xwiki-platform-core/xwiki-platform-oldcore/pom.xml
  43. +3 −4 xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/pdf/impl/PdfExportImpl.java
  44. +4 −4 xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/web/TempResourceAction.java
  45. +13 −4 ...ore/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/test/AbstractBridgedComponentTestCase.java
  46. +11 −4 ...wiki-platform-oldcore/src/test/java/com/xpn/xwiki/test/AbstractBridgedXWikiComponentTestCase.java
  47. +0 −61 ...platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/test/TestApplicationContext.java
  48. +18 −23 ...-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/web/TempResourceActionTest.java
  49. +3 −8 xwiki-platform-core/xwiki-platform-velocity/xwiki-platform-velocity-webapp/pom.xml
  50. +9 −13 ...ty/xwiki-platform-velocity-webapp/src/main/java/org/xwiki/velocity/XWikiWebappResourceLoader.java
  51. +8 −0 ...wiki-platform-velocity-webapp/src/test/java/org/xwiki/velocity/XWikiWebappResourceLoaderTest.java
  52. +7 −7 ...platform-tools/xwiki-platform-tool-configuration-resources/src/main/resources/xwiki.properties.vm
  53. +10 −0 xwiki-platform-tools/xwiki-platform-tool-packager-plugin/pom.xml
  54. +4 −6 ...xwiki-platform-tool-packager-plugin/src/main/java/com/xpn/xwiki/tool/backup/AbstractPackager.java
@@ -38,9 +38,9 @@
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.xwiki.platform</groupId>
- <artifactId>xwiki-platform-container-api</artifactId>
- <version>${project.version}</version>
+ <groupId>org.xwiki.commons</groupId>
+ <artifactId>xwiki-commons-environment-api</artifactId>
+ <version>${commons.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
@@ -44,8 +44,7 @@
import org.xwiki.component.manager.ComponentManager;
import org.xwiki.component.phase.Initializable;
import org.xwiki.component.phase.InitializationException;
-import org.xwiki.container.ApplicationContext;
-import org.xwiki.container.Container;
+import org.xwiki.environment.Environment;
/**
* Implements {@link org.xwiki.cache.CacheFactory} based on Infinispan.
@@ -76,9 +75,9 @@
private ComponentManager componentManager;
/**
- * Optional container used to access configuration files.
+ * Optional Environment used to access configuration files.
*/
- private Container container;
+ private Environment environment;
/**
* Used to create Infinispan caches.
@@ -99,9 +98,9 @@ public void initialize() throws InitializationException
// environments when there's no container.
try {
- this.container = this.componentManager.lookup(Container.class);
+ this.environment = this.componentManager.lookup(Environment.class);
} catch (ComponentLookupException e) {
- this.logger.debug("Can't find any Container", e);
+ this.logger.debug("Can't find any Environment", e);
}
InputStream configurationStream = getConfigurationFileAsStream();
@@ -150,11 +149,8 @@ private InputStream getConfigurationFileAsStream()
{
InputStream is = null;
- if (this.container != null) {
- ApplicationContext applicationContext = this.container.getApplicationContext();
- if (applicationContext != null) {
- is = applicationContext.getResourceAsStream(DEFAULT_CONFIGURATION_FILE);
- }
+ if (this.environment != null) {
+ is = this.environment.getResourceAsStream(DEFAULT_CONFIGURATION_FILE);
}
return is;
@@ -22,8 +22,7 @@
import org.jmock.Expectations;
import org.junit.Test;
import org.xwiki.cache.tests.AbstractTestCache;
-import org.xwiki.container.ApplicationContext;
-import org.xwiki.container.Container;
+import org.xwiki.environment.Environment;
/**
* Verify that defining an Infinispan config file is taken into account.
@@ -42,13 +41,10 @@ public InfinispanConfigTest()
public void testConfig() throws Exception
{
// We register a mock Container to verify that getCacheFactory() below will call
- // Container#getApplicationContext() which will mean that the configuration file is read.
- final Container mockContainer = registerMockComponent(Container.class);
- final ApplicationContext mockApplicationContext = getMockery().mock(ApplicationContext.class);
+ // Environment#getResourceAsStream() which will mean that the configuration file is read.
+ final Environment environment = registerMockComponent(Environment.class);
getMockery().checking(new Expectations() {{
- oneOf(mockContainer).getApplicationContext();
- will(returnValue(mockApplicationContext));
- oneOf(mockApplicationContext).getResourceAsStream("/WEB-INF/cache/infinispan/config.xml");
+ oneOf(environment).getResourceAsStream("/WEB-INF/cache/infinispan/config.xml");
will(returnValue(null));
}});
@@ -40,9 +40,9 @@
<version>${commons.version}</version>
</dependency>
<dependency>
- <groupId>org.xwiki.platform</groupId>
- <artifactId>xwiki-platform-container-api</artifactId>
- <version>${project.version}</version>
+ <groupId>org.xwiki.commons</groupId>
+ <artifactId>xwiki-commons-environment-api</artifactId>
+ <version>${commons.version}</version>
</dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
@@ -48,6 +48,11 @@
@Inject
private ConverterManager converterManager;
+ protected Configuration getConfiguration()
+ {
+ return this.configuration;
+ }
+
protected void setConfiguration(Configuration configuration)
{
this.configuration = configuration;
@@ -75,7 +80,7 @@ protected void setConfiguration(Configuration configuration)
@SuppressWarnings("unchecked")
public <T> T getProperty(String key)
{
- return (T) this.configuration.getProperty(key);
+ return (T) getConfiguration().getProperty(key);
}
@Override
@@ -86,11 +91,11 @@ protected void setConfiguration(Configuration configuration)
try {
if (String.class.getName().equals(valueClass.getName())) {
- result = (T) this.configuration.getString(key);
+ result = (T) getConfiguration().getString(key);
} else if (List.class.isAssignableFrom(valueClass)) {
- result = (T) this.configuration.getList(key);
+ result = (T) getConfiguration().getList(key);
} else if (Properties.class.isAssignableFrom(valueClass)) {
- result = (T) this.configuration.getProperties(key);
+ result = (T) getConfiguration().getProperties(key);
} else if (null != getProperty(key)) {
result = (T) this.converterManager.convert(valueClass, getProperty(key));
}
@@ -109,7 +114,7 @@ protected void setConfiguration(Configuration configuration)
public List<String> getKeys()
{
List<String> keysList = new ArrayList<String>();
- Iterator<String> keys = (Iterator<String>) this.configuration.getKeys();
+ Iterator<String> keys = (Iterator<String>) getConfiguration().getKeys();
while (keys.hasNext()) {
keysList.add(keys.next());
}
@@ -120,12 +125,12 @@ protected void setConfiguration(Configuration configuration)
@Override
public boolean containsKey(String key)
{
- return this.configuration.containsKey(key);
+ return getConfiguration().containsKey(key);
}
@Override
public boolean isEmpty()
{
- return this.configuration.isEmpty();
+ return getConfiguration().isEmpty();
}
}
@@ -31,7 +31,7 @@
import org.xwiki.component.annotation.Component;
import org.xwiki.component.phase.Initializable;
import org.xwiki.component.phase.InitializationException;
-import org.xwiki.container.Container;
+import org.xwiki.environment.Environment;
/**
* Looks for configuration data in {@code /WEB-INF/xwiki.properties}.
@@ -47,10 +47,10 @@
private static final String XWIKI_PROPERTIES_FILE = "/WEB-INF/xwiki.properties";
/**
- * Injected by the Component Manager.
+ * the Environment from where to get the XWiki properties file.
*/
@Inject
- private Container container;
+ private Environment environment;
/**
* The logger to log.
@@ -63,27 +63,27 @@ public void initialize() throws InitializationException
{
// Register the Commons Properties Configuration, looking for a xwiki.properties file
// in the XWiki path somewhere.
- URL xwikiPropertiesUrl;
+ URL xwikiPropertiesUrl = null;
try {
- xwikiPropertiesUrl = this.container.getApplicationContext().getResource(XWIKI_PROPERTIES_FILE);
+ xwikiPropertiesUrl = this.environment.getResource(XWIKI_PROPERTIES_FILE);
if (xwikiPropertiesUrl != null) {
setConfiguration(new PropertiesConfiguration(xwikiPropertiesUrl));
- } else if (this.logger.isDebugEnabled()) {
+ } else {
// We use a debug logging level here since we consider it's ok that there's no XWIKI_PROPERTIES_FILE
// available, in which case default values are used.
- this.logger.debug("No configuration file [" + XWIKI_PROPERTIES_FILE + "] found. "
- + "Using default configuration values.");
-
- // Use a default Commons Configuration implementation since we couldn't use a Properties configuration.
- setConfiguration(new BaseConfiguration());
+ this.logger.debug("No configuration file [{}] found. Using default configuration values.",
+ XWIKI_PROPERTIES_FILE);
}
} catch (Exception e) {
- // Note: if we cannot read the configuration file for any reasonwe log a warning but continue since XWiki
+ // Note: if we cannot read the configuration file for any reason we log a warning but continue since XWiki
// will use default values for all configurable elements.
- this.logger.warn("Failed to load configuration file [" + XWIKI_PROPERTIES_FILE
- + "]. Using default configuration values. " + " Internal error [" + e.getMessage() + "]");
+ this.logger.warn("Failed to load configuration file [{}]. Using default configuration values. "
+ + "Internal error [{}]", XWIKI_PROPERTIES_FILE, e.getMessage());
+ }
- // Use a default Commons Configuration implementation since we couldn't use a Properties configuration.
+ // If no Commons Properties Configuration has been set, use a default empty Commons Configuration
+ // implementation.
+ if (xwikiPropertiesUrl == null) {
setConfiguration(new BaseConfiguration());
}
}
@@ -24,8 +24,7 @@
import org.junit.Test;
import org.slf4j.Logger;
import org.xwiki.component.util.ReflectionUtils;
-import org.xwiki.container.ApplicationContext;
-import org.xwiki.container.Container;
+import org.xwiki.environment.Environment;
import org.xwiki.test.AbstractComponentTestCase;
/**
@@ -46,46 +45,32 @@ public void setUp() throws Exception
{
super.setUp();
- final ApplicationContext appContext = getMockery().mock(ApplicationContext.class);
+ final Environment environment = getMockery().mock(Environment.class);
getMockery().checking(new Expectations() {{
- oneOf(appContext).getResource("/WEB-INF/xwiki.properties");
+ oneOf(environment).getResource("/WEB-INF/xwiki.properties");
will(returnValue(null));
}});
- Container container = getComponentManager().lookup(Container.class);
- container.setApplicationContext(appContext);
-
// Set a mock Logger to capture all log outputs and perform verifications
this.logger = getMockery().mock(Logger.class);
this.source = new XWikiPropertiesConfigurationSource();
- ReflectionUtils.setFieldValue(this.source, "container", container);
+ ReflectionUtils.setFieldValue(this.source, "environment", environment);
ReflectionUtils.setFieldValue(this.source, "logger", this.logger);
}
@Test
- public void testInitializeWhenNoPropertiesFileAndDebugEnabled() throws Exception
+ public void testInitializeWhenNoPropertiesFile() throws Exception
{
getMockery().checking(new Expectations() {{
- oneOf(logger).isDebugEnabled();
- will(returnValue(true));
// This is the test
- oneOf(logger).debug("No configuration file [/WEB-INF/xwiki.properties] found. "
- + "Using default configuration values.");
+ oneOf(logger).debug("No configuration file [{}] found. Using default configuration values.",
+ "/WEB-INF/xwiki.properties");
}});
this.source.initialize();
- }
-
- @Test
- public void testInitializeWhenNoPropertiesFileAndDebugNotEnabled() throws Exception
- {
- getMockery().checking(new Expectations() {{
- oneOf(logger).isDebugEnabled();
- will(returnValue(false));
- // This is the test. It shows nothing is logged when the properties file is not available.
- }});
- this.source.initialize();
+ // Verifies that we can get a property from the source (i.e. that it's correctly initialized)
+ this.source.getProperty("key");
}
}
@@ -31,7 +31,9 @@
* Base class for {@link ApplicationContext} implementations.
*
* @version $Id$
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
*/
+@Deprecated
public abstract class AbstractApplicationContext implements ApplicationContext
{
/**
@@ -24,6 +24,11 @@
import java.net.MalformedURLException;
import java.net.URL;
+/**
+ * @version $Id$
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
+ */
+@Deprecated
public interface ApplicationContext
{
InputStream getResourceAsStream(String resourceName);
@@ -27,8 +27,10 @@
*
* @version $Id$
* @since 1.9M2
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
*/
@ComponentRole
+@Deprecated
public interface ApplicationContextListener
{
/**
@@ -26,21 +26,25 @@
*
* @version $Id$
* @since 1.9M2
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
*/
@ComponentRole
+@Deprecated
public interface ApplicationContextListenerManager
{
/**
* Looks up all {@link ApplicationContextListener} components and allows each of them to initialize.
*
* @param applicationContext the {@link ApplicationContext}.
*/
+ @Deprecated
void initializeApplicationContext(ApplicationContext applicationContext);
/**
* Looks up all {@link ApplicationContextListener} components and allows each of them to finalize.
*
* @param applicationContext the {@link ApplicationContext}.
*/
+ @Deprecated
void destroyApplicationContext(ApplicationContext applicationContext);
}
@@ -24,8 +24,16 @@
@ComponentRole
public interface Container
{
+ /**
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
+ */
+ @Deprecated
ApplicationContext getApplicationContext();
+ /**
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
+ */
+ @Deprecated
void setApplicationContext(ApplicationContext context);
Request getRequest();
@@ -37,9 +37,11 @@
*
* @version $Id$
* @since 1.9M2
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
*/
@Component
@Singleton
+@Deprecated
public class DefaultApplicationContextListenerManager implements ApplicationContextListenerManager
{
/**
Oops, something went wrong. Retry.

0 comments on commit b245d86

Please sign in to comment.