16 */ |
16 */ |
17 |
17 |
18 package com.nokia.helium.metadata.ant.taskdefs; |
18 package com.nokia.helium.metadata.ant.taskdefs; |
19 |
19 |
20 import java.io.File; |
20 import java.io.File; |
|
21 import java.util.ArrayList; |
|
22 import java.util.List; |
21 |
23 |
22 import org.apache.tools.ant.BuildException; |
24 import org.apache.tools.ant.BuildException; |
|
25 import org.apache.tools.ant.Project; |
23 import org.apache.tools.ant.Task; |
26 import org.apache.tools.ant.Task; |
|
27 import org.apache.tools.ant.types.ResourceCollection; |
|
28 |
|
29 import com.nokia.helium.metadata.MetadataException; |
24 import com.nokia.helium.metadata.ant.conditions.MetaDataLogCondition; |
30 import com.nokia.helium.metadata.ant.conditions.MetaDataLogCondition; |
|
31 import com.nokia.helium.metadata.ant.types.SeverityEnum; |
25 |
32 |
26 /** |
33 /** |
27 * This class sets a property to the number of matching severity inside a Metadata db for a log. |
34 * This class sets a property to the number of matching severity inside a Metadata db for a log. |
28 * Example: |
35 * Example: |
29 * <pre> |
36 * <pre> |
30 * <hlm:metadataCountSeverity severity="error" log="*_fixslashes_raptor.log" db="${build.log.dir}/metadata.db" property="fixslashes.error"/> |
37 * <hlm:metadataCountSeverity severity="error" |
|
38 * log="${compile.log.dir}/${build.id}_fixslashes_raptor.log" |
|
39 * database="${build.log.dir}/metadata_db" |
|
40 * property="fixslashes.error" /> |
31 * </pre> |
41 * </pre> |
32 |
42 |
33 * @ant.task name="metadataCountSeverity" category="Metadata" |
43 * @ant.task name="metadataCountSeverity" category="Metadata" |
34 */ |
44 */ |
35 public class MetaDataLogCountTask extends Task { |
45 public class MetaDataLogCountTask extends Task { |
36 |
46 |
37 private File fileName; |
47 private File database; |
38 private String logFile; |
48 private File log; |
39 private String severity; |
49 private SeverityEnum severity; |
40 private String property; |
50 private String property; |
41 private boolean countMissing = true; |
51 private List<ResourceCollection> resourceCollections = new ArrayList<ResourceCollection>(); |
|
52 |
|
53 public void add(ResourceCollection resourceCollection) { |
|
54 resourceCollections.add(resourceCollection); |
|
55 } |
42 |
56 |
43 /** |
57 /** |
44 * File to be parsed. |
58 * Location of the database. |
45 * |
59 * |
46 * @param filename |
60 * @param filename |
47 * @ant.required |
61 * @ant.required |
48 */ |
62 */ |
49 public void setDb(File filename) { |
63 @Deprecated |
50 fileName = filename; |
64 public void setDb(File database) { |
|
65 log("The usage of the db attribute is deprecated, please use the database attribute instead.", Project.MSG_WARN); |
|
66 this.database = database; |
|
67 } |
|
68 |
|
69 /** |
|
70 * Location of the database. |
|
71 * |
|
72 * @param filename |
|
73 * @ant.required |
|
74 */ |
|
75 public void setDatabase(File database) { |
|
76 this.database = database; |
51 } |
77 } |
52 |
78 |
53 public void setLog(String log) { |
79 public void setLog(File log) { |
54 logFile = log; |
80 this.log = log; |
55 } |
81 } |
56 |
82 |
57 /** |
83 /** |
58 * Defines the severity name to be counted. |
84 * Defines the severity name to be counted. |
59 * |
85 * |
60 * @param severity |
86 * @param severity |
61 * @ant.required |
87 * @ant.required |
62 */ |
88 */ |
63 public void setSeverity(String severity) { |
89 public void setSeverity(SeverityEnum severity) { |
64 this.severity = severity; |
90 this.severity = severity; |
65 } |
91 } |
66 |
92 |
67 /** |
93 /** |
68 * Name of the property to be set. |
94 * Name of the property to be set. |
77 * Should the count of missing files for error severity. |
103 * Should the count of missing files for error severity. |
78 * @param countMissing enable the count of missing files |
104 * @param countMissing enable the count of missing files |
79 * for error severity |
105 * for error severity |
80 * @ant.not-required Default is true |
106 * @ant.not-required Default is true |
81 */ |
107 */ |
|
108 @Deprecated |
82 public void setCountMissing(boolean countMissing) { |
109 public void setCountMissing(boolean countMissing) { |
83 this.countMissing = countMissing; |
110 // not active anymore |
84 } |
111 } |
85 |
112 |
86 /** |
113 /** |
87 * Execute the task. Set the property with number of severities. |
114 * Execute the task. Set the property with number of severities. |
88 * @throws BuildException |
115 * @throws BuildException |
89 */ |
116 */ |
90 public void execute() { |
117 public void execute() { |
91 if (property == null) |
118 if (property == null) { |
92 throw new BuildException("'property' attribute is not defined"); |
119 throw new BuildException("'property' attribute is not defined"); |
93 |
120 } |
94 MetaDataLogCondition cond = new MetaDataLogCondition(); |
121 try { |
95 cond.setDb(fileName); |
122 MetaDataLogCondition cond = new MetaDataLogCondition(); |
96 cond.setLog(logFile); |
123 cond.setProject(getProject()); |
97 cond.setSeverity(severity); |
124 cond.setDatabase(database); |
98 cond.setCountMissing(countMissing); |
125 cond.setLog(log); |
99 getProject().setNewProperty(property, "" + cond.getSeverity()); |
126 cond.setSeverity(severity); |
|
127 for (ResourceCollection rc : resourceCollections) { |
|
128 cond.add(rc); |
|
129 } |
|
130 getProject().setNewProperty(property, "" + cond.getSeverity()); |
|
131 } catch (MetadataException ex) { |
|
132 throw new BuildException(ex.getMessage(), ex); |
|
133 } |
100 } |
134 } |
101 } |
135 } |