blob: 58063f7e7daa2932a6749b8d806a24c08bed3cdc [file] [log] [blame]
<?php
require_once 'build.class.php';
require_once 'component.class.php';
require_once 'buildTypes.php';
$builds = array();
$currentBuild = null;
$currentComponent = null;
$currentBundle = null;
$latestBuild = null;
if (! ($xmlparser = xml_parser_create()) ) {
die ("Cannot create parser");
}
function handleBuild($attribs) {
// echo "<h2> Build: " . $attribs['NAME'] . "</h2>";
global $builds, $currentBuild;
$currentBuild = new Build( $attribs['NAME'], $attribs['TSTAMP'], $attribs['TYPE'], $attribs['STREAM']);
$builds[] = $currentBuild;
}
function handleComponent($attribs) {
global $currentComponent, $currentBuild;
$currentComponent = new Component( $attribs['NAME'], $attribs['SUMMARY'], $attribs['JUNITRESULTSURL']);
$currentBuild->addComponent($currentComponent);
}
function handleBundle($attribs) {
global $currentComponent, $currentBundle;
$currentBundle = new Bundle( $attribs['NAME'], $attribs['LINK'], $attribs['SIZE'], $attribs['SUMMARY']);
$currentComponent->addBundle($currentBundle);
}
function handleDependency($attribs) {
global $currentBuild;
$dependency = new Dependency( $attribs['NAME'], $attribs['LINK']);
$currentBuild->addDependency($dependency);
}
function handleDetail($attribs) {
global $currentBuild;
$detail = new Detail( $attribs['NAME'], $attribs['LINK'], $attribs['SUMMARY']);
$currentBuild->addDetail($detail);
}
function start_tag($parser, $name, $attribs) {
//echo "Current tag : ".$name."<br />";
if ( strcmp($name, "BUILD") == 0 ) handleBuild($attribs);
if ( strcmp($name, "COMPONENT") == 0) handleComponent($attribs);
if ( strcmp($name, "BUNDLE") == 0 ) handleBundle($attribs);
if ( strcmp($name, "DEPENDENCY") == 0 ) handleDependency($attribs);
if ( strcmp($name, "DETAIL") == 0 ) handleDetail($attribs);
}
function end_tag($parser, $name) {
// echo "Reached ending tag ".$name."<br /><br />";
}
xml_set_element_handler($xmlparser, "start_tag", "end_tag");
function tag_contents($parser, $data) {
//echo "Contents : ".$data."<br />";
}
/**
* Finds the latest stable build. Looking for latest timestamp for in the highest seniority of builds.
*
*/
function findLatestBuild() {
global $latestBuild, $builds, $buildTypes ;
$latestFound = false;
foreach( $buildTypes as $buildType ) {
if ( !$latestFound ) {
foreach( $builds as $build ) {
if ( strcmp($build->getType(), $buildType) == 0 ) {
if ( $latestBuild == null ) { $latestBuild = $build;}
else {
if ( $build->getTStamp() > $latestBuild->getTStamp() ) {
$latestBuild = $build;
}
}
$latestFound = true;
}
}
}
}
}
xml_set_character_data_handler($xmlparser, "tag_contents");
$filename = $App->getDownloadBasePath() ."/technology/tigerstripe/downloads.xml";
if (!($fp = fopen($filename, "r"))) { die("cannot open ".$filename); }
while ($data = fread($fp, 4096)){
$data=eregi_replace(">"."[[:space:]]+"."<","><",$data);
if (!xml_parse($xmlparser, $data, feof($fp))) {
$reason = xml_error_string(xml_get_error_code($xmlparser));
$reason .= xml_get_current_line_number($xmlparser);
die($reason);
}
}
xml_parser_free($xmlparser);
findLatestBuild();
?>