22 import java.util.List; |
22 import java.util.List; |
23 import java.util.regex.Matcher; |
23 import java.util.regex.Matcher; |
24 import java.util.regex.Pattern; |
24 import java.util.regex.Pattern; |
25 |
25 |
26 import org.apache.tools.ant.BuildException; |
26 import org.apache.tools.ant.BuildException; |
27 import org.apache.tools.ant.ProjectComponent; |
|
28 import org.apache.tools.ant.taskdefs.condition.Condition; |
27 import org.apache.tools.ant.taskdefs.condition.Condition; |
29 |
28 import org.apache.tools.ant.types.DataType; |
30 |
29 |
31 import com.nokia.helium.metadata.ant.types.MetaDataFilter; |
30 import com.nokia.helium.metadata.ant.types.MetaDataFilter; |
32 import com.nokia.helium.metadata.ant.types.MetaDataFilterSet; |
31 import com.nokia.helium.metadata.ant.types.MetaDataFilterSet; |
|
32 import com.nokia.helium.metadata.ant.types.SeverityEnum; |
33 |
33 |
34 /** |
34 /** |
35 * This class implements a Ant Condition which report true if it finds the given |
35 * This class implements a Ant Condition which report true if it finds the given |
36 * input string is matched against the given filter of given priority |
36 * input string is matched against the given filter of given severity |
37 * |
37 * |
38 * Example: |
38 * Example: |
39 * <pre> |
39 * <pre> |
40 * <target name="test-metadata-regex"> |
40 * <target name="test-metadata-regex"> |
41 * <au:assertTrue> |
41 * <au:assertTrue> |
44 * </hlm:metadataRegexTest> |
44 * </hlm:metadataRegexTest> |
45 * </au:assertTrue> |
45 * </au:assertTrue> |
46 * </target> |
46 * </target> |
47 * </pre> |
47 * </pre> |
48 * |
48 * |
49 * The condition will eval as true if the string is matched with any of the pattern in the given priority |
49 * The condition will eval as true if the string is matched with any of the pattern in the given severity |
50 * |
50 * |
51 * @ant.type name="metadataRegexTest" category="Metadata" |
51 * @ant.type name="metadataRegexTest" category="Metadata" |
52 */ |
52 */ |
53 public class MetaDataRegexTestCondition extends ProjectComponent implements Condition { |
53 public class MetaDataRegexTestCondition extends DataType implements Condition { |
54 |
54 |
55 private String severity; |
55 private SeverityEnum severity; |
56 private String string; |
56 private String string; |
57 |
57 |
58 private List<MetaDataFilterSet> filterSets = new ArrayList<MetaDataFilterSet>(); |
58 private List<MetaDataFilterSet> filterSets = new ArrayList<MetaDataFilterSet>(); |
59 |
59 |
60 /** |
60 /** |
61 * Sets which severity to be searched. |
61 * Sets which severity to be searched. |
62 * |
62 * |
63 * @param severity |
63 * @param severity |
64 * @ant.required |
64 * @ant.required |
65 */ |
65 */ |
66 public void setSeverity(String severity) { |
66 public void setSeverity(SeverityEnum severity) { |
67 this.severity = severity; |
67 this.severity = severity; |
68 } |
68 } |
69 /** |
69 /** |
70 * Sets which string to be matched against regular expression. |
70 * Sets which string to be matched against regular expression. |
71 * |
71 * |
88 |
88 |
89 |
89 |
90 |
90 |
91 /** |
91 /** |
92 * This method iterates through the regular expression patterns and match the input string against them. |
92 * This method iterates through the regular expression patterns and match the input string against them. |
93 * @return true if the string is matched with any of the pattern in the given priority, false otherwise. |
93 * @return true if the string is matched with any of the pattern in the given severity, false otherwise. |
94 */ |
94 */ |
95 public boolean eval() { |
95 public boolean eval() { |
96 if (this.severity == null || (this.severity != null && this.severity.trim().isEmpty())) |
96 if (this.severity == null) { |
97 throw new BuildException("'severity' attribute is not defined"); |
97 throw new BuildException("'severity' attribute is not defined"); |
98 if (this.string == null || (this.string != null && this.string.isEmpty())) |
98 } |
|
99 if (this.string == null || (this.string != null && this.string.isEmpty())) { |
99 throw new BuildException("'string' attribute is not defined"); |
100 throw new BuildException("'string' attribute is not defined"); |
|
101 } |
100 for (MetaDataFilterSet set : filterSets) { |
102 for (MetaDataFilterSet set : filterSets) { |
101 for (MetaDataFilter filter : set.getAllFilters()) { |
103 for (MetaDataFilter filter : set.getAllFilters()) { |
102 Pattern pattern = filter.getPattern(); |
104 Pattern pattern = filter.getPattern(); |
103 Matcher matcher = pattern.matcher(this.string); |
105 Matcher matcher = pattern.matcher(this.string); |
104 if (matcher.matches()) { |
106 if (matcher.matches()) { |
105 return this.severity.equalsIgnoreCase(filter.getPriority()); |
107 return severity.getSeverity().equals(filter.getSeverity()); |
106 } |
108 } |
107 } |
109 } |
108 } |
110 } |
109 return false; |
111 return false; |
110 } |
112 } |