1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
<?php
/**
* Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
*
* This file is a part of Fusionforge.
*
* Fusionforge is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Fusionforge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Fusionforge. If not, see <http://www.gnu.org/licenses/>.
*/
require_once 'hudson.class.php';
require_once 'HudsonJobURLMalformedException.class.php';
require_once 'HudsonJobURLFileException.class.php';
require_once 'HudsonJobURLFileNotFoundException.class.php';
class HudsonBuild {
protected $hudson_build_url;
protected $dom_build;
private $context;
/**
* Construct an Hudson build from a build URL
*/
function HudsonBuild($hudson_build_url) {
$parsed_url = parse_url($hudson_build_url);
if ( ! $parsed_url || ! array_key_exists('scheme', $parsed_url) ) {
throw new HudsonJobURLMalformedException(vsprintf(_("Wrong Job URL: %s"), array($hudson_build_url)));
}
$this->hudson_build_url = $hudson_build_url . "/api/xml";
$this->_setStreamContext();
$this->buildBuildObject();
}
public function buildBuildObject() {
$this->dom_build = $this->_getXMLObject($this->hudson_build_url);
}
protected function _getXMLObject($hudson_build_url) {
$xmlstr = @file_get_contents($hudson_build_url, false, $this->context);
if ($xmlstr !== false) {
$xmlobj = simplexml_load_string($xmlstr);
if ($xmlobj !== false) {
return $xmlobj;
} else {
throw new HudsonJobURLFileException(vsprintf(_("Unable to read file at URL: %s"), array($hudson_build_url)));
}
} else {
throw new HudsonJobURLFileNotFoundException(vsprintf(_("File not found at URL: %s"), array($hudson_build_url)));
}
}
private function _setStreamContext() {
if (array_key_exists('sys_proxy', $GLOBALS) && $GLOBALS['sys_proxy']) {
$context_opt = array(
'http' => array(
'method' => 'GET',
'proxy' => $GLOBALS['sys_proxy'],
'request_fulluri' => True,
'timeout' => 5.0,
),
);
$this->context = stream_context_create($context_opt);
} else {
$this->context = null;
}
}
function getDom() {
return $this->dom_build;
}
function getBuildStyle() {
return $this->dom_build->getName();
}
function isBuilding() {
return ($this->dom_build->building == "true");
}
function getUrl() {
return $this->dom_build->url;
}
function getResult() {
return $this->dom_build->result;
}
function getNumber() {
return $this->dom_build->number;
}
function getDuration() {
return $this->dom_build->duration;
}
function getTimestamp() {
return $this->dom_build->timestamp;
}
function getBuildTime() {
return format_date(_("Y-m-d H:i"), substr($this->getTimestamp(), 0, -3));
}
}
|