From 55e706dbe4f18d6bbf25680669e1a5ca340a418b Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Fri, 22 Sep 2006 18:42:21 +0000 Subject: [PATCH] incorporate new LogLevel EA into and . Are there others? git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@449046 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/taskdefs/Echo.java | 36 +------ .../apache/tools/ant/taskdefs/Recorder.java | 27 +---- .../org/apache/tools/ant/types/LogLevel.java | 99 +++++++++++++++++++ 3 files changed, 105 insertions(+), 57 deletions(-) create mode 100644 src/main/org/apache/tools/ant/types/LogLevel.java diff --git a/src/main/org/apache/tools/ant/taskdefs/Echo.java b/src/main/org/apache/tools/ant/taskdefs/Echo.java index 15777ff07..9a4107993 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Echo.java +++ b/src/main/org/apache/tools/ant/taskdefs/Echo.java @@ -30,7 +30,8 @@ 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; +import org.apache.tools.ant.types.LogLevel; + /** * Writes a message to the Ant logging facilities. * @@ -141,37 +142,6 @@ public class Echo extends Task { /** * The enumerated values for the level attribute. */ - public static class EchoLevel extends EnumeratedAttribute { - /** - * @see EnumeratedAttribute#getValues - * @return the strings allowed for the level attribute - */ - public String[] getValues() { - 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 the level - */ - public int getLevel() { - return levels[getIndex()]; - } + public static class EchoLevel extends LogLevel { } } diff --git a/src/main/org/apache/tools/ant/taskdefs/Recorder.java b/src/main/org/apache/tools/ant/taskdefs/Recorder.java index 25083e088..444df37d8 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Recorder.java +++ b/src/main/org/apache/tools/ant/taskdefs/Recorder.java @@ -24,6 +24,7 @@ import org.apache.tools.ant.Project; import org.apache.tools.ant.SubBuildListener; import org.apache.tools.ant.Task; import org.apache.tools.ant.types.EnumeratedAttribute; +import org.apache.tools.ant.types.LogLevel; /** * Adds a listener to the current build process that records the @@ -130,20 +131,7 @@ public class Recorder extends Task implements SubBuildListener { * @see VerbosityLevelChoices */ public void setLoglevel(VerbosityLevelChoices level) { - //I hate cascading if/elseif clauses !!! - String lev = level.getValue(); - - if (lev.equalsIgnoreCase("error")) { - loglevel = Project.MSG_ERR; - } else if (lev.equalsIgnoreCase("warn")) { - loglevel = Project.MSG_WARN; - } else if (lev.equalsIgnoreCase("info")) { - loglevel = Project.MSG_INFO; - } else if (lev.equalsIgnoreCase("verbose")) { - loglevel = Project.MSG_VERBOSE; - } else if (lev.equalsIgnoreCase("debug")) { - loglevel = Project.MSG_DEBUG; - } + loglevel = level.getLevel(); } ////////////////////////////////////////////////////////////////////// @@ -200,16 +188,7 @@ public class Recorder extends Task implements SubBuildListener { * A list of possible values for the setLoglevel() method. * Possible values include: error, warn, info, verbose, debug. */ - public static class VerbosityLevelChoices extends EnumeratedAttribute { - private static final String[] VALUES = {"error", "warn", "info", - "verbose", "debug"}; - - /** - * @see EnumeratedAttribute#getValues() - */ - public String[] getValues() { - return VALUES; - } + public static class VerbosityLevelChoices extends LogLevel { } diff --git a/src/main/org/apache/tools/ant/types/LogLevel.java b/src/main/org/apache/tools/ant/types/LogLevel.java new file mode 100644 index 000000000..f953b97fe --- /dev/null +++ b/src/main/org/apache/tools/ant/types/LogLevel.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.tools.ant.types; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.io.BufferedWriter; +import java.io.OutputStreamWriter; +import java.io.FileOutputStream; + +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; + +/** + * The enumerated values for Ant's log level. + */ +public class LogLevel extends EnumeratedAttribute { + + /** ERR loglevel constant. */ + public static final LogLevel ERR = new LogLevel("error"); + + /** WARN loglevel constant. */ + public static final LogLevel WARN = new LogLevel("warn"); + + /** INFO loglevel constant. */ + public static final LogLevel INFO = new LogLevel("info"); + + /** VERBOSE loglevel constant. */ + public static final LogLevel VERBOSE = new LogLevel("verbose"); + + /** DEBUG loglevel constant. */ + public static final LogLevel DEBUG = new LogLevel("debug"); + + /** + * Public constructor. + */ + public LogLevel() { + } + + private LogLevel(String value) { + this(); + setValue(value); + } + + /** + * @see EnumeratedAttribute#getValues + * @return the strings allowed for the level attribute + */ + public String[] getValues() { + return new String[] { + "error", + "warn", + "warning", + "info", + "verbose", + "debug"}; + } + + /** + * mapping of enumerated values to log levels + */ + private static int[] levels = { + Project.MSG_ERR, + Project.MSG_WARN, + Project.MSG_WARN, + Project.MSG_INFO, + Project.MSG_VERBOSE, + Project.MSG_DEBUG + }; + + /** + * get the level of the echo of the current value + * @return the level + */ + public int getLevel() { + return levels[getIndex()]; + } +}