root/trunk/midcom/build/generateSchemaFile.php

Revision 14773, 2.6 kB (checked in by rambo, 8 months ago)

scripted whitespace normalization, see r14772

Line 
1 <?php
2
3
4 /**
5  * Created on 10/09/2006
6  * @author tarjei huse
7  * @package midcom.admin.aegir
8  * @copyright The Midgard Project, http://www.midgard-project.org
9  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
10  *
11  */
12 require_once "phing/Task.php";
13 /**
14  * This class
15  */
16 class generateSchemaFile extends Task
17 {
18
19     
20
21     function __construct()
22     {
23
24     }
25
26     protected $returnProperty; // name of property to set to return value
27
28     /**
29      * The root path to where the module is stored.
30      */
31     private $root = null;
32     /**
33      * The target directory where the packagefile should be saved.
34      */
35     protected $target_dir = null;
36
37     public function setRoot($str)
38     {
39         $this->root = $str;
40     }
41
42     /** Sets property name to set with return value of function or expression.*/
43     public function setReturnProperty($r)
44     {
45         $this->returnProperty = $r;
46     }
47
48
49     /**
50      * The init method: Do init steps.
51      */
52     public function init()
53     {
54         
55     }
56
57     /**
58      * The main entry point method.
59      */
60     public function main()
61     {
62         $command = sprintf("find %s -name '*.xml'", $this->root);
63         exec($command, $result, $status);
64             
65         if ($status != 0 ) {
66             throw new Exception("Find returned nonzero error!\n");
67         }
68         $schemafiles = array();
69         foreach ($result as $key =>  $file ) {
70             $filename = basename($file);
71             if (is_dir($file)) continue;
72             
73             switch ($filename) {
74                 case 'mgdschema.xml':
75                     $schemafiles[] = $file;
76                     break;
77                 case 'package.xml':
78                 case 'build.xml':
79                     break;
80                 default:
81                     break;
82             }
83         }
84         //var_dump($schemafiles);
85         
86         $xml = $this->generateXML($schemafiles);
87         echo $xml;
88         $location = $this->root . "/includes.xml";
89         file_put_contents($location , $xml);
90         $this->project->setProperty($this->returnProperty, $location);
91     }
92     
93     protected function generate_include ($file) {
94         return sprintf('    <include name="%s" />"', $file);
95         //var_dump($var);
96     }
97     
98     protected function generateXML ($files) {
99         $includes = implode("\n", array_map(array($this,'generate_include'), $files));
100         
101         $xml = sprintf(
102 '<?xml version="1.0" encoding="UTF-8"?> <Schema xmlns="http://www.midgard-project.org/repligard/1.4">
103 %s
104 </Schema>' , $includes ) ;       
105         return $xml;   
106     }
107
108     
109 }
110 ?>
Note: See TracBrowser for help on using the browser.