Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions app/Http/Submission/Handlers/AbstractXmlHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use App\Utils\Stack;
use CDash\Model\Build;
use CDash\Model\Project;
use CDash\ServiceContainer;
use DOMDocument;
use Illuminate\Support\Facades\Storage;
use League\Flysystem\UnableToReadFile;
Expand All @@ -37,16 +36,13 @@ abstract class AbstractXmlHandler extends AbstractSubmissionHandler
protected Site $Site;
protected string $SubProjectName = '';

private ServiceContainer $ModelFactory;

protected static ?string $schema_file = null;

public function __construct(Build|Project $init)
{
parent::__construct($init);

$this->stack = new Stack();
$this->ModelFactory = ServiceContainer::getInstance();
}

/**
Expand Down Expand Up @@ -184,11 +180,6 @@ public function getSubProjectName()
return $this->Build->SubProjectName;
}

protected function getModelFactory(): ServiceContainer
{
return $this->ModelFactory;
}

public function GetSite(): Site
{
return $this->Site;
Expand Down
17 changes: 7 additions & 10 deletions app/Http/Submission/Handlers/BuildHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ public function __construct(Project $project)
public function startElement($parser, $name, $attributes): void
{
parent::startElement($parser, $name, $attributes);
$factory = $this->getModelFactory();

if ($this->currentPathMatches('site')) {
$site_name = !empty($attributes['NAME']) ? $attributes['NAME'] : '(empty)';
Expand Down Expand Up @@ -182,7 +181,7 @@ public function startElement($parser, $name, $attributes): void
$this->SubProjects[$this->SubProjectName] = [];
}
if (!array_key_exists($this->SubProjectName, $this->Builds)) {
$build = $factory->create(Build::class);
$build = app(Build::class);
if (!empty($this->PullRequest)) {
$build->SetPullRequest($this->PullRequest);
}
Expand All @@ -201,7 +200,7 @@ public function startElement($parser, $name, $attributes): void
} elseif ($name === 'BUILD') {
if (empty($this->Builds)) {
// No subprojects
$build = $factory->create(Build::class);
$build = app(Build::class);
if (!empty($this->PullRequest)) {
$build->SetPullRequest($this->PullRequest);
}
Expand All @@ -218,15 +217,15 @@ public function startElement($parser, $name, $attributes): void
$this->Builds[''] = $build;
}
} elseif ($name === 'WARNING') {
$this->Error = $factory->create(BuildError::class);
$this->Error = app(BuildError::class);
$this->Error->Type = 1;
$this->ErrorSubProjectName = '';
} elseif ($name === 'ERROR') {
$this->Error = $factory->create(BuildError::class);
$this->Error = app(BuildError::class);
$this->Error->Type = 0;
$this->ErrorSubProjectName = '';
} elseif ($name === 'FAILURE') {
$this->Error = $factory->create(BuildFailure::class);
$this->Error = app(BuildFailure::class);
$this->Error->Type = 0;
if ($attributes['TYPE'] === 'Error') {
$this->Error->Type = 0;
Expand All @@ -235,7 +234,7 @@ public function startElement($parser, $name, $attributes): void
}
$this->ErrorSubProjectName = '';
} elseif ($name === 'LABEL' && !$this->currentPathMatches('site.build.commands.*.labels.label')) {
$this->Label = $factory->create(Label::class);
$this->Label = app(Label::class);
} elseif ($this->currentPathMatches('site.build.targets.target')) {
if (array_key_exists($attributes['NAME'], $this->Targets)) {
// In theory, this case should never happen...
Expand Down Expand Up @@ -324,8 +323,6 @@ public function startElement($parser, $name, $attributes): void

public function endElement($parser, $name): void
{
$factory = $this->getModelFactory();

if ($name === 'BUILD') {
$start_time = gmdate(FMT_DATETIME, $this->StartTimeStamp);
$end_time = gmdate(FMT_DATETIME, $this->EndTimeStamp);
Expand Down Expand Up @@ -468,7 +465,7 @@ public function endElement($parser, $name): void
}
}
if (!$hasLabel) {
$label = $factory->create(Label::class);
$label = app(Label::class);
$label->text = $this->SubProjectName;
if (!$this->Error instanceof BuildFailure) {
throw new RuntimeException('Field "Error" is not instance of BuildFailure.');
Expand Down
15 changes: 6 additions & 9 deletions app/Http/Submission/Handlers/ConfigureHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ class ConfigureHandler extends AbstractXmlHandler implements ActionableBuildInte
public function __construct(Project $project)
{
parent::__construct($project);

// Instantiate model factory.
$this->getModelFactory();
}

public function startElement($parser, $name, $attributes): void
Expand Down Expand Up @@ -125,13 +122,13 @@ public function startElement($parser, $name, $attributes): void
$this->Builds[$this->SubProjectName] = $build;
}
} elseif ($this->currentPathMatches('site.configure')) {
$this->Configure = $this->getModelFactory()->create(BuildConfigure::class);
$this->Configure = app(BuildConfigure::class);
if (empty($this->Builds)) {
// No subprojects
$this->Builds[] = $this->CreateBuild();
}
} elseif ($name === 'LABEL') {
$this->Label = $this->getModelFactory()->create(Label::class);
$this->Label = app(Label::class);
}
}

Expand Down Expand Up @@ -182,7 +179,7 @@ public function endElement($parser, $name): void
// Honor the Append flag if this build already existed.
if ($this->Append) {
// Get existing log & status from the database.
$existing_config = $this->getModelFactory()->create(BuildConfigure::class);
$existing_config = app(BuildConfigure::class);
$existing_config->BuildId = $build->Id;
if ($existing_config->Exists()) {
$existing_config_results = $existing_config->GetConfigureForBuild();
Expand Down Expand Up @@ -225,7 +222,7 @@ public function endElement($parser, $name): void
$duration = $this->EndTimeStamp - $this->StartTimeStamp;
$build->SetConfigureDuration($duration, !$all_at_once);
if ($all_at_once && !$parent_duration_set) {
$parent_build = $this->getModelFactory()->create(Build::class);
$parent_build = app(Build::class);
$parent_build->Id = $build->GetParentId();
$parent_build->SetConfigureDuration($duration, false);
$parent_duration_set = true;
Expand Down Expand Up @@ -288,7 +285,7 @@ public function text($parser, $data): void
} elseif ($parent === 'SUBPROJECT' && $element === 'LABEL') {
$this->SubProjects[$this->SubProjectName][] = $data;
$build = $this->Builds[$this->SubProjectName];
$label = $this->getModelFactory()->create(Label::class);
$label = app(Label::class);
$label->text = $data;
$build->AddLabel($label);
} elseif ($parent === 'LABELS' && $element === 'LABEL') {
Expand Down Expand Up @@ -370,7 +367,7 @@ public function GetBuildGroup(): BuildGroup

protected function CreateBuild()
{
$build = $this->getModelFactory()->create(Build::class);
$build = app(Build::class);
$build->SiteId = $this->Site->id;
$build->Name = $this->BuildName;
$build->SetStamp($this->BuildStamp);
Expand Down
15 changes: 6 additions & 9 deletions app/Http/Submission/Handlers/DynamicAnalysisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public function __construct(Project $project)
public function startElement($parser, $name, $attributes): void
{
parent::startElement($parser, $name, $attributes);
$factory = $this->getModelFactory();

if ($this->currentPathMatches('site')) {
$site_name = !empty($attributes['NAME']) ? $attributes['NAME'] : '(empty)';
Expand Down Expand Up @@ -121,7 +120,7 @@ public function startElement($parser, $name, $attributes): void
} elseif ($name === 'DYNAMICANALYSIS') {
$this->Checker = $attributes['CHECKER'];
if (empty($this->DynamicAnalysisSummaries)) {
$summary = $factory->create(DynamicAnalysisSummary::class);
$summary = app(DynamicAnalysisSummary::class);
$summary->Empty = true;
$summary->Checker = $this->Checker;
$this->DynamicAnalysisSummaries[$this->SubProjectName] = $summary;
Expand All @@ -131,15 +130,15 @@ public function startElement($parser, $name, $attributes): void
}
}
} elseif ($name === 'TEST' && isset($attributes['STATUS'])) {
$this->DynamicAnalysis = $factory->create(DynamicAnalysis::class);
$this->DynamicAnalysis = app(DynamicAnalysis::class);
$this->DynamicAnalysis->Checker = $this->Checker;
$this->DynamicAnalysis->Status = $attributes['STATUS'];
$this->TestSubProjectName = '';
} elseif ($name === 'DEFECT') {
$this->DynamicAnalysisDefect = new DynamicAnalysisDefect();
$this->DynamicAnalysisDefect->type = $attributes['TYPE'];
} elseif ($name === 'LABEL') {
$this->Label = $factory->create(Label::class);
$this->Label = app(Label::class);
} elseif ($name === 'LOG') {
$this->DynamicAnalysis->LogCompression = $attributes['COMPRESSION'] ?? '';
$this->DynamicAnalysis->LogEncoding = $attributes['ENCODING'] ?? '';
Expand All @@ -149,7 +148,6 @@ public function startElement($parser, $name, $attributes): void
/** Function endElement */
public function endElement($parser, $name): void
{
$factory = $this->getModelFactory();
if ($name === 'STARTTESTTIME' && $this->getParent() === 'DYNAMICANALYSIS') {
if (empty($this->SubProjects)) {
// Not a SubProject build.
Expand Down Expand Up @@ -190,7 +188,7 @@ public function endElement($parser, $name): void
// If everything is perfect CTest doesn't send any <test>
// But we still want a line showing the current dynamic analysis
if ($this->DynamicAnalysisSummaries[$subprojectName]->Empty) {
$this->DynamicAnalysis = $factory->create(DynamicAnalysis::class);
$this->DynamicAnalysis = app(DynamicAnalysis::class);
$this->DynamicAnalysis->BuildId = (int) $build->Id;
$this->DynamicAnalysis->Status = 'passed';
$this->DynamicAnalysis->Checker = $this->Checker;
Expand Down Expand Up @@ -278,8 +276,7 @@ public function getSubProjectName()

private function createBuild($subprojectName): void
{
$factory = $this->getModelFactory();
$build = $factory->create(Build::class);
$build = app(Build::class);

$build->SiteId = $this->Site->id;
$build->Name = $this->BuildName;
Expand Down Expand Up @@ -320,7 +317,7 @@ private function createBuild($subprojectName): void
$this->Builds[$subprojectName] = $build;

// Initialize a dynamic analysis summary for this build.
$summary = $factory->create(DynamicAnalysisSummary::class);
$summary = app(DynamicAnalysisSummary::class);
$summary->Empty = true;
$summary->BuildId = (int) $build->Id;
$summary->Checker = $this->Checker;
Expand Down
14 changes: 5 additions & 9 deletions app/Http/Submission/Handlers/TestingHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public function __construct(Project $project)
public function startElement($parser, $name, $attributes): void
{
parent::startElement($parser, $name, $attributes);
$factory = $this->getModelFactory();

if ($this->currentPathMatches('site')) {
$site_name = !empty($attributes['NAME']) ? $attributes['NAME'] : '(empty)';
Expand Down Expand Up @@ -135,7 +134,7 @@ public function startElement($parser, $name, $attributes): void
$this->TestSubProjectName = '';
$this->Labels = [];
} elseif ($name === 'NAMEDMEASUREMENT' && array_key_exists('TYPE', $attributes)) {
$this->TestMeasurement = $factory->create(TestMeasurement::class);
$this->TestMeasurement = app(TestMeasurement::class);

if ($attributes['TYPE'] === 'file') {
$this->TestMeasurement->name = $attributes['FILENAME'];
Expand All @@ -148,15 +147,13 @@ public function startElement($parser, $name, $attributes): void
$this->TestCreator->alreadyCompressed = true;
}
} elseif ($name === 'LABEL' && $this->getParent() === 'LABELS') {
$this->Label = $factory->create(Label::class);
$this->Label = app(Label::class);
}
}

/** End Element */
public function endElement($parser, $name): void
{
$factory = $this->getModelFactory();

if ($name === 'TEST' && $this->getParent() === 'TESTING') {
// By now, will either have one subproject for the entire file
// Or a subproject specifically for this test
Expand Down Expand Up @@ -207,7 +204,7 @@ public function endElement($parser, $name): void

// If it's an image we add it as an image
if (str_contains($this->TestMeasurement->type, 'image')) {
$image = $factory->create(Image::class);
$image = app(Image::class);
$image->Extension = $this->TestMeasurement->type;
$image->Data = $this->TestMeasurement->value;
$image->Name = $this->TestMeasurement->name;
Expand Down Expand Up @@ -246,7 +243,7 @@ public function endElement($parser, $name): void
$duration = $this->EndTimeStamp - $this->StartTimeStamp;
$build->UpdateTestDuration($duration, !$all_at_once);
if ($all_at_once && !$parent_duration_set) {
$parent_build = $factory->create(Build::class);
$parent_build = app(Build::class);
$parent_build->Id = $build->GetParentId();
$parent_build->UpdateTestDuration($duration, false);
$parent_duration_set = true;
Expand Down Expand Up @@ -338,9 +335,8 @@ private function createBuild(): void
if (!array_key_exists($this->SubProjectName, $this->NumberTestsPassed)) {
$this->NumberTestsPassed[$this->SubProjectName] = 0;
}
$factory = $this->getModelFactory();
/** @var Build $build */
$build = $factory->create(Build::class);
$build = app(Build::class);
$build->SetSite($this->Site);

if (!empty($this->PullRequest)) {
Expand Down
3 changes: 1 addition & 2 deletions app/Http/Submission/Handlers/UpdateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ public function __construct(Project $project)
public function startElement($parser, $name, $attributes): void
{
parent::startElement($parser, $name, $attributes);
$factory = $this->getModelFactory();
if ($name === 'UPDATE') {
$this->Build = new Build();
$this->Update = $factory->create(BuildUpdate::class);
$this->Update = app(BuildUpdate::class);

if (isset($attributes['GENERATOR'])) {
$this->Build->Generator = $attributes['GENERATOR'];
Expand Down
61 changes: 0 additions & 61 deletions app/Utils/RepositoryUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use CDash\Database;
use CDash\Model\Build;
use CDash\Model\Project;
use CDash\ServiceContainer;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use Illuminate\Support\Uri;
Expand All @@ -35,66 +34,6 @@ public static function isGitHubUrl(string $url): bool
return false;
}

/** Return the GitHub diff URL */
public static function get_github_diff_url($projecturl, $directory, $file, $revision)
{
if (empty($directory) && empty($file) && empty($revision)) {
return;
}

// set a reasonable default revision if none was specified
if (empty($revision)) {
$revision = 'master';
}

$directory = trim($directory, '/');

$diff_url = "$projecturl/blob/$revision/";
$diff_url .= "$directory/$file";
return make_cdash_url($diff_url);
}

/** Return the GitLab diff URL */
public static function get_gitlab_diff_url($projecturl, $directory, $file, $revision): string
{
// Since GitLab supports arbitrarily nested groups, there is a `/-/`
// component to start per-project resources.
if ($revision !== '') {
$diff_url = $projecturl . '/-/commit/' . $revision;
} elseif ($file !== '') {
$diff_url = $projecturl . '/-/blob/master/';
if ($directory !== '') {
$diff_url .= $directory . '/';
}
$diff_url .= $file;
} else {
return '';
}
return make_cdash_url($diff_url);
}

/** Get the diff url based on the type of viewer */
public static function get_diff_url($projectid, $projecturl, $directory, $file, $revision = '')
{
if (!is_numeric($projectid)) {
return;
}

$service = ServiceContainer::getInstance();
$project = $service->get(Project::class);
$project->Id = $projectid;
$project->Fill();

$cvsviewertype = strtolower($project->CvsViewerType ?? '');
$difffunction = 'get_' . $cvsviewertype . '_diff_url';

if (method_exists(self::class, $difffunction)) {
return self::$difffunction($projecturl, $directory, $file, $revision);
}
// default is github
return self::get_github_diff_url($projecturl, $directory, $file, $revision);
}

/** Return the GitHub revision URL */
public static function get_github_revision_url($projecturl, $revision, $priorrevision): string
{
Expand Down
Loading
Loading