KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > vladium > emma > report > reportTask


1 /* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved.
2  *
3  * This program and the accompanying materials are made available under
4  * the terms of the Common Public License v1.0 which accompanies this distribution,
5  * and is available at http://www.eclipse.org/legal/cpl-v10.html
6  *
7  * $Id: reportTask.java,v 1.1.1.1.2.1 2004/07/08 10:52:11 vlad_r Exp $
8  */

9 package com.vladium.emma.report;
10
11 import org.apache.tools.ant.BuildException;
12 import org.apache.tools.ant.types.Path;
13 import org.apache.tools.ant.types.Reference;
14
15 import com.vladium.util.IProperties;
16 import com.vladium.emma.ant.FileTask;
17 import com.vladium.emma.ant.SuppressableTask;
18 import com.vladium.emma.report.ReportCfg.Element_HTML;
19 import com.vladium.emma.report.ReportCfg.Element_TXT;
20 import com.vladium.emma.report.ReportCfg.Element_XML;
21
22 // ----------------------------------------------------------------------------
23
/**
24  * @author Vlad Roubtsov, (C) 2003
25  */

26 public
27 final class reportTask extends FileTask implements IReportProperties, IReportEnums
28 {
29     public reportTask (final SuppressableTask parent)
30     {
31         super (parent);
32     }
33     
34     public void init () throws BuildException
35     {
36         super.init ();
37         
38         m_reportCfg = new ReportCfg (getProject (), this);
39     }
40
41     
42     public void execute () throws BuildException
43     {
44         if (isEnabled ())
45         {
46             final String JavaDoc [] reportTypes = m_reportCfg.getReportTypes ();
47             
48             if ((reportTypes == null) || (reportTypes.length == 0)) // no "txt" default for report processor
49
throw (BuildException) newBuildException (getTaskName ()
50                     + ": no report types specified: provide at least one of <txt>, <html>, <xml> nested elements", location).fillInStackTrace ();
51
52             String JavaDoc [] files = getDataPath (true);
53             if ((files == null) || (files.length == 0))
54                 throw (BuildException) newBuildException (getTaskName ()
55                     + ": no valid input data files have been specified", location).fillInStackTrace ();
56
57             final Path srcpath = m_reportCfg.getSourcepath ();
58             
59             // combine report and all generic settings:
60
final IProperties settings;
61             {
62                 final IProperties taskSettings = getTaskSettings ();
63                 final IProperties reportSettings = m_reportCfg.getReportSettings ();
64                 
65                 // named report settings override generic named settings and file
66
// settings have lower priority than any explicitly named overrides:
67
settings = IProperties.Factory.combine (reportSettings, taskSettings);
68             }
69
70             final ReportProcessor processor = ReportProcessor.create ();
71             
72             processor.setDataPath (files); files = null;
73             processor.setSourcePath (srcpath != null ? srcpath.list () : null);
74             processor.setReportTypes (reportTypes);
75             processor.setPropertyOverrides (settings);
76             
77             processor.run ();
78         }
79     }
80
81     
82     // sourcepath attribute/element:
83

84     public void setSourcepath (final Path path)
85     {
86         m_reportCfg.setSourcepath (path);
87     }
88     
89     public void setSourcepathRef (final Reference ref)
90     {
91         m_reportCfg.setSourcepathRef (ref);
92     }
93     
94     public Path createSourcepath ()
95     {
96         return m_reportCfg.createSourcepath ();
97     }
98     
99     
100     // generator elements:
101

102     public Element_TXT createTxt ()
103     {
104         return m_reportCfg.createTxt ();
105     }
106     
107     public Element_HTML createHtml ()
108     {
109         return m_reportCfg.createHtml ();
110     }
111     
112     public Element_XML createXml ()
113     {
114         return m_reportCfg.createXml ();
115     }
116     
117     
118     // report properties [defaults for all report types]:
119

120     public void setUnits (final UnitsTypeAttribute units)
121     {
122         m_reportCfg.setUnits (units);
123     }
124
125     public void setDepth (final DepthAttribute depth)
126     {
127         m_reportCfg.setDepth (depth);
128     }
129     
130     public void setColumns (final String JavaDoc columns)
131     {
132         m_reportCfg.setColumns (columns);
133     }
134     
135     public void setSort (final String JavaDoc sort)
136     {
137         m_reportCfg.setSort (sort);
138     }
139     
140     public void setMetrics (final String JavaDoc metrics)
141     {
142         m_reportCfg.setMetrics (metrics);
143     }
144
145     // not supported anymore:
146

147 // public void setOutdir (final File dir)
148
// {
149
// m_reportCfg.setOutdir (dir);
150
// }
151
//
152
// public void setDestdir (final File dir)
153
// {
154
// m_reportCfg.setDestdir (dir);
155
// }
156

157     // should not be set at the global level:
158

159 // public void setOutfile (final String fileName)
160
// {
161
// m_reportCfg.setOutfile (fileName);
162
// }
163

164     public void setEncoding (final String JavaDoc encoding)
165     {
166         m_reportCfg.setEncoding (encoding);
167     }
168         
169     // protected: .............................................................
170

171     // package: ...............................................................
172

173     // private: ...............................................................
174

175     
176     private ReportCfg m_reportCfg;
177
178 } // end of class
179
// ----------------------------------------------------------------------------
Popular Tags