You are viewing a plain text version of this content. The canonical link for it is here.
Posted to svn@forrest.apache.org by th...@apache.org on 2006/08/11 01:28:05 UTC

svn commit: r430588 - in /forrest/trunk: main/forrest.build.xml main/java/org/apache/forrest/conf/ForrestConfModule.java main/targets/context.xml main/targets/site.xml site-author/status.xml

Author: thorsten
Date: Thu Aug 10 16:28:05 2006
New Revision: 430588

URL: http://svn.apache.org/viewvc?rev=430588&view=rev
Log:
FOR-916 - adding site-wide configuration files
Applying patches from Mathieu Champlon.
Thanks Mathieu for your contribution.

Modified:
    forrest/trunk/main/forrest.build.xml
    forrest/trunk/main/java/org/apache/forrest/conf/ForrestConfModule.java
    forrest/trunk/main/targets/context.xml
    forrest/trunk/main/targets/site.xml
    forrest/trunk/site-author/status.xml

Modified: forrest/trunk/main/forrest.build.xml
URL: http://svn.apache.org/viewvc/forrest/trunk/main/forrest.build.xml?rev=430588&r1=430587&r2=430588&view=diff
==============================================================================
--- forrest/trunk/main/forrest.build.xml (original)
+++ forrest/trunk/main/forrest.build.xml Thu Aug 10 16:28:05 2006
@@ -96,6 +96,7 @@
     <property name="project.home" location="." />
     <property file="${project.home}/forrest.properties" />
     <property file="${user.home}/forrest.properties" />
+    <property file="${global.home}/forrest.properties" />
     <property file="${forrest.core.webapp}/default-forrest.properties" />
     
     <!-- people should use forrest.properties to override following defaults  -->
@@ -453,6 +454,8 @@
        <syspropertyset>
          <propertyref prefix="forrest."/>
          <propertyref prefix="project."/>
+         <propertyref name="user.home"/>
+         <propertyref name="global.home"/>
        </syspropertyset>
     </java>
   </target>
@@ -486,6 +489,8 @@
        <syspropertyset>
          <propertyref prefix="forrest."/>
          <propertyref prefix="project."/>
+         <propertyref name="user.home"/>
+         <propertyref name="global.home"/>
        </syspropertyset>
     </java>
   </target>

Modified: forrest/trunk/main/java/org/apache/forrest/conf/ForrestConfModule.java
URL: http://svn.apache.org/viewvc/forrest/trunk/main/java/org/apache/forrest/conf/ForrestConfModule.java?rev=430588&r1=430587&r2=430588&view=diff
==============================================================================
--- forrest/trunk/main/java/org/apache/forrest/conf/ForrestConfModule.java (original)
+++ forrest/trunk/main/java/org/apache/forrest/conf/ForrestConfModule.java Thu Aug 10 16:28:05 2006
@@ -16,7 +16,6 @@
  */
 package org.apache.forrest.conf;
 
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
@@ -60,8 +59,6 @@
 
     private SourceResolver m_resolver;
 
-    private final static String defaultHome = "context:/";
-
     public Object getAttribute(String name, Configuration modeConf, Map objectModel)
             throws ConfigurationException {
         String original;
@@ -82,7 +79,7 @@
                     + " in either forrest.properties.xml in $PROJECT_HOME "
                     + "or in the default.forrest.properties.xml of the plugin "
                     + "that is requesting this property."
-                    + "\n" 
+                    + "\n"
                     + "If you see this message, then most of the time you have spotted a plugin bug "
                     + "(i.e. forgot to define the plugin's default property). Please report to our mailing list.";
             throw new ConfigurationException(
@@ -109,77 +106,72 @@
         return attributeValues;
     }
 
-    private final String getSystemProperty(String propertyName) {
-
-        // if the property is not set, default to the webapp context
-        String propertyValue = System.getProperty(propertyName, defaultHome);
-
-        if (debugging())
-            debug("system property " + propertyName + "=" + propertyValue);
-
-        return propertyValue;
-    }
-
     public void initialize() throws Exception {
 
         // add all homes important to forrest to the properties
         setHomes();
 
+        loadSystemProperties(filteringProperties);
+
         // NOTE: the first values set get precedence, as in AntProperties
 
         String forrestPropertiesStringURI;
 
-        // get the values from local.forrest.properties.xml
         try {
+            // get the values from local.forrest.properties.xml
             forrestPropertiesStringURI = projectHome + SystemUtils.FILE_SEPARATOR
                     + "local.forrest.properties.xml";
-
             filteringProperties = loadXMLPropertiesFromURI(filteringProperties,
                     forrestPropertiesStringURI);
 
-        // get the values from forrest.properties.xml
+            // get the values from project forrest.properties.xml
             forrestPropertiesStringURI = projectHome + SystemUtils.FILE_SEPARATOR
                     + "forrest.properties.xml";
-
             filteringProperties = loadXMLPropertiesFromURI(filteringProperties,
                     forrestPropertiesStringURI);
 
-        // get the values from default.forrest.properties.xml
+            // get the values from user forrest.properties.xml
+            String userHome = filteringProperties.getProperty("user.home");
+            if (userHome != null)
+            {
+                forrestPropertiesStringURI = userHome + SystemUtils.FILE_SEPARATOR
+                        + "forrest.properties.xml";
+                filteringProperties = loadXMLPropertiesFromURI(filteringProperties,
+                        forrestPropertiesStringURI);
+            }
+
+            // get the values from global forrest.properties.xml
+            String globalHome = filteringProperties.getProperty("global.home");
+            if (globalHome != null)
+            {
+                forrestPropertiesStringURI = globalHome + SystemUtils.FILE_SEPARATOR
+                        + "forrest.properties.xml";
+                filteringProperties = loadXMLPropertiesFromURI(filteringProperties,
+                        forrestPropertiesStringURI);
+            }
+
+            // get the values from default.forrest.properties.xml
             forrestPropertiesStringURI = contextHome + SystemUtils.FILE_SEPARATOR
                     + "default.forrest.properties.xml";
-
             filteringProperties = loadXMLPropertiesFromURI(filteringProperties,
                     forrestPropertiesStringURI);
 
-        // get forrest.properties and load the values
-            forrestPropertiesStringURI = projectHome + SystemUtils.FILE_SEPARATOR
-                + "forrest.properties";        
-            filteringProperties = loadAntPropertiesFromURI(filteringProperties,
-                forrestPropertiesStringURI);
-
-        // get default-forrest.properties and load the values
-        String defaultForrestPropertiesStringURI = contextHome + SystemUtils.FILE_SEPARATOR
-                + "default-forrest.properties";
-        filteringProperties = loadAntPropertiesFromURI(filteringProperties,
-                defaultForrestPropertiesStringURI);
-
-        // Load plugin default properties
-        String strPluginList = filteringProperties.getProperty("project.required.plugins");
-        if (strPluginList != null) {
-            StringTokenizer st = new StringTokenizer(strPluginList, ",");
-            while (st.hasMoreTokens()) {
-                forrestPropertiesStringURI = ForrestConfUtils.getPluginDir(st.nextToken().trim());
+            // Load plugin default properties
+            String strPluginList = filteringProperties.getProperty("project.required.plugins");
+            if (strPluginList != null) {
+                StringTokenizer st = new StringTokenizer(strPluginList, ",");
+                while (st.hasMoreTokens()) {
+                    forrestPropertiesStringURI = ForrestConfUtils.getPluginDir(st.nextToken().trim());
                     forrestPropertiesStringURI = forrestPropertiesStringURI
                             + SystemUtils.FILE_SEPARATOR + "default.plugin.properties.xml";
                     filteringProperties = loadXMLPropertiesFromURI(filteringProperties,
                             forrestPropertiesStringURI);
+                }
             }
-        }
         } finally {
-        loadSystemProperties(filteringProperties);
-        ForrestConfUtils.aliasSkinProperties(filteringProperties);
-        if (debugging())
-            debug("Loaded project properties:" + filteringProperties);
+            ForrestConfUtils.aliasSkinProperties(filteringProperties);
+            if (debugging())
+                debug("Loaded project properties:" + filteringProperties);
         }
     }
 
@@ -202,17 +194,19 @@
     }
 
     /**
-     * Override any properties for which a system property exists
+     * Load system properties
      */
     private void loadSystemProperties(AntProperties props) {
-        for (Enumeration e = props.propertyNames(); e.hasMoreElements();) {
+        for (Enumeration e = System.getProperties().propertyNames(); e.hasMoreElements();) {
             String propName = (String) e.nextElement();
-            String systemPropValue = System.getProperty(propName);
-            if (systemPropValue != null) {
-                // AntProperties.setProperty doesn't let you override, so we
-                // have to remove the property then add it again
-                props.remove(propName);
-                props.setProperty(propName, systemPropValue);
+            if (propName.startsWith("forrest.")
+             || propName.startsWith("project.")
+             || propName.endsWith(".home"))
+            {
+                String systemPropValue = System.getProperty(propName);
+                if (systemPropValue != null) {
+                    props.setProperty(propName, systemPropValue);
+                }
             }
         }
     }
@@ -256,46 +250,6 @@
                     debug("Loaded:" + propertiesStringURI + filteringProperties.toString());
             }else if (debugging())
                 debug("Unable to find "+source.getURI()+", ignoring.");
-
-        } finally {
-            if (source != null) {
-                m_resolver.release(source);
-            }
-            if (in != null) {
-                try {
-                    in.close();
-                } catch (IOException e) {
-                }
-            }
-        }
-
-        return filteringProperties;
-    }
-
-    /**
-     * @param antPropertiesStringURI
-     * @throws MalformedURLException
-     * @throws IOException
-     * @throws SourceNotFoundException
-     */
-    private AntProperties loadAntPropertiesFromURI(AntProperties precedingProperties,
-            String antPropertiesStringURI) throws MalformedURLException, IOException,
-            SourceNotFoundException {
-
-        Source source = null;
-        InputStream in = null;
-        try {
-            source = m_resolver.resolveURI(antPropertiesStringURI);
-            if (debugging())
-                debug("Searching for forrest.properties in" + source.getURI());
-            if (source.exists()){
-            	in = source.getInputStream();
-                filteringProperties = new AntProperties(precedingProperties);
-                filteringProperties.load(in);
-
-                if (debugging())
-                    debug("Loaded:" + antPropertiesStringURI + filteringProperties.toString());
-            }
 
         } finally {
             if (source != null) {

Modified: forrest/trunk/main/targets/context.xml
URL: http://svn.apache.org/viewvc/forrest/trunk/main/targets/context.xml?rev=430588&r1=430587&r2=430588&view=diff
==============================================================================
--- forrest/trunk/main/targets/context.xml (original)
+++ forrest/trunk/main/targets/context.xml Thu Aug 10 16:28:05 2006
@@ -154,6 +154,8 @@
         <syspropertyset>
           <propertyref prefix="forrest."/>
           <propertyref prefix="project."/>
+          <propertyref name="user.home"/>
+          <propertyref name="global.home"/>
         </syspropertyset>
       </java>
 </target>

Modified: forrest/trunk/main/targets/site.xml
URL: http://svn.apache.org/viewvc/forrest/trunk/main/targets/site.xml?rev=430588&r1=430587&r2=430588&view=diff
==============================================================================
--- forrest/trunk/main/targets/site.xml (original)
+++ forrest/trunk/main/targets/site.xml Thu Aug 10 16:28:05 2006
@@ -58,6 +58,8 @@
           <syspropertyset>
             <propertyref prefix="forrest."/>
             <propertyref prefix="project."/>
+            <propertyref name="user.home"/>
+            <propertyref name="global.home"/>
           </syspropertyset>
         </java> 
   

Modified: forrest/trunk/site-author/status.xml
URL: http://svn.apache.org/viewvc/forrest/trunk/site-author/status.xml?rev=430588&r1=430587&r2=430588&view=diff
==============================================================================
--- forrest/trunk/site-author/status.xml (original)
+++ forrest/trunk/site-author/status.xml Thu Aug 10 16:28:05 2006
@@ -139,7 +139,11 @@
         Added document to facilitate
         <link href="site:v0.80//upgrading_08">upgrading to v0.8</link>
       </action>
-
+<!-- 2006-08 -->
+      <action context="code" type="update" dev="TS" fixes-bug="FOR-916"
+        due-to="Mathieu Champlon"> FOR-916 - adding site-wide configuration files
+        Applying patches from Mathieu Champlon. Thanks Mathieu for your contribution.
+        </action>
 <!-- 2006-07 -->
       <action context="code" type="update" dev="TS" due-to="David Crossley"> Updated the 
         forrest-core.xconf and declared the core components that are needed