Exemple #1
0
 /**
  * Creates a new instance of this builder element, with default values.
  */
 public static function create()
 {
     $o = new self();
     $fileset = new Build_BuilderElement_Type_Fileset();
     $fileset->setType(Build_BuilderElement_Type_Fileset::FILE);
     $fileset->setDir('${sourcesDir}');
     $fileset->addInclude('**/*.pl');
     $o->setFilesets(array($fileset));
     return $o;
 }
Exemple #2
0
 /**
  * Creates a new instance of this builder element, with default values.
  */
 public static function create()
 {
     $o = new self();
     $o->setIncludeEmptyDirs(true);
     $fileset = new Build_BuilderElement_Type_Fileset();
     $fileset->setType(Build_BuilderElement_Type_Fileset::BOTH);
     $fileset->setDefaultExcludes(false);
     $o->setFilesets(array($fileset));
     return $o;
 }
Exemple #3
0
 /**
  * Creates a new instance of this builder element, with default values.
  */
 public static function create()
 {
     $o = new self();
     $fileset = new Build_BuilderElement_Type_Fileset();
     $fileset->setType(Build_BuilderElement_Type_Fileset::FILE);
     $fileset->setDir('${sourcesDir}');
     $fileset->addInclude(CINTIENT_TEMP_UNIT_TESTS_DEFAULT_INCLUDE_MATCH);
     $o->setFilesets(array($fileset));
     $o->setLogJunitXmlFile($GLOBALS['project']->getReportsWorkingDir() . CINTIENT_JUNIT_REPORT_FILENAME);
     $o->setCodeCoverageXmlFile($GLOBALS['project']->getReportsWorkingDir() . CINTIENT_CODECOVERAGE_XML_REPORT_FILENAME);
     $o->setCodeCoverageHtmlDir($GLOBALS['project']->getReportsWorkingDir() . CINTIENT_CODECOVERAGE_HTML_DIR);
     return $o;
 }
Exemple #4
0
 public function toPhp(array &$context = array())
 {
     if (!$this->isActive()) {
         return '';
     }
     $php = '';
     if (!$this->getFile() && !$this->getFilesets()) {
         SystemEvent::raise(SystemEvent::ERROR, 'No source files set for task copy.', __METHOD__);
         return false;
     }
     if (!$this->getToFile() && !$this->getToDir()) {
         SystemEvent::raise(SystemEvent::ERROR, 'No destination set for task copy.', __METHOD__);
         return false;
     }
     $php .= "\n\$GLOBALS['result']['task'] = 'copy';\n\$baseToFilename = '';\n";
     if ($this->getToFile()) {
         $php .= "\n\$path = pathinfo(expandStr('{$this->getToFile()}'));\n\$baseToDir = \$path['dirname'];\n\$baseToFilename = '/' . \$path['basename']; // pathinfo's dirname *always* returns the dirname without the trailing slash.\n";
     } elseif ($this->getToDir()) {
         $php .= "\n\$baseToDir = expandStr('{$this->getToDir()}');\n";
     }
     //
     // TODO: Potential bug here. If the following generated mkdir does
     // indeed fail and failOnError == true, the execution will continue
     // because we are not returning true... A return true here would
     // halt the generated script execution (that's what return false does
     // in case of error...)
     //
     // Wrapping this whole element into a generated auto-executing closure
     // a la Javascript would be awesome, because that way we could just
     // force a return and not risk shutting down the whole builder script
     //
     $php .= "\nif (!file_exists(\$baseToDir) && !@mkdir(\$baseToDir, 0755, true)) {\n  output(\"Failed creating dir \$baseToDir.\");\n\tif ({$this->getFailOnError()}) {\n    \$GLOBALS['result']['ok'] = false;\n    return false;\n  } else {\n\t  \$GLOBALS['result']['ok'] = \$GLOBALS['result']['ok'] & true;\n  }\n}";
     //
     // Internally treat $this->getFile() as a fileset.
     //
     $filesets = array();
     if ($this->getFile()) {
         $getFile = self::_expandStr($this->getFile(), $context);
         $pathFrom = pathinfo($getFile);
         $fileset = new Build_BuilderElement_Type_Fileset();
         if (!file_exists($getFile)) {
             $php .= "\noutput(\"No such file or directory {$getFile}.\");\nif ({$this->getFailOnError()}) { // failonerror\n  \$GLOBALS['result']['ok'] = false;\n  return false;\n} else {\n  \$GLOBALS['result']['ok'] = \$GLOBALS['result']['ok'] & true;\n}\n";
         } elseif (is_file($getFile)) {
             $fileset->addInclude($pathFrom['basename']);
             $fileset->setDir($pathFrom['dirname']);
             $fileset->setType(Build_BuilderElement_Type_Fileset::FILE);
             $php .= "\n\$baseFromDir = '{$pathFrom['dirname']}';\n";
         } else {
             // It's a directory
             $fileset->addInclude('**/*');
             $fileset->setDir($getFile);
             $fileset->setType(Build_BuilderElement_Type_Fileset::BOTH);
             // Very important default!!!
             $php .= "\n\$baseFromDir = '{$getFile}';\n";
         }
         $filesets[] = $fileset;
     } elseif ($this->getFilesets()) {
         // If file exists, it takes precedence over filesets
         $realFilesets = $this->getFilesets();
         // Not to be overwritten
         if (!$realFilesets[0]->getDir() || !$realFilesets[0]->getInclude()) {
             SystemEvent::raise(SystemEvent::ERROR, 'No source files set for task copy.', __METHOD__);
             return false;
         }
         // Iterator mode for copy() must enforce parent dirs before their children,
         // so that we can mkdir the parent without first trying to copy in the children
         // on a non-existing dir.
         $fileset = new Build_BuilderElement_Type_Fileset();
         $fileset->setDir(self::_expandStr($realFilesets[0]->getDir(), $context));
         $fileset->setInclude(explode(' ', self::_expandStr(implode(' ', $realFilesets[0]->getInclude()), $context)));
         $fileset->setExclude(explode(' ', self::_expandStr(implode(' ', $realFilesets[0]->getExclude()), $context)));
         $filesets[] = $fileset;
         $php .= "\n\$baseFromDir = '{$fileset->getDir()}';\n";
     }
     $php .= "\n\$callback = function (\$entry) use (\$baseToDir, \$baseFromDir, \$baseToFilename) {\n  \$dest = \$baseToDir . (!empty(\$baseToFilename)?\$baseToFilename:substr(\$entry, strlen(\$baseFromDir)));\n  if (is_file(\$entry)) {\n    \$ret = @copy(\$entry, \$dest);\n  } elseif (is_dir(\$entry)) {\n  \tif (!file_exists(\$dest) && !@mkdir(\$dest, 0755, true)) {\n  \t  \$ret = false;\n  \t} else {\n  \t  \$ret = true;\n    }\n  } else {\n    \$ret = false;\n  }\n  if (!\$ret) {\n    output(\"Failed copy of \$entry to \$dest.\");\n  } else {\n    output(\"Copied \$entry to \$dest.\");\n  }\n  return \$ret;\n};\n";
     $context['iteratorMode'] = RecursiveIteratorIterator::SELF_FIRST;
     // Make sure dirs come before their children, in order to be created first
     foreach ($filesets as $fileset) {
         $php .= "\n" . $fileset->toPhp($context) . "\nif (!fileset{$fileset->getId()}_{$context['id']}(\$callback) && {$this->getFailOnError()}) {\n  \$GLOBALS['result']['ok'] = false;\n  return false;\n} else {\n  \$GLOBALS['result']['ok'] = \$GLOBALS['result']['ok'] & true;\n}\n";
     }
     return $php;
 }
 public function toPhp(array &$context = array())
 {
     if (!$this->isActive()) {
         return true;
     }
     $php = "\n\$GLOBALS['result']['task'] = 'replaceregexp';\n";
     if (empty($this->_filesets) && empty($this->_file)) {
         $msg = 'No files set for task replaceregexp.';
         SystemEvent::raise(SystemEvent::INFO, $msg, __METHOD__);
         $php .= "\noutput('{$msg}');\n\$GLOBALS['result']['ok'] = false;\nreturn false;\n";
         return $php;
     }
     if (empty($this->_match)) {
         $msg = 'Match attribute is mandatory for task replaceregexp.';
         SystemEvent::raise(SystemEvent::INFO, $msg, __METHOD__);
         $php .= "\noutput('{$msg}');\n\$GLOBALS['result']['ok'] = false;\nreturn false;\n";
         return $php;
     }
     if (empty($this->_replace)) {
         $msg = 'Replace attribute is mandatory for task replaceregexp.';
         SystemEvent::raise(SystemEvent::INFO, $msg, __METHOD__);
         $php .= "\noutput('{$msg}');\n\$GLOBALS['result']['ok'] = false;\nreturn false;\n";
         return $php;
     }
     $php .= "\n\$callback = function (\$entry) {\n  \$ret = true;\n  if (is_file(\$entry)) { // ignore anything other than files\n    if (\$fileContent = file_get_contents(\$entry)) {\n      \$replaces = 0;\n    \t\$newContent = preg_replace('/" . preg_replace("(')", "\\'", self::_expandStr(html_entity_decode($this->getMatch(), ENT_QUOTES), $context)) . "/', '" . preg_replace("(')", "\\'", self::_expandStr(html_entity_decode($this->getReplace(), ENT_QUOTES), $context)) . "', \$fileContent, -1, \$replaces); // Let the user know that he must escape singlequotes in the match textfield\n    \tif (\$replaces > 0) {\n    \t\t\$replaces = (\$replaces == 1 ? '' : 'es'); // Ugly code for nice output messages\n    \t\tif (!file_put_contents(\$entry, \$newContent)) {\n    \t\t\toutput(\"Found replaceable match\$replaces, but couldn't update file \$entry.\");\n    \t\t\t\$ret = false;\n    \t  } else {\n    \t    output(\"Replaced match\$replaces in \$entry.\");\n  \t\t\t}\n      } else {\n      \toutput(\"No matches in \$entry.\");\n      }\n    }\n  }\n  return \$ret;\n};\n";
     if ($this->getFile()) {
         $getFile = self::_expandStr($this->getFile(), $context);
         $pathFrom = pathinfo($getFile);
         $fileset = new Build_BuilderElement_Type_Fileset();
         $fileset->addInclude($pathFrom['basename']);
         $fileset->setDir($pathFrom['dirname']);
         $fileset->setType(Build_BuilderElement_Type_Fileset::FILE);
         // If File is set, it takes precedence over any set filesets,
         // for simplification purposes
         $this->setFilesets(array($fileset));
     }
     $filesets = $this->getFilesets();
     foreach ($filesets as $fileset) {
         $php .= "\n" . $fileset->toPhp($context) . "\nif (!fileset{$fileset->getId()}_{$context['id']}(\$callback) && {$this->getFailOnError()}) {\n  \$GLOBALS['result']['ok'] = false;\n  return false;\n} else {\n  \$GLOBALS['result']['ok'] = \$GLOBALS['result']['ok'] & true;\n}\n";
     }
     return $php;
 }