Merged V3.1 to HEAD

12898: Cleaned up svn:mergeinfo
   12905: Added 'js' to svn:ignore
   12916: Divorced repositories [sic] Log4J extension point from Log4J imports
   12939: Build/test fix (follow on from r12899)
   12945: Merged V2.1-A to V3.1
      7720: (record-only) Customer-specific request to allow domains to be case-sensitive
   12946: fix for ETHREEOH-1227 (bunch of FTL and JS files by Lawrence)
   12949: Merged V2.1-A to V3.1
      8123: (record-only) Allow authorities that are identical ignoring case (as we do in 2.2)
   ___________________________________________________________________
   Modified: svn:mergeinfo
      Merged /alfresco/BRANCHES/V2.1-A:r7720,8123
      Merged /alfresco/BRANCHES/V3.1:r12898,12905,12916,12939,12945-12946,12949


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13536 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2009-03-10 16:26:40 +00:00
parent 800c11f884
commit 42fa774d76
7 changed files with 180 additions and 236 deletions

View File

@@ -129,76 +129,17 @@
<property name="nfsServer"><ref bean="nfsServer"/></property> <property name="nfsServer"><ref bean="nfsServer"/></property>
</bean> </bean>
<!-- This bean will attempt to export extra beans to log4jHierarchy's MBeanServer, so it's vital that the exporter has been initialised --> <!--
<bean id="log4JHierarchyInit" class="org.alfresco.repo.admin.Log4JHierarchyInit" depends-on="exporter" init-method="init"> http://wiki.alfresco.com/wiki/Developing_an_Alfresco_Module#log4j.properties
<property name="log4jHierarchy" ref="log4jHierarchy"/> -->
<bean id="log4JHierarchyInit" class="org.alfresco.repo.admin.Log4JHierarchyInit" init-method="init">
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <property name="extraLog4jUrls">
<!-- Supplementary log4j.properties files -->
<!-- -->
<!-- Log4j settings specified here augment/override the webapp's main -->
<!-- log4j configuration file: WEB-INF/classes/log4j.properties -->
<!-- -->
<!-- This allows modules to maintain their own log4j.properties file, -->
<!-- which is typically deployed to: -->
<!-- WEB-INF/classes/alfresco/module/{module.id}/log4j.properties -->
<!-- -->
<!-- Where: module.id is whatever value is set within the AMP's -->
<!-- 'module.properties' file. -->
<!-- -->
<!-- Example: -->
<!-- WEB-INF/classes/alfresco/module/com.example.x.Y/log4j.properties -->
<!-- -->
<!-- Those who wish to configure log4j properties in Alfresco extensions -->
<!-- that aren't packaged as AMP modules can create log4j.properties file -->
<!-- of the form: {name}-log4j.properties and place it within some -->
<!-- alfresco/extension directory on the server's classpath. -->
<!-- -->
<!-- For example: -->
<!-- WEB-INF/classes/alfresco/extension/SIMPLE_EXAMPLE-log4j.properties -->
<!-- -->
<!-- That said, you are strongly encouraged to use the modular form -->
<!-- (i.e.: the first one), and use the AMP mechanism for packaging -->
<!-- whenever possible. This makes customizations easier to manage. -->
<!-- Note: {name}-log4j.properties files override/augment the -->
<!-- log4j.properties files packaged within modules. -->
<!-- -->
<!-- Developers may also wish to maintain a dev-log4j.properties file -->
<!-- outside of the webapp. This allows for changing log4j settings -->
<!-- without touching the "shipping product", or any of a customer's -->
<!-- local settings. Your optional dev-log4j.properties file should be -->
<!-- in some alfresco/extension directory within the server's classpath, -->
<!-- and outside the webapp itself (so you don't accidentally delete it). -->
<!-- Note: the dev-log4j.properties file augments/overrides all others. -->
<!-- -->
<!-- Example: -->
<!-- $TOMCAT_HOME/shared/classes/alfresco/extension/dev-log4j.properties -->
<!-- -->
<!-- -->
<!-- Best practices: -->
<!-- -->
<!-- Local customizations/licences are kept outside of the webapp. -->
<!-- Example: -->
<!-- $TOMCAT_HOME/shared/classes/alfresco/extension/...-log4j.properties -->
<!-- -->
<!-- Shipping config files should be kept/installed within webapp: -->
<!-- Example: -->
<!-- WEB-INF/classes/alfresco/extension/...-log4j.properties -->
<!-- -->
<!-- A dev-log4j.properties file should never be used in an ongoing -->
<!-- during production, nor packaged as a part of any product. -->
<!-- -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<property name="overriding_log4j_properties">
<list> <list>
<!-- NOTE: value entries are listed from lowest precedence to highest. --> <!-- NOTE: value entries are listed from lowest precedence to highest. -->
<!-- Installed AMP modules --> <!-- Installed AMP modules -->
<value>classpath*:alfresco/module/*/log4j.properties</value> <value>classpath*:alfresco/module/*/log4j.properties</value>
<!-- Enterprise extensions -->
<value>classpath*:alfresco/enterprise/*-log4j.properties</value>
<!-- Other installed extensions --> <!-- Other installed extensions -->
<value>classpath*:alfresco/extension/*-log4j.properties</value> <value>classpath*:alfresco/extension/*-log4j.properties</value>

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2007 Alfresco Software Limited. * Copyright (C) 2005-2008 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@@ -24,196 +24,129 @@
*/ */
package org.alfresco.repo.admin; package org.alfresco.repo.admin;
import java.io.BufferedInputStream; import java.lang.reflect.Method;
import java.io.InputStream; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.Properties;
import org.apache.log4j.jmx.HierarchyDynamicMBean; import org.apache.commons.logging.Log;
import org.apache.log4j.Logger; import org.apache.commons.logging.LogFactory;
import org.apache.log4j.LogManager;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.spi.LoggerRepository;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
/** /**
* Initialises Log4j's HierarchyDynamicMBean (refer to core-services-context.xml) * Initialises Log4j's HierarchyDynamicMBean (refer to core-services-context.xml) and any overriding log4.properties files.
* and any overriding log4.properties files. * The actual implementation uses introspection to avoid any hard-coded references to Log4J classes. If Log4J is
* not present, this class will do nothing.
* <p> * <p>
* Alfresco modules can provide their own log4j.properties file, * Alfresco modules can provide their own log4j.properties file, which augments/overrides the global log4j.properties
* which augments/overrides the global log4j.properties within * within the Alfresco webapp. Within the module's source tree, suppose you create:
* the Alfresco webapp. Within the module's source tree, suppose
* you create:<pre>
* config/alfresco/module/{module.id}/log4j.properties</pre>
* At deployment time, this log4j.properties file will be placed in:<pre>
* WEB-INF/classes/alfresco/module/{module.id}/log4j.properties</pre>
* Where {module.id} is whatever value is set within the AMP's
* module.properties file. For details, see:
* <a href='http://wiki.alfresco.com/wiki/Developing_an_Alfresco_Module'>Developing an Alfresco Module</a>
* <p>
* For example, if {module.id} is "org.alfresco.module.avmCompare", then
* within your source code you'll have:<pre>
* config/alfresco/module/org.alfresco.module.avmCompare/log4j.properties</pre>
* This would be deployed to:<pre>
* WEB-INF/classes/alfresco/module/org.alfresco.module.avmCompare/log4j.properties</pre>
* By default the 'overriding_log4j_properties' property of the
* 'log4JHierarchyInit' bean within core-services-context.xml is:<pre>
* classpath&#042;:alfresco/module/&#042;/log4j.properties</pre>
* Therefore, Log4JHierarchyInit will discover this supplimentary log4j.properties
* file, and merge it with the main log4j.file (WEB-INF/classes/log4j.properties).
* For example, the org.alfresco.module.avmCompare log4j.properties file might look like this:
* <pre> * <pre>
* #----------------------------------------------------------------------- * config/alfresco/module/{module.id}/log4j.properties
* # webscript module log4j.properties * </pre>
* # * At deployment time, this log4j.properties file will be placed in:
* # NOTE * <pre>
* # ---- * WEB-INF/classes/alfresco/module/{module.id}/log4j.properties
* # * </pre>
* # Log4j uses the following logging levels: * Where {module.id} is whatever value is set within the AMP's module.properties file. For details, see: <a
* # debug,info,warn,error,fatal * href='http://wiki.alfresco.com/wiki/Developing_an_Alfresco_Module'>Developing an Alfresco Module</a>
* # * <p>
* # To set the logging level of {fullClassName} to {loglevel}, * For example, if {module.id} is "org.alfresco.module.avmCompare", then within your source code you'll have:
* # add a line to this file of the following form:
* #
* # log4j.logger.{fullClassName}={loglevel}
* #
* # For example, to make 'com.example.MyExample' produce 'debug'
* # logs, add a line like this:
* #
* # log4j.logger.com.example.MyExample=debug
* #
* #
* # WARNING
* # -------
* # Log properties in this log4j.properties file override/augment
* # those in the webapp's main log4j.properties.
* #
* #-----------------------------------------------------------------------
* *
* log4j.logger.org.alfresco.module.avmCompare.AvmCompare=info * <pre>
* config / alfresco / module / org.alfresco.module.avmCompare / log4j.properties
* </pre> * </pre>
* *
* This system allows the author of any module to provide rich logging control * This would be deployed to:
* without concern for corrupting the central log4j.properties file during * <pre>
* AMP installation/deinstallation. For details, see: * WEB - INF / classes / alfresco / module / org.alfresco.module.avmCompare / log4j.properties
* <a href='http://wiki.alfresco.com/wiki/Module_Management_Tool'>Module Management Tool</a> * </pre>
*/ */
public class Log4JHierarchyInit public class Log4JHierarchyInit
{ {
private HierarchyDynamicMBean log4jHierarchy; private static Log logger = LogFactory.getLog(Log4JHierarchyInit.class);
private List<String> extra_log4j_urls; private List<String> extraLog4jUrls;
public Log4JHierarchyInit() public Log4JHierarchyInit()
{ {
extra_log4j_urls = new ArrayList<String>(); extraLog4jUrls = new ArrayList<String>();
} }
/** /**
* Loads a set of augmenting/overriding log4j.properties files * Loads a set of augmenting/overriding log4j.properties files from locations specified via an array of Srping URLS.
* from locations specified via an array of 'spring_urls' * <p>
* (typically provided by a core-services-context.xml). * This function supports Spring's syntax for retrieving multiple class path resources with the same name,
* * via the "classpath&#042;:" prefix. For details, see: {@link PathMatchingResourcePatternResolver}.
* This function supports Spring's syntax for retrieving
* multiple class path resources with the same name,
* via the "classpath&#042;:" prefix. For details, see:
* <a href='http://www.jdocs.com/spring/1.2.8/org/springframework/core/io/support/PathMatchingResourcePatternResolver.html'>PathMatchingResourcePatternResolver</a>.
*/ */
public void setOverriding_log4j_properties(List<String> spring_urls) public void setExtraLog4jUrls(List<String> urls)
{ {
for ( String url : spring_urls ) { extra_log4j_urls.add( url ); } for (String url : urls)
{
extraLog4jUrls.add(url);
} }
public void setLog4jHierarchy(HierarchyDynamicMBean log4jHierarchy)
{
this.log4jHierarchy = log4jHierarchy;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void init() public void init()
{ {
// Add each logger (that has a level set) from importLogSettings();
// the Log4J Repository to the Hierarchy MBean
LoggerRepository r = LogManager.getLoggerRepository();
// Include overriding loggers
//
// Typically, extra loggers come from AMP modules, but you
// could add others by augmenting core-services-context.xml
// This mechanism allows modules to have their own local
// log4j.properties file within:
//
// WEB-INF/classes/alfresco/module/{module.id}/log4j.properties
//
// Where: module.id is whatever value is set within the AMP's
// 'module.properties' file.
//
// See also:
// http://wiki.alfresco.com/wiki/Developing_an_Alfresco_Module
// (the module.properties section)
//
// And:
// core-services-context.xml
set_overriding_loggers( r );
Enumeration loggers = r.getCurrentLoggers();
Logger logger = null;
while (loggers.hasMoreElements())
{
logger = (Logger)loggers.nextElement();
if (logger.getLevel() != null)
{
log4jHierarchy.addLoggerMBean(logger.getName());
}
}
} }
void set_overriding_loggers( LoggerRepository hierarchy ) @SuppressWarnings("unchecked")
private void importLogSettings()
{ {
for ( String spring_url : extra_log4j_urls ) try
{ {
set_overriding_logger( spring_url, hierarchy ); // Get the PropertyConfigurator
Class clazz = Class.forName("org.apache.log4j.PropertyConfigurator");
Method method = clazz.getMethod("configure", URL.class);
// Import using this method
for (String url : extraLog4jUrls)
{
importLogSettings(method, url);
} }
} }
catch (ClassNotFoundException e)
void set_overriding_logger( String spring_url,
LoggerRepository hierarchy )
{ {
PathMatchingResourcePatternResolver resolver; // Log4J not present
PropertyConfigurator prop_config; return;
}
catch (NoSuchMethodException e)
{
throw new RuntimeException("Unable to find method 'configure' on class 'org.apache.log4j.PropertyConfigurator'");
}
prop_config = new PropertyConfigurator(); }
resolver = new PathMatchingResourcePatternResolver();
private void importLogSettings(Method method, String springUrl)
{
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = null; Resource[] resources = null;
try try
{ {
resources = resolver.getResources( spring_url ); resources = resolver.getResources(springUrl);
}
catch (Exception e)
{
logger.warn("Failed to find additional Logger configuration: " + springUrl);
} }
catch (Exception e) { return ; }
// Read each resource // Read each resource
for (Resource resource : resources ) for (Resource resource : resources)
{ {
try try
{ {
InputStream istream = new BufferedInputStream(resource.getInputStream()); URL url = resource.getURL();
Properties properties = new Properties(); method.invoke(null, url);
properties.load(istream); }
catch (Throwable e)
prop_config.doConfigure(properties, hierarchy); {
if (logger.isDebugEnabled())
{
logger.debug("Failed to add extra Logger configuration: \n" + " URL: " + springUrl + "\n" + " Error: " + e.getMessage(), e);
}
} }
catch (Throwable e) { /* do nothing */ }
} }
} }
} }

View File

@@ -0,0 +1,65 @@
/*
* Copyright (C) 2005-2008 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.admin;
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @see Log4JHierarchyInit
*
* @author Derek Hulley
* @since 2.2.3
*/
public class Log4JHierarchyInitTest extends TestCase
{
private static ApplicationContext ctx = new ClassPathXmlApplicationContext(
new String[] {"classpath:log4j/log4j-test-context.xml"}
);
public void setUp() throws Exception
{
}
public void testSetUp() throws Throwable
{
// Check that the bean is present
ctx.getBean("log4JHierarchyInit");
// Make sure that the default log4j.properties is being picked up
Log log = LogFactory.getLog("log4j.logger.org.alfresco");
assertFalse("Expect log level ERROR for 'org.alfresco'.", log.isWarnEnabled());
}
public void testAddingLog4jProperties() throws Throwable
{
Log log = LogFactory.getLog(this.getClass());
// We expect DEBUG to be on
assertTrue("DEBUG was not enabled for logger " + this.getClass(), log.isDebugEnabled());
}
}

View File

@@ -98,19 +98,6 @@ public final class ScriptUtils extends BaseScopableProcessorExtension
return Boolean.parseBoolean(booleanString); return Boolean.parseBoolean(booleanString);
} }
/**
* Converts the specified Date object to an
* <a href="http://www.iso.org/iso/date_and_time_format">ISO 8601</a>-formatted
* String.
*
* @param d date
* @return an ISO 8601-formatted date String.
*/
public String toISO8601(Date d)
{
return ISO8601DateFormat.format(d);
}
/** /**
* Function to check if a module is installed * Function to check if a module is installed
* *

View File

@@ -61,20 +61,20 @@ function testMembership()
var site = siteService.getSite("siteShortName"); var site = siteService.getSite("siteShortName");
test.assertNotNull(site); test.assertNotNull(site);
var members = site.listMembers(null, null); var members = site.listMembers(null, null, 0);
test.assertNotNull(members); test.assertNotNull(members);
test.assertEquals(1, members.length); test.assertEquals(1, members.length);
test.assertEquals("SiteManager", members["UserOne_SiteServiceImplTest"]); test.assertEquals("SiteManager", members["UserOne_SiteServiceImplTest"]);
site.setMembership("UserTwo_SiteServiceImplTest", "SiteCollaborator"); site.setMembership("UserTwo_SiteServiceImplTest", "SiteCollaborator");
members = site.listMembers(null, null); members = site.listMembers(null, null, 0);
test.assertNotNull(members); test.assertNotNull(members);
test.assertEquals(2, members.length); test.assertEquals(2, members.length);
test.assertEquals("SiteManager", members["UserOne_SiteServiceImplTest"]); test.assertEquals("SiteManager", members["UserOne_SiteServiceImplTest"]);
test.assertEquals("SiteCollaborator", members["UserTwo_SiteServiceImplTest"]); test.assertEquals("SiteCollaborator", members["UserTwo_SiteServiceImplTest"]);
site.removeMembership("UserTwo_SiteServiceImplTest"); site.removeMembership("UserTwo_SiteServiceImplTest");
members = site.listMembers(null, null); members = site.listMembers(null, null, 0);
test.assertNotNull(members); test.assertNotNull(members);
test.assertEquals(1, members.length); test.assertEquals(1, members.length);
test.assertEquals("SiteManager", members["UserOne_SiteServiceImplTest"]); test.assertEquals("SiteManager", members["UserOne_SiteServiceImplTest"]);

View File

@@ -0,0 +1,16 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<!-- Sample context to test Log4J hierarchy overrides -->
<beans>
<bean id="log4JHierarchyInit" class="org.alfresco.repo.admin.Log4JHierarchyInit" init-method="init">
<property name="extraLog4jUrls">
<list>
<!-- Uses 'test-resources' folder, which is on the classpath -->
<value>classpath*:log4j/log4j.properties</value>
</list>
</property>
</bean>
</beans>

View File

@@ -0,0 +1,2 @@
## Test to see that Log4J additions are picked up
log4j.logger.org.alfresco.repo.admin.Log4JHierarchyInitTest=DEBUG