KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > feedback > EmitLogsTask


1 /**
2  * $Id: EmitLogsTask.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2002-2003 iDare Media, Inc. All rights reserved.
4  *
5  * Originally written by iDare Media, Inc. for release into the public domain. This
6  * library, source form and binary form, is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation; either version 2.1 of the License, or (at your option) any
9  * later version.<p>
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU LGPL (GNU Lesser General Public License) for more details.<p>
14  *
15  * You should have received a copy of the GNU Lesser General Public License along with this
16  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite
17  * 330, Boston, MA 02111-1307 USA. The LGPL can be found online at
18  * http://www.fsf.org/copyleft/lesser.html<p>
19  *
20  * This product has been influenced by several projects within the open-source community.
21  * The JWare developers wish to acknowledge the open-source community's support. For more
22  * information regarding the open-source products used within JWare, please visit the
23  * JWare website.
24  *----------------------------------------------------------------------------------------*
25  * WEBSITE- http://www.jware.info EMAIL- inquiries@jware.info
26  *----------------------------------------------------------------------------------------*
27  **/

28
29 package com.idaremedia.antx.feedback;
30
31 import org.apache.tools.ant.Project;
32 import org.apache.tools.ant.types.Reference;
33
34 import com.idaremedia.antx.AntX;
35 import com.idaremedia.antx.helpers.Strings;
36 import com.idaremedia.antx.starters.TaskSet;
37
38 /**
39  * Bridge between Ant's build monitoring infrastructure and Apache's log4j.
40  * <p>
41  * <b>Examples:</b><pre>
42  * &lt;emitlogs with="log4j.config" labels="log4j.groups"&gt;
43  * &lt;echo message="foo"/&gt;
44  * &lt;property name="p" value="foo"/&gt;
45  * &lt;/emitlogs&gt;
46  * </pre>
47  *
48  * @since JWare/AntX 0.3
49  * @author ssmc, &copy;2002-2003 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
50  * @version 0.5
51  * @.safety single
52  * @.group impl,helper
53  * @see EventEmitConduit
54  **/

55
56 public class EmitLogsTask extends TaskSet implements EmitConfigurable
57 {
58     /**
59      * Initializes a new EmitLogsTask instance.
60      **/

61     public EmitLogsTask()
62     {
63         super(AntX.feedback);
64     }
65
66
67     /**
68      * Returns the fallback emit configuration this task will
69      * use to generate diagnostics emitters, etc. Never returns
70      * <i>null</i>; usually an enclosing emit configure task.
71      **/

72     public EmitConfiguration getDefaults()
73     {
74         return EmitContext.getConfigurationNoNull();
75     }
76
77
78     /**
79      * Assigns a primary emit configuration definition to this
80      * task. This task will use this configuration instead of
81      * any inherited context configuration.
82      * @param r the {@linkplain EmitConfiguration} reference
83      **/

84     public void setWith(Reference r)
85     {
86         require_(r!=null,"setWith- nonzro refid");
87         m_withEC= r;
88     }
89
90
91     /**
92      * Returns this task's user-defined emit configuration or
93      * <i>null</i> if none defined.
94      * @see #setWith
95      **/

96     public final Reference getWith()
97     {
98         return m_withEC;
99     }
100
101
102     /**
103      * Sets a custom grouping mapper for messages captured
104      * by this task.
105      * @param r the {@linkplain GroupingMapper} reference
106      **/

107     public void setLabels(Reference r)
108     {
109         require_(r!=null,"setLabels- nonzro refid");
110         m_withLabels = r;
111     }
112
113
114     /**
115      * Returns this task's user-defined grouping mapper or
116      * <i>null</i> if none defined.
117      **/

118     public final Reference getLabelsMapper()
119     {
120         return m_withLabels;
121     }
122
123
124     /**
125      * Returns this task' effective GroupingMapper object. Will
126      * return <i>null</i> if no custom mapper defined.
127      **/

128     protected GroupingMapper getGroupingMapper()
129     {
130         if (getLabelsMapper()!=null) {
131             return (GroupingMapper)getReferencedObject
132                 (getProject(), getLabelsMapper().getRefId(), GroupingMapper.class);
133         }
134         return null;
135     }
136
137
138
139     /**
140      * Sets a grouping hierarchy filter for this task. This filter
141      * only affects the standard main fields: project, target, and
142      * task. Indicator zones are always defined.
143      **/

144     public void setIncludes(String JavaDoc filterstring)
145     {
146         require_(filterstring!=null,"setInc- nonzro mask");
147         m_groupingFilter = filterstring;
148     }
149
150
151     /**
152      * Returns this task's grouping hierarchy filter. Will return
153      * "default" if never explicitly defined.
154      **/

155     public String JavaDoc getIncludes()
156     {
157         return m_groupingFilter;
158     }
159
160
161     /**
162      * Returns the effective EmitConfiguration used by this
163      * task. Never returns <i>null</i>.
164      * @see #setWith
165      * @see #getDefaults
166      * @.safety single
167      **/

168     protected EmitConfiguration getConfiguration()
169     {
170         if (m_ECInstance!=null) {
171             return m_ECInstance;
172         }
173         if (getWith()!=null) {
174             m_ECInstance = (EmitConfiguration)getReferencedObject
175                 (getProject(), getWith().getRefId(), EmitConfiguration.class);
176         }
177         else {
178             m_ECInstance = getDefaults();
179         }
180         return m_ECInstance;
181     }
182
183
184     /**
185      * Installs an event->emit conduit, performs nested tasks,
186      * and removes conduit.
187      **/

188     protected void performNestedTasks()
189     {
190         Project P = getProject();
191         EventEmitConduit conduit = getWorker();
192         try {
193             verify_(!m_isInstalled,"perform- not installed");
194             verify_(!P.getBuildListeners().contains(conduit),"perform- not installed");
195             conduit.setConfiguration(getConfiguration());
196             conduit.setIncludes(getIncludes());
197             conduit.setGroupingMapper(getGroupingMapper());
198             P.addBuildListener(conduit);
199             m_isInstalled = true;
200             performTheTasksList();
201         } finally {
202             if (m_isInstalled) {
203                 m_isInstalled = false;
204                 P.removeBuildListener(conduit);
205                 conduit.setConfiguration(null);
206             }
207         }
208     }
209
210
211     /**
212      * Returns the Ant logs -> Log4J logs transmorgifier helper.
213      * Never returns <i>null</i>.
214      **/

215     protected final EventEmitConduit getWorker()
216     {
217         return m_emitWorker;
218     }
219
220
221     private Reference m_withEC;
222     private EmitConfiguration m_ECInstance;
223     private volatile boolean m_isInstalled;
224     private final EventEmitConduit m_emitWorker = new EventEmitConduit();
225     private String JavaDoc m_groupingFilter=Strings.DEFAULT;
226     private Reference m_withLabels;
227 }
228
229 /* end-of-EmitLogsTask.java */
230
Popular Tags