git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@449046 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -30,7 +30,8 @@ import org.apache.tools.ant.BuildException; | |||||
| import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
| import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
| import org.apache.tools.ant.util.FileUtils; | 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. | * Writes a message to the Ant logging facilities. | ||||
| * | * | ||||
| @@ -141,37 +142,6 @@ public class Echo extends Task { | |||||
| /** | /** | ||||
| * The enumerated values for the level attribute. | * 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 { | |||||
| } | } | ||||
| } | } | ||||
| @@ -24,6 +24,7 @@ import org.apache.tools.ant.Project; | |||||
| import org.apache.tools.ant.SubBuildListener; | import org.apache.tools.ant.SubBuildListener; | ||||
| import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
| import org.apache.tools.ant.types.EnumeratedAttribute; | 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 | * Adds a listener to the current build process that records the | ||||
| @@ -130,20 +131,7 @@ public class Recorder extends Task implements SubBuildListener { | |||||
| * @see VerbosityLevelChoices | * @see VerbosityLevelChoices | ||||
| */ | */ | ||||
| public void setLoglevel(VerbosityLevelChoices level) { | 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 <code>setLoglevel()</code> method. | * A list of possible values for the <code>setLoglevel()</code> method. | ||||
| * Possible values include: error, warn, info, verbose, debug. | * 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 { | |||||
| } | } | ||||
| @@ -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()]; | |||||
| } | |||||
| } | |||||