@@ -11,32 +11,29 @@ import java.io.File;
import java.io.FileWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.IOException;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.EnumeratedAttribute;
/**
/**
* Log
* Log
*
*
* @author costin@dnt.ro
* @author costin@dnt.ro
*/
*/
public class Echo extends Task
public class Echo
extends Task
{
{
protected String message = "";// required
protected File file = null;
protected boolean append = false;
// by default, messages are always displayed
protected int logLevel = Project.MSG_WARN;
private String m_message = "";// required
private File m_file;
private boolean m_append;
private EchoLevel m_echoLevel;
/**
/**
* Shall we append to an existing file?
* Shall we append to an existing file?
*
*
* @param append The new Append value
* @param append The new Append value
*/
*/
public void setAppend( boolean append )
public void setAppend( final boolean append )
{
{
this. append = append;
m_ append = append;
}
}
/**
/**
@@ -44,9 +41,9 @@ public class Echo extends Task
*
*
* @param file The new File value
* @param file The new File value
*/
*/
public void setFile( File file )
public void setFile( final File file )
{
{
this. file = file;
m_ file = file;
}
}
/**
/**
@@ -64,30 +61,9 @@ public class Echo extends Task
*
*
* @param echoLevel The new Level value
* @param echoLevel The new Level value
*/
*/
public void setLevel( EchoLevel echoLevel )
public void setLevel( final EchoLevel echoLevel )
{
{
String option = echoLevel.getValue();
if( option.equals( "error" ) )
{
logLevel = Project.MSG_ERR;
}
else if( option.equals( "warning" ) )
{
logLevel = Project.MSG_WARN;
}
else if( option.equals( "info" ) )
{
logLevel = Project.MSG_INFO;
}
else if( option.equals( "verbose" ) )
{
logLevel = Project.MSG_VERBOSE;
}
else
{
// must be "debug"
logLevel = Project.MSG_DEBUG;
}
m_echoLevel = echoLevel;
}
}
/**
/**
@@ -95,9 +71,9 @@ public class Echo extends Task
*
*
* @param msg Sets the value for the message variable.
* @param msg Sets the value for the message variable.
*/
*/
public void setMessage( String msg )
public void setMessage( final String mes sa ge )
{
{
this.message = msg ;
m_message = message ;
}
}
/**
/**
@@ -105,10 +81,10 @@ public class Echo extends Task
*
*
* @param msg The feature to be added to the Text attribute
* @param msg The feature to be added to the Text attribute
*/
*/
public void addText( String msg )
public void addText( final String mes sa ge )
throws TaskException
throws TaskException
{
{
message += getProject().replaceProperties( msg );
m_m essage += getProject().replaceProperties( mes sa ge );
}
}
/**
/**
@@ -119,17 +95,17 @@ public class Echo extends Task
public void execute()
public void execute()
throws TaskException
throws TaskException
{
{
if( file == null )
if( m_ file == null )
{
{
log( message, logLevel );
doLog( );
}
}
else
else
{
{
FileWriter out = null;
FileWriter out = null;
try
try
{
{
out = new FileWriter( file.getAbsolutePath(), append );
out.write( message, 0, message.length() );
out = new FileWriter( m_ file.getAbsolutePath(), m_ append );
out.write( m_m essage, 0, m_ message.length() );
}
}
catch( IOException ioe )
catch( IOException ioe )
{
{
@@ -151,11 +127,24 @@ public class Echo extends Task
}
}
}
}
public static class EchoLevel extends EnumeratedAttribute
private void doLog()
{
{
public String[] getValues()
final String option = m_echoLevel.getValue();
if( option.equals( "error" ) )
{
getLogger().error( m_message );
}
else if( option.equals( "warning" ) )
{
getLogger().warn( m_message );
}
else if( option.equals( "info" ) )
{
getLogger().info( m_message );
}
else
{
{
return new String[]{"error", "warning", "info", "verbose", "debug"};
getLogger().debug( m_message ) ;
}
}
}
}
}
}