KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antmod > tasks > MessageOutputLevel


1 package org.antmod.tasks;
2
3 import java.util.Enumeration JavaDoc;
4
5 import org.apache.tools.ant.BuildException;
6 import org.apache.tools.ant.BuildListener;
7 import org.apache.tools.ant.BuildLogger;
8 import org.apache.tools.ant.Task;
9
10 /**
11  * Sets the message output level of the Ant project.
12  *
13  * @author Klaas Waslander
14  */

15 public final class MessageOutputLevel extends Task {
16
17     private int outputLevel;
18
19     private String JavaDoc unless = "antmod.verbose";
20
21     /**
22      * Construct a new MessageOutputLevel task.
23      */

24     public MessageOutputLevel() {
25     }
26
27     /**
28      * The desired outputLevel.
29      */

30     public void setOutputLevel(int outputLevel) {
31         this.outputLevel = outputLevel;
32     }
33
34     /**
35      * The name of the variable that, if set, will prevent the message outputlevel to be changed;
36      * defaults to "antmod.verbose".
37      * @param unless The Ant variable name that, if set, prevents execution of this task
38      */

39     public void setUnless(String JavaDoc unless) {
40         this.unless = unless;
41     }
42
43     public void execute() throws BuildException {
44         if (this.unless != null) {
45             // use ant outputlevel ?
46
boolean useAnt = true;
47             String JavaDoc prop = getProject().getProperty(this.unless);
48             if (prop == null || prop.trim().length() == 0) {
49                 useAnt = false;
50             } else {
51                 if (prop.trim().equalsIgnoreCase("false")) {
52                     useAnt = false;
53                 } else {
54                     useAnt = true;
55                 }
56             }
57
58             if (!useAnt) {
59                 setMessageOutputLevel(this.outputLevel);
60             }
61         }
62     }
63
64     /**
65      * Sets the message output level of all build loggers.
66      */

67     private void setMessageOutputLevel(int level) {
68         Enumeration JavaDoc bl = getProject().getBuildListeners().elements();
69         while (bl.hasMoreElements()) {
70             BuildListener listener = (BuildListener)bl.nextElement();
71             if (listener instanceof BuildLogger) {
72                 ((BuildLogger)listener).setMessageOutputLevel(level);
73             }
74         }
75     }
76 }
77
Popular Tags