Author: ate
Date: Fri Apr 18 05:01:12 2008
New Revision: 649476

URL: http://svn.apache.org/viewvc?rev=649476&view=rev
Log:
Many fixes and enhancements for how Jetspeed loads its properties configuration:
- allow defining jetspeed.properties outside applicationRoot
- derive new global property ${jetspeedPropertiesPath} from the 
jetspeed.properties file location (still defaults to /WEB-INF/conf)
- load all other configuration properties from this ${jetspeedPropertiesPath}
    NB: moving jetspeed.properties thus requires moving the other properties as 
well to that same location!
- adjust assembly references to these property files using the new 
${jetspeedPropertiesPath}
- fix proper "override" behavior by individually loading the property files and 
copy the key/values to the master (Commons) Configuration
  instead of having Commons Configuration load and thereby incorrectly *append* 
multiple values for the same key (dropping the include=override.properties 
definition and usage in jetspeed.properties)
- allow overriding the spring.filter.key property through a separate properties 
file, spring-filter-key.properties:
    - *only* property spring.filter.key will be loaded from this file (if it 
exists)
    - this makes it easy for simple switching to another assembly configuration 
by just replacing/overwriting that properties file
- define proper constants for all these in JetspeedEngineConstants
- splitting off a new assembly configuration file, jetspeed-properties.xml 
containing only the PortalConfiguration and Spring PropertyPlaceHolderConfigurer
  so these can more easily used by test cases 

Added:
    
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-properties.xml
   (with props)
Modified:
    
portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/SpringComponentManager.java
    
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/engine/JetspeedServlet.java
    
portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/engine/JetspeedEngineConstants.java
    
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-production.xml
    
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-spring.xml
    
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/conf/jetspeed/jetspeed.properties

Modified: 
portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/SpringComponentManager.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/SpringComponentManager.java?rev=649476&r1=649475&r2=649476&view=diff
==============================================================================
--- 
portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/SpringComponentManager.java
 (original)
+++ 
portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/SpringComponentManager.java
 Fri Apr 18 05:01:12 2008
@@ -67,6 +67,10 @@
             initProperties = new Properties();
         }
         
initProperties.setProperty(JetspeedEngineConstants.APPLICATION_ROOT_KEY, 
appRoot);
+        if 
(!initProperties.containsKey(JetspeedEngineConstants.JETSPEED_PROPERTIES_PATH_KEY))
+        {
+            
initProperties.put(JetspeedEngineConstants.JETSPEED_PROPERTIES_PATH_KEY, 
appRoot+JetspeedEngineConstants.JETSPEED_PROPERTIES_PATH_DEFAULT);
+        }
         
         if (bootConfigs != null && bootConfigs.length > 0)
         {
@@ -96,6 +100,10 @@
             initProperties = new Properties();
         }
         
initProperties.setProperty(JetspeedEngineConstants.APPLICATION_ROOT_KEY, 
appRoot);
+        if 
(!initProperties.containsKey(JetspeedEngineConstants.JETSPEED_PROPERTIES_PATH_KEY))
+        {
+            
initProperties.put(JetspeedEngineConstants.JETSPEED_PROPERTIES_PATH_KEY, 
appRoot+JetspeedEngineConstants.JETSPEED_PROPERTIES_PATH_DEFAULT);
+        }
         
         if (bootConfigs != null && bootConfigs.length > 0)
         {

Modified: 
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/engine/JetspeedServlet.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/engine/JetspeedServlet.java?rev=649476&r1=649475&r2=649476&view=diff
==============================================================================
--- 
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/engine/JetspeedServlet.java
 (original)
+++ 
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/engine/JetspeedServlet.java
 Fri Apr 18 05:01:12 2008
@@ -16,8 +16,10 @@
  */
 package org.apache.jetspeed.engine;
 
+import java.io.File;
 import java.io.IOException;
 import java.security.Principal;
+import java.util.Properties;
 
 import javax.security.auth.Subject;
 import javax.servlet.ServletConfig;
@@ -30,6 +32,7 @@
 import javax.servlet.http.HttpSessionListener;
 
 import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationUtils;
 import org.apache.commons.configuration.PropertiesConfiguration;
 import org.apache.commons.lang.exception.ExceptionUtils;
 import org.apache.commons.logging.Log;
@@ -145,12 +148,40 @@
                     applicationRoot = webappRoot;
                 }
 
-                Configuration properties = new 
PropertiesConfiguration(ServletHelper.getRealPath(
-                        config, propertiesFilename));
-
+                // load jetspeed.properties, override.properties and 
spring-filter-key.properties separately
+                // and "merge" them by hand instead of relaying on Commons 
Configuration "include" functionality...
+                // Commons Configuration performs property value *appending* 
if keys are encountered multiple times,
+                // thereby *not* resulting in the proper override 
functionality we need.
+                PropertiesConfiguration properties = new 
PropertiesConfiguration();
+                File propsFile = new File(ServletHelper.getRealPath(config, 
propertiesFilename));
+                if (!propsFile.isFile())
+                {
+                    throw new IOException("Jetspeed properties not found: 
"+propsFile.getAbsolutePath());
+                }
+                File jetspeedPropertiesPath = propsFile.getParentFile();
+                properties.load(propsFile);
+                propsFile = new 
File(jetspeedPropertiesPath,OVERRIDE_PROPERTIES);
+                if (propsFile.exists())
+                {
+                    PropertiesConfiguration extraProps = new 
PropertiesConfiguration();
+                    extraProps.load(propsFile);
+                    ConfigurationUtils.copy(extraProps,properties);
+                }
+                propsFile = new 
File(jetspeedPropertiesPath,SPRING_FILTER_KEY_PROPERTIES);
+                if (propsFile.exists())
+                {
+                    PropertiesConfiguration extraProps = new 
PropertiesConfiguration();
+                    extraProps.load(propsFile);
+                    Object springFilterKey = 
extraProps.getProperty(SPRING_FILTER_KEY);
+                    if (springFilterKey != null)
+                    {
+                        properties.setProperty(SPRING_FILTER_KEY, 
springFilterKey);
+                    }
+                }
                 properties.setProperty(APPLICATION_ROOT_KEY, applicationRoot);
                 properties.setProperty(WEBAPP_ROOT_KEY, webappRoot);
-
+                properties.setProperty(JETSPEED_PROPERTIES_PATH_KEY, 
jetspeedPropertiesPath.getAbsolutePath());
+                
                 console.info("JetspeedServlet attempting to create the  
portlet engine...");
 
                 engine = new JetspeedEngine(properties, applicationRoot, 
config, initializeComponentManager(config, applicationRoot, properties));
@@ -313,13 +344,19 @@
         ServletConfigFactoryBean.setServletConfig(servletConfig);
         final String assemblyDir = 
configuration.getString("assembly.dir","/WEB-INF/assembly");
         final String assemblyFileExtension = 
configuration.getString("assembly.extension",".xml");
-        String springFilterKey = configuration.getString("spring.filter.key", 
"portal");
-                    
+        String springFilterKey = configuration.getString(SPRING_FILTER_KEY, 
SPRING_FILTER_KEY_DEFAULT);
+        File springFilterProperties = new 
File(configuration.getString(JETSPEED_PROPERTIES_PATH_KEY), 
SPRING_FILTER_PROPERTIES);
+        if (!springFilterProperties.isFile())
+        {
+            throw new IOException("Spring filter properties not found: 
"+springFilterProperties.getAbsolutePath());
+        }
         String[] bootConfigs = new String[] {"/WEB-INF/assembly/boot/*.xml"};
         String[] appConfigs =  new String[] 
{assemblyDir+"/*"+assemblyFileExtension, 
assemblyDir+"/override/*"+assemblyFileExtension};
         ServletContext servletContext = servletConfig.getServletContext();
-        JetspeedBeanDefinitionFilter filter = new 
JetspeedBeanDefinitionFilter("file:"+appRoot+"/WEB-INF/conf/spring-filter.properties",
 springFilterKey);
-        SpringComponentManager cm = new SpringComponentManager(filter, 
bootConfigs, appConfigs, servletContext, appRoot);      
+        JetspeedBeanDefinitionFilter filter = new 
JetspeedBeanDefinitionFilter("file:"+springFilterProperties.getAbsolutePath(), 
springFilterKey);
+        Properties initProperties = new Properties();
+        initProperties.put(JETSPEED_PROPERTIES_PATH_KEY, 
configuration.getString(JETSPEED_PROPERTIES_PATH_KEY));
+        SpringComponentManager cm = new SpringComponentManager(filter, 
bootConfigs, appConfigs, servletContext, appRoot, initProperties);      
         
         return cm;        
     }

Modified: 
portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/engine/JetspeedEngineConstants.java
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/engine/JetspeedEngineConstants.java?rev=649476&r1=649475&r2=649476&view=diff
==============================================================================
--- 
portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/engine/JetspeedEngineConstants.java
 (original)
+++ 
portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/engine/JetspeedEngineConstants.java
 Fri Apr 18 05:01:12 2008
@@ -63,6 +63,13 @@
 
     public static final String JETSPEED_PROPERTIES_KEY = "properties";
     public static final String JETSPEED_PROPERTIES_DEFAULT = 
"/WEB-INF/conf/jetspeed.properties";
+    public static final String JETSPEED_PROPERTIES_PATH_KEY = 
"jetspeedPropertiesPath";
+    public static final String JETSPEED_PROPERTIES_PATH_DEFAULT = 
"/WEB-INF/conf";
+    public static final String OVERRIDE_PROPERTIES = "override.properties";
+    public static final String SPRING_FILTER_KEY_PROPERTIES = 
"spring-filter-key.properties";
+    public static final String SPRING_FILTER_KEY = "spring.filter.key";
+    public static final String SPRING_FILTER_KEY_DEFAULT = "portal";
+    public static final String SPRING_FILTER_PROPERTIES = 
"spring-filter.properties";
 
     /** If this value is set as applicationRoot, then the webContext is used
      * as application root

Modified: 
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-production.xml
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-production.xml?rev=649476&r1=649475&r2=649476&view=diff
==============================================================================
--- 
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-production.xml
 (original)
+++ 
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-production.xml
 Fri Apr 18 05:01:12 2008
@@ -23,7 +23,7 @@
   <bean id="ProductionConfiguration" 
class="org.apache.commons.configuration.PropertiesConfiguration">
     <meta key="j2:cat" value="default" />
     <constructor-arg>
-      
<value>${applicationRoot}/WEB-INF/conf/jetspeed-production.properties</value>
+      <value>${jetspeedPropertiesPath}/jetspeed-production.properties</value>
     </constructor-arg>
   </bean>
 </beans>

Added: 
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-properties.xml
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-properties.xml?rev=649476&view=auto
==============================================================================
--- 
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-properties.xml
 (added)
+++ 
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-properties.xml
 Fri Apr 18 05:01:12 2008
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+  
+  http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd";>
+
+  <!-- Commons configuration object generated from jetspeed.properties + 
override.properties -->
+  <bean id="portal_configuration" 
class="org.apache.jetspeed.components.util.ConfigurationProperties">
+    <meta key="j2:cat" value="default" />
+    <property name="locations">
+      <list>
+        <value>file:///${jetspeedPropertiesPath}/jetspeed.properties</value>
+        <value>file:///${jetspeedPropertiesPath}/override.properties</value>
+      </list>
+    </property>
+    <property name="properties">
+      <value>applicationRoot=${applicationRoot}</value>
+    </property>
+  </bean>
+
+  <!-- Adds jetspeed.properties as our configuration object to support ${...} 
vars -->
+  <bean id="placeholderConfig" 
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
+    <meta key="j2:cat" value="default,springProperties" />
+    <property name="locations">
+      <list>
+        <value>file:///${jetspeedPropertiesPath}/jetspeed.properties</value>
+        <value>file:///${jetspeedPropertiesPath}/override.properties</value>
+      </list>
+    </property>
+    <property name="properties">
+      <value>applicationRoot=${applicationRoot}</value>
+    </property>
+  </bean>
+
+</beans>

Propchange: 
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-properties.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-properties.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: 
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-properties.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-spring.xml
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-spring.xml?rev=649476&r1=649475&r2=649476&view=diff
==============================================================================
--- 
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-spring.xml
 (original)
+++ 
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-spring.xml
 Fri Apr 18 05:01:12 2008
@@ -18,14 +18,6 @@
 <beans xmlns="http://www.springframework.org/schema/beans"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
   xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd";>
 
-  <!-- Commons configuration object generated from jetspeed.properties -->
-  <bean id="portal_configuration" 
class="org.apache.commons.configuration.PropertiesConfiguration">
-    <meta key="j2:cat" value="default" />
-    <constructor-arg>
-      <value>${applicationRoot}/WEB-INF/conf/jetspeed.properties</value>
-    </constructor-arg>
-  </bean>
-
   <bean id="PortalConfiguration" 
class="org.apache.jetspeed.administration.PortalConfigurationImpl">
     <meta key="j2:cat" value="default" />
     <constructor-arg>
@@ -192,22 +184,6 @@
     </property>
     <property name="responseFactory">
       <ref bean="ServletResponseFactory" />
-    </property>
-  </bean>
-
-  <!-- Adds jetspeed.properties as our configuration object to support ${...} 
vars -->
-  <!-- ${applicationRoot} is acutally set as a system property via the 
SpringEngine -->
-
-  <bean id="placeholderConfig" 
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
-    <meta key="j2:cat" value="default,springProperties" />
-    <property name="locations">
-      <list>
-        
<value>file:///${applicationRoot}/WEB-INF/conf/jetspeed.properties</value>
-        
<value>file:///${applicationRoot}/WEB-INF/conf/override.properties</value>
-      </list>
-    </property>
-    <property name="properties">
-      <value>applicationRoot=${applicationRoot}</value>
     </property>
   </bean>
 

Modified: 
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/conf/jetspeed/jetspeed.properties
URL: 
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/conf/jetspeed/jetspeed.properties?rev=649476&r1=649475&r2=649476&view=diff
==============================================================================
--- 
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/conf/jetspeed/jetspeed.properties
 (original)
+++ 
portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/conf/jetspeed/jetspeed.properties
 Fri Apr 18 05:01:12 2008
@@ -21,12 +21,6 @@
 #
 # ------------------------------------------------------------------------
 
-#-------------------------------------------------------------------------
-# override for jetspeed.properties.  This include needs to be come before
-# any other prop definitions.
-#-------------------------------------------------------------------------
-include=override.properties
-
 portal.name = Jetspeed
 portal.version = 2.2-SNAPSHOT
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to