Changeset 13818

Show
Ignore:
Timestamp:
12/10/07 16:28:46 (10 months ago)
Author:
bergie
Message:

New phing package options: -Dversion=1.0.0 and -Dstate=stable that will also update manifest accordingly

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/build.xml

    r13572 r13818  
    77    <property name="phpdocdir" value="documentation/api" /> 
    88    <property name="coreVersion" value="2.9.0beta16" /> 
     9    <property name="version" value="" /> 
     10    <property name="state" value="" /> 
    911    <resolvepath propertyName="absolute_basedir" file="${project.basedir}"/> 
    1012 
     
    175177            path="${project.basedir}" 
    176178            package="${module}" 
     179            version="${version}" 
     180            state="${state}" 
    177181            target_dir="${target_dir}" 
    178182            returnProperty="pear_name" 
  • trunk/midcom/build/packageMidCOM.php

    r12312 r13818  
    1717{ 
    1818 
    19         protected $package = null; // package name 
    20         /** 
    21          * The PEAR name of the package. 
    22          */ 
    23         protected $package_name; 
    24         protected $channel = "pear.midcom-project.org"; 
    25  
    26         function __construct() 
    27         { 
     19    /** 
     20     * Component name 
     21     */ 
     22    protected $package = null;  
     23     
     24    /** 
     25     * Package version 
     26     */ 
     27    protected $version = null; 
     28 
     29    /** 
     30     * Package state 
     31     */ 
     32    protected $state = null; 
     33     
     34    /** 
     35     * MidCOM component manifest array 
     36     */ 
     37    protected $manifest = null; 
     38     
     39    /** 
     40     * The PEAR name of the package. 
     41     */ 
     42    protected $package_name; 
     43    protected $channel = "pear.midcom-project.org"; 
     44 
     45    protected $returnProperty; // name of property to set to return value 
     46 
     47    /** 
     48     * The root path to where the module is stored. 
     49     */ 
     50    private $path = null; 
     51    /** 
     52     * The target directory where the packagefile should be saved. 
     53     */ 
     54    protected $target_dir = null; 
     55     
     56    function __construct() 
     57    { 
    2858        ini_set('memory_limit', '-1');  
    29         } 
    30  
    31         protected $returnProperty; // name of property to set to return value 
    32  
    33         /** 
    34          * The root path to where the module is stored. 
    35          */ 
    36         private $path = null; 
    37         /** 
    38          * The target directory where the packagefile should be saved. 
    39          */ 
    40         protected $target_dir = null; 
    41         /** 
    42          * The setter for the attribute "message" 
    43          */ 
    44         public function setTarget_dir($str) 
    45         { 
    46                 $this->target_dir = $str; 
    47         } 
    48         public function setPath($str) 
    49         { 
    50                 $this->path = $str; 
    51         } 
    52         public function setPackage($str) 
    53         { 
    54                 $this->package = $str; 
    55         } 
    56         public function setChannel($str) 
    57         { 
    58                 $this->channel = $str; 
    59         } 
    60         /** Sets property name to set with return value of function or expression.*/ 
    61         public function setReturnProperty($r) 
    62         { 
    63                 $this->returnProperty = $r; 
    64         } 
    65  
    66         protected $copyfiles = array (); 
    67  
    68         /** 
    69          * The init method: Do init steps. 
    70          */ 
    71         public function init() 
    72         { 
    73                 // nothing to do here 
    74         } 
    75  
    76         /** 
    77          * The main entry point method. 
    78          */ 
    79         public function main() 
    80         { 
    81                 $this->package_name = str_replace('.', '_', $this->package); 
    82                 $this->package_name = str_replace('/', '', $this->package_name); 
    83                 echo "Using package name : {$this->package_name} \n"; 
    84                 // todo add more validation 
    85                 if ($this->target_dir === null   
    86                         || !is_dir($this->target_dir)   
    87                 ) { 
    88                         throw new Exception("You must set the target attribute to a writable directory (current: {$this->target_dir})!\n"); 
    89                 } 
    90                 // read the manifest 
    91                 $this->readManifest(); 
    92                 $packageInfo = $this->getComponentInfo(); 
    93                 // build the filelist 
    94                 $filelist = $this->getFileList($packageInfo); 
    95                 // create the xml for package.xml 
    96                 $xml = $this->createXml($packageInfo, $filelist); 
    97                 // save package.xml. 
    98                 file_put_contents($this->path . "/" . $this->package . "/package.xml", $xml); 
    99                  
    100                 $this->execPearPackage(); 
    101                 // I planned to use the tar task to create the package, then this would be needed 
    102                 $name = $this->package_name . "-" . $packageInfo['version']; 
    103                 $this->project->setProperty($this->returnProperty, $name); 
    104                 // should I delete package.xml? Hmm, todo I think. 
    105  
    106         } 
    107  
    108         protected function execPearPackage() 
    109         { 
    110                 $curr_dir = getcwd(); 
    111                 chdir($this->target_dir); 
    112                 $pear = exec('which pear'); 
    113                 if (!is_executable($pear)) 
    114                 { 
    115                         die("Pear executable $pear is not executable!"); 
    116                 } 
    117                  
    118                 $ret = exec("$pear package-validate {$this->path}/{$this->package}/package.xml", $out, $status); 
    119                 $out = null; 
    120                 if ($status == 0) 
    121                 { 
    122                         $ret = exec("$pear package {$this->path}/{$this->package}/package.xml", $out, $status); 
    123                         foreach ($out as $line) { 
    124                                 if (stripos($line, 'error')) { 
    125                                         echo $line . "\n"; 
    126                                 } 
    127                                 if (stripos($line, 'warning')) { 
    128                                         echo $line . "\n"; 
    129                                 } 
    130                                  
    131                         } 
    132                          
    133                 }  
    134                 else  
    135                 { 
    136                         chdir($curr_dir); 
    137                         if (!is_null($out)) 
    138                         { 
    139                         echo implode($out); 
    140             } 
    141                         die ("Packagefile did not validate! Exiting."); 
    142                 } 
    143                 chdir($curr_dir); 
    144                  
    145         } 
    146  
    147         protected function getFileList($packageInfo) 
    148         { 
    149  
    150                 $filelist_config = array ( 
    151                         'filelist' => '', 
    152                         'package' => $packageInfo, 
    153                         'component' => $this->package_name, 
    154                         'path' => $this->path . "/" . $this->package, 
    155                         'prefix' => '    ', 
    156                         'baseinstalldir' => 'midcom/lib/' . str_replace('.', 
    157                         '/', 
    158                         $this->package 
    159                 ), 'static' => false,); 
    160                 $filelist = $this->directory_list_contents($filelist_config); 
    161                 return $filelist; 
    162         } 
    163  
    164         /** 
    165          * Generate the filelist 
    166          *ᅵ@param array $config File listing configuration 
    167          * @return string File XML list 
    168          */ 
    169         function directory_list_contents($config, $directory_name_override = null) 
    170         { 
    171                 $directory = dir($config['path']); 
    172  
    173                 if ($directory_name_override) 
    174                 { 
    175                         $dir_name = $directory_name_override; 
    176                 } else 
    177                 { 
    178                         $dir_name = basename($config['path']); 
    179                 } 
    180  
    181                 // Add more to the prefix 
    182                 $config['prefix'] .= '    '; 
    183  
    184                 // Start the directory output 
    185                 if ($dir_name == 'static' && $config['prefix'] != '        ') 
    186                 { 
    187                         // All static files are handled through Role_Web 
    188                         $config['static'] = true; 
    189                         $config['filelist'] .= "{$config['prefix']}<dir name=\"{$dir_name}\">\n"; 
    190                         $config['baseinstalldir'] = str_replace('_', '.', "/{$config['component']}"); 
    191                         $config['install-as-prefix'] = ''; 
    192                 } else 
    193                 { 
    194                         $config['filelist'] .= "{$config['prefix']}<dir name=\"{$dir_name}\">\n"; 
    195                 } 
    196  
    197                 // List contents 
    198                 while (false !== ($entry = $directory->read())) 
    199                 { 
    200                         if (substr($entry, 0, 1) == '.') 
    201                         { 
    202                                 // Ignore dotfiles 
    203                                 continue; 
    204                         } 
    205                         if ($entry == 'CVS' || $entry == '.svn') 
    206                         { 
    207                                 // Ignore CVS directories 
    208                                 continue; 
    209                         } 
    210                         if ($entry == 'package.xml') 
    211                         { 
    212                                 // Ignore the package file itself 
    213                                 continue; 
    214                         } 
    215  
    216                         // Handle packaging file roles  
    217                         elseif ($dir_name == 'config' && $entry == 'mgdschema.xml') 
    218                         { 
    219                                 // MgdSchemas shipped by components are placed in config/mgdschema.xml 
    220                                 $role = 'mgdschema'; 
    221                         } 
    222                         elseif ($dir_name == 'config' && $entry == 'mgdschema.sql') 
    223                         { 
    224                                 // SQL files shipped by components are placed in config/mgdschema.xml 
    225                                 // These will be installed via the Datagard database update command 
    226                                 $role = 'midgardsql'; 
    227                         } else 
    228                         { 
    229                                 // All files are by default PHP 
    230                                 $role = 'php'; 
    231  
    232                                 // Check for potential other file extensions 
    233                                 $path_parts = pathinfo($entry); 
    234                                 switch ($path_parts['extension']) 
    235                                 { 
    236                                         // binary formats 
    237                                         case 'jpg' : 
    238                                         case 'gif' : 
    239                                         case 'png' : 
    240                                         case 'zip' : 
    241                                         case 'tgz' : 
    242                                                 $role = 'data'; 
    243                                                 break; 
    244                                                 // Web formats *not* in static directory 
    245                                         case 'html' : 
    246                                         case 'js' : 
    247                                         case 'htc' : 
    248                                         case 'css' : 
    249                                                 $role = 'data'; 
    250                                                 break; 
    251                                 } 
    252                         } 
    253  
    254                         if (is_dir("{$config['path']}/{$entry}")) 
    255                         { 
    256                                 // List the subdirectory 
    257                                 $subconfig = $config; 
    258                                 $subconfig['path'] = "{$config['path']}/{$entry}"; 
    259                                 $subconfig['install-as-prefix'] .= "{$entry}/"; 
    260                                 $config['filelist'] = $this->directory_list_contents($subconfig); 
    261                         } else 
    262                         { 
    263                                 // List the files 
    264                                 if ($config['static']) 
    265                                 { 
    266                                         $role = 'web'; 
    267                                         $config['filelist'] .= "{$config['prefix']}    <file baseinstalldir=\"{$config['baseinstalldir']}\" install-as=\"{$config['install-as-prefix']}{$entry}\" name=\"{$entry}\" role=\"{$role}\" />\n"; 
    268                                 } else 
    269                                 { 
    270                                         $config['filelist'] .= "{$config['prefix']}    <file baseinstalldir=\"{$config['baseinstalldir']}\" name=\"{$entry}\" role=\"{$role}\" />\n"; 
    271                                 } 
    272                         } 
    273                         $this->copyfiles[] = $config['path'] . "/" . $entry; 
    274                 } 
    275  
    276                 $directory->close(); 
    277                 $config['filelist'] .= "{$config['prefix']}</dir>\n"; 
    278                 return $config['filelist']; 
    279         } 
    280  
    281         public function getComponentInfo() 
    282         { 
    283                 $component = array (); 
    284                 $component['baseinstalldir'] = "midcom/lib"; 
    285                 $component_path_array = explode('.', $this->package); 
    286                 foreach ($component_path_array as $directory) 
    287                 { 
    288                         $component['baseinstalldir'] = "{$component['baseinstalldir']}/{$directory}"; 
    289                 } 
    290                 // PEAR packages can't have dots in their names 
    291                 $package['name'] = $this->package_name; 
    292  
    293                 // Default license to LGPL if missing 
    294                 if (array_key_exists('license', $this->manifest['package.xml'])) 
    295                 { 
    296                         $package['license'] = $this->manifest['package.xml']['license']; 
    297                 } else 
    298                 { 
    299                         $package['license'] = 'LGPL'; 
    300                 } 
    301  
    302                 // Version string is a string 
    303                 $package['version'] = $this->manifest['version']; 
    304  
    305                 // Release date is today 
    306                 // TODO: Get latest modification date from CHANGES 
    307                 $package['date'] = date('Y-m-d'); 
    308                 $package['time'] = date('H:i:s'); 
    309  
    310                 // Package state. Default to stable 
    311                 if (array_key_exists('state', $this->manifest)) 
    312                 { 
    313                         $package['state'] = $this->manifest['state']; 
    314                 } else 
    315                 { 
    316                         echo "Note: You have not set packagestate. Defaulting to alpha.\n"; 
    317                         $package['state'] = 'alpha'; 
    318                 } 
    319  
    320                 // Load the summary 
    321                 if (array_key_exists('summary', $this->manifest['package.xml'])) 
    322                 { 
    323                         $package['summary'] = $this->manifest['package.xml']['summary']; 
    324                 } else 
    325                 { 
    326                         $package['summary'] = "MidCOM component {$this->package}"; 
    327                 } 
    328  
    329                 // Load the description 
    330                 if (array_key_exists('description', $this->manifest['package.xml'])) 
    331                 { 
    332                         $package['description'] = $this->manifest['package.xml']['description']; 
    333                 } else 
    334                 { 
    335                         $package['description'] = "MidCOM component {$this->package}"; 
    336                 } 
    337  
    338                 //      Generate the maintainer list 
    339                 $package['maintainers'] = ''; 
    340                 if (array_key_exists('maintainers', $this->manifest['package.xml']) && is_array($this->manifest['package.xml']['maintainers'])) 
    341                 { 
    342                         foreach ($this->manifest['package.xml']['maintainers'] as $username => $person) 
    343                         { 
    344                                 if (!is_array($person)) 
    345                                 { 
    346                                         $person = Array (); 
    347                                 } 
    348  
    349                                 if (!array_key_exists('name', $person)) 
    350                                 { 
    351                                         // Maintainer must have a name 
    352                                         continue; 
    353                                 } 
    354  
    355                                 if (!array_key_exists('role', $person)) 
    356                                 { 
    357                                         $person['role'] = 'developer'; 
    358                                 } 
    359  
    360                                 if (!array_key_exists('active', $person)) 
    361                                 { 
    362                                         $person['active'] = 'yes'; 
    363                                 } 
    364  
    365                                 $package['maintainers'] .= " 
    366                                                                                             <{$person['role']}> 
    367                                                                                                 <name>{$person['name']}</name>     
    368                                                                                                 <user>{$username}</user> 
    369                                                                                                 <email>{$person['email']}</email> 
    370                                                                                                 <active>{$person['active']}</active> 
    371                                                                                             </{$person['role']}> 
    372                                                                                         "; 
    373                         } 
    374                 } 
    375  
    376                 // Generate dependencies, if any 
    377                 $package['dependencies'] = ''; 
    378                 if (array_key_exists('dependencies', $this->manifest['package.xml']) && is_array($this->manifest['package.xml']['dependencies'])) 
    379                 { 
    380                         foreach ($this->manifest['package.xml']['dependencies'] as $requirement => $dependency) 
    381                         { 
    382                                 if (!is_array($dependency)) 
    383                                 { 
    384                                         $dependency = Array (); 
    385                                 } 
    386  
    387                                 $dependency['min'] = ''; 
    388                                 if (array_key_exists('version', $dependency)) 
    389                                 { 
    390                                         // No version specified, the dependency just needs to exist 
    391                                         $dependency['min'] = "<min>{$dependency['version']}</min>"; 
    392                                 } 
    393  
    394                                 if (!array_key_exists('type', $dependency)) 
    395                                 { 
    396                                         // Default to depending on PEAR packages 
    397                                         $dependency['type'] = 'package'; 
    398                                 } 
    399  
    400                                 if (!array_key_exists('channel', $dependency)) 
    401                                 { 
    402                                         // Default to depending on packages from MidCOM repository 
    403                                         $dependency['channel'] = $this->channel; 
    404                                 } 
    405  
    406                                 if (strstr($requirement, '.')) 
    407                                 { 
    408                                         // Convert dots in component names to underscores used in PEAR packages 
    409                                         $requirement = str_replace('.', '_', $requirement); 
    410                                 } 
    411  
    412                                 $package['dependencies'] .= " 
    413                                                                                             <{$dependency['type']}> 
    414                                                                                                 <name>{$requirement}</name> 
    415                                                                                                 <channel>{$dependency['channel']}</channel> 
    416                                                                                                 {$dependency['min']} 
    417                                                                                             </{$dependency['type']}>             
    418                                                                                         "; 
    419                         } 
    420                 } 
    421                 return $package; 
    422         } 
    423         /** 
    424          * Reads the manifest file and redies it for parsing. 
    425          */ 
    426         protected $manifest = null; 
    427         protected function readManifest() 
    428         { 
    429                 $file = sprintf("%s/%s/config/manifest.inc", $this->path, $this->package); 
    430                 $manifest = array (); 
    431                 if (!file_exists($file)) 
    432                 { 
    433                         die("Missing componentfile $file. Cannot package {$this->package}\n"); 
    434                 } 
    435                 eval ('$manifest = Array(' . file_get_contents($file) . ');'); 
    436  
    437                 $this->manifest = $manifest; 
    438                 // Require PEAR information 
    439                 if (!array_key_exists('package.xml', $this->manifest) || !is_array($this->manifest['package.xml'])) 
    440                 { 
    441                         die("PEAR packaging information missing from component manifest {$component['manifest_file']}.\n"); 
    442                 } 
    443  
    444         } 
    445  
    446         protected function createXml($package, $filelist) 
    447         { 
    448  
    449                 // Create package XML 
    450                 return "<?xml version=\"1.0\" encoding=\"UTF-8\"?> 
    451                                 <package packagerversion=\"1.4.5\" version=\"2.0\" xmlns=\"http://pear.php.net/dtd/package-2.0\" xmlns:tasks=\"http://pear.php.net/dtd/tasks-1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://pear.php.net/dtd/tasks-1.0 
    452                                 http://pear.php.net/dtd/tasks-1.0.xsd 
    453                                 http://pear.php.net/dtd/package-2.0 
    454                                 http://pear.php.net/dtd/package-2.0.xsd\"> 
    455                                     <name>{$package['name']}</name> 
    456                                     <channel>{$this->channel}</channel> 
    457                                     <summary> 
    458                                         {$package['summary']} 
    459                                     </summary> 
    460                                     <description> 
    461                                         {$package['description']} 
    462                                     </description> 
    463                                     {$package['maintainers']} 
    464                                     <date>{$package['date']}</date> 
    465                                     <time>{$package['time']}</time> 
    466                                     <version> 
    467                                         <release>{$package['version']}</release> 
    468                                         <api>{$package['version']}</api> 
    469                                     </version> 
    470                                     <stability> 
    471                                         <release>{$package['state']}</release> 
    472                                         <api>{$package['state']}</api> 
    473                                     </stability> 
    474                                     <license>{$package['license']}</license> 
    475                                     <notes>{$package['version']} {$package['state']}</notes>         
    476                                     <contents>\n{$filelist}    </contents>         
    477                                     <dependencies> 
    478                                         <required> 
    479                                             <php> 
    480                                                 <min>4.3.0</min> 
    481                                             </php> 
    482                                             <pearinstaller> 
    483                                                 <min>1.4.0</min> 
    484                                             </pearinstaller>         
    485                                             {$package['dependencies']}   
     59    } 
     60     
     61    /** 
     62     * The setter for the attribute "message" 
     63     */ 
     64    public function setTarget_dir($str) 
     65    { 
     66        $this->target_dir = $str; 
     67    } 
     68    public function setPath($str) 
     69    { 
     70        $this->path = $str; 
     71    } 
     72    public function setPackage($str) 
     73    { 
     74        $this->package = $str; 
     75    } 
     76    public function setVersion($str) 
     77    { 
     78        $this->version = $str; 
     79    } 
     80    public function setState($str) 
     81    { 
     82        $this->state = $str; 
     83    } 
     84    public function setChannel($str) 
     85    { 
     86        $this->channel = $str; 
     87    } 
     88    /** Sets property name to set with return value of function or expression.*/ 
     89    public function setReturnProperty($r) 
     90    { 
     91        $this->returnProperty = $r; 
     92    } 
     93 
     94    protected $copyfiles = array (); 
     95 
     96    /** 
     97     * The init method: Do init steps. 
     98     */ 
     99    public function init() 
     100    { 
     101        // nothing to do here 
     102    } 
     103 
     104    /** 
     105     * The main entry point method. 
     106     */ 
     107    public function main() 
     108    { 
     109        $this->package_name = str_replace('.', '_', $this->package); 
     110        $this->package_name = str_replace('/', '', $this->package_name); 
     111        echo "Using package name : {$this->package_name} \n"; 
     112        // todo add more validation 
     113        if ($this->target_dir === null   
     114            || !is_dir($this->target_dir)   
     115        ) { 
     116            throw new Exception("You must set the target attribute to a writable directory (current: {$this->target_dir})!\n"); 
     117        } 
     118        // read the manifest 
     119        $this->readManifest(); 
     120        $packageInfo = $this->getComponentInfo(); 
     121        // build the filelist 
     122        $filelist = $this->getFileList($packageInfo); 
     123        // create the xml for package.xml 
     124        $xml = $this->createXml($packageInfo, $filelist); 
     125        // save package.xml. 
     126        file_put_contents($this->path . "/" . $this->package . "/package.xml", $xml); 
     127         
     128        $this->execPearPackage(); 
     129        // I planned to use the tar task to create the package, then this would be needed 
     130        $name = $this->package_name . "-" . $packageInfo['version']; 
     131        $this->project->setProperty($this->returnProperty, $name); 
     132        // should I delete package.xml? Hmm, todo I think. 
     133 
     134    } 
     135 
     136    protected function execPearPackage() 
     137    { 
     138        $curr_dir = getcwd(); 
     139        chdir($this->target_dir); 
     140        $pear = exec('which pear'); 
     141        if (!is_executable($pear)) 
     142        { 
     143            die("Pear executable $pear is not executable!"); 
     144        } 
     145         
     146        $ret = exec("$pear package-validate {$this->path}/{$this->package}/package.xml", $out, $status); 
     147        $out = null; 
     148        if ($status == 0) 
     149        { 
     150            $ret = exec("$pear package {$this->path}/{$this->package}/package.xml", $out, $status); 
     151            foreach ($out as $line) { 
     152                if (stripos($line, 'error')) { 
     153                    echo $line . "\n"; 
     154                } 
     155                if (stripos($line, 'warning')) { 
     156                    echo $line . "\n"; 
     157                } 
     158                 
     159            } 
     160             
     161        }  
     162        else  
     163        { 
     164            chdir($curr_dir); 
     165            if (!is_null($out)) 
     166            { 
     167                echo implode($out); 
     168            } 
     169            die ("Packagefile did not validate! Exiting."); 
     170        } 
     171        chdir($curr_dir); 
     172         
     173    } 
     174 
     175    protected function getFileList($packageInfo) 
     176    { 
     177 
     178        $filelist_config = array 
     179        ( 
     180            'filelist' => '', 
     181            'package' => $packageInfo, 
     182            'component' => $this->package_name, 
     183            'path' => $this->path . "/" . $this->package, 
     184            'prefix' => '    ', 
     185            'baseinstalldir' => 'midcom/lib/' . str_replace('.', '/', $this->package), 
     186            'static' => false, 
     187        ); 
     188        $filelist = $this->directory_list_contents($filelist_config); 
     189        return $filelist; 
     190    } 
     191 
     192    /** 
     193     * Generate the filelist 
     194     *ᅵ@param array $config File listing configuration 
     195     * @return string File XML list 
     196     */ 
     197    function directory_list_contents($config, $directory_name_override = null) 
     198    { 
     199        $directory = dir($config['path']); 
     200 
     201        if ($directory_name_override) 
     202        { 
     203            $dir_name = $directory_name_override; 
     204        } else 
     205        { 
     206            $dir_name = basename($config['path']); 
     207        } 
     208 
     209        // Add more to the prefix 
     210        $config['prefix'] .= '    '; 
     211 
     212        // Start the directory output 
     213        if ($dir_name == 'static' && $config['prefix'] != '        ') 
     214        { 
     215            // All static files are handled through Role_Web 
     216            $config['static'] = true; 
     217            $config['filelist'] .= "{$config['prefix']}<dir name=\"{$dir_name}\">\n"; 
     218            $config['baseinstalldir'] = str_replace('_', '.', "/{$config['component']}"); 
     219            $config['install-as-prefix'] = ''; 
     220        } else 
     221        { 
     222            $config['filelist'] .= "{$config['prefix']}<dir name=\"{$dir_name}\">\n"; 
     223        } 
     224 
     225        // List contents 
     226        while (false !== ($entry = $directory->read())) 
     227        { 
     228            if (substr($entry, 0, 1) == '.') 
     229            { 
     230                // Ignore dotfiles 
     231                continue; 
     232            } 
     233            if ($entry == 'CVS' || $entry == '.svn') 
     234            { 
     235                // Ignore CVS directories 
     236                continue; 
     237            } 
     238            if ($entry == 'package.xml') 
     239            { 
     240                // Ignore the package file itself 
     241                continue; 
     242            } 
     243 
     244            // Handle packaging file roles  
     245            elseif ($dir_name == 'config' && $entry == 'mgdschema.xml') 
     246            { 
     247                // MgdSchemas shipped by components are placed in config/mgdschema.xml 
     248                $role = 'mgdschema'; 
     249            } 
     250            elseif ($dir_name == 'config' && $entry == 'mgdschema.sql') 
     251            { 
     252                // SQL files shipped by components are placed in config/mgdschema.xml 
     253                // These will be installed via the Datagard database update command 
     254                $role = 'midgardsql'; 
     255            } else 
     256            { 
     257                // All files are by default PHP 
     258                $role = 'php'; 
     259 
     260                // Check for potential other file extensions 
     261                $path_parts = pathinfo($entry); 
     262                switch ($path_parts['extension']) 
     263                { 
     264                    // binary formats 
     265                    case 'jpg' : 
     266                    case 'gif' : 
     267                    case 'png' : 
     268                    case 'zip' : 
     269                    case 'tgz' : 
     270                        $role = 'data'; 
     271                        break; 
     272                        // Web formats *not* in static directory 
     273                    case 'html' : 
     274                    case 'js' : 
     275                    case 'htc' : 
     276                    case 'css' : 
     277                        $role = 'data'; 
     278                        break; 
     279                } 
     280            } 
     281 
     282            if (is_dir("{$config['path']}/{$entry}")) 
     283            { 
     284                // List the subdirectory 
     285                $subconfig = $config; 
     286                $subconfig['path'] = "{$config['path']}/{$entry}"; 
     287                $subconfig['install-as-prefix'] .= "{$entry}/"; 
     288                $config['filelist'] = $this->directory_list_contents($subconfig); 
     289            } else 
     290            { 
     291                // List the files 
     292                if ($config['static']) 
     293                { 
     294                    $role = 'web'; 
     295                    $config['filelist'] .= "{$config['prefix']}    <file baseinstalldir=\"{$config['baseinstalldir']}\" install-as=\"{$config['install-as-prefix']}{$entry}\" name=\"{$entry}\" role=\"{$role}\" />\n"; 
     296                } else 
     297                { 
     298                    $config['filelist'] .= "{$config['prefix']}    <file baseinstalldir=\"{$config['baseinstalldir']}\" name=\"{$entry}\" role=\"{$role}\" />\n"; 
     299                } 
     300            } 
     301            $this->copyfiles[] = $config['path'] . "/" . $entry; 
     302        } 
     303 
     304        $directory->close(); 
     305        $config['filelist'] .= "{$config['prefix']}</dir>\n"; 
     306        return $config['filelist']; 
     307    } 
     308 
     309    public function getComponentInfo() 
     310    { 
     311        $component = array (); 
     312        $component['baseinstalldir'] = "midcom/lib"; 
     313        $component_path_array = explode('.', $this->package); 
     314        foreach ($component_path_array as $directory) 
     315        { 
     316            $component['baseinstalldir'] = "{$component['baseinstalldir']}/{$directory}"; 
     317        } 
     318        // PEAR packages can't have dots in their names 
     319        $package['name'] = $this->package_name; 
     320 
     321        // Default license to LGPL if missing 
     322        if (array_key_exists('license', $this->manifest['package.xml'])) 
     323        { 
     324            $package['license'] = $this->manifest['package.xml']['license']; 
     325        } else 
     326        { 
     327            $package['license'] = 'LGPL'; 
     328        } 
     329 
     330        // Version string is a string 
     331        $package['version'] = $this->manifest['version']; 
     332 
     333        // Release date is today 
     334        // TODO: Get latest modification date from CHANGES 
     335        $package['date'] = date('Y-m-d'); 
     336        $package['time'] = date('H:i:s'); 
     337 
     338        // Package state. Default to stable 
     339        if (array_key_exists('state', $this->manifest)) 
     340        { 
     341            $package['state'] = $this->manifest['state']; 
     342        }  
     343        else 
     344        { 
     345            echo "Note: You have not set packagestate. Defaulting to devel.\n"; 
     346            $package['state'] = 'devel'; 
     347        } 
     348 
     349        // Load the summary 
     350        if (array_key_exists('summary', $this->manifest['package.xml'])) 
     351        { 
     352            $package['summary'] = $this->manifest['package.xml']['summary']; 
     353        }  
     354        else 
     355        { 
     356            $package['summary'] = "MidCOM component {$this->package}"; 
     357        } 
     358 
     359        // Load the description 
     360        if (array_key_exists('description', $this->manifest['package.xml'])) 
     361        { 
     362            $package['description'] = $this->manifest['package.xml']['description']; 
     363        } else 
     364        { 
     365            $package['description'] = "MidCOM component {$this->package}"; 
     366        } 
     367 
     368        //     Generate the maintainer list 
     369        $package['maintainers'] = ''; 
     370        if (array_key_exists('maintainers', $this->manifest['package.xml']) && is_array($this->manifest['package.xml']['maintainers'])) 
     371        { 
     372            foreach ($this->manifest['package.xml']['maintainers'] as $username => $person) 
     373            { 
     374                if (!is_array($person)) 
     375                { 
     376                    $person = Array (); 
     377                } 
     378 
     379                if (!array_key_exists('name', $person)) 
     380                { 
     381                    // Maintainer must have a name 
     382                    continue; 
     383                } 
     384 
     385                if (!array_key_exists('role', $person)) 
     386                { 
     387                    $person['role'] = 'developer'; 
     388                } 
     389 
     390                if (!array_key_exists('active', $person)) 
     391                { 
     392                    $person['active'] = 'yes'; 
     393                } 
     394 
     395                $package['maintainers'] .= " 
     396                                                <{$person['role']}> 
     397                                                    <name>{$person['name']}</name>     
     398                                                    <user>{$username}</user> 
     399                                                    <email>{$person['email']}</email> 
     400                                                    <active>{$person['active']}