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