Changeset 235

Show
Ignore:
Timestamp:
02/06/07 16:26:07 (1 year ago)
Author:
mikey
Message:

added possibility to add arbitrary metadata to star files

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/build/star/compile-reader.ini

    r115 r235  
    77[PREFACE] 
    88preface.1="build/star/preface-reader.php" 
     9 
     10[META-INF] 
     11title = "Stubbles Archive Reader" 
     12package = "net.stubbles.star" 
     13version = "0.5.0" 
     14author = "Stubbles Development Team <http://stubbles.net> 
     15copyright = "© 2007 Stubbles Development Team" 
  • trunk/build/star/compile-writer-archive.ini

    r218 r235  
    1111[PREFACE] 
    1212preface.1="build/star/preface-writer.php" 
     13 
     14[META-INF] 
     15title = "Stubbles Archive Writer" 
     16package = "net.stubbles.star" 
     17version = "0.5.0" 
     18author = "Stubbles Development Team <http://stubbles.net> 
     19copyright = "© 2007 Stubbles Development Team" 
  • trunk/build/star/compile-writer-cli.ini

    r218 r235  
    1212preface.1="build/star/preface-writer.php" 
    1313preface.2="build/star/preface-writer-cli.php" 
     14 
     15[META-INF] 
     16title = "Stubbles Archive CLI Writer" 
     17package = "net.stubbles.star" 
     18version = "0.5.0" 
     19author = "Stubbles Development Team <http://stubbles.net> 
     20copyright = "© 2007 Stubbles Development Team" 
  • trunk/build/stubbles/build.php

    r225 r235  
    4848$preface = "<?php require 'star://' . __FILE__ . '?net.stubbles.star.StarClassRegistry'; ?>" . file_get_contents(realpath(dirname(__FILE__) . '/../../src/main/php') . '/net/stubbles/stubClassLoader.php'); 
    4949$starArchive->setPreface($preface); 
     50$starArchive->addMetaData('title', 'Stubbles'); 
     51$starArchive->addMetaData('package', 'net.stubbles'); 
     52$starArchive->addMetaData('version', '0.1.0'); 
     53$starArchive->addMetaData('author', 'Stubbles Development Team <http://stubbles.net>'); 
     54$starArchive->addMetaData('copyright', '© 2007 Stubbles Development Team'); 
    5055$starArchive->create(); 
    5156 
  • trunk/lib/starReader.php

    r221 r235  
    8787            } 
    8888             
    89             $header = unpack('a4id/c1version/a8indexsize/a*reserved', fread($current['handle'], 0x0100)); 
     89            $header = unpack('a4id/c1version/a8indexsize/a14buildtime/a*reserved', fread($current['handle'], 0x0100)); 
    9090            if (false === $header) { 
    9191                // invalid star file 
     
    9393            } 
    9494             
    95             $current['index'] = array(); 
     95            $current['index']  = array(); 
     96            $current['header'] = $header; 
     97            if (__FILE__ == $archive && defined('__COMPILER_HALT_OFFSET__') == true) { 
     98                $current['header']['totalSize'] = __COMPILER_HALT_OFFSET__ + 0x0100; 
     99            } else { 
     100                $current['header']['totalSize'] = 0x0100; 
     101            } 
    96102            for ($i = 0; $i < $header['indexsize']; $i++) { 
    97103                $entry = unpack('a80id/a72filename/a80path/a8size/a8offset/a*reserved', 
     
    99105                ); 
    100106                 
    101                 $current['index'][$entry['id']]= array('size' => (int) $entry['size'], 'offset' => (int) $entry['offset']); 
     107                $current['index'][$entry['id']]  = array('size' => (int) $entry['size'], 'offset' => (int) $entry['offset']); 
     108                $current['header']['totalSize'] += 0x0100 + ((int) $entry['size']); 
    102109            } 
    103110        } 
    104111         
    105112        return $archives[$archive]; 
     113    } 
     114     
     115    /** 
     116     * returns the metadata of an archive 
     117     * 
     118     * @param   string  $archive  archive to retrieve metadata for 
     119     * @return  array 
     120     */ 
     121    public static function getMetaData($archive) 
     122    { 
     123        $current  = self::acquire($archive); 
     124        if (isset($current['index']) == false) { 
     125            throw new StarException('Star file ' . $archive . ' does not exist or is not a valid star file.'); 
     126        } 
     127         
     128        $metaData = array(); 
     129        fseek($current['handle'], $current['header']['totalSize']); 
     130        while (feof($current['handle']) == false) { 
     131            $line = trim(fgets($current['handle'], 4096)); 
     132            if (empty($line) == true) { 
     133                continue; 
     134            } 
     135             
     136            $lineData = explode(' => ', $line); 
     137            $metaData[$lineData[0]] = $lineData[1]; 
     138        } 
     139         
     140        return $metaData; 
    106141    } 
    107142     
     
    215250?><?php StarStreamWrapper::register(); ?><?php 
    216251require 'star://' . __FILE__ . '?net.stubbles.star.StarClassRegistry'; 
    217 ?><?php __halt_compiler();star1net.stubbles.star.StarClassRegistryStarClassRegistry.phpsrc/main/php/net/stubbles/star48356151<?php 
     252?><?php __halt_compiler();star120070206161833net.stubbles.star.StarClassRegistryStarClassRegistry.phpsrc/main/php/net/stubbles/star48427448<?php 
    218253/** 
    219254 * Class registry for mapping of classes to star files. 
     
    303338     * @return  array 
    304339     */ 
    305     public function getClassNamesFromFile($file) 
     340    public static function getClassNamesFromFile($file) 
    306341    { 
    307342        self::init(); 
     
    374409} 
    375410?> 
     411package => net.stubbles.star 
     412version => 0.5.0 
  • trunk/src/main/php/net/stubbles/star/StarArchive.php

    r225 r235  
    4444    protected $index                = array(); 
    4545    /** 
     46     * metadata of star archive: could be version, packages, etc. 
     47     * 
     48     * @var  array<string,string> 
     49     */ 
     50    protected $metadata             = array(); 
     51    /** 
    4652     * star archive version 
    4753     */ 
     
    6773    public function add(StarFile $file, $id) 
    6874    { 
    69         $data = $file->getContents(); 
     75        $data             = $file->getContents(); 
    7076        $this->index[$id] = array('basename' => $file->getBaseName(), 
    7177                                  'path'     => $file->getPathWithBaseRemoved(), 
     
    7480                                  'payload'  => $data 
    7581                            ); 
     82    } 
     83     
     84    /** 
     85     * adds meta data to the star archive 
     86     * 
     87     * @param  string  $name 
     88     * @param  string  $value 
     89     */ 
     90    public function addMetaData($name, $value) 
     91    { 
     92        $this->metadata[$name] = $value; 
    7693    } 
    7794     
     
    118135         
    119136        $ids = array_keys($this->index); 
    120         $this->writer->write(pack('a4c1a8a243', 
     137        $this->writer->write(pack('a4c1a8a14a229', 
    121138                                  'star', 
    122139                                  self::VERSION, 
    123140                                  (string) count($ids), 
     141                                  date('YmdHis'), 
    124142                                  "\0" 
    125143                             ) 
     
    145163        } 
    146164         
     165        if (count($this->metadata) > 0) { 
     166            $this->writer->write("\n"); 
     167            foreach ($this->metadata as $name => $value) { 
     168                $this->writer->write($name . ' => ' . $value . "\n"); 
     169            } 
     170        } 
     171         
    147172        $this->writer->close(); 
    148173    } 
  • trunk/src/main/php/net/stubbles/star/StarClassRegistry.php

    r221 r235  
    8787     * @return  array 
    8888     */ 
    89     public function getClassNamesFromFile($file) 
     89    public static function getClassNamesFromFile($file) 
    9090    { 
    9191        self::init(); 
  • trunk/src/main/php/net/stubbles/star/StarConsole.php

    r225 r235  
    188188        } 
    189189         
     190        if (isset($conf['META-INF']) == true && is_array($conf['META-INF']) == true) { 
     191            foreach ($conf['META-INF'] as $name => $value) { 
     192                $starArchive->addMetaData($name, $value); 
     193            } 
     194        } 
     195         
    190196        $this->verbose("Creating star\n"); 
    191197        $starArchive->create(); 
  • trunk/src/main/php/net/stubbles/star/StarStreamWrapper.php

    r218 r235  
    8787            } 
    8888             
    89             $header = unpack('a4id/c1version/a8indexsize/a*reserved', fread($current['handle'], 0x0100)); 
     89            $header = unpack('a4id/c1version/a8indexsize/a14buildtime/a*reserved', fread($current['handle'], 0x0100)); 
    9090            if (false === $header) { 
    9191                // invalid star file 
     
    9393            } 
    9494             
    95             $current['index'] = array(); 
     95            $current['index']  = array(); 
     96            $current['header'] = $header; 
     97            if (__FILE__ == $archive && defined('__COMPILER_HALT_OFFSET__') == true) { 
     98                $current['header']['totalSize'] = __COMPILER_HALT_OFFSET__ + 0x0100; 
     99            } else { 
     100                $current['header']['totalSize'] = 0x0100; 
     101            } 
    96102            for ($i = 0; $i < $header['indexsize']; $i++) { 
    97103                $entry = unpack('a80id/a72filename/a80path/a8size/a8offset/a*reserved', 
     
    99105                ); 
    100106                 
    101                 $current['index'][$entry['id']]= array('size' => (int) $entry['size'], 'offset' => (int) $entry['offset']); 
     107                $current['index'][$entry['id']]  = array('size' => (int) $entry['size'], 'offset' => (int) $entry['offset']); 
     108                $current['header']['totalSize'] += 0x0100 + ((int) $entry['size']); 
    102109            } 
    103110        } 
    104111         
    105112        return $archives[$archive]; 
     113    } 
     114     
     115    /** 
     116     * returns the metadata of an archive 
     117     * 
     118     * @param   string  $archive  archive to retrieve metadata for 
     119     * @return  array 
     120     */ 
     121    public static function getMetaData($archive) 
     122    { 
     123        $current  = self::acquire($archive); 
     124        if (isset($current['index']) == false) { 
     125            throw new StarException('Star file ' . $archive . ' does not exist or is not a valid star file.'); 
     126        } 
     127         
     128        $metaData = array(); 
     129        fseek($current['handle'], $current['header']['totalSize']); 
     130        while (feof($current['handle']) == false) { 
     131            $line = trim(fgets($current['handle'], 4096)); 
     132            if (empty($line) == true) { 
     133                continue; 
     134            } 
     135             
     136            $lineData = explode(' => ', $line); 
     137            $metaData[$lineData[0]] = $lineData[1]; 
     138        } 
     139         
     140        return $metaData; 
    106141    } 
    107142