Browse Source

Update to use getLogger().<method>() rather than log()

Move EchoLevel inner class to top level class


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270416 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 23 years ago
parent
commit
76d232ed49
2 changed files with 72 additions and 94 deletions
  1. +36
    -47
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Echo.java
  2. +36
    -47
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Echo.java

+ 36
- 47
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Echo.java View File

@@ -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 message )
{ {
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 message )
throws TaskException throws TaskException
{ {
message += getProject().replaceProperties( msg );
m_message += getProject().replaceProperties( message );
} }


/** /**
@@ -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_message, 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 );
} }
} }
} }

+ 36
- 47
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Echo.java View File

@@ -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 message )
{ {
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 message )
throws TaskException throws TaskException
{ {
message += getProject().replaceProperties( msg );
m_message += getProject().replaceProperties( message );
} }


/** /**
@@ -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_message, 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 );
} }
} }
} }

Loading…
Cancel
Save