3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
5 * This file is a part of Codendi.
7 * Codendi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * Codendi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Codendi. If not, see <http://www.gnu.org/licenses/>.
20 require_once 'hudson.class.php';
21 require_once 'HudsonJobURLMalformedException.class.php';
22 require_once 'HudsonJobURLFileException.class.php';
23 require_once 'HudsonJobURLFileNotFoundException.class.php';
27 protected $hudson_build_url;
33 * Construct an Hudson build from a build URL
35 function HudsonBuild($hudson_build_url) {
36 $parsed_url = parse_url($hudson_build_url);
38 if ( ! $parsed_url || ! array_key_exists('scheme', $parsed_url) ) {
39 throw new HudsonJobURLMalformedException(vsprintf(_("Wrong Job URL: %s"), array($hudson_build_url)));
42 $this->hudson_build_url = $hudson_build_url . "/api/xml";
44 $this->_setStreamContext();
46 $this->buildBuildObject();
50 public function buildBuildObject() {
51 $this->dom_build = $this->_getXMLObject($this->hudson_build_url);
54 protected function _getXMLObject($hudson_build_url) {
55 $xmlstr = @file_get_contents($hudson_build_url, false, $this->context);
56 if ($xmlstr !== false) {
57 $xmlobj = simplexml_load_string($xmlstr);
58 if ($xmlobj !== false) {
61 throw new HudsonJobURLFileException(vsprintf(_("Unable to read file at URL: %s"), array($hudson_build_url)));
64 throw new HudsonJobURLFileNotFoundException(vsprintf(_("File not found at URL: %s"), array($hudson_build_url)));
68 private function _setStreamContext() {
69 if (array_key_exists('sys_proxy', $GLOBALS) && $GLOBALS['sys_proxy']) {
73 'proxy' => $GLOBALS['sys_proxy'],
74 'request_fulluri' => True,
78 $this->context = stream_context_create($context_opt);
80 $this->context = null;
85 return $this->dom_build;
88 function getBuildStyle() {
89 return $this->dom_build->getName();
91 function isBuilding() {
92 return ($this->dom_build->building == "true");
95 return $this->dom_build->url;
97 function getResult() {
98 return $this->dom_build->result;
100 function getNumber() {
101 return $this->dom_build->number;
103 function getDuration() {
104 return $this->dom_build->duration;
106 function getTimestamp() {
107 return $this->dom_build->timestamp;
109 function getBuildTime() {
110 return format_date(_("Y-m-d H:i"), substr($this->getTimestamp(), 0, -3));