From d54f545f7e9accd456b2b94ec279217ee91bdf5c Mon Sep 17 00:00:00 2001 From: Glyn Normington Date: Tue, 13 Jul 2010 11:54:04 +0100 Subject: place generated config directory in target directory --- org.eclipse.gemini.web.core/.classpath | 2 +- .../localhost/war-with-context-xml-resources.xml | 9 +++++ .../test/tomcat/TomcatServletContainerTests.java | 12 +++++-- .../web/tomcat/internal/TomcatConfigLocator.java | 38 ++++++++++++++-------- 4 files changed, 43 insertions(+), 18 deletions(-) create mode 100644 org.eclipse.gemini.web.test/config/Catalina/localhost/war-with-context-xml-resources.xml diff --git a/org.eclipse.gemini.web.core/.classpath b/org.eclipse.gemini.web.core/.classpath index dfeb4f0..e185010 100644 --- a/org.eclipse.gemini.web.core/.classpath +++ b/org.eclipse.gemini.web.core/.classpath @@ -21,7 +21,7 @@ - + diff --git a/org.eclipse.gemini.web.test/config/Catalina/localhost/war-with-context-xml-resources.xml b/org.eclipse.gemini.web.test/config/Catalina/localhost/war-with-context-xml-resources.xml new file mode 100644 index 0000000..b0623f6 --- /dev/null +++ b/org.eclipse.gemini.web.test/config/Catalina/localhost/war-with-context-xml-resources.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/org.eclipse.gemini.web.test/src/test/java/org/eclipse/gemini/web/test/tomcat/TomcatServletContainerTests.java b/org.eclipse.gemini.web.test/src/test/java/org/eclipse/gemini/web/test/tomcat/TomcatServletContainerTests.java index 2acfffd..c21b9d6 100644 --- a/org.eclipse.gemini.web.test/src/test/java/org/eclipse/gemini/web/test/tomcat/TomcatServletContainerTests.java +++ b/org.eclipse.gemini.web.test/src/test/java/org/eclipse/gemini/web/test/tomcat/TomcatServletContainerTests.java @@ -38,6 +38,7 @@ import java.util.Set; import javax.servlet.ServletContext; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.osgi.framework.Bundle; @@ -87,6 +88,11 @@ public class TomcatServletContainerTests { private BundleContext bundleContext; private ServletContainer container; + + @BeforeClass + public static void beforeClass() throws Exception { + System.setProperty("org.eclipse.gemini.web.tomcat.config.path", "target/config"); + } @Before public void before() throws Exception { @@ -351,17 +357,17 @@ public class TomcatServletContainerTests { @Test public void testWarWithContextXml() throws Exception { // Copy default context.xml - File defaultContextXml = new File("config/context.xml"); + File defaultContextXml = new File("target/config/context.xml"); createFileWithContent(defaultContextXml, ""); // Copy default context.xml.default - File defaultHostContextXml = new File("config/Catalina/localhost/context.xml.default"); + File defaultHostContextXml = new File("target/config/Catalina/localhost/context.xml.default"); String content = "" + "" + ""; createFileWithContent(defaultHostContextXml, content); - File tomcatServerXml = new File("config/tomcat-server.xml"); + File tomcatServerXml = new File("target/config/tomcat-server.xml"); createFileWithContent(tomcatServerXml, ""); String location1 = LOCATION_WAR_WITH_CONTEXT_XML_RESOURCES; diff --git a/org.eclipse.gemini.web.tomcat/src/main/java/org/eclipse/gemini/web/tomcat/internal/TomcatConfigLocator.java b/org.eclipse.gemini.web.tomcat/src/main/java/org/eclipse/gemini/web/tomcat/internal/TomcatConfigLocator.java index 160a2a3..0126e30 100644 --- a/org.eclipse.gemini.web.tomcat/src/main/java/org/eclipse/gemini/web/tomcat/internal/TomcatConfigLocator.java +++ b/org.eclipse.gemini.web.tomcat/src/main/java/org/eclipse/gemini/web/tomcat/internal/TomcatConfigLocator.java @@ -48,7 +48,7 @@ final class TomcatConfigLocator { private static final Logger LOGGER = LoggerFactory.getLogger(TomcatConfigLocator.class); static final String CONFIG_PATH_FRAMEWORK_PROPERTY = "org.eclipse.gemini.web.tomcat.config.path"; - + static final String DEFAULT_CONFIG_FILE_PATH = "config" + File.separator + "tomcat-server.xml"; static final String CONFIG_PATH = "META-INF/tomcat"; @@ -73,22 +73,23 @@ final class TomcatConfigLocator { * * The location algorithm is as follows: *
    - *
  1. Check for org.eclipse.gemini.web.tomcat.config.path - * framework property, use if found
  2. - *
  3. Check for config/tomcat-server.xml in the current - * working directory, use if found
  4. - *
  5. If the previous checks do not return a result, return - * null
  6. + *
  7. Check for org.eclipse.gemini.web.tomcat.config.path framework property, use if found
  8. + *
  9. Check for config/tomcat-server.xml in the current working directory, use if found
  10. + *
  11. If the previous checks do not return a result, return null
  12. *
* - * @param context - * the bundle context + * @param context the bundle context * @return the directory where the Tomcat configuration files resides. */ public static File resolveConfigDir(BundleContext context) { File configFile = null; - // Search for the property 'org.eclipse.gemini.web.tomcat.config.path' + /* + * Search for the framework property 'org.eclipse.gemini.web.tomcat.config.path' + * + * Note: this is supposed to search framework and system properties but appears to ignore system properties which + * are set after the framework has initialised. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=319679. + */ String path = context.getProperty(TomcatConfigLocator.CONFIG_PATH_FRAMEWORK_PROPERTY); if (path != null) { configFile = new File(path); @@ -97,6 +98,15 @@ final class TomcatConfigLocator { } } + // Search for the system property 'org.eclipse.gemini.web.tomcat.config.path' + path = System.getProperty(TomcatConfigLocator.CONFIG_PATH_FRAMEWORK_PROPERTY); + if (path != null) { + configFile = new File(path); + if (configFile.exists()) { + return configFile.getParentFile(); + } + } + // Search for the 'config' directory configFile = new File(TomcatConfigLocator.DEFAULT_CONFIG_FILE_PATH); if (configFile.exists()) { @@ -110,11 +120,11 @@ final class TomcatConfigLocator { InputStream result = null; String path = context.getProperty(CONFIG_PATH_FRAMEWORK_PROPERTY); - if(path != null) { + if (path != null) { result = tryGetStreamForFilePath(path); } - - if(result == null) { + + if (result == null) { result = tryGetStreamForFilePath(DEFAULT_CONFIG_FILE_PATH); } return result; @@ -149,7 +159,7 @@ final class TomcatConfigLocator { entry = bundle.getEntry(DEFAULT_CONFIG_PATH); if (entry == null) { throw new IllegalStateException("Unable to locate default Tomcat configuration. Is the '" + bundle + "' bundle corrupt?"); - } else if(LOGGER.isInfoEnabled()) { + } else if (LOGGER.isInfoEnabled()) { LOGGER.info("Configuring Tomcat from default config file"); } } -- cgit v1.2.3