Browse Source

Push logging methods into TaskContext.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271766 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 23 years ago
parent
commit
49c2480ab2
5 changed files with 231 additions and 62 deletions
  1. +88
    -0
      proposal/myrmidon/src/java/org/apache/myrmidon/api/TaskContext.java
  2. +135
    -54
      proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultTaskContext.java
  3. +6
    -6
      proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java
  4. +1
    -1
      proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/DefaultConfigurerTest.java
  5. +1
    -1
      proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/DefaultConfigurerTest.java

+ 88
- 0
proposal/myrmidon/src/java/org/apache/myrmidon/api/TaskContext.java View File

@@ -100,6 +100,94 @@ public interface TaskContext
void setProperty( String name, Object value )
throws TaskException;

/**
* Log a debug message.
*
* @param message the message
*/
void debug( String message );

/**
* Log a debug message.
*
* @param message the message
* @param throwable the throwable
*/
void debug( String message, Throwable throwable );

/**
* Determine if messages of priority "debug" will be logged.
*
* @return true if "debug" messages will be logged
*/
boolean isDebugEnabled();

/**
* Log a info message.
*
* @param message the message
*/
void info( String message );

/**
* Log a info message.
*
* @param message the message
* @param throwable the throwable
*/
void info( String message, Throwable throwable );

/**
* Determine if messages of priority "info" will be logged.
*
* @return true if "info" messages will be logged
*/
boolean isInfoEnabled();

/**
* Log a warn message.
*
* @param message the message
*/
void warn( String message );

/**
* Log a warn message.
*
* @param message the message
* @param throwable the throwable
*/
void warn( String message, Throwable throwable );

/**
* Determine if messages of priority "warn" will be logged.
*
* @return true if "warn" messages will be logged
*/
boolean isWarnEnabled();

/**
* Log a error message.
*
* @param message the message
*/
void error( String message );

/**
* Log a error message.
*
* @param message the message
* @param throwable the throwable
*/
void error( String message, Throwable throwable );

/**
* Determine if messages of priority "error" will be logged.
*
* @return true if "error" messages will be logged
*/
boolean isErrorEnabled();

/**
* Create a Child Context.
* This allows separate hierarchly contexts to be easily constructed.


+ 135
- 54
proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultTaskContext.java View File

@@ -13,6 +13,7 @@ import java.util.Map;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.excalibur.io.FileUtil;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.myrmidon.api.TaskContext;
@@ -33,64 +34,18 @@ public class DefaultTaskContext
private final Map m_contextData = new Hashtable();
private final TaskContext m_parent;
private ServiceManager m_serviceManager;

/**
* Constructor for Context with no parent contexts.
*/
public DefaultTaskContext()
{
this( null, null );
}

/**
* Constructor that specified parent context.
*/
public DefaultTaskContext( final TaskContext parent )
{
this( parent, null );
}

/**
* Constructor that specifies the service directory for context.
*/
public DefaultTaskContext( final ServiceManager serviceManager )
{
this( null, serviceManager );
}
private Logger m_logger;

/**
* Constructor that takes both parent context and a service directory.
*/
public DefaultTaskContext( final TaskContext parent,
final ServiceManager serviceManager )
final ServiceManager serviceManager,
final Logger logger )
{
m_parent = parent;
m_serviceManager = serviceManager;
}

/**
* Retrieve a property.
*/
private Object get( final String key )
{
final Object data = m_contextData.get( key );
if( null != data )
{
// if( data instanceof Resolvable )
// {
// return ( (Resolvable)data ).resolve( this );
// }
return data;
}

// If data was null, check the parent
if( null == m_parent )
{
// There was no parent, and no data
return null;
}

return m_parent.getProperty( key );
m_logger = logger;
}

/**
@@ -100,7 +55,7 @@ public class DefaultTaskContext
*/
public String getName()
{
return (String)get( NAME );
return (String)m_contextData.get( NAME );
}

/**
@@ -110,7 +65,7 @@ public class DefaultTaskContext
*/
public File getBaseDirectory()
{
return (File)get( BASE_DIRECTORY );
return (File)m_contextData.get( BASE_DIRECTORY );
}

/**
@@ -206,7 +161,7 @@ public class DefaultTaskContext
*/
public Object getProperty( final String name )
{
return get( name );
return m_contextData.get( name );
}

/**
@@ -232,6 +187,130 @@ public class DefaultTaskContext
m_contextData.put( name, value );
}

/**
* Log a debug message.
*
* @param message the message
*/
public void debug( final String message )
{
m_logger.debug( message );
}

/**
* Log a debug message.
*
* @param message the message
* @param throwable the throwable
*/
public void debug( final String message, final Throwable throwable )
{
m_logger.debug( message, throwable );
}

/**
* Determine if messages of priority "debug" will be logged.
*
* @return true if "debug" messages will be logged
*/
public boolean isDebugEnabled()
{
return m_logger.isDebugEnabled();
}

/**
* Log a info message.
*
* @param message the message
*/
public void info( final String message )
{
m_logger.info( message );
}

/**
* Log a info message.
*
* @param message the message
* @param throwable the throwable
*/
public void info( final String message, final Throwable throwable )
{
m_logger.info( message, throwable );
}

/**
* Determine if messages of priority "info" will be logged.
*
* @return true if "info" messages will be logged
*/
public boolean isInfoEnabled()
{
return m_logger.isInfoEnabled();
}

/**
* Log a warn message.
*
* @param message the message
*/
public void warn( final String message )
{
m_logger.warn( message );
}

/**
* Log a warn message.
*
* @param message the message
* @param throwable the throwable
*/
public void warn( final String message, final Throwable throwable )
{
m_logger.warn( message, throwable );
}

/**
* Determine if messages of priority "warn" will be logged.
*
* @return true if "warn" messages will be logged
*/
public boolean isWarnEnabled()
{
return m_logger.isWarnEnabled();
}

/**
* Log a error message.
*
* @param message the message
*/
public void error( final String message )
{
m_logger.error( message );
}

/**
* Log a error message.
*
* @param message the message
* @param throwable the throwable
*/
public void error( final String message, final Throwable throwable )
{
m_logger.error( message, throwable );
}

/**
* Determine if messages of priority "error" will be logged.
*
* @return true if "error" messages will be logged
*/
public boolean isErrorEnabled()
{
return m_logger.isErrorEnabled();
}

/**
* Create a Child Context.
* This allows separate hierarchly contexts to be easily constructed.
@@ -243,7 +322,9 @@ public class DefaultTaskContext
public TaskContext createSubContext( final String name )
throws TaskException
{
final DefaultTaskContext context = new DefaultTaskContext( this );
final Logger logger = m_logger.getChildLogger( name );
final DefaultTaskContext context =
new DefaultTaskContext( this, m_serviceManager, logger );

context.setProperty( TaskContext.NAME, getName() + "." + name );
context.setProperty( TaskContext.BASE_DIRECTORY, getBaseDirectory() );


+ 6
- 6
proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java View File

@@ -142,7 +142,7 @@ public class DefaultWorkspace
private TaskContext createBaseContext()
throws TaskException
{
final TaskContext context = new DefaultTaskContext();
final TaskContext context = new DefaultTaskContext( null, null, null );

final String[] names = m_parameters.getNames();
for( int i = 0; i < names.length; i++ )
@@ -256,16 +256,16 @@ public class DefaultWorkspace
serviceManager.put( Project.ROLE + "/" + name, other );
}

// Create and configure the context
final DefaultTaskContext context =
new DefaultTaskContext( m_baseContext, serviceManager );
context.setProperty( TaskContext.BASE_DIRECTORY, project.getBaseDirectory() );

// Create a logger
final Logger logger =
new LogKitLogger( m_hierarchy.getLoggerFor( "project" + m_projectID ) );
m_projectID++;

// Create and configure the context
final DefaultTaskContext context =
new DefaultTaskContext( m_baseContext, serviceManager, logger );
context.setProperty( TaskContext.BASE_DIRECTORY, project.getBaseDirectory() );

final DefaultExecutionFrame frame = new DefaultExecutionFrame( logger, context, typeManager );

/**


+ 1
- 1
proposal/myrmidon/src/test/org/apache/myrmidon/components/configurer/DefaultConfigurerTest.java View File

@@ -75,7 +75,7 @@ public class DefaultConfigurerTest
m_configurer = (Configurer)getServiceManager().lookup( Configurer.ROLE );

// Setup a context
m_context = new DefaultTaskContext();
m_context = new DefaultTaskContext( null, getServiceManager(), getLogger() );
final File baseDir = new File( "." ).getAbsoluteFile();
m_context.setProperty( TaskContext.BASE_DIRECTORY, baseDir );
}


+ 1
- 1
proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/DefaultConfigurerTest.java View File

@@ -75,7 +75,7 @@ public class DefaultConfigurerTest
m_configurer = (Configurer)getServiceManager().lookup( Configurer.ROLE );

// Setup a context
m_context = new DefaultTaskContext();
m_context = new DefaultTaskContext( null, getServiceManager(), getLogger() );
final File baseDir = new File( "." ).getAbsoluteFile();
m_context.setProperty( TaskContext.BASE_DIRECTORY, baseDir );
}


Loading…
Cancel
Save