/**
  * Executes the task.
  */
 public function main()
 {
     if ($this->file === null) {
         throw new BuildException('The file attribute must be set');
     }
     $properties = new Properties();
     if ($this->update === true) {
         /* Load existing properties. */
         try {
             $properties->load($this->file);
         } catch (IOException $ioe) {
             /* File doesn't exist or isn't readable, so don't worry here. */
         }
     }
     /* Add new properties. */
     foreach ($this->properties as $property) {
         foreach ($property->resolve()->getProperties() as $name => $value) {
             $properties->setProperty($name, $value);
         }
     }
     $properties->store($this->file, 'Automatically-updated properties file ' . 'generated by the Agavi write-properties task');
 }
Exemplo n.º 2
0
 /**
  * Create the sql -> database map.
  *
  * @throws IOException - if unable to store properties
  */
 private function createSqlDbMap()
 {
     if ($this->getSqlDbMap() === null) {
         return;
     }
     // Produce the sql -> database map
     $sqldbmap = new Properties();
     // Check to see if the sqldbmap has already been created.
     if ($this->getSqlDbMap()->exists()) {
         $sqldbmap->load($this->getSqlDbMap());
     }
     if ($this->packageObjectModel) {
         // in this case we'll get the sql file name from the package attribute
         $dataModels = $this->packageDataModels();
         foreach ($dataModels as $package => $dataModel) {
             foreach ($dataModel->getDatabases() as $database) {
                 $name = ($package ? $package . '.' : '') . 'schema.xml';
                 $sqlFile = $this->getMappedFile($name);
                 $sqldbmap->setProperty($sqlFile->getName(), $database->getName());
             }
         }
     } else {
         // the traditional way is to map the schema.xml filenames
         $dmMap = $this->getDataModelDbMap();
         foreach (array_keys($dmMap) as $dataModelName) {
             $sqlFile = $this->getMappedFile($dataModelName);
             if ($this->getDatabase() === null) {
                 $databaseName = $dmMap[$dataModelName];
             } else {
                 $databaseName = $this->getDatabase();
             }
             $sqldbmap->setProperty($sqlFile->getName(), $databaseName);
         }
     }
     try {
         $sqldbmap->store($this->getSqlDbMap(), "Sqlfile -> Database map");
     } catch (IOException $e) {
         throw new IOException("Unable to store properties: " . $e->getMessage());
     }
 }
Exemplo n.º 3
0
 static function merge($project, $codeCoverageInformation)
 {
     $coverageDatabase = $project->getProperty('coverage.database');
     if (!$coverageDatabase) {
         throw new BuildException("Property coverage.database is not set - please include coverage-setup in your build file");
     }
     $database = new PhingFile($coverageDatabase);
     $props = new Properties();
     $props->load($database);
     $coverageTotal = $codeCoverageInformation;
     foreach ($coverageTotal as $filename => $data) {
         if (version_compare(PHPUnit_Runner_Version::id(), '3.5.0') >= 0) {
             $ignoreLines = PHP_CodeCoverage_Util::getLinesToBeIgnored($filename);
         } else {
             // FIXME retrieve ignored lines for PHPUnit Version < 3.5.0
             $ignoreLines = array();
         }
         $lines = array();
         $filename = strtolower($filename);
         if ($props->getProperty($filename) != null) {
             foreach ($data as $_line => $_data) {
                 if (is_array($_data)) {
                     $count = count($_data);
                 } else {
                     if (isset($ignoreLines[$_line])) {
                         // line is marked as ignored
                         $count = 1;
                     } else {
                         if ($_data == -1) {
                             // not executed
                             $count = -1;
                         } else {
                             if ($_data == -2) {
                                 // dead code
                                 $count = -2;
                             }
                         }
                     }
                 }
                 $lines[$_line] = $count;
             }
             ksort($lines);
             $file = unserialize($props->getProperty($filename));
             $left = $file['coverage'];
             $coverageMerged = CoverageMerger::mergeCodeCoverage($left, $lines);
             $file['coverage'] = $coverageMerged;
             $props->setProperty($filename, serialize($file));
         }
     }
     $props->store($database);
 }
Exemplo n.º 4
0
 /**
  * Create the data XML -> database map.
  *
  * This is necessary because there is currently no other method of knowing which
  * data XML files correspond to which database.  This map allows us to convert multiple
  * data XML files into SQL.
  *
  * @throws IOException - if unable to store properties
  */
 private function createDataDbMap()
 {
     if ($this->getDataDbMap() === null) {
         return;
     }
     // Produce the sql -> database map
     $datadbmap = new Properties();
     // Check to see if the sqldbmap has already been created.
     if ($this->getDataDbMap()->exists()) {
         $datadbmap->load($this->getDataDbMap());
     }
     foreach ($this->getDataModels() as $dataModel) {
         // there is really one 1 db per datamodel
         foreach ($dataModel->getDatabases() as $database) {
             // if database name is specified, then we only want to dump that one db.
             if (empty($this->databaseName) || $this->databaseName && $database->getName() == $this->databaseName) {
                 $outFile = $this->getMappedFile($dataModel->getName());
                 $datadbmap->setProperty($outFile->getName(), $database->getName());
             }
         }
     }
     try {
         $datadbmap->store($this->getDataDbMap(), "Data XML file -> Database map");
     } catch (IOException $e) {
         throw new IOException("Unable to store properties: " . $e->getMessage());
     }
 }
Exemplo n.º 5
0
 function main()
 {
     $files = $this->getFilenames();
     $this->log("Setting up coverage database for " . count($files) . " files");
     $props = new Properties();
     foreach ($files as $file) {
         $fullname = $file['fullname'];
         $filename = $file['key'];
         $props->setProperty($filename, serialize(array('fullname' => $fullname, 'coverage' => array())));
     }
     $dbfile = new PhingFile($this->database);
     $props->store($dbfile);
     $this->project->setProperty('coverage.database', $dbfile->getAbsolutePath());
 }
Exemplo n.º 6
0
 function main()
 {
     $files = $this->getFilenames();
     $this->log("Setting up coverage database for " . count($files) . " files");
     $props = new Properties();
     foreach ($files as $file) {
         $fullname = $file['fullname'];
         $filename = $file['key'];
         $props->setProperty($filename, serialize(array('fullname' => $fullname, 'coverage' => array())));
     }
     $dbfile = new PhingFile($this->database);
     $props->store($dbfile);
     $this->project->setProperty('coverage.database', $dbfile->getAbsolutePath());
     foreach ($files as $file) {
         $fullname = $file['fullname'];
         xdebug_start_code_coverage(XDEBUG_CC_UNUSED);
         Phing::__import($fullname, $this->classpath);
         $coverage = xdebug_get_code_coverage();
         xdebug_stop_code_coverage();
         CoverageMerger::merge($this->project, array($coverage));
     }
 }
Exemplo n.º 7
0
 static function merge($project, $codeCoverageInformation)
 {
     $database = new PhingFile($project->getProperty('coverage.database'));
     $props = new Properties();
     $props->load($database);
     $coverageTotal = $codeCoverageInformation;
     foreach ($coverageTotal as $coverage) {
         foreach ($coverage as $filename => $coverageFile) {
             $filename = strtolower($filename);
             if ($props->getProperty($filename) != null) {
                 $file = unserialize($props->getProperty($filename));
                 $left = $file['coverage'];
                 $right = $coverageFile;
                 if (!is_array($right)) {
                     $right = array_shift(PHPUnit_Util_CodeCoverage::bitStringToCodeCoverage(array($right), 1));
                 }
                 $coverageMerged = CoverageMerger::mergeCodeCoverage($left, $right);
                 foreach ($coverageMerged as $key => $value) {
                     if ($value == -2) {
                         unset($coverageMerged[$key]);
                     }
                 }
                 $file['coverage'] = $coverageMerged;
                 $props->setProperty($filename, serialize($file));
             }
         }
     }
     $props->store($database);
 }
Exemplo n.º 8
0
 /**
  * Main method parses the XML files and creates SQL files.
  *
  * @return void
  * @throws Exception If there is an error parsing the data xml.
  */
 public function main()
 {
     $this->validate();
     $targetDatabase = $this->getTargetDatabase();
     $platform = $this->getPlatformForTargetDatabase();
     // Load the Data XML -> DB Name properties
     $map = new Properties();
     try {
         $map->load($this->getDataDbMap());
     } catch (IOException $ioe) {
         throw new BuildException("Cannot open and process the datadbmap!", $ioe);
     }
     DataModelBuilder::setBuildProperties($this->getPropelProperties());
     // Parse each file in teh data -> db map
     foreach ($map->keys() as $dataXMLFilename) {
         $dataXMLFile = new PhingFile($this->srcDir, $dataXMLFilename);
         // if file exists then proceed
         if ($dataXMLFile->exists()) {
             $dbname = $map->get($dataXMLFilename);
             $db = $this->getDatabase($dbname);
             if (!$db) {
                 throw new BuildException("Cannot find instantiated Database for name '{$dbname}' from datadbmap file.");
             }
             $db->setPlatform($platform);
             $outFile = $this->getMappedFile($dataXMLFilename);
             $this->log("Creating SQL from XML data dump file: " . $dataXMLFile->getAbsolutePath());
             try {
                 $dataXmlParser = new XmlToData($db, $this->dbEncoding);
                 $data = $dataXmlParser->parseFile($dataXMLFile->getAbsolutePath());
             } catch (Exception $e) {
                 throw new Exception("Exception parsing data XML: " . $e->getMessage());
             }
             $fp = fopen($outFile->getAbsolutePath(), 'w');
             $currTable = null;
             foreach ($data as $dataRow) {
                 if ($currTable !== $dataRow->getTable()) {
                     $currTable = $dataRow->getTable();
                     $builder = DataModelBuilder::builderFactory($currTable, 'datasql');
                 }
                 $sql = $builder->buildRowSql($dataRow);
                 fwrite($fp, $sql);
             }
             fclose($fp);
             // Place the generated SQL file(s)
             $p = new Properties();
             if ($this->getSqlDbMap()->exists()) {
                 $p->load($this->getSqlDbMap());
             }
             $p->setProperty($outFile->getName(), $db->getName());
             $p->store($this->getSqlDbMap(), "Sqlfile -> Database map");
         } else {
             $this->log("File '" . $dataXMLFile->getAbsolutePath() . "' in datadbmap does not exist, so skipping it.", PROJECT_MSG_WARN);
         }
     }
     // foreach data xml file
 }
 /**
  * Main method parses the XML files and creates SQL files.
  *
  * @return void
  * @throws Exception      If there is an error parsing the data xml.
  * @throws BuildException
  */
 public function main()
 {
     $this->validate();
     $targetDatabase = $this->getTargetDatabase();
     $platform = $this->getGeneratorConfig()->getConfiguredPlatform();
     // Load the Data XML -> DB Name properties
     $map = new Properties();
     try {
         $map->load($this->getDataDbMap());
     } catch (IOException $ioe) {
         throw new BuildException("Cannot open and process the datadbmap!", $ioe);
     }
     // Parse each file in the data -> db map
     foreach ($map->keys() as $dataXMLFilename) {
         $dataXMLFile = new PhingFile($this->srcDir, $dataXMLFilename);
         // if file exists then proceed
         if ($dataXMLFile->exists()) {
             $dbname = $map->get($dataXMLFilename);
             $db = $this->getDatabase($dbname);
             if (!$db) {
                 throw new BuildException("Cannot find instantiated Database for name '{$dbname}' from datadbmap file.");
             }
             $db->setPlatform($platform);
             $outFile = $this->getMappedFile($dataXMLFilename);
             $sqlWriter = new FileWriter($outFile);
             $this->log("Creating SQL from XML data dump file: " . $dataXMLFile->getAbsolutePath());
             try {
                 $dataXmlParser = new XmlToDataSQL($db, $this->getGeneratorConfig(), $this->dbEncoding);
                 $dataXmlParser->transform($dataXMLFile, $sqlWriter);
             } catch (Exception $e) {
                 throw new BuildException("Exception parsing data XML: " . $e->getMessage(), $x);
             }
             // Place the generated SQL file(s)
             $p = new Properties();
             if ($this->getSqlDbMap()->exists()) {
                 $p->load($this->getSqlDbMap());
             }
             $p->setProperty($outFile->getName(), $db->getName());
             $p->store($this->getSqlDbMap(), "Sqlfile -> Database map");
         } else {
             $this->log("File '" . $dataXMLFile->getAbsolutePath() . "' in datadbmap does not exist, so skipping it.", Project::MSG_WARN);
         }
     }
     // foreach data xml file
 }
Exemplo n.º 10
0
 static function merge($project, $codeCoverageInformation)
 {
     $coverageDatabase = $project->getProperty('coverage.database');
     if (!$coverageDatabase) {
         throw new BuildException("Property coverage.database is not set - please include coverage-setup in your build file");
     }
     $database = new PhingFile($coverageDatabase);
     $props = new Properties();
     $props->load($database);
     $coverageTotal = $codeCoverageInformation;
     foreach ($coverageTotal as $filename => $data) {
         $lines = array();
         $filename = strtolower($filename);
         if ($props->getProperty($filename) != null) {
             foreach ($data as $_line => $_data) {
                 if (is_array($_data)) {
                     $count = count($_data);
                 } else {
                     if ($_data == -1) {
                         // not executed
                         $count = -1;
                     } else {
                         if ($_data == -2) {
                             // dead code
                             $count = -2;
                         }
                     }
                 }
                 $lines[$_line] = $count;
             }
             ksort($lines);
             $file = unserialize($props->getProperty($filename));
             $left = $file['coverage'];
             $coverageMerged = CoverageMerger::mergeCodeCoverage($left, $lines);
             $file['coverage'] = $coverageMerged;
             $props->setProperty($filename, serialize($file));
         }
     }
     $props->store($database);
 }
Exemplo n.º 11
0
 static function merge($project, $codeCoverageInformation)
 {
     $database = new PhingFile($project->getProperty('coverage.database'));
     $props = new Properties();
     $props->load($database);
     $coverageTotal = $codeCoverageInformation;
     foreach ($coverageTotal as $coverage) {
         foreach ($coverage as $filename => $coverageFile) {
             $filename = strtolower($filename);
             if ($props->getProperty($filename) != null) {
                 $file = unserialize($props->getProperty($filename));
                 $left = $file['coverage'];
                 $right = $coverageFile;
                 $coverageMerged = CoverageMerger::mergeCodeCoverage($left, $right);
                 $file['coverage'] = $coverageMerged;
                 $props->setProperty($filename, serialize($file));
             }
         }
     }
     $props->store($database);
 }
Exemplo n.º 12
0
 function main()
 {
     /**
      * Whitelist files when using PHPUnit > 3.5
      */
     @(include_once 'PHPUnit/Runner/Version.php');
     if (version_compare(PHPUnit_Runner_Version::id(), '3.5.0') >= 0) {
         $newFilter = true;
     } else {
         $newFilter = false;
         @(include_once 'PHPUnit/Util/Filter.php');
     }
     $files = $this->getFilenames();
     $this->log("Setting up coverage database for " . count($files) . " files");
     $props = new Properties();
     foreach ($files as $file) {
         $fullname = $file['fullname'];
         $filename = $file['key'];
         $props->setProperty($filename, serialize(array('fullname' => $fullname, 'coverage' => array())));
         if ($newFilter) {
             PHP_CodeCoverage_Filter::getInstance()->addFileToWhiteList($file['fullname']);
         } else {
             PHPUnit_Util_Filter::addFileToWhitelist($file['fullname']);
         }
     }
     $dbfile = new PhingFile($this->database);
     $props->store($dbfile);
     $this->project->setProperty('coverage.database', $dbfile->getAbsolutePath());
 }