Skip to content

Commit

Permalink
Homepage|BuildRepository: Refactor AbstractPackage hierarchy moving i…
Browse files Browse the repository at this point in the history
…BuilderProduct upward

The iBuilderProduct inteface defines the functionality of an object
which represents a package (or some other resource) produced by the
autobuilder.

Previously this interface was implemented by AbstractUnstablePackage
rather than AbstractPackage (meaning on the former objects could be
instantiated using the build log parser).
  • Loading branch information
danij-deng committed Mar 16, 2012
1 parent 74dd179 commit 66f2c4b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 68 deletions.
6 changes: 1 addition & 5 deletions web/plugins/buildrepository/buildlogparser.class.php
Expand Up @@ -104,11 +104,7 @@ private static function parseBuildLogDOM(&$log, &$builds)
try
{
$pack = PackageFactory::newFromSimpleXMLElement($child, $build->releaseTypeId());

if($build->releaseTypeId() !== RT_STABLE)
{
$pack->setBuildUniqueId($build->uniqueId());
}
$pack->setBuildUniqueId($build->uniqueId());

$build->addPackage($pack);
}
Expand Down
62 changes: 60 additions & 2 deletions web/plugins/buildrepository/packages/abstractpackage.class.php
Expand Up @@ -27,29 +27,57 @@

require_once('basepackage.class.php');
require_once(dirname(__FILE__) . '/../downloadable.interface.php');
require_once(dirname(__FILE__) . '/../builderproduct.interface.php');

abstract class AbstractPackage extends BasePackage implements iDownloadable
abstract class AbstractPackage extends BasePackage implements iDownloadable, iBuilderProduct
{
static protected $emptyString = '';

protected $directDownloadUri = NULL;

public function __construct($platformId=PID_ANY, $title=NULL, $version=NULL, $directDownloadUri=NULL)
protected $buildId = 0; /// Unique.

protected $compileLogUri;
protected $compileWarnCount;
protected $compileErrorCount;

public function __construct($platformId=PID_ANY, $title=NULL, $version=NULL, $directDownloadUri=NULL,
$compileLogUri=NULL, $compileWarnCount=0, $compileErrorCount=0)
{
parent::__construct($platformId, $title, $version);

if(!is_null($directDownloadUri) && strlen($directDownloadUri) > 0)
$this->directDownloadUri = "$directDownloadUri";

if(!is_null($compileLogUri))
$this->compileLogUri = "$compileLogUri";

$this->compileWarnCount = intval($compileWarnCount);
$this->compileErrorCount = intval($compileErrorCount);
}

// Extends implementation in AbstractPackage.
public function populateGraphTemplate(&$tpl)
{
global $FrontController;

if(!is_array($tpl))
throw new Exception('Invalid template argument, array expected');

parent::populateGraphTemplate($tpl);

$tpl['direct_download_uri'] = $this->directDownloadUri();

$build = $FrontController->findPlugin('BuildRepository')->buildByUniqueId($this->buildId);
if($build instanceof BuildEvent)
{
$tpl['build_startdate'] = date(DATE_ATOM, $build->startDate());
$tpl['build_uniqueid'] = $this->buildId;
}

$tpl['compile_loguri'] = $this->compileLogUri;
$tpl['compile_errorcount'] = $this->compileErrorCount;
$tpl['compile_warncount'] = $this->compileWarnCount;
}

// Implements iDownloadable
Expand Down Expand Up @@ -84,4 +112,34 @@ public function genDownloadBadge()
}
return $html;
}

// Implements iBuilderProduct.
public function setBuildUniqueId($id)
{
$this->buildId = intval($id);
}

// Implements iBuilderProduct.
public function buildUniqueId()
{
return $this->buildId;
}

// Implements iBuilderProduct.
public function &compileLogUri()
{
return $this->compileLogUri;
}

// Implements iBuilderProduct.
public function compileWarnCount()
{
return $this->compileWarnCount;
}

// Implements iBuilderProduct.
public function compileErrorCount()
{
return $this->compileErrorCount;
}
}
Expand Up @@ -26,28 +26,9 @@
includeGuard('AbstractUnstablePackage');

require_once('abstractpackage.class.php');
require_once(dirname(__FILE__) . '/../builderproduct.interface.php');

abstract class AbstractUnstablePackage extends AbstractPackage implements iBuilderProduct
abstract class AbstractUnstablePackage extends AbstractPackage
{
protected $buildId = 0; /// Unique.

protected $compileLogUri;
protected $compileWarnCount;
protected $compileErrorCount;

public function __construct($platformId=PID_ANY, $title=NULL, $version=NULL,
$downloadUri=NULL, $compileLogUri=NULL, $compileWarnCount=0, $compileErrorCount=0)
{
parent::__construct($platformId, $title, $version, $downloadUri);

if(!is_null($compileLogUri))
$this->compileLogUri = "$compileLogUri";

$this->compileWarnCount = intval($compileWarnCount);
$this->compileErrorCount = intval($compileErrorCount);
}

// Override implementation in AbstractPackage.
public function composeFullTitle($includeVersion=true, $includePlatformName=true, $includeBuildId=true)
{
Expand Down Expand Up @@ -77,46 +58,5 @@ public function populateGraphTemplate(&$tpl)

parent::populateGraphTemplate($tpl);
$tpl['is_unstable'] = true;

$build = $FrontController->findPlugin('BuildRepository')->buildByUniqueId($this->buildId);
if($build instanceof BuildEvent)
{
$tpl['build_startdate'] = date(DATE_ATOM, $build->startDate());
$tpl['build_uniqueid'] = $this->buildId;
}

$tpl['compile_loguri'] = $this->compileLogUri;
$tpl['compile_errorcount'] = $this->compileErrorCount;
$tpl['compile_warncount'] = $this->compileWarnCount;
}

// Implements iBuilderProduct.
public function setBuildUniqueId($id)
{
$this->buildId = intval($id);
}

// Implements iBuilderProduct.
public function buildUniqueId()
{
return $this->buildId;
}

// Implements iBuilderProduct.
public function &compileLogUri()
{
return $this->compileLogUri;
}

// Implements iBuilderProduct.
public function compileWarnCount()
{
return $this->compileWarnCount;
}

// Implements iBuilderProduct.
public function compileErrorCount()
{
return $this->compileErrorCount;
}
}

0 comments on commit 66f2c4b

Please sign in to comment.