15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 package com.nokia.helium.sbs.ant.taskdefs; |
18 package com.nokia.helium.sbs.ant.taskdefs; |
19 |
19 |
|
20 import java.io.File; |
|
21 import java.util.ArrayList; |
|
22 import java.util.Collection; |
|
23 import java.util.Hashtable; |
20 import java.util.List; |
24 import java.util.List; |
21 import org.w3c.dom.*; |
25 |
22 import javax.xml.parsers.DocumentBuilder; |
26 import org.apache.log4j.Logger; |
23 import javax.xml.parsers.DocumentBuilderFactory; |
|
24 import javax.xml.transform.*; |
|
25 import javax.xml.transform.dom.*; |
|
26 import javax.xml.transform.stream.*; |
|
27 import java.io.FileWriter; |
|
28 import java.text.DecimalFormat; |
|
29 import java.util.Date; |
|
30 import com.nokia.helium.core.plexus.AntStreamConsumer; |
|
31 import java.io.File; |
|
32 import org.apache.tools.ant.BuildException; |
27 import org.apache.tools.ant.BuildException; |
33 import org.apache.tools.ant.Project; |
28 import org.apache.tools.ant.Project; |
34 import org.apache.tools.ant.Task; |
29 import org.apache.tools.ant.Task; |
|
30 import org.apache.tools.ant.types.PatternSet; |
35 |
31 |
36 import com.nokia.helium.core.ant.MappedVariable; |
32 import com.nokia.helium.core.ant.MappedVariable; |
37 import com.nokia.helium.core.ant.types.VariableSet; |
33 import com.nokia.helium.core.ant.types.VariableSet; |
38 import com.nokia.helium.sbs.ant.types.*; |
34 import com.nokia.helium.core.plexus.AntStreamConsumer; |
39 import org.apache.log4j.Logger; |
|
40 import org.apache.tools.ant.types.PatternSet; |
|
41 import com.nokia.helium.sbs.SAXSysdefParser; |
35 import com.nokia.helium.sbs.SAXSysdefParser; |
42 import com.nokia.helium.sbs.SBSCommandBase; |
36 import com.nokia.helium.sbs.SBSCommandBase; |
43 import com.nokia.helium.sbs.SBSException; |
37 import com.nokia.helium.sbs.SBSException; |
44 import java.util.ArrayList; |
38 import com.nokia.helium.sbs.ant.types.SBSInput; |
45 import java.util.Hashtable; |
39 import com.nokia.helium.sbs.ant.types.SBSMakeOptions; |
46 import com.nokia.helium.sbs.plexus.SBSErrorStreamConsumer; |
40 import com.nokia.helium.sbs.plexus.SBSErrorStreamConsumer; |
47 import java.util.Collection; |
|
48 import javax.xml.parsers.ParserConfigurationException; |
|
49 import java.io.IOException; |
|
50 |
41 |
51 /** |
42 /** |
52 * This task is to execute the actual sbs commands with the list of sbs parameters |
43 * This task is to execute the actual sbs commands with the list of sbs parameters using sbsinput |
53 * using sbsinput type. Based on the raptor input list of additional log file path |
44 * type. Based on the raptor input list of additional log file path used needs to be set, so that |
54 * used needs to be set, so that the scanlog, additional log files are generated |
45 * the scanlog, additional log files are generated properly. |
55 * properly. |
|
56 * |
46 * |
57 * <pre> |
47 * <pre> |
58 * Example 1: |
48 * Example 1: |
59 * |
49 * |
60 * <sbstask sbsinput="sbs.input" sysdefFile="system.def.file" |
50 * <sbstask sbsinput="sbs.input" sysdefFile="system.def.file" |
73 private File sysDefFile; |
63 private File sysDefFile; |
74 private File workingDir; |
64 private File workingDir; |
75 private File errorFile; |
65 private File errorFile; |
76 private String logSuffix; |
66 private String logSuffix; |
77 private File outputLogName; |
67 private File outputLogName; |
78 private File statsLog; |
|
79 private boolean executeCmd = true; |
68 private boolean executeCmd = true; |
80 private boolean failOnError = true; |
69 private boolean failOnError = true; |
81 private boolean addMakeOptions = true; |
70 private boolean addMakeOptions = true; |
82 private Date startTime; |
|
83 private Date endTime; |
|
84 private SBSCommandBase sbsCmd = new SBSCommandBase();; |
71 private SBSCommandBase sbsCmd = new SBSCommandBase();; |
85 private String errorPattern; |
72 private String errorPattern; |
86 |
73 |
87 |
74 public SBSCommandBase getSbsCmd() { |
88 |
75 return sbsCmd; |
89 public SBSCommandBase getSbsCmd() { return sbsCmd; } |
76 } |
90 |
77 |
91 /** |
78 /** |
92 * Helper function to set the clean log file. The cleanlog file captures the |
79 * Helper function to set the clean log file. The cleanlog file captures the clean output from |
93 * clean output from raptor and stores into a separate log. This is being used |
80 * raptor and stores into a separate log. This is being used to backtrace the error information |
94 * to backtrace the error information to associate the components. The clean log |
81 * to associate the components. The clean log contains the list of files has to be cleaned by |
95 * contains the list of files has to be cleaned by the raptor command for a |
82 * the raptor command for a specific components. An environment varialbe is set which is used by |
96 * specific components. An environment varialbe is set which is used by |
83 * filterMetadata plugin to store the clean log file in python. |
97 * filterMetadata plugin to store the clean log file in python. |
84 * |
98 * @param logPath, path of the clean log file. |
85 * @param logPath, path of the clean log file. |
99 * @deprecated |
86 * @deprecated |
100 */ |
87 */ |
101 @Deprecated |
88 @Deprecated |
102 public void setCleanLog(String logPath) { |
89 public void setCleanLog(String logPath) { |
103 //cleanLog = logPath; |
90 // cleanLog = logPath; |
104 log("The usage of the cleanLog attribute is deprecated."); |
91 log("The usage of the cleanLog attribute is deprecated."); |
105 } |
92 } |
106 |
93 |
107 /** |
94 /** |
108 * Helper function to set the what log file. The what log file captures the |
95 * Helper function to set the what log file. The what log file captures the what output from |
109 * what output from raptor and stores into a separate log. This is being used |
96 * raptor and stores into a separate log. This is being used to backtrace the error information |
110 * to backtrace the error information to associate the components. The clean log |
97 * to associate the components. The clean log contains the list of files has to be cleaned by |
111 * contains the list of files has to be cleaned by the raptor command for a |
98 * the raptor command for a specific components. An environment varialbe is set which is used by |
112 * specific components. An environment varialbe is set which is used by |
99 * filterMetadata plugin to store the clean log file in python. |
113 * filterMetadata plugin to store the clean log file in python. |
100 * |
114 * @param logPath, path of the clean log file. |
101 * @param logPath, path of the clean log file. |
115 * @deprecated |
102 * @deprecated |
116 */ |
103 */ |
117 @Deprecated |
104 @Deprecated |
118 public void setWhatLog(String logPath) { |
105 public void setWhatLog(String logPath) { |
119 //whatLog = logPath; |
106 // whatLog = logPath; |
120 log("The usage of the whatLog attribute is deprecated."); |
107 log("The usage of the whatLog attribute is deprecated."); |
121 } |
108 } |
122 |
109 |
123 /** |
110 /** |
124 * Helper function to set the output log file name. Path of the output log |
111 * Helper function to set the output log file name. Path of the output log where the raptor |
125 * where the raptor command output to be stored. This would be obtained from |
112 * command output to be stored. This would be obtained from sbsinput, if the raptor argument |
126 * sbsinput, if the raptor argument --logfile set. |
113 * --logfile set. |
|
114 * |
127 * @param logName, name of the logfile to store the raptor output. |
115 * @param logName, name of the logfile to store the raptor output. |
128 */ |
116 */ |
129 public void setOutputLog(File logName) { |
117 public void setOutputLog(File logName) { |
130 outputLogName = logName; |
118 outputLogName = logName; |
131 } |
119 } |
132 |
120 |
133 /** |
121 /** |
134 * To get the output log. |
122 * To get the output log. |
|
123 * |
135 * @return |
124 * @return |
136 */ |
125 */ |
137 public File getOutputLog() { |
126 public File getOutputLog() { |
138 return outputLogName ; |
127 return outputLogName; |
139 } |
128 } |
140 |
129 |
141 |
130 /** |
142 |
131 * Helper function to set the statistics info of the raptor command. The stats file contains how |
143 /** |
132 * long the build being executed, the log file for which the stats is obtained. Used during |
144 * Helper function to set the statistics info of the raptor command. The |
133 * scanlog generation from template file. Once ORM is working an additional table could be |
145 * stats file contains how long the build being executed, the log file for |
134 * created which stores the statistics information, in which case, there won't be the need for |
146 * which the stats is obtained. Used during scanlog generation from template file. |
135 * the statistics file. |
147 * Once ORM is working an additional table could be created which stores the |
136 * |
148 * statistics information, in which case, there won't be the need for the |
|
149 * statistics file. |
|
150 * @param log name of the logfile to store the raptor command statistics information. |
137 * @param log name of the logfile to store the raptor command statistics information. |
151 * @deprecated |
138 * @deprecated |
152 */ |
139 */ |
153 @Deprecated |
140 @Deprecated |
154 public void setStatsLog(File log) { |
141 public void setStatsLog(File log) { |
155 statsLog = log; |
142 // statsLog = log; |
156 } |
143 } |
157 |
144 |
158 |
145 /** |
159 /** |
146 * Helper function to set the sbsinput name for which the sbs to be executed. The sbsinput |
160 * Helper function to set the sbsinput name for which the sbs to be executed. |
147 * contains the raptor parameter both the sbs options and sbs make options. |
161 * The sbsinput contains the raptor parameter both the sbs options and sbs make options. |
148 * |
162 * @param inputName name of the sbs input which contains the list of sbs parameters. |
149 * @param inputName name of the sbs input which contains the list of sbs parameters. |
163 */ |
150 */ |
164 public void setSBSInput(String inputName) { |
151 public void setSBSInput(String inputName) { |
165 sbsInputName = inputName; |
152 sbsInputName = inputName; |
166 } |
153 } |
167 |
154 |
168 /** |
155 /** |
169 * To get the sbs name. |
156 * To get the sbs name. |
|
157 * |
170 * @return |
158 * @return |
171 */ |
159 */ |
172 public String getSBSInput() { |
160 public String getSBSInput() { |
173 return sbsInputName ; |
161 return sbsInputName; |
174 } |
162 } |
175 |
163 |
176 |
164 /** |
177 |
165 * Helper function to set the sbs error log file path. The error log file contains the errors |
178 /** |
166 * captured from the raptor error stream and processed separately. |
179 * Helper function to set the sbs error log file path. The error log file contains |
167 * |
180 * the errors captured from the raptor error stream and processed separately. |
|
181 * @param file path of the error output to be stored for the raptor command execution. |
168 * @param file path of the error output to be stored for the raptor command execution. |
182 */ |
169 */ |
183 public void setErrorOutput(File file) { |
170 public void setErrorOutput(File file) { |
184 errorFile = file; |
171 errorFile = file; |
185 } |
172 } |
186 |
173 |
187 /** |
174 /** |
188 * To get the error output file. |
175 * To get the error output file. |
|
176 * |
189 * @return |
177 * @return |
190 */ |
178 */ |
191 public File getErrorOutput() { |
179 public File getErrorOutput() { |
192 return errorFile ; |
180 return errorFile; |
193 } |
181 } |
194 |
182 |
195 /** |
183 /** |
196 * Helper function to set the sysdef file path. System definition file contains |
184 * Helper function to set the sysdef file path. System definition file contains the full list of |
197 * the full list of components to be build with the sbs input. For 1.4.0 schema |
185 * components to be build with the sbs input. For 1.4.0 schema the sysdef file should be already |
198 * the sysdef file should be already filtered for the corresponding abld configuration |
186 * filtered for the corresponding abld configuration and the sysdef file associated here |
199 * and the sysdef file associated here contains only layers for which the sbs command |
187 * contains only layers for which the sbs command needs to be executed with sbsinput arguments. |
200 * needs to be executed with sbsinput arguments. |
188 * |
201 * @param file sysdef file path. |
189 * @param file sysdef file path. |
202 */ |
190 */ |
203 public void setSysDefFile(File file) { |
191 public void setSysDefFile(File file) { |
204 sysDefFile = file; |
192 sysDefFile = file; |
205 } |
193 } |
206 |
194 |
207 /** |
195 /** |
208 * To get the sysdef file. |
196 * To get the sysdef file. |
|
197 * |
209 * @return |
198 * @return |
210 */ |
199 */ |
211 public File getSysDefFile() { |
200 public File getSysDefFile() { |
212 return sysDefFile ; |
201 return sysDefFile; |
213 } |
202 } |
214 |
203 |
215 |
204 /** |
216 /** |
205 * Helper function to set the log suffix. |
217 * Helper function to set the log suffix. |
206 * |
218 * @param suffix logfile suffix. |
207 * @param suffix logfile suffix. |
219 */ |
208 */ |
220 public void setLogSuffix(String suffix) { |
209 public void setLogSuffix(String suffix) { |
221 logSuffix = suffix; |
210 logSuffix = suffix; |
222 } |
211 } |
223 |
212 |
224 /** |
213 /** |
225 * To get the logsuffix. |
214 * To get the logsuffix. |
|
215 * |
226 * @return |
216 * @return |
227 */ |
217 */ |
228 public String getLogSuffix() { |
218 public String getLogSuffix() { |
229 return logSuffix ; |
219 return logSuffix; |
230 } |
220 } |
231 |
221 |
232 /** |
222 /** |
233 * Patternset is used to filter the layers from the sysdef file for which the sbs |
223 * Patternset is used to filter the layers from the sysdef file for which the sbs commands need |
234 * commands need to be executed instead of all the layers in the system definition files. |
224 * to be executed instead of all the layers in the system definition files. This is useful for |
235 * This is useful for example in order to execute only the test layer, a patter set could |
225 * example in order to execute only the test layer, a patter set could contain test*, then all |
236 * contain test*, then all the layers begining with test are matched and passed as |
226 * the layers begining with test are matched and passed as raptor input. |
237 * raptor input. |
227 * |
238 * @param id patternset id, for which the patterns to be filtered. |
228 * @param id patternset id, for which the patterns to be filtered. |
239 */ |
229 */ |
240 public void setLayerPatternSetRef(String id) { |
230 public void setLayerPatternSetRef(String id) { |
241 layerPatternSetRef = id; |
231 layerPatternSetRef = id; |
242 } |
232 } |
243 |
233 |
244 /** |
234 /** |
245 * |
235 * |
246 * To get the layer pattern set. |
236 * To get the layer pattern set. |
|
237 * |
247 * @return |
238 * @return |
248 */ |
239 */ |
249 public String getLayerPatternSetRef() { |
240 public String getLayerPatternSetRef() { |
250 return layerPatternSetRef ; |
241 return layerPatternSetRef; |
251 } |
242 } |
252 |
243 |
253 /** |
244 /** |
254 * Helper function to set the current working directory. This would be mostly the |
245 * Helper function to set the current working directory. This would be mostly the root of the |
255 * root of the build area. |
246 * build area. |
256 * @param dir root of the build area location from which to execute the raptor commands. |
247 * |
|
248 * @param dir root of the build area location from which to execute the raptor commands. |
257 */ |
249 */ |
258 public void setWorkingDir(File dir) { |
250 public void setWorkingDir(File dir) { |
259 workingDir = dir; |
251 workingDir = dir; |
260 } |
252 } |
261 |
253 |
262 /** |
254 /** |
263 * To get the working dir. |
255 * To get the working dir. |
|
256 * |
264 * @return |
257 * @return |
265 */ |
258 */ |
266 public File getWorkingDir() { |
259 public File getWorkingDir() { |
267 return workingDir ; |
260 return workingDir; |
268 } |
261 } |
269 |
262 |
270 |
263 /** |
271 |
264 * Helper function to execute the actual commands or just print the commands and not execute the |
272 /** |
265 * actual commands. |
273 * Helper function to execute the actual commands or just print the commands and |
266 * |
274 * not execute the actual commands. |
267 * @param execute true / false if true print and execute the commands, otherwise just print the |
275 * @param execute true / false if true print and execute the commands, otherwise just |
268 * commands. |
276 * print the commands. |
|
277 */ |
269 */ |
278 public void setExecute(boolean execute) { |
270 public void setExecute(boolean execute) { |
279 executeCmd = execute; |
271 executeCmd = execute; |
280 } |
272 } |
281 |
273 |
282 /** |
274 /** |
283 * To get execute value. |
275 * To get execute value. |
|
276 * |
284 * @return |
277 * @return |
285 */ |
278 */ |
286 public boolean getExecute() { |
279 public boolean getExecute() { |
287 return executeCmd ; |
280 return executeCmd; |
288 } |
281 } |
289 |
282 |
290 /** |
283 /** |
291 * Helper function to set whether to fail the build or not. |
284 * Helper function to set whether to fail the build or not. |
292 * |
285 * |
293 * @param failBuild true / false - true to fail the build otherwise false. |
286 * @param failBuild true / false - true to fail the build otherwise false. |
294 */ |
287 */ |
295 public void setFailOnError(boolean failBuild) { |
288 public void setFailOnError(boolean failBuild) { |
296 failOnError = failBuild; |
289 failOnError = failBuild; |
297 } |
290 } |
298 |
291 |
299 /** |
292 /** |
300 * To get the failonError value. |
293 * To get the failonError value. |
|
294 * |
301 * @return |
295 * @return |
302 */ |
296 */ |
303 public boolean getFailOnError() { |
297 public boolean getFailOnError() { |
304 return failOnError ; |
298 return failOnError; |
305 } |
299 } |
306 |
300 |
307 /** |
301 /** |
308 * @param addMakeOptions the addMakeOptions to set |
302 * @param addMakeOptions the addMakeOptions to set |
309 */ |
303 */ |
310 protected void setAddMakeOptions(boolean addMakeOptions) { |
304 protected void setAddMakeOptions(boolean addMakeOptions) { |
311 this.addMakeOptions = addMakeOptions; |
305 this.addMakeOptions = addMakeOptions; |
312 } |
306 } |
313 |
307 |
314 |
|
315 /** |
308 /** |
316 * To get the error Pattern. |
309 * To get the error Pattern. |
|
310 * |
317 * @return |
311 * @return |
318 */ |
312 */ |
319 protected String getErrorStreamPattern() { |
313 protected String getErrorStreamPattern() { |
320 return this.errorPattern; |
314 return this.errorPattern; |
321 } |
315 } |
322 |
316 |
323 /** |
317 /** |
324 * Execute the sbs commands from sbsinput. |
318 * Execute the sbs commands from sbsinput. |
|
319 * |
325 * @throws BuildException |
320 * @throws BuildException |
326 */ |
321 */ |
327 public void execute() { |
322 public void execute() { |
328 SBSErrorStreamConsumer sbsErrorConsumer = null; |
323 SBSErrorStreamConsumer sbsErrorConsumer = null; |
329 validateParameter(); |
324 validateParameter(); |
332 log.debug("error stream file : " + errorFile); |
327 log.debug("error stream file : " + errorFile); |
333 sbsCmd.addOutputLineHandler(new AntStreamConsumer(this)); |
328 sbsCmd.addOutputLineHandler(new AntStreamConsumer(this)); |
334 if (errorFile == null) { |
329 if (errorFile == null) { |
335 log.debug("redirecting error to Antstream"); |
330 log.debug("redirecting error to Antstream"); |
336 sbsCmd.addErrorLineHandler(new AntStreamConsumer(this)); |
331 sbsCmd.addErrorLineHandler(new AntStreamConsumer(this)); |
337 } else { |
332 } |
|
333 else { |
338 sbsErrorConsumer = new SBSErrorStreamConsumer(errorFile, getErrorStreamPattern()); |
334 sbsErrorConsumer = new SBSErrorStreamConsumer(errorFile, getErrorStreamPattern()); |
339 log.debug("redirecting error to file stream"); |
335 log.debug("redirecting error to file stream"); |
340 sbsCmd.addErrorLineHandler(sbsErrorConsumer); |
336 sbsCmd.addErrorLineHandler(sbsErrorConsumer); |
341 } |
337 } |
342 } catch (java.io.FileNotFoundException ex) { |
338 } |
343 log("file path: " + errorFile + "Not valid" ); |
339 catch (java.io.FileNotFoundException ex) { |
344 } |
340 log("file path: " + errorFile + "Not valid"); |
345 |
341 } |
346 startTime = new Date(); |
342 |
347 try { |
343 try { |
348 String cmdLine = getSBSCmdLine(); |
344 String cmdLine = getSBSCmdLine(); |
349 if (cmdLine == null) { |
345 if (cmdLine == null) { |
350 // this happens in case there is nothing to be done, let's just run |
346 // this happens in case there is nothing to be built, let's just run |
351 // sbs anyway so the output log is generated |
347 // sbs anyway so the output log is generated |
352 cmdLine = " --logfile " + getOutputLog().getAbsolutePath(); |
348 cmdLine = " --logfile " + getOutputLog().getAbsolutePath(); |
353 } |
349 } |
354 log(getSbsCmd().getExecutable() + " commands: " + cmdLine); |
350 log(getSbsCmd().getExecutable() + " commands: " + cmdLine); |
355 if (executeCmd) { |
351 if (executeCmd) { |
356 sbsCmd.execute(cmdLine); |
352 sbsCmd.execute(cmdLine); |
357 } |
353 } |
358 } catch (SBSException sex) { |
354 } |
|
355 catch (SBSException sex) { |
359 log.debug("SBS exception occured during sbs execution", sex); |
356 log.debug("SBS exception occured during sbs execution", sex); |
360 if (failOnError) { |
357 if (failOnError) { |
361 throw new BuildException("exception during SBS execution", sex); |
358 throw new BuildException("exception during SBS execution", sex); |
362 } |
359 } |
363 } finally { |
360 } |
364 //Called to update the error stream, better would be the commandbase |
361 finally { |
365 //handling the closing of streams in case of exceptions. |
362 // Called to update the error stream, better would be the commandbase |
|
363 // handling the closing of streams in case of exceptions. |
366 if (sbsErrorConsumer != null) { |
364 if (sbsErrorConsumer != null) { |
367 sbsErrorConsumer.close(); |
365 sbsErrorConsumer.close(); |
368 } |
366 } |
369 } |
367 } |
370 endTime = new Date(); |
368 } |
371 /*if (statsLog != null) { |
369 |
372 updateSBSLogStatistics(statsLog, outputLogName, startTime, endTime); |
370 /** |
373 }*/ |
371 * Internal function to get the filtered layers by processing the system definition file with |
374 } |
372 * list of matched layers. |
375 |
373 * |
376 /** |
374 * @return list of filtered layers from the sysdef file for which the raptor commands to be |
377 * Internal function to get the filtered layers by |
375 * executed. |
378 * processing the system definition file with list of matched layers. |
|
379 * |
|
380 * @return list of filtered layers from the sysdef file for which |
|
381 * the raptor commands to be executed. |
|
382 */ |
376 */ |
383 private List<String> getFilteredLayers() { |
377 private List<String> getFilteredLayers() { |
384 List<String> filteredLayers = null; |
378 List<String> filteredLayers = null; |
385 if (layerPatternSetRef != null) { |
379 if (layerPatternSetRef != null) { |
386 Hashtable references = getProject().getReferences(); |
380 Hashtable references = getProject().getReferences(); |
387 Object layerPatternSetObject = references.get(layerPatternSetRef); |
381 Object layerPatternSetObject = references.get(layerPatternSetRef); |
388 if ( layerPatternSetObject != null && ! (layerPatternSetObject instanceof PatternSet)) { |
382 if (layerPatternSetObject != null && !(layerPatternSetObject instanceof PatternSet)) { |
389 throw new BuildException("Layer Pattern set is not of type PatternSet"); |
383 throw new BuildException("Layer Pattern set is not of type PatternSet"); |
390 } |
384 } |
391 if (layerPatternSetObject != null) { |
385 if (layerPatternSetObject != null) { |
392 PatternSet layerPatternSet = (PatternSet) layerPatternSetObject; |
386 PatternSet layerPatternSet = (PatternSet) layerPatternSetObject; |
393 SAXSysdefParser sysDefParser = new SAXSysdefParser(sysDefFile); |
387 SAXSysdefParser sysDefParser = new SAXSysdefParser(sysDefFile); |
394 List<String> fullLayerList = sysDefParser.getLayers(); |
388 List<String> fullLayerList = sysDefParser.getLayers(); |
395 filteredLayers = new ArrayList<String>(); |
389 filteredLayers = new ArrayList<String>(); |
396 String[] includes = layerPatternSet.getIncludePatterns(getProject()); |
390 String[] includes = layerPatternSet.getIncludePatterns(getProject()); |
397 String[] excludes = layerPatternSet.getExcludePatterns(getProject()); |
391 String[] excludes = layerPatternSet.getExcludePatterns(getProject()); |
398 if (includes == null && excludes == null) { |
392 if (includes == null && excludes == null) { |
399 throw new BuildException("No patterns specified"); |
393 throw new BuildException("No patterns specified"); |
410 } |
404 } |
411 return filteredLayers; |
405 return filteredLayers; |
412 } |
406 } |
413 |
407 |
414 /** |
408 /** |
415 * Update the raptor build statistics by generating an xml file containing |
409 * Internal function to find the included layer patterns. |
416 * the build time and the log file name, used to generate the scanlog. |
410 * |
417 * @param infoFileName |
|
418 * @param logFileName |
|
419 * @param startTime |
|
420 * @param endTime |
|
421 */ |
|
422 protected void updateSBSLogStatistics(File infoFileName, String logFileName, Date startTime, Date endTime) { |
|
423 |
|
424 try { |
|
425 DocumentBuilderFactory sbsInfo = DocumentBuilderFactory.newInstance(); |
|
426 DocumentBuilder docBuilder = sbsInfo.newDocumentBuilder(); |
|
427 Document doc = docBuilder.newDocument(); |
|
428 Element root = doc.createElement("sbsinfo"); |
|
429 doc.appendChild(root); |
|
430 Element child = doc.createElement("logfile"); |
|
431 child.setAttribute("name", logFileName); |
|
432 root.appendChild(child); |
|
433 |
|
434 long timeDiff = (endTime.getTime() - startTime.getTime()) / 1000; |
|
435 child = doc.createElement("durationlong"); |
|
436 child.setAttribute("time", "" + timeDiff); |
|
437 root.appendChild(child); |
|
438 child = doc.createElement("duration"); |
|
439 int hours = (int) (timeDiff / 3600); |
|
440 int minutesSeconds = (int)(timeDiff % 3600); |
|
441 int minutes = minutesSeconds / 60; |
|
442 int seconds = minutesSeconds % 60; |
|
443 DecimalFormat decimalFormat = new DecimalFormat(); |
|
444 decimalFormat.setMinimumIntegerDigits(2); |
|
445 String duration = decimalFormat.format(hours) + "H:" + |
|
446 decimalFormat.format(minutes) + "M:" + decimalFormat.format(seconds) + "S"; |
|
447 //Todo: handle if the time difference is greater than 24 hours |
|
448 child.setAttribute("time", duration); |
|
449 root.appendChild(child); |
|
450 Transformer transformer = TransformerFactory.newInstance().newTransformer(); |
|
451 transformer.setOutputProperty(OutputKeys.INDENT, "yes"); |
|
452 FileWriter sbsWriter = new FileWriter(infoFileName); |
|
453 StreamResult result = new StreamResult(sbsWriter); |
|
454 DOMSource sbsSource = new DOMSource(doc); |
|
455 transformer.transform(sbsSource, result); |
|
456 } catch (ParserConfigurationException ex) { |
|
457 log.debug("ParserConfigurationException while xml writing sbs log info", ex); |
|
458 } catch (TransformerConfigurationException ex) { |
|
459 log.debug("TransformerConfigurationException while xml writing sbs log info", ex); |
|
460 } catch (IOException ex) { |
|
461 log.debug("IOException while xml writing sbs log info", ex); |
|
462 } catch (TransformerException ex) { |
|
463 log.debug("TransformerException while xml writing sbs log info", ex); |
|
464 } |
|
465 } |
|
466 |
|
467 |
|
468 /** |
|
469 * Internal function to find the included layer patterns. |
|
470 * |
|
471 * @param text - layer name to be compared with |
411 * @param text - layer name to be compared with |
472 * @param includes - compare the layer name with the includes list. |
412 * @param includes - compare the layer name with the includes list. |
473 * @return true if the text containing layer name to be included. |
413 * @return true if the text containing layer name to be included. |
474 */ |
414 */ |
475 private boolean isIncluded(String text, String[] includes) { |
415 private boolean isIncluded(String text, String[] includes) { |
476 if (includes == null) { |
416 if (includes == null) { |
477 return true; |
417 return true; |
478 } else { |
418 } |
|
419 else { |
479 for (String pattern : includes) { |
420 for (String pattern : includes) { |
480 if (text.matches(pattern)) { |
421 if (text.matches(pattern)) { |
481 return true; |
422 return true; |
482 } |
423 } |
483 } |
424 } |
484 return false; |
425 return false; |
485 } |
426 } |
486 } |
427 } |
487 |
428 |
488 /** |
429 /** |
489 * Internal function to find the excluded layer patterns. |
430 * Internal function to find the excluded layer patterns. |
490 * |
431 * |
491 * @param text - layer name to be compared with |
432 * @param text - layer name to be compared with |
492 * @param excludes - compare the layer name with the excludes list. |
433 * @param excludes - compare the layer name with the excludes list. |
493 * @return true if the text containing layer name to be excluded. |
434 * @return true if the text containing layer name to be excluded. |
494 */ |
435 */ |
495 private boolean isExcluded(String text, String[] excludes) { |
436 private boolean isExcluded(String text, String[] excludes) { |
519 throw new BuildException("'workingDir' must be set"); |
459 throw new BuildException("'workingDir' must be set"); |
520 } |
460 } |
521 if (getOutputLog() == null) { |
461 if (getOutputLog() == null) { |
522 throw new BuildException("'OutputLog' must be set"); |
462 throw new BuildException("'OutputLog' must be set"); |
523 } |
463 } |
524 |
464 |
525 } |
465 } |
526 |
466 |
527 /** |
467 /** |
528 * To get the SBS command line parameters. |
468 * To get the SBS command line parameters. |
|
469 * |
529 * @return |
470 * @return |
530 */ |
471 */ |
531 protected String getSBSCmdLine() { |
472 protected String getSBSCmdLine() { |
532 |
473 |
533 List <String> filteredLayers = getFilteredLayers(); |
474 List<String> filteredLayers = getFilteredLayers(); |
534 |
475 |
535 Object refObject = getProject().getReferences().get(sbsInputName); |
476 Object refObject = getProject().getReferences().get(sbsInputName); |
536 if (refObject == null) { |
477 if (refObject == null) { |
537 throw new BuildException("invalid sbs input reference: " + sbsInputName); |
478 throw new BuildException("invalid sbs input reference: " + sbsInputName); |
538 } |
479 } |
539 if ( refObject != null && ! (refObject instanceof SBSInput)) { |
480 if (refObject != null && !(refObject instanceof SBSInput)) { |
540 throw new BuildException("sbs input name " + sbsInputName + "is not valid"); |
481 throw new BuildException("sbs input name " + sbsInputName + "is not valid"); |
541 } |
482 } |
542 SBSInput sbsInput = (SBSInput)refObject; |
483 SBSInput sbsInput = (SBSInput) refObject; |
543 StringBuffer cmdOptions = new StringBuffer(); |
484 StringBuffer cmdOptions = new StringBuffer(); |
544 VariableSet sbsOptions = sbsInput.getFullSBSOptions(); |
485 VariableSet sbsOptions = sbsInput.getFullSBSOptions(); |
545 cmdOptions.append(" -s " + sysDefFile); |
486 cmdOptions.append(" -s " + sysDefFile); |
546 Collection<MappedVariable> variableList = sbsOptions.getVariables(); |
487 Collection<MappedVariable> variableList = sbsOptions.getVariables(); |
547 if (sbsOptions != null ) { |
488 if (sbsOptions != null) { |
548 if (variableList.isEmpty()) { |
489 if (variableList.isEmpty()) { |
549 throw new BuildException("sbsoptions cannot be empty for input: " + sbsInputName); |
490 throw new BuildException("sbsoptions cannot be empty for input: " + sbsInputName); |
550 } |
491 } |
551 } |
492 } |
552 cmdOptions.append(" --logfile " + getOutputLog().getAbsolutePath()); |
493 cmdOptions.append(" --logfile " + getOutputLog().getAbsolutePath()); |
553 for (MappedVariable variable : variableList) { |
494 for (MappedVariable variable : variableList) { |
554 if (variable.getParameter().startsWith("--logfile")) { |
495 if (variable.getParameter().startsWith("--logfile")) { |
555 this.log("The following command line argument will be ignored: " + variable.getParameter(), Project.MSG_WARN); |
496 this.log("The following command line argument will be ignored: " |
556 } else { |
497 + variable.getParameter(), Project.MSG_WARN); |
|
498 } |
|
499 else { |
557 cmdOptions.append(" " + variable.getParameter()); |
500 cmdOptions.append(" " + variable.getParameter()); |
558 } |
501 } |
559 } |
502 } |
560 SBSMakeOptions sbsMakeOptions = sbsInput.getFullSBSMakeOptions(); |
503 SBSMakeOptions sbsMakeOptions = sbsInput.getFullSBSMakeOptions(); |
561 variableList = null; |
504 variableList = null; |