3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
5 * This file is a part of Fusionforge.
7 * Fusionforge 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 * Fusionforge 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 Fusionforge. If not, see <http://www.gnu.org/licenses/>.
21 require_once 'hudson.class.php';
22 require_once 'HudsonJobURLMalformedException.class.php';
23 require_once 'HudsonJobURLFileException.class.php';
24 require_once 'HudsonJobURLFileNotFoundException.class.php';
28 protected $hudson_build_url;
34 * Construct an Hudson build from a build URL
36 function HudsonBuild($hudson_build_url) {
37 $parsed_url = parse_url($hudson_build_url);
39 if ( ! $parsed_url || ! array_key_exists('scheme', $parsed_url) ) {
40 throw new HudsonJobURLMalformedException(vsprintf(_("Wrong Job URL: %s"), array($hudson_build_url)));
43 $this->hudson_build_url = $hudson_build_url . "/api/xml";
44 $this->_setStreamContext();
45 $this->buildBuildObject();
48 public function buildBuildObject() {
49 $this->dom_build = $this->_getXMLObject($this->hudson_build_url);
52 protected function _getXMLObject($hudson_build_url) {
53 $xmlstr = @file_get_contents($hudson_build_url, false, $this->context);
54 if ($xmlstr !== false) {
55 $xmlobj = simplexml_load_string($xmlstr);
56 if ($xmlobj !== false) {
59 throw new HudsonJobURLFileException(vsprintf(_("Unable to read file at URL: %s"), array($hudson_build_url)));
62 throw new HudsonJobURLFileNotFoundException(vsprintf(_("File not found at URL: %s"), array($hudson_build_url)));
66 private function _setStreamContext() {
67 if (array_key_exists('sys_proxy', $GLOBALS) && $GLOBALS['sys_proxy']) {
71 'proxy' => $GLOBALS['sys_proxy'],
72 'request_fulluri' => True,
76 $this->context = stream_context_create($context_opt);
78 $this->context = null;
83 return $this->dom_build;
86 function getBuildStyle() {
87 return $this->dom_build->getName();
90 function isBuilding() {
91 return ($this->dom_build->building == "true");
95 return $this->dom_build->url;
98 function getResult() {
99 return $this->dom_build->result;
102 function getNumber() {
103 return $this->dom_build->number;
106 function getDuration() {
107 return $this->dom_build->duration;
110 function getTimestamp() {
111 return $this->dom_build->timestamp;
114 function getBuildTime() {
115 return format_date(_("Y-m-d H:i"), substr($this->getTimestamp(), 0, -3));