Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

… notion of Environment
  • Loading branch information...
commit b245d86bea602940589a66a4f0a5545cb3b112e1 1 parent 700cf1d
@vmassol vmassol authored
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 ...iki-platform-cache-infinispan/src/main/java/org/xwiki/cache/infinispan/internal/InfinispanCacheFactory.java
  3. +4 −8 ...rm-cache/xwiki-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 ...atform-configuration-default/src/main/java/org/xwiki/configuration/internal/CommonsConfigurationSource.java
  6. +15 −15 ...onfiguration-default/src/main/java/org/xwiki/configuration/internal/XWikiPropertiesConfigurationSource.java
  7. +9 −24 ...guration-default/src/test/java/org/xwiki/configuration/internal/XWikiPropertiesConfigurationSourceTest.java
  8. +2 −0  ...m-containers/xwiki-platform-container-api/src/main/java/org/xwiki/container/AbstractApplicationContext.java
  9. +5 −0 ...-platform-containers/xwiki-platform-container-api/src/main/java/org/xwiki/container/ApplicationContext.java
  10. +2 −0  ...m-containers/xwiki-platform-container-api/src/main/java/org/xwiki/container/ApplicationContextListener.java
  11. +4 −0 ...iners/xwiki-platform-container-api/src/main/java/org/xwiki/container/ApplicationContextListenerManager.java
  12. +8 −0 ...ore/xwiki-platform-containers/xwiki-platform-container-api/src/main/java/org/xwiki/container/Container.java
  13. +2 −0  ...form-container-api/src/main/java/org/xwiki/container/internal/DefaultApplicationContextListenerManager.java
  14. +13 −0 ...rm-containers/xwiki-platform-container-api/src/main/java/org/xwiki/container/internal/DefaultContainer.java
  15. +4 −0 ...s/xwiki-platform-container-portlet/src/main/java/org/xwiki/container/portlet/PortletApplicationContext.java
  16. +4 −0 ...xwiki-platform-container-portlet/src/main/java/org/xwiki/container/portlet/PortletContainerInitializer.java
  17. +4 −0 ...ontainer-portlet/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 ...s/xwiki-platform-container-servlet/src/main/java/org/xwiki/container/servlet/ServletApplicationContext.java
  20. +5 −1 ...xwiki-platform-container-servlet/src/main/java/org/xwiki/container/servlet/ServletContainerInitializer.java
  21. +20 −1 ...xwiki-platform-container-servlet/src/main/java/org/xwiki/container/servlet/XWikiServletContextListener.java
  22. +4 −0 ...ontainer-servlet/src/main/java/org/xwiki/container/servlet/internal/DefaultServletContainerInitializer.java
  23. +72 −0 ...rm-container-servlet/src/main/java/org/xwiki/container/servlet/internal/LegacyEnvironmentConfiguration.java
  24. +2 −1  ...-core/xwiki-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 ...platform-extension-api/src/main/java/org/xwiki/extension/internal/DefaultExtensionManagerConfiguration.java
  27. +1 −1  ...-extension-api/src/main/java/org/xwiki/extension/repository/internal/DefaultExtensionRepositoryManager.java
  28. +4 −0 ...form-extension-api/src/test/java/org/xwiki/extension/internal/DefaultExtensionManagerConfigurationTest.java
  29. +1 −1  ...ion/xwiki-platform-extension-api/src/test/java/org/xwiki/extension/job/internal/DefaultJobProgressTest.java
  30. +1 −1  ...latform-extension-api/src/test/java/org/xwiki/extension/repository/DefaultLocalExtensionRepositoryTest.java
  31. +1 −1  ...nsion/xwiki-platform-extension-api/src/test/java/org/xwiki/extension/test/AbstractExtensionHandlerTest.java
  32. +10 −1 ...-platform-extension/xwiki-platform-extension-api/src/test/java/org/xwiki/extension/test/RepositoryUtil.java
  33. +1 −1  ...ers/xwiki-platform-extension-handler-xar/src/test/java/org/xwiki/extension/xar/XarExtensionHandlerTest.java
  34. +5 −2 ...platform-extension/xwiki-platform-extension-repositories/xwiki-platform-extension-repository-aether/pom.xml
  35. +6 −5 .../src/main/java/org/xwiki/extension/repository/aether/internal/configuration/DefaultAetherConfiguration.java
  36. +1 −1  ...aether/src/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 ...m-observation-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 ...ffice/xwiki-platform-office-viewer/src/main/java/org/xwiki/office/viewer/internal/AbstractOfficeViewer.java
  41. +3 −18 ...ce/xwiki-platform-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 ...platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/test/AbstractBridgedComponentTestCase.java
  46. +11 −4 ...orm-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/test/AbstractBridgedXWikiComponentTestCase.java
  47. +0 −61 xwiki-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/test/TestApplicationContext.java
  48. +18 −23 xwiki-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 ...orm-velocity/xwiki-platform-velocity-webapp/src/main/java/org/xwiki/velocity/XWikiWebappResourceLoader.java
  51. +8 −0 ...velocity/xwiki-platform-velocity-webapp/src/test/java/org/xwiki/velocity/XWikiWebappResourceLoaderTest.java
  52. +7 −7 xwiki-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 ...orm-tools/xwiki-platform-tool-packager-plugin/src/main/java/com/xpn/xwiki/tool/backup/AbstractPackager.java
View
6 xwiki-platform-core/xwiki-platform-cache/xwiki-platform-cache-infinispan/pom.xml
@@ -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>
View
18 ...-platform-cache-infinispan/src/main/java/org/xwiki/cache/infinispan/internal/InfinispanCacheFactory.java
@@ -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;
View
12 ...cache/xwiki-platform-cache-infinispan/src/test/java/org/xwiki/cache/infinispan/InfinispanConfigTest.java
@@ -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));
}});
View
6 xwiki-platform-core/xwiki-platform-configuration/xwiki-platform-configuration-default/pom.xml
@@ -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>
View
19 ...orm-configuration-default/src/main/java/org/xwiki/configuration/internal/CommonsConfigurationSource.java
@@ -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();
}
}
View
30 ...iguration-default/src/main/java/org/xwiki/configuration/internal/XWikiPropertiesConfigurationSource.java
@@ -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());
}
}
View
33 ...ation-default/src/test/java/org/xwiki/configuration/internal/XWikiPropertiesConfigurationSourceTest.java
@@ -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");
}
}
View
2  ...ontainers/xwiki-platform-container-api/src/main/java/org/xwiki/container/AbstractApplicationContext.java
@@ -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
{
/**
View
5 ...atform-containers/xwiki-platform-container-api/src/main/java/org/xwiki/container/ApplicationContext.java
@@ -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);
View
2  ...ontainers/xwiki-platform-container-api/src/main/java/org/xwiki/container/ApplicationContextListener.java
@@ -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
{
/**
View
4 ...rs/xwiki-platform-container-api/src/main/java/org/xwiki/container/ApplicationContextListenerManager.java
@@ -26,8 +26,10 @@
*
* @version $Id$
* @since 1.9M2
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
*/
@ComponentRole
+@Deprecated
public interface ApplicationContextListenerManager
{
/**
@@ -35,6 +37,7 @@
*
* @param applicationContext the {@link ApplicationContext}.
*/
+ @Deprecated
void initializeApplicationContext(ApplicationContext applicationContext);
/**
@@ -42,5 +45,6 @@
*
* @param applicationContext the {@link ApplicationContext}.
*/
+ @Deprecated
void destroyApplicationContext(ApplicationContext applicationContext);
}
View
8 .../xwiki-platform-containers/xwiki-platform-container-api/src/main/java/org/xwiki/container/Container.java
@@ -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();
View
2  ...m-container-api/src/main/java/org/xwiki/container/internal/DefaultApplicationContextListenerManager.java
@@ -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
{
/**
View
13 ...containers/xwiki-platform-container-api/src/main/java/org/xwiki/container/internal/DefaultContainer.java
@@ -37,11 +37,20 @@
@Component
public class DefaultContainer implements Container
{
+ /**
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
+ */
+ @Deprecated
private ApplicationContext applicationContext;
+
private ThreadLocal<Stack<Request>> request = new ThreadLocal<Stack<Request>>();
private ThreadLocal<Stack<Response>> response = new ThreadLocal<Stack<Response>>();
private ThreadLocal<Stack<Session>> session = new ThreadLocal<Stack<Session>>();
+ /**
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
+ */
+ @Deprecated
public ApplicationContext getApplicationContext()
{
return this.applicationContext;
@@ -125,6 +134,10 @@ public void popSession()
}
}
+ /**
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
+ */
+ @Deprecated
public void setApplicationContext(ApplicationContext context)
{
this.applicationContext = context;
View
4 ...wiki-platform-container-portlet/src/main/java/org/xwiki/container/portlet/PortletApplicationContext.java
@@ -29,6 +29,10 @@
import org.xwiki.component.manager.ComponentManager;
import org.xwiki.container.AbstractApplicationContext;
+/**
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
+ */
+@Deprecated
public class PortletApplicationContext extends AbstractApplicationContext
{
private PortletContext portletContext;
View
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
void initializeSession(javax.portlet.PortletRequest request);
+ /**
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
+ */
+ @Deprecated
void initializeApplicationContext(PortletContext servletContext);
}
View
4 ...ainer-portlet/src/main/java/org/xwiki/container/portlet/internal/DefaultPortletContainerInitializer.java
@@ -63,6 +63,10 @@
@Inject
private ComponentManager componentManager;
+ /**
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
+ */
+ @Deprecated
@Override
public void initializeApplicationContext(PortletContext portletContext)
{
View
5 xwiki-platform-core/xwiki-platform-containers/xwiki-platform-container-servlet/pom.xml
@@ -50,6 +50,11 @@
<version>${commons.version}</version>
</dependency>
<dependency>
+ <groupId>org.xwiki.commons</groupId>
+ <artifactId>xwiki-commons-environment-servlet</artifactId>
+ <version>${commons.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-action</artifactId>
<version>${project.version}</version>
View
4 ...wiki-platform-container-servlet/src/main/java/org/xwiki/container/servlet/ServletApplicationContext.java
@@ -31,6 +31,10 @@
import org.xwiki.component.manager.ComponentManager;
import org.xwiki.container.AbstractApplicationContext;
+/**
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
+ */
+@Deprecated
public class ServletApplicationContext extends AbstractApplicationContext
{
/**
View
6 ...ki-platform-container-servlet/src/main/java/org/xwiki/container/servlet/ServletContainerInitializer.java
@@ -37,6 +37,10 @@ void initializeRequest(HttpServletRequest request)
void initializeResponse(HttpServletResponse response);
void initializeSession(HttpServletRequest request);
-
+
+ /**
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
+ */
+ @Deprecated
void initializeApplicationContext(ServletContext servletContext);
}
View
21 ...ki-platform-container-servlet/src/main/java/org/xwiki/container/servlet/XWikiServletContextListener.java
@@ -28,6 +28,8 @@
import org.xwiki.component.manager.ComponentManager;
import org.xwiki.container.ApplicationContextListenerManager;
import org.xwiki.container.Container;
+import org.xwiki.environment.Environment;
+import org.xwiki.environment.internal.ServletEnvironment;
import org.xwiki.observation.ObservationManager;
import org.xwiki.observation.event.ApplicationStartedEvent;
import org.xwiki.observation.event.ApplicationStoppedEvent;
@@ -57,7 +59,20 @@ public void contextInitialized(ServletContextEvent servletContextEvent)
StackingComponentEventManager eventManager = new StackingComponentEventManager();
this.componentManager.setComponentEventManager(eventManager);
- // Initializes XWiki's Container with the Servlet Context.
+ // Initialize the Environment
+ try {
+ ServletEnvironment servletEnvironment =
+ (ServletEnvironment) this.componentManager.lookup(Environment.class);
+ servletEnvironment.setServletContext(servletContextEvent.getServletContext());
+ } catch (ComponentLookupException e) {
+ throw new RuntimeException("Failed to initialize the Servlet Environment", e);
+ }
+
+ // Initializes the Application Context.
+ // Even though the notion of ApplicationContext has been deprecated in favor of the notion of Environment we
+ // still keep this initialization for backward-compatibility.
+ // TODO: Add an Observation Even that we send when the Environment is initialized so that we can move the code
+ // below in an Event Listener and move it to the legacy module.
try {
ServletContainerInitializer containerInitializer =
this.componentManager.lookup(ServletContainerInitializer.class);
@@ -106,6 +121,10 @@ public void contextDestroyed(ServletContextEvent sce)
// TODO: Log a warning
}
+ // Even though the notion of ApplicationContext has been deprecated in favor of the notion of Environment we
+ // still keep this destruction for backward-compatibility.
+ // TODO: Add an Observation Even that we send when the Environment is destroyed so that we can move the code
+ // below in an Event Listener and move it to the legacy module.
try {
ApplicationContextListenerManager applicationContextListenerManager =
this.componentManager.lookup(ApplicationContextListenerManager.class);
View
4 ...ainer-servlet/src/main/java/org/xwiki/container/servlet/internal/DefaultServletContainerInitializer.java
@@ -80,6 +80,10 @@
@Inject
private Logger logger;
+ /**
+ * @deprecated starting with 3.5M1, use the notion of Environment instead
+ */
+ @Deprecated
@Override
public void initializeApplicationContext(ServletContext servletContext)
{
View
72 ...container-servlet/src/main/java/org/xwiki/container/servlet/internal/LegacyEnvironmentConfiguration.java
@@ -0,0 +1,72 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.xwiki.container.servlet.internal;
+
+import java.io.File;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.slf4j.Logger;
+import org.xwiki.component.annotation.Component;
+import org.xwiki.environment.internal.DefaultEnvironmentConfiguration;
+
+/**
+ * Overrides the {@link DefaultEnvironmentConfiguration} component in order to take into account the deprecated
+ * permanent directory configuration property "container.persistentDirectory" and use it if the newer
+ * "environment.permanentDirectory" property isn't set.
+ *
+ * @version $Id$
+ * @since 3.5M1
+ * @deprecated starting with 3.5M1 use the "environment.permanentDirectory" property instead
+ */
+@Component
+@Singleton
+@Deprecated
+public class LegacyEnvironmentConfiguration extends DefaultEnvironmentConfiguration
+{
+ /**
+ * The name of the property for configuring the permanent directory.
+ */
+ private static final String PROPERTY_DEPRECATED_PERMANENTDIRECTORY = "container.persistentDirectory";
+
+ /**
+ * The logger to log.
+ */
+ @Inject
+ private Logger logger;
+
+ @Override
+ public File getPermanentDirectory()
+ {
+ File directory = super.getPermanentDirectory();
+ if (directory == null) {
+ // Fallback to the old deprecated permanent directory configuration property
+ directory = initializeDirectory(
+ getConfigurationSource().getProperty(PROPERTY_DEPRECATED_PERMANENTDIRECTORY, String.class));
+ // Display a warning to the user so that he upgrades
+ if (directory != null) {
+ this.logger.warn("You're using the deprecated [{}] configuration property. You should instead use the "
+ + "newer [{}] one", PROPERTY_DEPRECATED_PERMANENTDIRECTORY, "environment.permanentDirectory");
+ }
+ }
+ return directory;
+ }
+}
View
3  ...re/xwiki-platform-containers/xwiki-platform-container-servlet/src/main/resources/META-INF/components.txt
@@ -1 +1,2 @@
-org.xwiki.container.servlet.internal.DefaultServletContainerInitializer
+org.xwiki.container.servlet.internal.DefaultServletContainerInitializer
+900:org.xwiki.container.servlet.internal.LegacyEnvironmentConfiguration
View
4 xwiki-platform-core/xwiki-platform-extension/xwiki-platform-extension-api/pom.xml
@@ -70,8 +70,8 @@
<version>${rendering.version}</version>
</dependency>
<dependency>
- <groupId>org.xwiki.platform</groupId>
- <artifactId>xwiki-platform-container-api</artifactId>
+ <groupId>org.xwiki.commons</groupId>
+ <artifactId>xwiki-commons-environment-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
View
8 ...tform-extension-api/src/main/java/org/xwiki/extension/internal/DefaultExtensionManagerConfiguration.java
@@ -37,7 +37,7 @@
import org.slf4j.Logger;
import org.xwiki.component.annotation.Component;
import org.xwiki.configuration.ConfigurationSource;
-import org.xwiki.container.Container;
+import org.xwiki.environment.Environment;
import org.xwiki.extension.ExtensionManagerConfiguration;
import org.xwiki.extension.repository.ExtensionRepositoryId;
@@ -67,10 +67,10 @@
private Logger logger;
/**
- * Used to get work directory.
+ * Used to get permanent directory.
*/
@Inject
- private Container container;
+ private Environment environment;
/**
* The configuration.
@@ -91,7 +91,7 @@
*/
public File getHome()
{
- return new File(this.container.getApplicationContext().getPermanentDirectory(), "extension/");
+ return new File(this.environment.getPermanentDirectory(), "extension/");
}
@Override
View
2  ...tension-api/src/main/java/org/xwiki/extension/repository/internal/DefaultExtensionRepositoryManager.java
@@ -112,7 +112,7 @@ public ExtensionRepository addRepository(ExtensionRepositoryId repositoryId) thr
addRepository(repository);
} catch (ComponentLookupException e) {
- throw new ExtensionRepositoryException("Unsupported repository type[" + repositoryId.getType() + "]", e);
+ throw new ExtensionRepositoryException("Unsupported repository type [" + repositoryId.getType() + "]", e);
}
return repository;
View
4 ...m-extension-api/src/test/java/org/xwiki/extension/internal/DefaultExtensionManagerConfigurationTest.java
@@ -26,6 +26,7 @@
import junit.framework.Assert;
import org.junit.Test;
+import org.xwiki.environment.Environment;
import org.xwiki.extension.ExtensionManagerConfiguration;
import org.xwiki.extension.repository.ExtensionRepositoryId;
import org.xwiki.test.AbstractComponentTestCase;
@@ -39,6 +40,9 @@ public void setUp() throws Exception
{
super.setUp();
+ // Register a Mocked Environment since we need to provide one.
+ registerMockComponent(Environment.class);
+
this.configuration = getComponentManager().lookup(ExtensionManagerConfiguration.class);
}
View
2  .../xwiki-platform-extension-api/src/test/java/org/xwiki/extension/job/internal/DefaultJobProgressTest.java
@@ -43,7 +43,7 @@ public void setUp() throws Exception
super.setUp();
this.repositoryUtil =
new RepositoryUtil(getClass().getSimpleName(), getConfigurationSource(), getComponentManager());
- this.repositoryUtil.setup();
+ this.repositoryUtil.setup(getMockery());
this.observation = getComponentManager().lookup(ObservationManager.class);
this.progress = new DefaultJobProgress("id");
View
2  ...form-extension-api/src/test/java/org/xwiki/extension/repository/DefaultLocalExtensionRepositoryTest.java
@@ -58,7 +58,7 @@ public void setUp() throws Exception
this.repositoryUtil =
new RepositoryUtil(getClass().getSimpleName(), getConfigurationSource(), getComponentManager());
- this.repositoryUtil.setup();
+ this.repositoryUtil.setup(getMockery());
// lookup
View
2  ...on/xwiki-platform-extension-api/src/test/java/org/xwiki/extension/test/AbstractExtensionHandlerTest.java
@@ -54,7 +54,7 @@ public void setUp() throws Exception
this.repositoryUtil =
new RepositoryUtil(getClass().getSimpleName(), getConfigurationSource(), getComponentManager());
- this.repositoryUtil.setup();
+ this.repositoryUtil.setup(getMockery());
// lookup
View
11 ...atform-extension/xwiki-platform-extension-api/src/test/java/org/xwiki/extension/test/RepositoryUtil.java
@@ -28,6 +28,7 @@
import java.util.regex.Pattern;
import org.apache.commons.io.FileUtils;
+import org.jmock.Mockery;
import org.reflections.Reflections;
import org.reflections.scanners.ResourcesScanner;
import org.reflections.util.ClasspathHelper;
@@ -35,7 +36,9 @@
import org.reflections.util.FilterBuilder;
import org.xwiki.component.annotation.ComponentAnnotationLoader;
import org.xwiki.component.descriptor.ComponentDescriptor;
+import org.xwiki.component.descriptor.DefaultComponentDescriptor;
import org.xwiki.component.manager.ComponentManager;
+import org.xwiki.environment.Environment;
import org.xwiki.extension.handler.ExtensionInitializer;
import org.xwiki.extension.repository.CoreExtensionRepository;
import org.xwiki.extension.repository.ExtensionRepositoryId;
@@ -123,10 +126,16 @@ public String getRemoteRepositoryId()
return MAVENREPOSITORY_ID;
}
- public void setup() throws Exception
+ public void setup(Mockery mockery) throws Exception
{
clean();
+ // Mock Environment
+ Environment environment = mockery.mock(Environment.class);
+ DefaultComponentDescriptor<Environment> dcd = new DefaultComponentDescriptor<Environment>();
+ dcd.setRole(Environment.class);
+ this.componentManager.registerComponent(dcd, environment);
+
// disable default configuration
// TODO: probably mean that this default configuration should not be at this level
View
2  .../xwiki-platform-extension-handler-xar/src/test/java/org/xwiki/extension/xar/XarExtensionHandlerTest.java
@@ -84,7 +84,7 @@ public void setUp() throws Exception
this.repositoryUtil =
new RepositoryUtil(getClass().getSimpleName(), getConfigurationSource(), getComponentManager());
- this.repositoryUtil.setup();
+ this.repositoryUtil.setup(getMockery());
// mock
View
7 ...tform-extension/xwiki-platform-extension-repositories/xwiki-platform-extension-repository-aether/pom.xml
@@ -42,8 +42,11 @@
<artifactId>xwiki-commons-properties</artifactId>
<version>${commons.version}</version>
</dependency>
-
-
+ <dependency>
+ <groupId>org.xwiki.commons</groupId>
+ <artifactId>xwiki-commons-environment-api</artifactId>
+ <version>${commons.version}</version>
+ </dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-extension-api</artifactId>
View
11 ...c/main/java/org/xwiki/extension/repository/aether/internal/configuration/DefaultAetherConfiguration.java
@@ -28,7 +28,7 @@
import org.xwiki.component.annotation.Component;
import org.xwiki.configuration.ConfigurationSource;
-import org.xwiki.container.Container;
+import org.xwiki.environment.Environment;
@Component
@Singleton
@@ -36,19 +36,20 @@
{
@Inject
@Named("configurationSource")
- private Provider<ConfigurationSource> configurationSource;
+ private Provider<ConfigurationSource> configurationSourceProvider;
@Inject
- private Container container;
+ private Environment environment;
@Override
public File getLocalRepository()
{
- String localRepositoryPath = this.configurationSource.get().getProperty("extension.aether.localRepository");
+ String localRepositoryPath =
+ this.configurationSourceProvider.get().getProperty("extension.aether.localRepository");
File directory;
if (localRepositoryPath == null) {
- directory = new File(this.container.getApplicationContext().getTemporaryDirectory(), "aether-repository");
+ directory = new File(this.environment.getTemporaryDirectory(), "aether-repository");
} else {
directory = new File(localRepositoryPath);
}
View
2  ...her/src/test/java/org/xwiki/extension/repository/aether/internal/AetherDefaultRepositoryManagerTest.java
@@ -75,7 +75,7 @@ public void setUp() throws Exception
this.repositoryUtil =
new RepositoryUtil(getClass().getSimpleName(), getConfigurationSource(), getComponentManager());
- this.repositoryUtil.setup();
+ this.repositoryUtil.setup(getMockery());
this.extensionId = new ExtensionId(GROUPID + ':' + ARTIfACTID, "version");
this.extensionDependencyId = new ExtensionId("dgroupid:dartifactid", "dversion");
View
4 xwiki-platform-core/xwiki-platform-observation/xwiki-platform-observation-remote/pom.xml
@@ -45,8 +45,8 @@
<version>${commons.version}</version>
</dependency>
<dependency>
- <groupId>org.xwiki.platform</groupId>
- <artifactId>xwiki-platform-container-api</artifactId>
+ <groupId>org.xwiki.commons</groupId>
+ <artifactId>xwiki-commons-environment-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
View
40 ...bservation-remote/src/main/java/org/xwiki/observation/remote/internal/jgroups/JGroupsNetworkAdapter.java
@@ -42,8 +42,7 @@
import org.xwiki.component.annotation.Component;
import org.xwiki.component.manager.ComponentLookupException;
import org.xwiki.component.manager.ComponentManager;
-import org.xwiki.container.ApplicationContext;
-import org.xwiki.container.Container;
+import org.xwiki.environment.Environment;
import org.xwiki.observation.remote.NetworkAdapter;
import org.xwiki.observation.remote.RemoteEventData;
import org.xwiki.observation.remote.RemoteEventException;
@@ -82,11 +81,7 @@
*/
private Map<String, JChannel> channels = new ConcurrentHashMap<String, JChannel>();
- /**
- * {@inheritDoc}
- *
- * @see org.xwiki.observation.remote.NetworkAdapter#send(org.xwiki.observation.remote.RemoteEventData)
- */
+ @Override
public void send(RemoteEventData remoteEvent)
{
this.logger.debug("Send JGroups remote event [" + remoteEvent + "]");
@@ -105,11 +100,7 @@ public void send(RemoteEventData remoteEvent)
}
}
- /**
- * {@inheritDoc}
- *
- * @see org.xwiki.observation.remote.NetworkAdapter#startChannel(java.lang.String)
- */
+ @Override
public void startChannel(String channelId) throws RemoteEventException
{
if (this.channels.containsKey(channelId)) {
@@ -137,11 +128,7 @@ public void startChannel(String channelId) throws RemoteEventException
this.logger.info("Channel [{}] started", channelId);
}
- /**
- * {@inheritDoc}
- *
- * @see org.xwiki.observation.remote.NetworkAdapter#stopChannel(java.lang.String)
- */
+ @Override
public void stopChannel(String channelId) throws RemoteEventException
{
JChannel channel = this.channels.get(channelId);
@@ -215,18 +202,15 @@ private ProtocolStackConfigurator loadChannelConfiguration(String channelId) thr
InputStream is = null;
try {
- Container container = this.componentManager.lookup(Container.class);
- ApplicationContext applicationContext = container.getApplicationContext();
-
- if (applicationContext != null) {
- is = applicationContext.getResourceAsStream(path);
- }
+ Environment environment = this.componentManager.lookup(Environment.class);
+ is = environment.getResourceAsStream(path);
} catch (ComponentLookupException e) {
- this.logger.debug("Failed to lookup Container component.");
+ // Environment not found, continue by fallbacking on JGroups's standard configuration.
+ this.logger.debug("Failed to lookup the Environment component.", e);
}
if (is == null) {
- // Fallback on JGroups standard configuraton locations
+ // Fallback on JGroups standard configuration locations
is = ConfiguratorFactory.getConfigStream(channelFile);
if (is == null && !JChannel.DEFAULT_PROTOCOL_STACK.equals(channelFile)) {
@@ -238,11 +222,7 @@ private ProtocolStackConfigurator loadChannelConfiguration(String channelId) thr
return XmlConfigurator.getInstance(is);
}
- /**
- * {@inheritDoc}
- *
- * @see org.xwiki.observation.remote.NetworkAdapter#stopAllChannels()
- */
+ @Override
public void stopAllChannels() throws RemoteEventException
{
for (Map.Entry<String, JChannel> channelEntry : this.channels.entrySet()) {
View
13 xwiki-platform-core/xwiki-platform-office/xwiki-platform-office-viewer/pom.xml
@@ -32,16 +32,21 @@
<description>A module providing support for viewing office documents attached to wiki pages.</description>
<dependencies>
<dependency>
- <groupId>org.xwiki.rendering</groupId>
- <artifactId>xwiki-rendering-api</artifactId>
- <version>${rendering.version}</version>
+ <groupId>org.xwiki.commons</groupId>
+ <artifactId>xwiki-commons-script</artifactId>
+ <version>${commons.version}</version>
</dependency>
<dependency>
<groupId>org.xwiki.commons</groupId>
- <artifactId>xwiki-commons-script</artifactId>
+ <artifactId>xwiki-commons-environment-api</artifactId>
<version>${commons.version}</version>
</dependency>
<dependency>
+ <groupId>org.xwiki.rendering</groupId>
+ <artifactId>xwiki-rendering-api</artifactId>
+ <version>${rendering.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-bridge</artifactId>
<version>${project.version}</version>
View
10 ...ce/xwiki-platform-office-viewer/src/main/java/org/xwiki/office/viewer/internal/AbstractOfficeViewer.java
@@ -36,7 +36,7 @@
import org.xwiki.cache.config.CacheConfiguration;
import org.xwiki.component.phase.Initializable;
import org.xwiki.component.phase.InitializationException;
-import org.xwiki.container.Container;
+import org.xwiki.environment.Environment;
import org.xwiki.model.reference.AttachmentReference;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.model.reference.EntityReferenceSerializer;
@@ -72,7 +72,7 @@
* Used to access the temporary directory.
*/
@Inject
- private Container container;
+ private Environment environment;
/**
* Used for serializing {@link AttachmentReference}s.
@@ -221,12 +221,12 @@ protected File getTemporaryDirectory(AttachmentReference attachmentReference) th
// Create temporary directory.
String path = String.format("temp/%s/%s/%s/%s/%s/", MODULE_NAME, wiki, space, page, attachmentName);
- File rootDir = container.getApplicationContext().getTemporaryDirectory();
+ File rootDir = this.environment.getTemporaryDirectory();
File tempDir = new File(rootDir, path);
boolean success = (tempDir.exists() || tempDir.mkdirs()) && tempDir.isDirectory() && tempDir.canWrite();
if (!success) {
- String message = "Error while creating temporary directory for attachment [%s].";
- throw new Exception(String.format(message, attachmentName));
+ String message = "Error while creating temporary directory [%s] for attachment [%s].";
+ throw new Exception(String.format(message, tempDir, attachmentName));
}
return tempDir;
}
View
21 ...xwiki-platform-office-viewer/src/test/java/org/xwiki/office/viewer/internal/DefaultOfficeViewerTest.java
@@ -37,8 +37,7 @@
import org.xwiki.cache.Cache;
import org.xwiki.cache.CacheManager;
import org.xwiki.cache.config.CacheConfiguration;
-import org.xwiki.container.ApplicationContext;
-import org.xwiki.container.Container;
+import org.xwiki.environment.Environment;
import org.xwiki.model.reference.AttachmentReference;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.model.reference.EntityReferenceSerializer;
@@ -108,11 +107,6 @@
*/
private Cache<OfficeDocumentView> cache;
- /**
- * {@inheritDoc}
- *
- * @see AbstractMockingComponentTestCase#setUp()
- */
@Override
@Before
public void setUp() throws Exception
@@ -124,11 +118,6 @@ public void setUp() throws Exception
officeDocumentBuilder = getComponentManager().lookup(XDOMOfficeDocumentBuilder.class);
}
- /**
- * {@inheritDoc}
- *
- * @see AbstractMockingComponentTestCase#configure()
- */
@SuppressWarnings("unchecked")
@Override
public void configure() throws Exception
@@ -323,16 +312,12 @@ public void testViewANewVersionOfAnExistingOfficeAttachment() throws Exception
@Test
public void testGetTemporaryDirectory() throws Exception
{
- final Container container = getComponentManager().lookup(Container.class);
- final ApplicationContext applicationContext = getMockery().mock(ApplicationContext.class);
+ final Environment environment = getComponentManager().lookup(Environment.class);
getMockery().checking(new Expectations()
{
{
- oneOf(container).getApplicationContext();
- will(returnValue(applicationContext));
-
- oneOf(applicationContext).getTemporaryDirectory();
+ oneOf(environment).getTemporaryDirectory();
will(returnValue(new File(System.getProperty("java.io.tmpdir"))));
}
});
View
27 xwiki-platform-core/xwiki-platform-oldcore/pom.xml
@@ -414,9 +414,19 @@
<!-- Other XWiki modules -->
<dependency>
- <groupId>org.xwiki.platform</groupId>
- <artifactId>xwiki-platform-configuration-default</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.commons</groupId>
+ <artifactId>xwiki-commons-context</artifactId>
+ <version>${commons.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.xwiki.commons</groupId>
+ <artifactId>xwiki-commons-script</artifactId>
+ <version>${commons.version}</version>
</dependency>
<dependency>
<groupId>org.xwiki.commons</groupId>
@@ -434,14 +444,9 @@
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.xwiki.commons</groupId>
- <artifactId>xwiki-commons-script</artifactId>
- <version>${commons.version}</version>
- </dependency>
- <dependency>
- <groupId>org.xwiki.commons</groupId>
- <artifactId>xwiki-commons-context</artifactId>
- <version>${commons.version}</version>
+ <groupId>org.xwiki.platform</groupId>
+ <artifactId>xwiki-platform-configuration-default</artifactId>
+ <version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
View
7 xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/pdf/impl/PdfExportImpl.java
@@ -75,9 +75,8 @@
import org.w3c.tidy.Tidy;
import org.xml.sax.InputSource;
import org.xwiki.bridge.DocumentAccessBridge;
-import org.xwiki.container.ApplicationContext;
-import org.xwiki.container.Container;
import org.xwiki.context.Execution;
+import org.xwiki.environment.Environment;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.model.reference.DocumentReferenceResolver;
import org.xwiki.model.reference.EntityReferenceSerializer;
@@ -173,8 +172,8 @@
// ----------------------------------------------------------------------
fopFactory = FopFactory.newInstance();
try {
- ApplicationContext context = Utils.getComponent(Container.class).getApplicationContext();
- String fontsPath = context.getResource(FONTS_PATH).getPath();
+ Environment environment = Utils.getComponent(Environment.class);
+ String fontsPath = environment.getResource(FONTS_PATH).getPath();
Execution execution = Utils.getComponent(Execution.class);
XWikiContext xcontext = (XWikiContext) execution.getContext().getProperty("xwikicontext");
if (xcontext != null) {
View
8 xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/web/TempResourceAction.java
@@ -34,7 +34,7 @@
import org.apache.tika.mime.MimeTypes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.xwiki.container.Container;
+import org.xwiki.environment.Environment;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
@@ -69,9 +69,9 @@
private Tika tika = new Tika();
/**
- * Used to resolve temporary working dir.
+ * Used to find the temporary dir.
*/
- private Container container = Utils.getComponent(Container.class);
+ private Environment environment = Utils.getComponent(Environment.class);
/**
* {@inheritDoc}
@@ -136,7 +136,7 @@ protected File getTemporaryFile(String uri, XWikiContext context)
String prefix = String.format("temp/%s/%s/%s/%s/", module, wiki, space, page);
String path = URI.create(prefix + filePath).normalize().toString();
if (path.startsWith(prefix)) {
- result = new File(container.getApplicationContext().getTemporaryDirectory(), path);
+ result = new File(this.environment.getTemporaryDirectory(), path);
result = result.exists() ? result : null;
}
}
View
17 ...tform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/test/AbstractBridgedComponentTestCase.java
@@ -19,14 +19,17 @@
*/
package com.xpn.xwiki.test;
+import javax.servlet.ServletContext;
+
import org.jmock.Expectations;
import org.jmock.api.Imposteriser;
import org.jmock.lib.legacy.ClassImposteriser;
import org.junit.After;
import org.junit.Before;
import org.xwiki.component.manager.ComponentManager;
-import org.xwiki.container.Container;
import org.xwiki.context.Execution;
+import org.xwiki.environment.Environment;
+import org.xwiki.environment.internal.ServletEnvironment;
import org.xwiki.rendering.syntax.Syntax;
import org.xwiki.test.AbstractComponentTestCase;
@@ -78,9 +81,15 @@ public void setUp() throws Exception
execution.getContext().setProperty("xwikicontext", this.context);
getComponentManager().lookup(XWikiStubContextProvider.class).initialize(this.context);
- // Set a simple application context, as some components fail to start without one.
- Container c = getComponentManager().lookup(Container.class);
- c.setApplicationContext(new TestApplicationContext());
+ // Since the oldcore module draws the Servlet Environment in its dependencies we need to ensure it's set up
+ // correctly with a Servlet Context.
+ ServletEnvironment environment = (ServletEnvironment) getComponentManager().lookup(Environment.class);
+ final ServletContext mockServletContext = getMockery().mock(ServletContext.class);
+ environment.setServletContext(mockServletContext);
+ getMockery().checking(new Expectations() {{
+ allowing(mockServletContext).getResourceAsStream("/WEB-INF/cache/infinispan/config.xml");
+ will(returnValue(null));
+ }});
final CoreConfiguration mockCoreConfiguration = registerMockComponent(CoreConfiguration.class);
getMockery().checking(new Expectations() {{
View
15 ...-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/test/AbstractBridgedXWikiComponentTestCase.java
@@ -19,10 +19,13 @@
*/
package com.xpn.xwiki.test;
+import javax.servlet.ServletContext;
+
import org.jmock.Mock;
import org.xwiki.component.manager.ComponentManager;
-import org.xwiki.container.Container;
import org.xwiki.context.Execution;
+import org.xwiki.environment.Environment;
+import org.xwiki.environment.internal.ServletEnvironment;
import org.xwiki.rendering.syntax.Syntax;
import com.xpn.xwiki.CoreConfiguration;
@@ -66,9 +69,13 @@ protected void setUp() throws Exception
execution.getContext().setProperty("xwikicontext", this.context);
getComponentManager().lookup(XWikiStubContextProvider.class).initialize(this.context);
- // Set a simple application context, as some components fail to start without one.
- Container c = getComponentManager().lookup(Container.class);
- c.setApplicationContext(new TestApplicationContext());
+ // Since the oldcore module draws the Servlet Environment in its dependencies we need to ensure it's set up
+ // correctly with a Servlet Context.
+ ServletEnvironment environment = (ServletEnvironment) getComponentManager().lookup(Environment.class);
+ Mock mockServletContext = mock(ServletContext.class);
+ environment.setServletContext((ServletContext) mockServletContext.proxy());
+ mockServletContext.stubs().method("getResourceAsStream").with(eq("/WEB-INF/cache/infinispan/config.xml"))
+ .will(returnValue(null));
Mock mockCoreConfiguration = registerMockComponent(CoreConfiguration.class);
mockCoreConfiguration.stubs().method("getDefaultDocumentSyntax").will(returnValue(Syntax.XWIKI_1_0));
View
61 xwiki-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/test/TestApplicationContext.java
@@ -1,61 +0,0 @@
-/*
- * See the NOTICE file distributed with this work for additional
- * information regarding copyright ownership.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package com.xpn.xwiki.test;
-
-import java.io.File;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import org.apache.commons.lang3.StringUtils;
-import org.xwiki.container.ApplicationContext;
-
-/**
- * Simple {@link ApplicationContext} implementation that uses the classloader's <code>getResource</code> and
- * <code>getResourceAsStream</code> methods to access resources. Useful for running tests without a real live container.
- *
- * @version $Id$
- */
-public class TestApplicationContext implements ApplicationContext
-{
- @Override
- public URL getResource(String resourceName) throws MalformedURLException
- {
- return getClass().getClassLoader().getResource(StringUtils.removeStart(resourceName, "/"));
- }
-
- @Override
- public InputStream getResourceAsStream(String resourceName)
- {
- return getClass().getResourceAsStream(StringUtils.removeStart(resourceName, "/"));
- }
-
- @Override
- public File getTemporaryDirectory()
- {
- throw new UnsupportedOperationException("This method is not implemented for this test class.");
- }
-
- @Override
- public File getPermanentDirectory()
- {
- throw new UnsupportedOperationException("This method is not implemented for this test class.");
- }
-}
View
41 xwiki-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/web/TempResourceActionTest.java
@@ -26,11 +26,11 @@
import org.jmock.Expectations;
import org.junit.Test;
-import org.xwiki.container.ApplicationContext;
-import org.xwiki.container.Container;
import org.xwiki.context.Execution;
import org.xwiki.context.ExecutionContext;
import org.xwiki.context.ExecutionContextManager;
+import org.xwiki.environment.Environment;
+import org.xwiki.environment.internal.ServletEnvironment;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.test.AbstractBridgedComponentTestCase;
@@ -55,14 +55,27 @@
private ExecutionContext executionContext;
@Override
+ public void setUp() throws Exception
+ {
+ base = new File(getClass().getResource("/").toURI());
+
+ super.setUp();
+
+ action = new TempResourceAction();
+ }
+
+ @Override
protected void registerComponents() throws Exception
{
super.registerComponents();
this.executionContext = new ExecutionContext();
-
- final Container mockContainer = registerMockComponent(Container.class);
- final ApplicationContext mockAppContext = registerMockComponent(ApplicationContext.class);
+
+ // Configure Servlet Environment defined in AbstractBridgedComponentTestCase so that it returns a good
+ // temporary directory
+ ServletEnvironment environment = (ServletEnvironment) getComponentManager().lookup(Environment.class);
+ environment.setTemporaryDirectory(base);
+
final ExecutionContextManager mockExecutionContextManager =
registerMockComponent(ExecutionContextManager.class);
final Execution mockExecution = registerMockComponent(Execution.class);
@@ -74,28 +87,10 @@ protected void registerComponents() throws Exception
allowing(mockExecution).getContext(); will(returnValue(executionContext));
allowing(mockExecution).removeContext();
-
- ignoring(mockContainer).setApplicationContext(with(any(ApplicationContext.class)));
-
- allowing(mockContainer).getApplicationContext();
- will(returnValue(mockAppContext));
-
- allowing(mockAppContext).getTemporaryDirectory();
- will(returnValue(base));
}
});
}
- @Override
- public void setUp() throws Exception
- {
- base = new File(getClass().getResource("/").toURI());
-
- super.setUp();
-
- action = new TempResourceAction();
- }
-
/**
* Creates an empty file at the specified path.
*
View
11 xwiki-platform-core/xwiki-platform-velocity/xwiki-platform-velocity-webapp/pom.xml
@@ -35,14 +35,9 @@
<description>Velocity Engine implementation when in a Servlet environment (templates located in the webapp's root)</description>
<dependencies>
<dependency>
- <groupId>org.xwiki.platform</groupId>
- <artifactId>xwiki-platform-container-servlet</artifactId>
- <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-servlet</artifactId>
+ <version>${commons.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
View
22 ...-velocity/xwiki-platform-velocity-webapp/src/main/java/org/xwiki/velocity/XWikiWebappResourceLoader.java
@@ -23,9 +23,8 @@
import org.apache.velocity.tools.view.servlet.WebappLoader;
import org.xwiki.component.manager.ComponentLookupException;
import org.xwiki.component.manager.ComponentManager;
-import org.xwiki.container.ApplicationContext;
-import org.xwiki.container.Container;
-import org.xwiki.container.servlet.ServletApplicationContext;
+import org.xwiki.environment.Environment;
+import org.xwiki.environment.internal.ServletEnvironment;
/**
* Extends the Velocity Tool's {@link WebappLoader} by adding the ServletContext to the Velocity Engine's Application
@@ -38,31 +37,28 @@
*/
public class XWikiWebappResourceLoader extends WebappLoader
{
- /**
- * {@inheritDoc}
- */
@Override
public void init(ExtendedProperties configuration)
{
- ApplicationContext context = getContainer().getApplicationContext();
- if (context instanceof ServletApplicationContext) {
+ Environment environment = getEnvironment();
+ if (environment instanceof ServletEnvironment) {
this.rsvc.setApplicationAttribute("javax.servlet.ServletContext",
- ((ServletApplicationContext) context).getServletContext());
+ ((ServletEnvironment) environment).getServletContext());
}
super.init(configuration);
}
/**
- * @return the Container component implementation retrieved from the Component Manager
+ * @return the Environment component implementation retrieved from the Component Manager
*/
- private Container getContainer()
+ private Environment getEnvironment()
{
try {
- return getComponentManager().lookup(Container.class);
+ return getComponentManager().lookup(Environment.class);
} catch (ComponentLookupException e) {
throw new RuntimeException(
- "Cannot initialize Velocity subsystem: missing Container component implementation");
+ "Cannot initialize Velocity subsystem: missing Environment component implementation");
}
}
View
8 ...ocity/xwiki-platform-velocity-webapp/src/test/java/org/xwiki/velocity/XWikiWebappResourceLoaderTest.java
@@ -22,9 +22,13 @@
import java.io.StringWriter;
import java.util.Properties;
+import javax.servlet.ServletContext;
+
import org.apache.velocity.VelocityContext;
import org.junit.Assert;
import org.junit.Test;
+import org.xwiki.environment.Environment;
+import org.xwiki.environment.internal.ServletEnvironment;
import org.xwiki.test.AbstractComponentTestCase;
/**
@@ -38,6 +42,10 @@
@Test
public void testVelocityInitialization() throws Exception
{
+ // Fake the initialization of the Servlet Environment
+ ServletEnvironment environment = (ServletEnvironment) getComponentManager().lookup(Environment.class);
+ environment.setServletContext(getMockery().mock(ServletContext.class));
+
Properties properties = new Properties();
properties.setProperty("resource.loader", "xwiki");
properties.setProperty("xwiki.resource.loader.class", XWikiWebappResourceLoader.class.getName());
View
14 xwiki-platform-tools/xwiki-platform-tool-configuration-resources/src/main/resources/xwiki.properties.vm
@@ -55,13 +55,13 @@
# core.renderingcache.size=100
#-------------------------------------------------------------------------------------
-# Container
+# Environment
#-------------------------------------------------------------------------------------
-#-# [Since 3.2M3]
+#-# [Since 3.5M1, replaces the container.persistentDirectory property]
#-# The directory used to store persistent data (data that should persist across server restarts). This is an
-#-# important directory containing important data and thus it should never be deleted (it should be backupped along
-#-# with the dabatase).
+#-# important directory containing important data and thus it should never be deleted (it should be backed-up along
+#-# with the database).
#-# For example this is where the Extension Manager stores downloaded extensions if the extension.localRepository
#-# property isn't configured.
#-#
@@ -72,10 +72,10 @@
#-#
#-# If not specified, the Servlet container's temporary directory is used. This is absolutely not recommended and you
#-# should specify a value.
-#if ($xwikiPropertiesContainerPersistentDirectory)
-container.persistentDirectory=$xwikiPropertiesContainerPersistentDirectory
+#if ($xwikiPropertiesEnvironmentPermanentDirectory)
+environment.permanentDirectory=$xwikiPropertiesEnvironmentPermanentDirectory
#else
-# container.persistentDirectory=/var/local/xwiki/
+# environment.permanentDirectory=/var/local/xwiki/
#end
#-------------------------------------------------------------------------------------
View
10 xwiki-platform-tools/xwiki-platform-tool-packager-plugin/pom.xml
@@ -89,9 +89,19 @@
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
+ <!-- Exclude Servlet Environment since we want to run our code in a Standard Environment -->
+ <exclusion>
+ <groupId>org.xwiki.commons</groupId>
+ <artifactId>xwiki-commons-environment-servlet</artifactId>
+ </exclusion>
</exclusions>
</dependency>
<dependency>
+ <groupId>org.xwiki.commons</groupId>
+ <artifactId>xwiki-commons-environment-standard</artifactId>
+ <version>${commons.version}</version>
+ </dependency>
+ <dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.7</version>
View
10 ...-tools/xwiki-platform-tool-packager-plugin/src/main/java/com/xpn/xwiki/tool/backup/AbstractPackager.java
@@ -23,7 +23,6 @@
import java.net.MalformedURLException;
import java.net.URL;
-import org.xwiki.component.embed.EmbeddableComponentManager;
import org.xwiki.component.manager.ComponentManager;
import org.xwiki.context.ExecutionContext;
import org.xwiki.context.ExecutionContextException;
@@ -56,13 +55,12 @@
*/
protected XWikiContext createXWikiContext(String databaseName, File hibernateConfig) throws Exception
{
- EmbeddableComponentManager ecm = new EmbeddableComponentManager();
- ecm.initialize(this.getClass().getClassLoader());
- Utils.setComponentManager(ecm);
+ // Initialize the Component Manager and Environment
+ ComponentManager cm = org.xwiki.environment.System.initialize();
+ Utils.setComponentManager(cm);
- // We need to initialize the Component Manager so that the components can be looked up
XWikiContext xcontext = new XWikiContext();
- xcontext.put(ComponentManager.class.getName(), ecm);
+ xcontext.put(ComponentManager.class.getName(), cm);
// Initialize the Container fields (request, response, session).
ExecutionContextManager ecim = Utils.getComponent(ExecutionContextManager.class);
Please sign in to comment.
Something went wrong with that request. Please try again.