You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by st...@apache.org on 2004/08/04 01:19:08 UTC
cvs commit: ant/src/main/org/apache/tools/ant/taskdefs Echo.java
stevel 2004/08/03 16:19:08
Modified: src/main/org/apache/tools/ant/taskdefs Echo.java
Log:
Echo cleanup. Too much duplicate logic.
Revision Changes Path
1.35 +29 -22 ant/src/main/org/apache/tools/ant/taskdefs/Echo.java
Index: Echo.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Echo.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- Echo.java 9 Mar 2004 16:48:04 -0000 1.34
+++ Echo.java 3 Aug 2004 23:19:08 -0000 1.35
@@ -20,9 +20,11 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
+import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.types.EnumeratedAttribute;
/**
* Writes a message to the Ant logging facilities.
@@ -55,13 +57,7 @@
} catch (IOException ioe) {
throw new BuildException(ioe, getLocation());
} finally {
- if (out != null) {
- try {
- out.close();
- } catch (IOException ioex) {
- //ignore
- }
- }
+ FileUtils.close(out);
}
}
}
@@ -115,19 +111,7 @@
* @param echoLevel the logging level
*/
public void setLevel(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;
- }
+ logLevel=echoLevel.getLevel();
}
/**
@@ -139,8 +123,31 @@
* @return the strings allowed for the level attribute
*/
public String[] getValues() {
- return new String[] {"error", "warning", "info",
- "verbose", "debug"};
+ return new String[] {
+ "error",
+ "warning",
+ "info",
+ "verbose",
+ "debug"};
+ }
+
+ /**
+ * mapping of enumerated values to log levels
+ */
+ private static int levels[]={
+ Project.MSG_ERR,
+ Project.MSG_WARN,
+ Project.MSG_INFO,
+ Project.MSG_VERBOSE,
+ Project.MSG_DEBUG
+ };
+
+ /**
+ * get the level of the echo of the current value
+ * @return
+ */
+ public int getLevel() {
+ return levels[getIndex()];
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org