34 import org.apache.tools.ant.BuildException; |
34 import org.apache.tools.ant.BuildException; |
35 import org.apache.tools.ant.Project; |
35 import org.apache.tools.ant.Project; |
36 import org.apache.tools.ant.Target; |
36 import org.apache.tools.ant.Target; |
37 import org.apache.tools.ant.util.DateUtils; |
37 import org.apache.tools.ant.util.DateUtils; |
38 |
38 |
39 import com.nokia.helium.logger.ant.types.Stage; |
39 import com.nokia.helium.core.ant.types.Stage; |
40 import com.nokia.helium.logger.ant.types.StageSummary; |
40 import com.nokia.helium.logger.ant.types.StageSummary; |
41 |
41 |
42 import freemarker.cache.FileTemplateLoader; |
42 import freemarker.cache.FileTemplateLoader; |
43 import freemarker.template.Configuration; |
43 import freemarker.template.Configuration; |
44 import freemarker.template.Template; |
44 import freemarker.template.Template; |
81 |
81 |
82 /** |
82 /** |
83 * {@inheritDoc} |
83 * {@inheritDoc} |
84 */ |
84 */ |
85 public void handleBuildFinished(BuildEvent event) { |
85 public void handleBuildFinished(BuildEvent event) { |
86 if (summarize && currentStage != null) |
86 if (summarize && currentStage != null) { |
87 endCurrentStage(); |
87 endCurrentStage(); |
|
88 } |
88 if (summarize && !completedStages.isEmpty()) { |
89 if (summarize && !completedStages.isEmpty()) { |
89 generateSummary(event.getProject()); |
90 generateSummary(event.getProject()); |
90 log.debug("Stage Summary generation completed"); |
91 log.debug("Stage Summary generation completed"); |
91 } |
92 } |
92 } |
93 } |
114 } |
115 } |
115 |
116 |
116 log.debug("Handling target - " + event.getTarget().getName()); |
117 log.debug("Handling target - " + event.getTarget().getName()); |
117 if (summarize && doRunTarget(event)) { |
118 if (summarize && doRunTarget(event)) { |
118 StageWrapper stage = searchNewStage(event); |
119 StageWrapper stage = searchNewStage(event); |
119 if (stage != null) |
120 if (stage != null) { |
120 startNewStage(stage); |
121 startNewStage(stage); |
|
122 } |
121 } |
123 } |
122 } |
124 } |
123 |
125 |
124 /** |
126 /** |
125 * {@inheritDoc} |
127 * {@inheritDoc} |
126 */ |
128 */ |
127 public void handleTargetFinished(BuildEvent event) { |
129 public void handleTargetFinished(BuildEvent event) { |
128 if (summarize && isCurrentStageToEnd(event)) |
130 if (summarize && isCurrentStageToEnd(event)) { |
129 endCurrentStage(); |
131 endCurrentStage(); |
|
132 } |
130 } |
133 } |
131 |
134 |
132 /** |
135 /** |
133 * Indicates whether the current stage is ending or not. |
136 * Indicates whether the current stage is ending or not. |
134 * |
137 * |
165 for (Enumeration<String> en = references.keys(); en.hasMoreElements();) { |
169 for (Enumeration<String> en = references.keys(); en.hasMoreElements();) { |
166 Object object = references.get(en.nextElement()); |
170 Object object = references.get(en.nextElement()); |
167 if (object instanceof StageSummary) { |
171 if (object instanceof StageSummary) { |
168 count++; |
172 count++; |
169 if (count > 1) { |
173 if (count > 1) { |
170 raiseException("Multiple entries of 'hlm:stagesummary' found in " |
174 throw new BuildException("Multiple entries of 'hlm:stagesummary' found in " |
171 + "stages_config.ant.xml."); |
175 + "stages_config.ant.xml."); |
172 } |
176 } |
173 stageSummary = (StageSummary) object; |
177 stageSummary = (StageSummary) object; |
174 } |
178 } |
175 } |
179 } |
176 return stageSummary; |
180 return stageSummary; |
177 } |
181 } |
178 |
182 |
179 /** |
183 /** |
180 * Raise a {@link BuildException} with the specified error message. |
|
181 * |
|
182 * @param message |
|
183 * is the error message to display. |
|
184 */ |
|
185 private void raiseException(String message) { |
|
186 throw new BuildException(message); |
|
187 } |
|
188 |
|
189 /** |
|
190 * Start the given stage as a new build stage. |
184 * Start the given stage as a new build stage. |
191 * |
185 * |
192 * @param newStage |
186 * @param newStage |
193 * is the new build stage to start. |
187 * is the new build stage to start. |
194 */ |
188 */ |
195 private void startNewStage(StageWrapper newStage) { |
189 private void startNewStage(StageWrapper newStage) { |
196 endCurrentStage(); |
190 endCurrentStage(); |
197 Long currTime = getCurrentTime(); |
191 Long currTime = getCurrentTime(); |
198 if (!completedStages.containsKey(newStage.stageName)) |
192 if (!completedStages.containsKey(newStage.stageName)) { |
199 newStage.setStageStartTime(getTimestamp(currTime)); |
193 newStage.setStageStartTime(getTimestamp(currTime)); |
|
194 } |
200 newStage.setStartTime(currTime); |
195 newStage.setStartTime(currTime); |
201 this.currentStage = newStage; |
196 this.currentStage = newStage; |
202 log.debug("New stage [" + newStage.stageName + "] started at " |
197 log.debug("New stage [" + newStage.stageName + "] started at " |
203 + getTimestamp(currTime)); |
198 + getTimestamp(currTime)); |
204 } |
199 } |