-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the submission XML validation script (#2335)
This PR expands on the initial implementation of the submission XML validator introduced in #2277. The validator now supports parsing bigger XML files, can process multiple files per invocation, and provides better error handling. The logic for determining the submission XML file type has been pulled out to be used by both the submission parsers and the XML validation code. To use the validator from a CDash container, run: ``` php <cdash_base>/artisan submission:validate <xml_file>... ``` where `<cdash_base>` is the path to the application root directory (e.g., `/cdash`), and `<xml_file>...` are one or more file paths to to be validated.
- Loading branch information
Showing
4 changed files
with
200 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Utils; | ||
|
||
class SubmissionUtils | ||
{ | ||
|
||
/** | ||
* Figure out what type of XML file this is | ||
* @return array<string,mixed> | ||
*/ | ||
public static function get_xml_type(mixed $filehandle): array | ||
{ | ||
$file = ''; | ||
$handler = null; | ||
// read file contents until we recognize its elements | ||
while ($file === '' && !feof($filehandle)) { | ||
$content = fread($filehandle, 8192); | ||
if ($content === false) { | ||
// if read failed, fallback onto default null values | ||
break; | ||
} | ||
if (str_contains($content, '<Update')) { | ||
// Should be first otherwise confused with Build | ||
$handler = \UpdateHandler::class; | ||
$file = 'Update'; | ||
} elseif (str_contains($content, '<Build')) { | ||
$handler = \BuildHandler::class; | ||
$file = 'Build'; | ||
} elseif (str_contains($content, '<Configure')) { | ||
$handler = \ConfigureHandler::class; | ||
$file = 'Configure'; | ||
} elseif (str_contains($content, '<Testing')) { | ||
$handler = \TestingHandler::class; | ||
$file = 'Test'; | ||
} elseif (str_contains($content, '<CoverageLog')) { | ||
// Should be before coverage | ||
$handler = \CoverageLogHandler::class; | ||
$file = 'CoverageLog'; | ||
} elseif (str_contains($content, '<Coverage')) { | ||
$handler = \CoverageHandler::class; | ||
$file = 'Coverage'; | ||
} elseif (str_contains($content, '<report')) { | ||
$handler = \CoverageJUnitHandler::class; | ||
$file = 'CoverageJUnit'; | ||
} elseif (str_contains($content, '<Notes')) { | ||
$handler = \NoteHandler::class; | ||
$file = 'Notes'; | ||
} elseif (str_contains($content, '<DynamicAnalysis')) { | ||
$handler = \DynamicAnalysisHandler::class; | ||
$file = 'DynamicAnalysis'; | ||
} elseif (str_contains($content, '<Project')) { | ||
$handler = \ProjectHandler::class; | ||
$file = 'Project'; | ||
} elseif (str_contains($content, '<Upload')) { | ||
$handler = \UploadHandler::class; | ||
$file = 'Upload'; | ||
} elseif (str_contains($content, '<testsuite')) { | ||
$handler = \TestingJUnitHandler::class; | ||
$file = 'TestJUnit'; | ||
} elseif (str_contains($content, '<Done')) { | ||
$handler = \DoneHandler::class; | ||
$file = 'Done'; | ||
} | ||
} | ||
|
||
// restore the file descriptor to beginning of file | ||
rewind($filehandle); | ||
|
||
return [ | ||
'file_handle' => $filehandle, | ||
'xml_handler' => $handler, | ||
'xml_type' => $file, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters