git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271825 13f79535-47bb-0310-9956-ffa450edef68master
@@ -15,9 +15,9 @@ import org.apache.avalon.excalibur.i18n.Resources; | |||||
import org.apache.avalon.excalibur.io.FileUtil; | import org.apache.avalon.excalibur.io.FileUtil; | ||||
import org.apache.avalon.framework.context.Context; | import org.apache.avalon.framework.context.Context; | ||||
import org.apache.avalon.framework.context.ContextException; | import org.apache.avalon.framework.context.ContextException; | ||||
import org.apache.avalon.framework.logger.Logger; | |||||
import org.apache.avalon.framework.service.ServiceException; | import org.apache.avalon.framework.service.ServiceException; | ||||
import org.apache.avalon.framework.service.ServiceManager; | import org.apache.avalon.framework.service.ServiceManager; | ||||
import org.apache.avalon.framework.logger.Logger; | |||||
import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
import org.apache.myrmidon.interfaces.model.DefaultNameValidator; | import org.apache.myrmidon.interfaces.model.DefaultNameValidator; | ||||
@@ -36,18 +36,18 @@ public class DefaultTaskContext | |||||
ResourceManager.getPackageResources( DefaultTaskContext.class ); | ResourceManager.getPackageResources( DefaultTaskContext.class ); | ||||
// Property name validator allows digits, but no internal whitespace. | // Property name validator allows digits, but no internal whitespace. | ||||
private static DefaultNameValidator m_propertyNameValidator = new DefaultNameValidator(); | |||||
private static DefaultNameValidator c_propertyNameValidator = new DefaultNameValidator(); | |||||
static | static | ||||
{ | { | ||||
m_propertyNameValidator.setAllowInternalWhitespace( false ); | |||||
c_propertyNameValidator.setAllowInternalWhitespace( false ); | |||||
} | } | ||||
private final Map m_contextData = new Hashtable(); | private final Map m_contextData = new Hashtable(); | ||||
private final TaskContext m_parent; | private final TaskContext m_parent; | ||||
private ServiceManager m_serviceManager; | |||||
private Logger m_logger; | |||||
private PropertyResolver m_propertyResolver; | |||||
private final ServiceManager m_serviceManager; | |||||
private final Logger m_logger; | |||||
private final PropertyResolver m_propertyResolver; | |||||
/** | /** | ||||
* Constructor that takes both parent context and a service directory. | * Constructor that takes both parent context and a service directory. | ||||
@@ -55,10 +55,12 @@ public class DefaultTaskContext | |||||
public DefaultTaskContext( final TaskContext parent, | public DefaultTaskContext( final TaskContext parent, | ||||
final ServiceManager serviceManager, | final ServiceManager serviceManager, | ||||
final Logger logger ) | final Logger logger ) | ||||
throws TaskException | |||||
{ | { | ||||
m_parent = parent; | m_parent = parent; | ||||
m_serviceManager = serviceManager; | m_serviceManager = serviceManager; | ||||
m_logger = logger; | m_logger = logger; | ||||
m_propertyResolver = (PropertyResolver)getService( PropertyResolver.class ); | |||||
} | } | ||||
/** | /** | ||||
@@ -96,7 +98,7 @@ public class DefaultTaskContext | |||||
{ | { | ||||
// Try this context first | // Try this context first | ||||
final String name = serviceClass.getName(); | final String name = serviceClass.getName(); | ||||
if( m_serviceManager != null && m_serviceManager.hasService( name ) ) | |||||
if( null != m_serviceManager && m_serviceManager.hasService( name ) ) | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
@@ -148,15 +150,8 @@ public class DefaultTaskContext | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
// Lazy lookup of the PropertyResolver | |||||
if( m_propertyResolver == null ) | |||||
{ | |||||
m_propertyResolver = (PropertyResolver)getService( PropertyResolver.class ); | |||||
} | |||||
final Object object = | final Object object = | ||||
m_propertyResolver.resolveProperties( value, this ); | m_propertyResolver.resolveProperties( value, this ); | ||||
if( null == object ) | if( null == object ) | ||||
{ | { | ||||
final String message = REZ.getString( "null-resolved-value.error", value ); | final String message = REZ.getString( "null-resolved-value.error", value ); | ||||
@@ -347,9 +342,8 @@ public class DefaultTaskContext | |||||
public TaskContext createSubContext( final String name ) | public TaskContext createSubContext( final String name ) | ||||
throws TaskException | throws TaskException | ||||
{ | { | ||||
final Logger logger = m_logger.getChildLogger( name ); | |||||
final DefaultTaskContext context = | final DefaultTaskContext context = | ||||
new DefaultTaskContext( this, m_serviceManager, logger ); | |||||
new DefaultTaskContext( this, m_serviceManager, m_logger ); | |||||
context.setProperty( TaskContext.NAME, getName() + "." + name ); | context.setProperty( TaskContext.NAME, getName() + "." + name ); | ||||
context.setProperty( TaskContext.BASE_DIRECTORY, getBaseDirectory() ); | context.setProperty( TaskContext.BASE_DIRECTORY, getBaseDirectory() ); | ||||
@@ -378,7 +372,7 @@ public class DefaultTaskContext | |||||
{ | { | ||||
try | try | ||||
{ | { | ||||
m_propertyNameValidator.validate( name ); | |||||
c_propertyNameValidator.validate( name ); | |||||
} | } | ||||
catch( Exception e ) | catch( Exception e ) | ||||
{ | { | ||||
@@ -16,7 +16,6 @@ import org.apache.avalon.excalibur.i18n.Resources; | |||||
import org.apache.avalon.framework.activity.Initializable; | import org.apache.avalon.framework.activity.Initializable; | ||||
import org.apache.avalon.framework.configuration.Configuration; | import org.apache.avalon.framework.configuration.Configuration; | ||||
import org.apache.avalon.framework.logger.AbstractLogEnabled; | import org.apache.avalon.framework.logger.AbstractLogEnabled; | ||||
import org.apache.avalon.framework.logger.LogKitLogger; | |||||
import org.apache.avalon.framework.logger.Logger; | import org.apache.avalon.framework.logger.Logger; | ||||
import org.apache.avalon.framework.parameters.ParameterException; | import org.apache.avalon.framework.parameters.ParameterException; | ||||
import org.apache.avalon.framework.parameters.Parameterizable; | import org.apache.avalon.framework.parameters.Parameterizable; | ||||
@@ -25,7 +24,6 @@ import org.apache.avalon.framework.service.DefaultServiceManager; | |||||
import org.apache.avalon.framework.service.ServiceException; | import org.apache.avalon.framework.service.ServiceException; | ||||
import org.apache.avalon.framework.service.ServiceManager; | import org.apache.avalon.framework.service.ServiceManager; | ||||
import org.apache.avalon.framework.service.Serviceable; | import org.apache.avalon.framework.service.Serviceable; | ||||
import org.apache.log.Hierarchy; | |||||
import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
import org.apache.myrmidon.framework.conditions.Condition; | import org.apache.myrmidon.framework.conditions.Condition; | ||||
@@ -62,8 +60,6 @@ public class DefaultWorkspace | |||||
private HashMap m_entries = new HashMap(); | private HashMap m_entries = new HashMap(); | ||||
private TypeManager m_typeManager; | private TypeManager m_typeManager; | ||||
private Deployer m_deployer; | private Deployer m_deployer; | ||||
private Hierarchy m_hierarchy; | |||||
private int m_projectID; | |||||
/** | /** | ||||
* Add a listener to project events. | * Add a listener to project events. | ||||
@@ -110,11 +106,6 @@ public class DefaultWorkspace | |||||
throws Exception | throws Exception | ||||
{ | { | ||||
m_baseContext = createBaseContext(); | m_baseContext = createBaseContext(); | ||||
m_hierarchy = new Hierarchy(); | |||||
final LogTargetToListenerAdapter target = new LogTargetToListenerAdapter( m_listenerSupport ); | |||||
m_hierarchy.setDefaultLogTarget( target ); | |||||
} | } | ||||
/** | /** | ||||
@@ -258,8 +249,7 @@ public class DefaultWorkspace | |||||
// Create a logger | // Create a logger | ||||
final Logger logger = | final Logger logger = | ||||
new LogKitLogger( m_hierarchy.getLoggerFor( "project" + m_projectID ) ); | |||||
m_projectID++; | |||||
new RoutingLogger( RoutingLogger.LEVEL_DEBUG, m_listenerSupport ); | |||||
// Create and configure the context | // Create and configure the context | ||||
final DefaultTaskContext context = | final DefaultTaskContext context = | ||||
@@ -1,43 +0,0 @@ | |||||
/* | |||||
* Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
* | |||||
* This software is published under the terms of the Apache Software License | |||||
* version 1.1, a copy of which has been included with this distribution in | |||||
* the LICENSE.txt file. | |||||
*/ | |||||
package org.apache.myrmidon.components.workspace; | |||||
import org.apache.log.LogEvent; | |||||
import org.apache.log.LogTarget; | |||||
/** | |||||
* Adapter between Avalon LogKit and Project listener interfaces. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
public class LogTargetToListenerAdapter | |||||
implements LogTarget | |||||
{ | |||||
private final ProjectListenerSupport m_listenerSupport; | |||||
/** | |||||
* Constructor taking listener to convert to. | |||||
* | |||||
* @param listenerSupport the ProjectListener | |||||
*/ | |||||
public LogTargetToListenerAdapter( final ProjectListenerSupport listenerSupport ) | |||||
{ | |||||
m_listenerSupport = listenerSupport; | |||||
} | |||||
/** | |||||
* Process a log event. | |||||
* | |||||
* @param event the event | |||||
*/ | |||||
public void processEvent( final LogEvent event ) | |||||
{ | |||||
m_listenerSupport.log( event.getMessage(), event.getThrowable() ); | |||||
} | |||||
} |
@@ -0,0 +1,44 @@ | |||||
/* | |||||
* Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
* | |||||
* This software is published under the terms of the Apache Software License | |||||
* version 1.1, a copy of which has been included with this distribution in | |||||
* the LICENSE.txt file. | |||||
*/ | |||||
package org.apache.myrmidon.components.workspace; | |||||
import org.apache.myrmidon.frontends.BasicLogger; | |||||
/** | |||||
* A basic logger that just routes the messages to the ProjectListenerSupport. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
* @version $Revision$ $Date$ | |||||
*/ | |||||
final class RoutingLogger | |||||
extends BasicLogger | |||||
{ | |||||
/** | |||||
* The endpoint of all the logging messages. | |||||
*/ | |||||
private final ProjectListenerSupport m_listenerSupport; | |||||
/** | |||||
* Create a Logger that routes messages at specified level | |||||
* to specified support. | |||||
*/ | |||||
public RoutingLogger( final int logLevel, | |||||
final ProjectListenerSupport listenerSupport ) | |||||
{ | |||||
super( null, logLevel ); | |||||
m_listenerSupport = listenerSupport; | |||||
} | |||||
/** | |||||
* Utility method to output messages. | |||||
*/ | |||||
protected void output( final String message, final Throwable throwable ) | |||||
{ | |||||
m_listenerSupport.log( message, throwable ); | |||||
} | |||||
} |
@@ -16,7 +16,7 @@ import org.apache.avalon.framework.logger.Logger; | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
* @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
*/ | */ | ||||
class BasicLogger | |||||
public class BasicLogger | |||||
implements Logger | implements Logger | ||||
{ | { | ||||
public final static int LEVEL_DEBUG = 0; | public final static int LEVEL_DEBUG = 0; | ||||
@@ -246,7 +246,7 @@ class BasicLogger | |||||
/** | /** | ||||
* Utility method to output messages. | * Utility method to output messages. | ||||
*/ | */ | ||||
private void output( final String message, final Throwable throwable ) | |||||
protected void output( final String message, final Throwable throwable ) | |||||
{ | { | ||||
final StringBuffer sb = new StringBuffer( m_prefix ); | final StringBuffer sb = new StringBuffer( m_prefix ); | ||||
if( null != message ) | if( null != message ) | ||||