blob: 826687900eff8f0290e78952a2c83a13d998b85a [file] [log] [blame]
jlanuti6f30d402007-04-18 19:54:42 +00001<?php
2 function count_pattern($directory, $filenameFilter, $pattern)
3 {
4 $count = 0;
5 $dir = dir($directory);
6 while ($anEntry = $dir->read())
7 {
8 if ($anEntry != "." && $anEntry != "..")
9 {
10 $anEntry = $directory."/".$anEntry;
11 if (is_dir($anEntry))
12 {
13 $count += count_pattern($anEntry, $filenameFilter, $pattern);
14 }
15 else
16 {
17 if (stristr($anEntry, $filenameFilter))
18 {
19 $handle = @fopen($anEntry, "r");
20 if (FALSE !== $handle) {
21 $size = filesize($anEntry);
22 $content = fread($handle, $size);
23 fclose($handle);
24 $count += substr_count($content, $pattern);
25 }
26 }
27 }
28 }
29 }
30 return $count;
31 }
32
33 function parse_testResult($filename)
34 {
35 $junitFailures = 0;
36 $compileErrors = 0;
37 $compileWarnings = 0;
38 if (is_file($filename)) {
39 $handle = @fopen($filename, "r");
40 if ($handle)
41 {
42 $size = filesize($filename);
43 $content = fread($handle, $size);
44 fclose($handle);
45 $junitStart = strpos($content, "Errors &amp; Failures");
46 $junitEnd = strpos($content, "</table>", $junitStart);
47 $junitInfo = substr($content, $junitStart, $junitEnd - $junitStart);
48 $start = strpos($junitInfo, "<td><b><font color=\"#ff0000\">");
49 while ($start !== false)
50 {
51 $start += 29;
52 $stop = strpos($junitInfo, "</font></b></td>", $start);
53 if ($stop !== false)
54 {
55 $result = substr($junitInfo, $start, $stop - $start);
56 if (is_numeric($result))
57 {
58 $junitFailures += $result;
59 }
60 else if (strcmp($result, "DNF") == 0)
61 {
62 $junitFailures++;
63 }
64 }
65 $start = strpos($junitInfo, "<td><b><font color=\"#ff0000\">", $stop);
66 }
67 $compileStart = strpos($content, "Compile Logs (Jar Files)");
68 $compileEnd = strpos($content, "</table>", $compileStart);
69 $compileInfo = substr($content, $compileStart, $compileEnd - $compileStart);
70 $rowStart = strpos($compileInfo, "<tr>");
71 while ($rowStart !== false)
72 {
73 $start += 4;
74 $rowStop = strpos($compileInfo, "</tr>", $rowStart);
75 if ($rowStop !== false)
76 {
77 $row = substr($compileInfo, $rowStart, $rowStop - $rowStart);
78 $cellStart = strpos($row, "<td");
79 $gotError = false;
80 $gotWarning = false;
81 while ($cellStart !== false && (!$gotError || !$gotWarning))
82 {
83 // this parsing logic got a bit more complicated in M2_33 basebuild, as the
84 // tag <td align="center"> was used, instead of <td>
85 // $cellStart += 4;
86 $cellStart = strpos($row, ">", $cellStart);
87 $cellStart = $cellStart + 1;
88 $cellStop = strpos($row, "</td>", $cellStart);
89 if ($cellStop !== false)
90 {
91 $cell = substr($row, $cellStart, $cellStop - $cellStart);
92 if (is_numeric($cell))
93 {
94 if (!$gotError)
95 {
96 $compileErrors += $cell;
97 $gotError = true;
98 }
99 else if (!$gotWarning)
100 {
101 $compileWarnings += $cell;
102 $gotWarning = true;
103 }
104 }
105 }
106 // this parsing logic got a bit more complicated in M2_33 basebuild, as the
107 // tag <td align="center"> was used, instead of <td>
108 $cellStart = strpos($row, "<td", $cellStop);
109 }
110 }
111 $rowStart = strpos($compileInfo, "<tr>", $rowStop);
112 }
113 }
114 }
115 $results = array($compileErrors, $compileWarnings, $junitFailures);
116 return $results;
117 }
118
119 function parse($filename, $key)
120 {
121 if (!is_readable($filename))
122 {
123 return 0;
124 }
125 $value;
126 $handle = @fopen($filename, "r");
127 if (!$handle)
128 {
129 return 0;
130 }
131 $size = filesize($filename);
132 $content = fread($handle, $size);
133 fclose($handle);
134 $start = strpos($content, $key);
135 while ($start !== false)
136 {
137 $start += strlen($key);
138 $stop = strpos($content, "\"", $start);
139 if ($stop !== false)
140 {
141 $value += substr($content, $start, $stop - $start);
142 }
143 $start = strpos($content, $key, $stop);
144 }
145 return $value;
146 }
147?>