EMMA Coverage Report (generated Wed Dec 16 17:19:59 CET 2009)
[all classes][org.sourceforge.xradar.ant]

COVERAGE SUMMARY FOR SOURCE FILE [DynamicsTask.java]

nameclass, %method, %block, %line, %
DynamicsTask.java0%   (0/1)0%   (0/14)0%   (0/474)0%   (0/87)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DynamicsTask0%   (0/1)0%   (0/14)0%   (0/474)0%   (0/87)
DynamicsTask (): void 0%   (0/1)0%   (0/15)0%   (0/4)
addInput (Input): void 0%   (0/1)0%   (0/14)0%   (0/4)
dynamicsInitializtion (): void 0%   (0/1)0%   (0/11)0%   (0/5)
execute (): void 0%   (0/1)0%   (0/128)0%   (0/21)
getConfig (): String 0%   (0/1)0%   (0/3)0%   (0/1)
getTarget (): String 0%   (0/1)0%   (0/3)0%   (0/1)
isDebug (): boolean 0%   (0/1)0%   (0/3)0%   (0/1)
isStaticsConfigured (): boolean 0%   (0/1)0%   (0/3)0%   (0/1)
setConfig (String): void 0%   (0/1)0%   (0/4)0%   (0/2)
setDebug (boolean): void 0%   (0/1)0%   (0/4)0%   (0/2)
setStaticsConfigured (boolean): void 0%   (0/1)0%   (0/4)0%   (0/2)
setTarget (String): void 0%   (0/1)0%   (0/4)0%   (0/2)
validate (): void 0%   (0/1)0%   (0/129)0%   (0/21)
validate (Input): void 0%   (0/1)0%   (0/149)0%   (0/20)

1/**
2 * BSD-style license; for more info see http://xradar.sourceforge.net/license.html
3 */
4package org.sourceforge.xradar.ant;
5 
6import java.util.ArrayList;
7import java.util.List;
8 
9import org.apache.tools.ant.BuildException;
10import org.apache.tools.ant.Project;
11import org.sourceforge.xradar.XRadarException;
12import org.sourceforge.xradar.dynamics.Dynamics;
13import org.sourceforge.xradar.dynamics.Input;
14 
15/**
16 * This class is a simple wrapper for Statics merge for Ant.
17 * Xml configuration will be :
18 *
19 *<code>
20         <xradar-dynamics        debug="false"
21                                                        config="etc/radar-config.xml"
22                                                        target="${docs.home}"
23                                                        staticsConfigured="true"> <!--  false will render staticsRoot attributes optionnal -->
24                        <!-- If orderId == 1, 'previousReport' is not required as it is the first version of the project 
25                                Xradar will use the etc/config/dynamics/dynamics-master-base.xml
26                                embedded in the jar distribution.
27                        -->
28                        <input                    reportToMerge="release1/docs/xml/radar_report_normalized.xml"
29                                                        qualityReportPath="release1/docs/xml/reports/"
30                                                        versionId="1"
31                                                        daysSinceLast="1"
32                                                        staticsRoot="release1/docs"
33                                                        masterFinal="${docs.home}/xml/dynamics-master-final.xml"/>
34                        
35                        --release1.2 => version = 1 
36                        
37                        <input                    previousReport="${docs.home}/xml/dynamics-master-final.xml"
38                                                        reportToMerge="release2/docs/xml/radar_report_normalized.xml"
39                                                        qualityReportPath="release2/docs/xml/reports/"
40                                                        versionId="2"
41                                                        daysSinceLast="1"
42                                                        staticsRoot="release2/docs"
43                                                        masterFinal="${docs.home}/xml/dynamics-master-final.xml"/>
44                                                        
45 
46                </xradar-dynamics>
47        </code>
48 *
49 * @author Romain PELISSE, belaran@gmail.com
50 *
51 */
52public class DynamicsTask extends AbstractXRadarAntTask
53{
54 
55        /*
56         * Fields accessible through getter/setters
57         */
58        private boolean debug = false;
59        private String config;
60        private String target;                
61        private boolean staticsConfigured = true;
62        
63        /*
64         * Included element
65         */
66        private List<Input> inputs = new ArrayList<Input>(0);
67        
68        /*
69         * Internal fields
70         */
71        private Dynamics        dynamicsEngine;
72 
73        
74        public void addInput(Input input)
75        {
76                if ( this.inputs == null )
77                        this.inputs = new ArrayList<Input>();
78                this.inputs.add(input);
79        }
80        /**
81         * Execute the merges of the reports
82         */
83        public void execute() throws BuildException
84        {
85                validate();
86                dynamicsInitializtion();
87                try 
88                {
89                        for ( Input input : this.inputs )
90                        {
91                                
92                                // Version specific settings
93                                dynamicsEngine.setSequenceId(String.valueOf(input.getVersionId()));
94                                dynamicsEngine.setDaysSinceLast(String.valueOf(input.getDaysSinceLast()));
95                                dynamicsEngine.setQualityReportPath(input.getQualityReportPath());
96                                dynamicsEngine.setMasterFinal(input.getMasterFinal());
97                                if ( isStaticsConfigured() )
98                                        dynamicsEngine.setStaticRoot(input.getStaticsRoot());
99 
100                                // Updating file from previous version to the current version
101                                log("Calling execute merge with " + input.getPreviousReport() + " and " + input.getReportToMerge(),Project.MSG_VERBOSE);                        
102                                this.dynamicsEngine.executeMerge(input.getPreviousReport(),input.getReportToMerge());
103                                // Post processing the previousVersion
104                                log("Calling post process with " +  input.getMasterFinal(),Project.MSG_VERBOSE);                        
105                                this.dynamicsEngine.postProcess(input.getMasterFinal());
106                                // Adding static images
107                                log("Adding static images to website",Project.MSG_VERBOSE);                        
108                                this.dynamicsEngine.copyImagesToWebSite();
109                                // Generating the dynamics 'website'
110                                log("Calling dynamics style report with " +  input.getMasterFinal(),Project.MSG_VERBOSE);                        
111                                this.dynamicsEngine.dynamicsStyleReport(input.getMasterFinal(),this.target + Dynamics.EMPTY);
112                        }
113                        
114                }
115                catch (XRadarException e) 
116                {
117                        throw new BuildException(e);
118                }
119 
120        }
121 
122        private void dynamicsInitializtion() throws BuildException
123        {
124                try 
125                {
126                        this.dynamicsEngine.init();
127                } 
128                catch (XRadarException e) 
129                {
130                        throw new BuildException(e);
131                }
132        }
133 
134        private void validate() throws BuildException
135        {
136                // attribute validation
137                if ( "".equals(this.getConfig()) )
138                        throw new BuildException("Config field is not optionnal.");
139                if ( "".equals(this.getTarget()) )
140                        throw new BuildException("Target field is not optionnal.");
141                // Validating 'input' reports
142                if ( this.inputs.size() <= 0 )
143                        throw new BuildException("At least one element <input> is required !");
144                // Logging settings
145                log("Debug:" + this.debug, Project.MSG_VERBOSE);
146                log("Target:" + this.target, Project.MSG_VERBOSE);
147                log("Config:" + this.config, Project.MSG_VERBOSE);
148                log("Is Statics configured ?" + this.isStaticsConfigured(),Project.MSG_VERBOSE);
149                // Validating each report
150                for ( Input input : this.inputs )
151                        validate(input);
152                // Setting the engine
153                this.dynamicsEngine = new Dynamics();
154                this.dynamicsEngine.initializedXmlCatalog((! super.isOnline()));
155                // Setting (and creating docs-home)
156                this.dynamicsEngine.setDebug(this.debug);
157                this.dynamicsEngine.setConfig(this.config);
158                try 
159                {
160                        this.dynamicsEngine.setDocsHome(this.target);
161                }
162                catch (XRadarException e) 
163                {
164                        throw new BuildException(e);
165                }
166        }
167 
168        private void validate(Input input) throws BuildException 
169        {
170                String mssg = "Configure input with versionId" + input.getVersionId();
171                // Previous version filename not setted
172                if ( input.getPreviousReport() == null || "".equals(input.getPreviousReport()) )
173                {
174                        // VersionId is 1, using default file
175                        if ( input.getVersionId() == 1 )
176                                        input.setPreviousReport(Dynamics.DEFAULT_BASE_MASTER_REPORT);
177                        else // this is an error...
178                                throw new BuildException("PreviousReport field is not optionnal." + mssg);                        
179                }
180                if ( input.getReportToMerge() == null || "".equals(input.getReportToMerge()))
181                        throw new BuildException("Report-to-merge field is not optionnal." + mssg );
182                if ( input.getQualityReportPath() == null && "".equals(input.getQualityReportPath() ) )
183                        throw new BuildException("qualityReportPath field is not optionnal."+ mssg );
184                if ( "".equals(input.getDaysSinceLast()) )
185                        input.setDaysSinceLast(0);
186                if ( "".equals(input.getVersionId()) )
187                        input.setVersionId(1);
188                if ( input.getMasterFinal() == null || "".equals(input.getMasterFinal()) )
189                        throw new BuildException("masterFinal field is not optionnal." + mssg );
190                if ( this.isStaticsConfigured() )
191                {
192                        if ( "".equals(input.getStaticsRoot()) )
193                                throw new BuildException("Statics root is required if staticConfigured is set to true." + mssg );
194                        //TODO: Check that directory exists and is readable ! 
195                        //TODO: Also check for an index.html file to assert if the report was successfully generated ?
196 
197                }
198                log("Following input is valid:" + input.toString(),Project.MSG_VERBOSE);
199        }
200 
201        /**
202         * @return the debug
203         */
204        public boolean isDebug() {
205                return debug;
206        }
207 
208        /**
209         * @param debug the debug to set
210         */
211        public void setDebug(boolean debug) {
212                this.debug = debug;
213        }
214 
215        /**
216         * @return the target
217         */
218        public String getTarget() {
219                return target;
220        }
221 
222        /**
223         * @param target the target to set
224         */
225        public void setTarget(String target) {
226                this.target = target;
227        }
228 
229        /**
230         * @return the config
231         */
232        public String getConfig() {
233                return config;
234        }
235 
236        /**
237         * @param config the config to set
238         */
239        public void setConfig(String config) {
240                this.config = config;
241        }
242        /**
243         * @return the staticsConfigured
244         */
245        public boolean isStaticsConfigured() {
246                return staticsConfigured;
247        }
248 
249        /**
250         * @param staticsConfigured the staticsConfigured to set
251         */
252        public void setStaticsConfigured(boolean staticsConfigured) {
253                this.staticsConfigured = staticsConfigured;
254        }
255 
256}

[all classes][org.sourceforge.xradar.ant]
EMMA 2.0.5312 (C) Vladimir Roubtsov