package.xml checker
[m6w6/pecl-ci] / check-packagexml.php
1 #!/usr/bin/env php
2 <?php
3
4 error_reporting(E_ALL & ~(E_DEPRECATED|E_STRICT));
5
6 if ($argc < 2) {
7 fprintf(STDERR, "Usage: %s <path/to/package.xml>\n", $argv[0]);
8 exit(1);
9 }
10
11 require_once "PEAR/Config.php";
12 require_once "PEAR/PackageFile.php";
13
14 define("PACKAGE_XML", $argv[1]);
15 define("PACKAGE_DIR", dirname(PACKAGE_XML));
16
17 $factory = new PEAR_PackageFile(PEAR_Config::singleton());
18 $pf = $factory->fromPackageFile($argv[1], PEAR_VALIDATE_NORMAL);
19
20 if (PEAR::isError($pf)) {
21 fprintf(STDERR, "ERROR: %s\n", $pf->getMessage());
22 exit(1);
23 }
24
25 foreach ($pf->getValidationWarnings() as $warning) {
26 fprintf(STDERR, "%s: %s\n", strtoupper($warning["level"]), $warning["message"]);
27 }
28
29 $exit = 0;
30 foreach ($pf->getFilelist() as $file => $attr) {
31 if (!file_exists(PACKAGE_DIR."/".$file)) {
32 $exit++;
33 fprintf(STDERR, "File '%s' with role '%s' not found in '%s'\n",
34 $file, $attr["role"], PACKAGE_DIR);
35 }
36 }
37
38 if ($exit) {
39 fprintf(STDERR, "%3d failure(s)\n", $exit);
40 exit(1);
41 }