private function setOptions($pkg)
 {
     $options['baseinstalldir'] = 'phing';
     $options['packagedirectory'] = $this->dir->getAbsolutePath();
     if (empty($this->filesets)) {
         throw new BuildException("You must use a <fileset> tag to specify the files to include in the package.xml");
     }
     $options['filelistgenerator'] = 'Fileset';
     // Some PHING-specific options needed by our Fileset reader
     $options['phing_project'] = $this->getProject();
     $options['phing_filesets'] = $this->filesets;
     if ($this->packageFile !== null) {
         // create one w/ full path
         $f = new PhingFile($this->packageFile->getAbsolutePath());
         $options['packagefile'] = $f->getName();
         // must end in trailing slash
         $options['outputdirectory'] = $f->getParent() . DIRECTORY_SEPARATOR;
         $this->log("Creating package file: " . $f->getPath(), Project::MSG_INFO);
     } else {
         $this->log("Creating [default] package.xml file in base directory.", Project::MSG_INFO);
     }
     if ($this->mode == "docs") {
         $options['dir_roles'] = array('phing_guide' => 'doc', 'api' => 'doc', 'example' => 'doc');
     } else {
         // add install exceptions
         $options['installexceptions'] = array('bin/phing.php' => '/', 'bin/pear-phing' => '/', 'bin/pear-phing.bat' => '/');
         $options['dir_roles'] = array('etc' => 'data');
         $options['exceptions'] = array('bin/pear-phing.bat' => 'script', 'bin/pear-phing' => 'script', 'CREDITS' => 'doc', 'CHANGELOG' => 'doc', 'README' => 'doc', 'UPGRADE' => 'doc', 'TODO' => 'doc');
     }
     $pkg->setOptions($options);
 }
 protected function doApply()
 {
     $dataDir = $this->dataDir->getAbsolutePath();
     $htmlDir = $this->htmlDir->getAbsolutePath();
     define('HTML_REALDIR', rtrim(realpath($htmlDir), '/\\') . '/');
     require_once HTML_REALDIR . '/define.php';
     require_once HTML_REALDIR . HTML2DATA_DIR . '/require_base.php';
     $query = SC_Query_Ex::getSingletonInstance();
     $storage = new Zeclib_DefaultMigrationStorage($query, $this->system);
     $storage->versionTable = $this->versionTable;
     $storage->containerDirectories[] = $this->containerDir->getPath();
     $migrator = new Zeclib_Migrator($storage, $query);
     $migrator->logger = new Zeclib_Phing_TaskMigrationLogger($this);
     $migrations = array();
     $versions = preg_split('/[,\\s]+/', $this->version, 0, PREG_SPLIT_NO_EMPTY);
     foreach ($versions as $version) {
         try {
             $migrations[] = $migrator->loadMigration($version);
         } catch (Zeclib_MigrationException $e) {
             $message = $e->getMessage();
             $this->log($message, Zeclib_MigrationLogger::TYPE_WARNING);
         }
     }
     $num = $migrator->apply($migrations);
     $this->log(sprintf('%d migrations are applied.', $num));
 }
Example #3
0
 public function setDir(PhingFile $dir)
 {
     if (!$dir->exists()) {
         throw new BuildException("Can not find asset directory: " . $dir->getAbsolutePath(), $this->location);
     }
     $this->assetDir = $dir->getAbsolutePath();
 }
 public function main()
 {
     if (empty($this->filesets)) {
         throw new BuildException("You must specify a file or fileset(s).");
     }
     if (empty($this->_compilePath)) {
         throw new BuildException("You must specify location for compiled templates.");
     }
     date_default_timezone_set("America/New_York");
     $project = $this->getProject();
     $this->_count = $this->_total = 0;
     $smartyCompilePath = new PhingFile($this->_compilePath);
     if (!$smartyCompilePath->exists()) {
         $this->log("Compile directory does not exist, creating: " . $smartyCompilePath->getPath(), Project::MSG_VERBOSE);
         if (!$smartyCompilePath->mkdirs()) {
             throw new BuildException("Error creating compile path for Smarty in " . $this->_compilePath);
         }
     }
     $this->_smarty = new Smarty();
     $this->_smarty->use_sub_dirs = true;
     $this->_smarty->compile_dir = $smartyCompilePath;
     $this->_smarty->plugins_dir[] = $this->_pluginsPath;
     $this->_smarty->force_compile = $this->_forceCompile;
     // process filesets
     foreach ($this->filesets as $fs) {
         $ds = $fs->getDirectoryScanner($project);
         $fromDir = $fs->getDir($project);
         $srcFiles = $ds->getIncludedFiles();
         $this->_compile($fromDir, $srcFiles);
     }
     $this->log("Compiled " . $this->_count . " out of " . $this->_total . " Smarty templates");
 }
Example #5
0
 /**
  * Returns the stream with an additional linebreak.
  *
  * @return the resulting stream, or -1
  *         if the end of the resulting stream has been reached
  *
  * @throws IOException if the underlying stream throws an IOException
  *                        during reading
  */
 function read($len = null)
 {
     if ($this->processed === true) {
         return -1;
         // EOF
     }
     // Read
     $php = null;
     while (($buffer = $this->in->read($len)) !== -1) {
         $php .= $buffer;
     }
     if ($php === null) {
         // EOF?
         return -1;
     }
     if (empty($php)) {
         $this->log("File is empty!", Project::MSG_WARN);
         return '';
         // return empty string
     }
     // write buffer to a temporary file, since php_strip_whitespace() needs a filename
     $file = new PhingFile(tempnam(PhingFile::getTempDir(), 'stripwhitespace'));
     file_put_contents($file->getAbsolutePath(), $php);
     $output = file_get_contents($file->getAbsolutePath()) . "\r\n";
     unlink($file->getAbsolutePath());
     $this->processed = true;
     return $output;
 }
 /**
  * Uses a builder class to create the output class.
  * This method assumes that the DataModelBuilder class has been initialized with the build properties.
  *
  * @param OMBuilder $builder
  * @param boolean   $overwrite Whether to overwrite existing files with te new ones (default is YES).
  *
  * @todo       -cPropelOMTask Consider refactoring build() method into AbstractPropelDataModelTask (would need to be more generic).
  * @return int
  */
 protected function build(OMBuilder $builder, $overwrite = true)
 {
     $path = $builder->getClassFilePath();
     $this->ensureDirExists(dirname($path));
     $_f = new PhingFile($this->getOutputDirectory(), $path);
     // skip files already created once
     if ($_f->exists() && !$overwrite) {
         $this->log("\t-> (exists) " . $builder->getClassFilePath(), Project::MSG_VERBOSE);
         return 0;
     }
     $script = $builder->build();
     foreach ($builder->getWarnings() as $warning) {
         $this->log($warning, Project::MSG_WARN);
     }
     // skip unchanged files
     if ($_f->exists() && $script == $_f->contents()) {
         $this->log("\t-> (unchanged) " . $builder->getClassFilePath(), Project::MSG_VERBOSE);
         return 0;
     }
     // write / overwrite new / changed files
     $action = $_f->exists() ? 'Updating' : 'Creating';
     $this->log(sprintf("\t-> %s %s (table: %s, builder: %s)", $action, $builder->getClassFilePath(), $builder->getTable()->getName(), get_class($builder)));
     file_put_contents($_f->getAbsolutePath(), $script);
     return 1;
 }
 /**
  * This test is our selection test that compared the file with the destfile.
  *
  * @param PhingFile $srcfile the source file
  * @param PhingFile $destfile the destination file
  * @return bool true if the files are different
  *
  * @throws BuildException
  */
 protected function selectionTest(PhingFile $srcfile, PhingFile $destfile)
 {
     try {
         // if either of them is missing, they are different
         if ($srcfile->exists() !== $destfile->exists()) {
             return true;
         }
         if ($srcfile->length() !== $destfile->length()) {
             // different size => different files
             return true;
         }
         if (!$this->ignoreFileTimes) {
             // different dates => different files
             if ($destfile->lastModified() !== $srcfile->lastModified()) {
                 return true;
             }
         }
         if (!$this->ignoreContents) {
             //here do a bulk comparison
             $fu = new FileUtils();
             return !$fu->contentEquals($srcfile, $destfile);
         }
     } catch (IOException $e) {
         throw new BuildException("while comparing {$srcfile} and {$destfile}", $e);
     }
     return false;
 }
 public function main()
 {
     $plugin = $this->plugin->getAbsolutePath();
     $infoFile = $plugin . '/' . self::INFO_FILE;
     if (!file_exists($infoFile)) {
         $message = sprintf('Unable to read plugin_info.php file at "%s"', $plugin);
         throw new BuildException($message);
     }
     require_once $infoFile;
     $class = new ReflectionClass('plugin_info');
     try {
         $value = $class->getStaticPropertyValue($this->key);
     } catch (Exception $e) {
         $message = sprintf('Unable to read property with "%s"', $this->key);
         throw new BuildException($message, $e);
     }
     if (!is_string($value) && !is_int($value) && !is_float($value)) {
         $value = json_encode($value);
     }
     if ($this->to != '') {
         $this->project->setProperty($this->to, $value);
     } else {
         $this->log($value);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function parseFile(PhingFile $file)
 {
     if (!$file->canRead()) {
         throw new IOException("Unable to read file: " . $file);
     }
     try {
         // We load the Yaml class without the use of namespaces to prevent
         // parse errors in PHP 5.2.
         $parserClass = '\\Symfony\\Component\\Yaml\\Parser';
         $parser = new $parserClass();
         // Cast properties to array in case parse() returns null.
         $properties = (array) $parser->parse(file_get_contents($file->getAbsolutePath()));
     } catch (Exception $e) {
         if (is_a($e, '\\Symfony\\Component\\Yaml\\Exception\\ParseException')) {
             throw new IOException("Unable to parse contents of " . $file . ": " . $e->getMessage());
         }
         throw $e;
     }
     $flattenedProperties = $this->flattenArray($properties);
     foreach ($flattenedProperties as $key => $flattenedProperty) {
         if (is_array($flattenedProperty)) {
             $flattenedProperties[$key] = implode(',', $flattenedProperty);
         }
     }
     return $flattenedProperties;
 }
 private function setOptions($pkg)
 {
     $options['baseinstalldir'] = 'propel';
     $options['packagedirectory'] = $this->dir->getAbsolutePath();
     if (empty($this->filesets)) {
         throw new BuildException("You must use a <fileset> tag to specify the files to include in the package.xml");
     }
     $options['filelistgenerator'] = 'Fileset';
     // Some PHING-specific options needed by our Fileset reader
     $options['phing_project'] = $this->getProject();
     $options['phing_filesets'] = $this->filesets;
     if ($this->packageFile !== null) {
         // create one w/ full path
         $f = new PhingFile($this->packageFile->getAbsolutePath());
         $options['packagefile'] = $f->getName();
         // must end in trailing slash
         $options['outputdirectory'] = $f->getParent() . DIRECTORY_SEPARATOR;
         $this->log("Creating package file: " . $f->getPath(), Project::MSG_INFO);
     } else {
         $this->log("Creating [default] package.xml file in base directory.", Project::MSG_INFO);
     }
     // add install exceptions
     $options['installexceptions'] = array('pear/pear-propel-gen' => '/', 'pear/pear-propel-gen.bat' => '/', 'pear/pear-build.xml' => '/', 'pear/build.properties' => '/');
     $options['dir_roles'] = array('projects' => 'data', 'test' => 'test', 'templates' => 'data', 'resources' => 'data');
     $options['exceptions'] = array('pear/pear-propel-gen.bat' => 'script', 'pear/pear-propel-gen' => 'script', 'pear/pear-build.xml' => 'data', 'build.xml' => 'data', 'build-propel.xml' => 'data');
     $pkg->setOptions($options);
 }
Example #11
0
    /**
     *
     */
    public function parseFile($xmlFile)
    {
        try {

            $this->data = array();
			
            try {
                $fr = new FileReader($xmlFile);
            } catch (Exception $e) {
                $f = new PhingFile($xmlFile);
                throw new BuildException("XML File not found: " . $f->getAbsolutePath());
            }

            $br = new BufferedReader($fr);

            $this->parser = new ExpatParser($br);
            $this->parser->parserSetOption(XML_OPTION_CASE_FOLDING, 0);
            $this->parser->setHandler($this);

            try {
                $this->parser->parse();
            } catch (Exception $e) {
                print $e->getMessage() . "\n";
                $br->close();
            }
            $br->close();
        } catch (Exception $e) {
            print $e->getMessage() . "\n";
            print $e->getTraceAsString();
        }

        return $this->data;
    }
 /**
  * Constructs a new ProjectConfigurator object
  * This constructor is private. Use a static call to
  * <code>configureProject</code> to configure a project.
  *
  * @param  Project $project     the Project instance this configurator should use
  * @param  PhingFile $buildFile the buildfile object the parser should use
  */
 public function __construct(Project $project, PhingFile $buildFile)
 {
     $this->project = $project;
     $this->buildFile = new PhingFile($buildFile->getAbsolutePath());
     $this->buildFileParent = new PhingFile($this->buildFile->getParent());
     $this->parseEndTarget = new Target();
 }
Example #13
0
 private function createDirectories($path)
 {
     $f = new PhingFile($path);
     if (!$f->exists()) {
         $f->mkdirs();
     }
 }
 /**
  * Sets output directory
  * @param string $toDir
  */
 public function setToDir($toDir)
 {
     if (!is_dir($toDir)) {
         $toDir = new PhingFile($toDir);
         $toDir->mkdirs();
     }
     $this->toDir = $toDir;
 }
 public function testCorrectModeSet()
 {
     $this->executeTarget("test");
     $dir = new PhingFile(PHING_TEST_BASE . "/etc/regression/745/testdir");
     $mode = $dir->getMode() & 511;
     $this->assertEquals($mode, 511);
     $dir->delete(true);
 }
 /**
  * Load properties from a file.
  *
  * @param PhingFile $file
  * @return void
  * @throws IOException - if unable to read file.
  */
 function load(PhingFile $file)
 {
     if ($file->canRead()) {
         $this->parse($file->getPath(), false);
     } else {
         throw new IOException("Can not read file " . $file->getPath());
     }
 }
 function copyFile(PhingFile $sourceFile, PhingFile $destFile, $overwrite = false, $preserveLastModified = true, &$filterChains = null, Project $project)
 {
     // writes to tmp file first, then rename it to avoid file locking race
     // conditions
     $parent = $destFile->getParentFile();
     $tmpFile = new PhingFile($parent, substr(md5(time()), 0, 8));
     parent::copyFile($sourceFile, $tmpFile, $overwrite, $preserveLastModified, $filterChains, $project);
     $tmpFile->renameTo($destFile);
 }
Example #18
0
 /**
  * Copied from 'CopyTask.php'
  */
 protected function doWork()
 {
     // These "slots" allow filters to retrieve information about the currently-being-process files
     $fromSlot = $this->getRegisterSlot("currentFromFile");
     $fromBasenameSlot = $this->getRegisterSlot("currentFromFile.basename");
     $toSlot = $this->getRegisterSlot("currentToFile");
     $toBasenameSlot = $this->getRegisterSlot("currentToFile.basename");
     $mapSize = count($this->fileCopyMap);
     $total = $mapSize;
     if ($mapSize > 0) {
         $this->log("Minifying " . $mapSize . " file" . ($mapSize === 1 ? '' : 's') . " to " . $this->destDir->getAbsolutePath());
         // walks the map and actually copies the files
         $count = 0;
         foreach ($this->fileCopyMap as $from => $to) {
             if ($from === $to) {
                 $this->log("Skipping self-copy of " . $from, $this->verbosity);
                 $total--;
                 continue;
             }
             $this->log("From " . $from . " to " . $to, $this->verbosity);
             try {
                 // try to copy file
                 $fromFile = new PhingFile($from);
                 $toFile = new PhingFile($to);
                 $fromSlot->setValue($fromFile->getPath());
                 $fromBasenameSlot->setValue($fromFile->getName());
                 $toSlot->setValue($toFile->getPath());
                 $toBasenameSlot->setValue($toFile->getName());
                 $this->fileUtils->copyFile($fromFile, $toFile, $this->overwrite, $this->preserveLMT, $this->filterChains, $this->getProject());
                 // perform ''minification'' once all other things are done on it.
                 $this->minify($toFile);
                 $count++;
             } catch (IOException $ioe) {
                 $this->log("Failed to minify " . $from . " to " . $to . ": " . $ioe->getMessage(), Project::MSG_ERR);
             }
         }
     }
     // handle empty dirs if appropriate
     if ($this->includeEmpty) {
         $destdirs = array_values($this->dirCopyMap);
         $count = 0;
         foreach ($destdirs as $destdir) {
             $d = new PhingFile((string) $destdir);
             if (!$d->exists()) {
                 if (!$d->mkdirs()) {
                     $this->log("Unable to create directory " . $d->__toString(), Project::MSG_ERR);
                 } else {
                     $count++;
                 }
             }
         }
         if ($count > 0) {
             $this->log("Copied " . $count . " empty director" . ($count == 1 ? "y" : "ies") . " to " . $this->destDir->getAbsolutePath());
         }
     }
 }
Example #19
0
 /**
  * List archive content
  * @param PhingFile Zip file to list content
  * @return array List of files inside $zipfile
  */
 protected function listArchiveContent(PhingFile $zipfile)
 {
     $zip = new ZipArchive();
     $zip->open($zipfile->getAbsolutePath());
     $content = array();
     for ($i = 0; $i < $zip->numFiles; $i++) {
         $content[] = array('filename' => $zip->getNameIndex($i));
     }
     return $content;
 }
 public function testFlipFlopTarget()
 {
     // calls target in main that depends on target in import that depends on
     // target orverridden in main
     $this->executeTarget("flipflop");
     $f1 = new PhingFile(PHING_TEST_BASE . "/etc/tasks/importing.xml");
     $f2 = new PhingFile(PHING_TEST_BASE . "/etc/tasks/imports/imported.xml");
     $this->assertInLogs("This is " . $f1->getAbsolutePath() . " flop target.");
     $this->assertInLogs("This is " . $f2->getAbsolutePath() . " flip target.");
     $this->assertInLogs("This is " . $f1->getAbsolutePath() . " flipflop target.");
 }
 /**
  * Wrapper for PHPCPD 2.0
  *
  * @param CodeCloneMap   $clones
  * @param boolean        $useFile
  * @param PhingFile|null $outFile
  */
 private function processClonesNew($clones, $useFile = false, $outFile = null)
 {
     if ($useFile) {
         $resource = fopen($outFile->getPath(), "w");
     } else {
         $resource = fopen("php://output", "w");
     }
     $output = new \Symfony\Component\Console\Output\StreamOutput($resource);
     $logger = new \SebastianBergmann\PHPCPD\Log\Text();
     $logger->printResult($output, $clones);
 }
 /**
  * Execute this task.
  *
  * @throws BuildException on error
  */
 public function main()
 {
     if ($this->property == null) {
         throw new BuildException("property attribute required", $this->getLocation());
     }
     if ($this->file == null) {
         throw new BuildException("file attribute required", $this->getLocation());
     } else {
         $value = $this->file->getAbsoluteFile()->getParent();
         $this->getProject()->setNewProperty($this->property, $value);
     }
 }
 /**
  * Evaluate the condition.
  */
 public function evaluate()
 {
     foreach ($this->filelists as $filelist) {
         $dir = $filelist->getDir($this->getProject());
         foreach ($filelist->getFiles($this->getProject()) as $file) {
             $file = new PhingFile($dir, $file);
             if (!$file->exists()) {
                 return FALSE;
             }
         }
     }
     return TRUE;
 }
Example #24
0
 /**
  * Reading a file.
  * 
  * Read a file and strip the fisrt line contains php tag.
  * 
  * @param  PhingFile $file The file to read
  * @return string
  * @access protected
  **/
 protected function _readFile(PhingFile $file)
 {
     $content = file($file->getPath(), FILE_IGNORE_NEW_LINES);
     while (list($k, $v) = each($content)) {
         $pos = mb_strpos($v, '<?php', $this->getToEncoding());
         if (false !== $pos) {
             $this->log(sprintf('PHP tag found at line %s column %s', $k + 1, ++$pos), $this->getVerbose());
             unset($content[$k]);
             break;
         }
     }
     unset($k, $v, $pos);
     return implode($this->getEol(), $content);
 }
Example #25
0
 /**
  * Init a Archive_Tar class with correct compression for the given file.
  *
  * @param PhingFile $tarfile
  * @return Archive_Tar the tar class instance
  */
 private function initTar(PhingFile $tarfile)
 {
     $compression = null;
     $tarfileName = $tarfile->getName();
     $mode = strtolower(substr($tarfileName, strrpos($tarfileName, '.')));
     $compressions = array('gz' => array('.gz', '.tgz'), 'bz2' => array('.bz2'));
     foreach ($compressions as $algo => $ext) {
         if (array_search($mode, $ext) !== false) {
             $compression = $algo;
             break;
         }
     }
     return new Archive_Tar($tarfile->getAbsolutePath(), $compression);
 }
Example #26
0
 /**
  * Iterate over all filesets and return all the filenames.
  *
  * @return array an array of filenames
  */
 private function getFilenames()
 {
     $files = array();
     foreach ($this->filesets as $fileset) {
         $ds = $fileset->getDirectoryScanner($this->project);
         $ds->scan();
         $includedFiles = $ds->getIncludedFiles();
         foreach ($includedFiles as $file) {
             $fs = new PhingFile(basename($ds->getBaseDir()), $file);
             $files[] = $fs->getAbsolutePath();
         }
     }
     return $files;
 }
 protected function destroyDatabase()
 {
     $dataDir = $this->dataDir->getAbsolutePath();
     $htmlDir = $this->htmlDir->getAbsolutePath();
     define('HTML_REALDIR', rtrim(realpath($htmlDir), '/\\') . '/');
     require_once HTML_REALDIR . '/define.php';
     require_once HTML_REALDIR . HTML2DATA_DIR . '/require_base.php';
     $query = SC_Query_Ex::getSingletonInstance();
     $mdb2 = $query->conn;
     $mdb2->loadModule('Manager');
     $result = $mdb2->dropTable($this->versionTable);
     if (PEAR::isError($result)) {
         throw new BuildException($result->getMessage());
     }
 }
 /**
  * Evaluate the selector with the file.
  * @return true if the file is selected by the embedded selector.
  */
 public function evaluate()
 {
     if ($this->file === null) {
         throw new BuildException('file attribute not set');
     }
     $this->validate();
     $myBaseDir = $this->baseDir;
     if ($myBaseDir === null) {
         $myBaseDir = $this->getProject()->getBaseDir();
     }
     /** @var FileSelector $f */
     $file = $this->getSelectors($this->getProject());
     $f = $file[0];
     return $f->isSelected($myBaseDir, $this->file->getName(), $this->file);
 }
 /**
  * Processes a list of clones.
  *
  * @param PHPCPD_CloneMap $clones
  */
 public function processClones(PHPCPD_CloneMap $clones, PhingFile $outfile, Project $project)
 {
     $logger = new PHPCPD_TextUI_ResultPrinter();
     // default format goes to logs, no buffering
     ob_start();
     $logger->printResult($clones, $project->getBaseDir());
     $output = ob_get_contents();
     ob_end_clean();
     if (!$this->usefile) {
         echo $output;
     } else {
         $outputFile = $outfile->getPath();
         file_put_contents($outputFile, $output);
     }
 }
Example #30
0
 /**
  * Uses a builder class to create the output class.
  * This method assumes that the DataModelBuilder class has been initialized with the build properties.
  * @param      OMBuilder $builder
  * @param      boolean $overwrite Whether to overwrite existing files with te new ones (default is YES).
  * @todo       -cPropelOMTask Consider refactoring build() method into AbstractPropelDataModelTask (would need to be more generic).
  */
 protected function build(OMBuilder $builder, $overwrite = true)
 {
     $path = $builder->getClassFilePath();
     $this->ensureDirExists(dirname($path));
     $_f = new PhingFile($this->getOutputDirectory(), $path);
     if ($overwrite || !$_f->exists()) {
         $this->log("\t\t-> " . $builder->getClassname() . " [builder: " . get_class($builder) . "]");
         $script = $builder->build();
         file_put_contents($_f->getAbsolutePath(), $script);
         foreach ($builder->getWarnings() as $warning) {
             $this->log($warning, Project::MSG_WARN);
         }
     } else {
         $this->log("\t\t-> (exists) " . $builder->getClassname());
     }
 }