/**
  * 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);
 }
 /**
  * @throws BuildException
  */
 public function main()
 {
     $this->checkPreconditions();
     try {
         $this->log('Building archive: ' . $this->destinationFile->__toString(), Project::MSG_INFO);
         /**
          * Delete old archive, if exists.
          */
         if ($this->destinationFile->exists()) {
             $isDeleted = $this->destinationFile->delete();
             if (!$isDeleted) {
                 $this->log("Could not delete destination file {$this->destinationFile}", Project::MSG_WARN);
             }
         }
         $pharData = new PharData($this->baseDirectory->getPath() . '/' . $this->destinationFile->getName());
         foreach ($this->filesets as $fileset) {
             $this->log('Adding specified files in ' . $fileset->getDir($this->project) . ' to archive', Project::MSG_VERBOSE);
             $pharData->buildFromIterator($fileset->getIterator(), $fileset->getDir($this->project));
         }
         if ($this->compression !== PHAR::NONE && $pharData->canCompress($this->compression)) {
             try {
                 $pharData->compress($this->compression);
             } catch (UnexpectedValueException $uve) {
                 $pharData->compressFiles($this->compression);
             }
             unset($pharData);
         }
     } catch (Exception $e) {
         throw new BuildException('Problem creating archive: ' . $e->getMessage(), $e, $this->getLocation());
     }
 }
 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);
 }
 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);
 }
Example #5
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 #6
0
 /**
  * do the work
  * @throws BuildException if required attributes are not supplied
  *                        property and attribute are required attributes
  */
 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());
     }
     $value = $this->file->getName();
     if ($this->suffix != null && StringHelper::endsWith($this->suffix, $value)) {
         // if the suffix does not starts with a '.' and the
         // char preceding the suffix is a '.', we assume the user
         // wants to remove the '.' as well
         $pos = strlen($value) - strlen($this->suffix) - 1;
         if ($pos > 0 && $this->suffix[0] !== '.' && $value[$pos] === '.') {
             $pos--;
         }
         $value = StringHelper::substring($value, 0, $pos);
     }
     $this->getProject()->setNewProperty($this->property, $value);
 }
Example #7
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 #8
0
 private function setOptions($pkg)
 {
     $options = array();
     $options['baseinstalldir'] = 'spindash';
     $options['packagedirectory'] = $this->dir->getAbsolutePath();
     $options['filelistgenerator'] = 'Fileset';
     $options['phing_project'] = $this->getProject();
     $options['phing_filesets'] = $this->filesets;
     if (!is_null($this->packageFile)) {
         $f = new PhingFile($this->packageFile->getAbsolutePath());
         $options['packagefile'] = $f->getName();
         $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);
     }
     $pkg->setOptions($options);
 }
 /**
  * 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 = substr($tarfileName, strrpos($tarfileName, '.'));
     switch ($mode) {
         case '.gz':
             $compression = 'gz';
             break;
         case '.bz2':
             $compression = 'bz2';
             break;
         case '.tar':
             break;
         default:
             $this->log('Ignoring unknown compression mode: ' . $mode, PROJECT_MSG_WARN);
     }
     return new Archive_Tar($tarfile->getAbsolutePath(), $compression);
 }
 /**
  * The heart of the matter. This is where the selector gets to decide
  * on the inclusion of a file in a particular fileset.
  *
  * @param PhingFile $basedir the base directory the scan is being done from
  * @param string $filename is the name of the file to check
  * @param PhingFile $file is a java.io.File object the selector can use
  *
  * @return bool whether the file should be selected or not
  *
  * @throws BuildException
  */
 public function isSelected(PhingFile $basedir, $filename, PhingFile $file)
 {
     // throw BuildException on error
     $this->validate();
     // Determine file whose out-of-dateness is to be checked
     $destfiles = $this->map->main($filename);
     // If filename does not match the To attribute of the mapper
     // then filter it out of the files we are considering
     if (empty($destfiles)) {
         return false;
     }
     // Sanity check
     if (count($destfiles) !== 1 || $destfiles[0] === null) {
         throw new BuildException('Invalid destination file results for ' . $this->targetdir->getName() . ' with filename ' . $filename);
     }
     $destname = $destfiles[0];
     $fu = new FileUtils();
     $destfile = $fu->resolveFile($this->targetdir, $destname);
     return $this->selectionTest($file, $destfile);
 }
 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);
     }
     $pkg->setOptions($options);
 }
 public function setFile(PhingFile $file)
 {
     $this->setDir($file->getParentFile());
     $this->createInclude()->setName($file->getName());
 }
Example #13
0
 /**
  * Main method builds all the targets for a typical propel project.
  */
 public function main()
 {
     // check to make sure task received all correct params
     $this->validate();
     $generatorConfig = $this->getGeneratorConfig();
     // loading model from database
     $this->log('Reading databases structure...');
     $connections = $generatorConfig->getBuildConnections();
     if (!$connections) {
         throw new Exception('You must define database connection settings in a buildtime-conf.xml file to use diff');
     }
     $totalNbTables = 0;
     $ad = new AppData();
     foreach ($connections as $name => $params) {
         $this->log(sprintf('Connecting to database "%s" using DSN "%s"', $name, $params['dsn']), Project::MSG_VERBOSE);
         $pdo = $generatorConfig->getBuildPDO($name);
         $database = new Database($name);
         $platform = $generatorConfig->getConfiguredPlatform($pdo);
         $database->setPlatform($platform);
         $database->setDefaultIdMethod(IDMethod::NATIVE);
         $parser = $generatorConfig->getConfiguredSchemaParser($pdo);
         $nbTables = $parser->parse($database, $this);
         $ad->addDatabase($database);
         $totalNbTables += $nbTables;
         $this->log(sprintf('%d tables imported from database "%s"', $nbTables, $name), Project::MSG_VERBOSE);
     }
     if ($totalNbTables) {
         $this->log(sprintf('%d tables imported from databases.', $totalNbTables));
     } else {
         $this->log('Database is empty');
     }
     // loading model from XML
     $this->packageObjectModel = true;
     $appDatasFromXml = $this->getDataModels();
     $appDataFromXml = array_pop($appDatasFromXml);
     // comparing models
     $this->log('Comparing models...');
     $manager = new PropelMigrationManager();
     $manager->setConnections($connections);
     $manager->setMigrationDir($this->getOutputDirectory());
     $migrationsUp = array();
     $migrationsDown = array();
     foreach ($ad->getDatabases() as $database) {
         $name = $database->getName();
         $this->log(sprintf('Comparing database "%s"', $name), Project::MSG_VERBOSE);
         if (!$appDataFromXml->hasDatabase($name)) {
             // FIXME: tables present in database but not in XML
             continue;
         }
         $databaseDiff = PropelDatabaseComparator::computeDiff($database, $appDataFromXml->getDatabase($name), $this->isCaseInsensitive());
         if (!$databaseDiff) {
             $this->log(sprintf('Same XML and database structures for datasource "%s" - no diff to generate', $name), Project::MSG_VERBOSE);
             continue;
         }
         $this->log(sprintf('Structure of database was modified in datasource "%s": %s', $name, $databaseDiff->getDescription()));
         $platform = $generatorConfig->getConfiguredPlatform(null, $name);
         $migrationsUp[$name] = $platform->getModifyDatabaseDDL($databaseDiff);
         $migrationsDown[$name] = $platform->getModifyDatabaseDDL($databaseDiff->getReverseDiff());
     }
     if (!$migrationsUp) {
         $this->log('Same XML and database structures for all datasource - no diff to generate');
         return;
     }
     $timestamp = time();
     $migrationFileName = $manager->getMigrationFileName($timestamp);
     $migrationClassBody = $manager->getMigrationClassBody($migrationsUp, $migrationsDown, $timestamp);
     $_f = new PhingFile($this->getOutputDirectory(), $migrationFileName);
     file_put_contents($_f->getAbsolutePath(), $migrationClassBody);
     $this->log(sprintf('"%s" file successfully created in %s', $_f->getName(), $_f->getParent()));
     if ($editorCmd = $this->getEditorCmd()) {
         $this->log(sprintf('Using "%s" as text editor', $editorCmd));
         shell_exec($editorCmd . ' ' . escapeshellarg($_f->getAbsolutePath()));
     } else {
         $this->log('  Please review the generated SQL statements, and add data migration code if necessary.');
         $this->log('  Once the migration class is valid, call the "migrate" task to execute it.');
     }
 }
 /**
  * Executes the task.
  */
 public function main()
 {
     if ($this->property === null) {
         throw new BuildException('The property attribute must be specified');
     }
     if ($this->path === null) {
         throw new BuildException('The path attribute must be specified');
     }
     if ($this->ignoreIfSet && $this->project->getProperty($this->property) !== null) {
         return;
     }
     if (!$this->path->exists()) {
         throw new BuildException('The path ' . $this->path->getAbsolutePath() . ' does not exist');
     }
     $this->path = $this->path->getAbsoluteFile();
     if (!$this->path->isDirectory()) {
         $this->path = $this->path->getParentFile();
     }
     /* Check if the current directory is a project directory. */
     $check = new AgaviModuleFilesystemCheck();
     $check->setConfigDirectory($this->project->getProperty('module.directory.config'));
     $check->setPath($this->path->getAbsolutePath());
     if ($check->check()) {
         /* The current path is the project directory. */
         $this->log('Module base directory: ' . $this->path);
         $this->project->setUserProperty($this->property, $this->path->getName());
         return;
     }
     /* Check if "actions", "views", "templates", or "config" are in the current path. */
     if (preg_match(sprintf('#^(.+?)/(?:%s|%s|%s|%s)(?:/|$)#', $this->project->getProperty('module.directory.actions'), $this->project->getProperty('module.directory.views'), $this->project->getProperty('module.directory.templates'), $this->project->getProperty('module.directory.config')), $this->path->getPath(), $matches)) {
         $directory = new PhingFile($matches[1]);
         $check->setPath($directory->getAbsolutePath());
         if ($check->check()) {
             $this->log('Module base directory: ' . $directory);
             $this->project->setUserProperty($this->property, $directory->getName());
             return;
         }
     }
     /* Last chance: recurse upward and check for a project directory. */
     $directory = $this->path;
     while (($directory = $directory->getParentFile()) !== null) {
         $check->setPath($directory->getAbsolutePath());
         if ($check->check()) {
             $this->log('Module base directory: ' . $directory);
             $this->project->setUserProperty($this->property, $directory->getName());
             return;
         }
     }
 }
Example #15
0
 /**
  * Sets the options on the passed-in phpdoc setup object.
  * @param PhingPhpDocumentorSetup $phpdoc
  */
 protected function setPhpDocumentorOptions(PhingPhpDocumentorSetup $phpdoc)
 {
     // Title MUST be set first ... (because it re-initializes the internal state of the PhpDocu renderer)
     if ($this->title) {
         $phpdoc->setTitle($this->title);
     }
     if ($this->parsePrivate) {
         $phpdoc->setParsePrivate();
     }
     if ($this->javadocDesc) {
         $phpdoc->setJavadocDesc();
     }
     if ($this->quiet) {
         $phpdoc->setQuietMode();
     }
     if ($this->destdir) {
         $phpdoc->setTargetDir($this->destdir->getAbsolutePath());
     }
     if ($this->packages) {
         $phpdoc->setPackageOutput($this->packages);
     }
     if ($this->templateBase) {
         $phpdoc->setTemplateBase($this->templateBase->getAbsolutePath());
     }
     if ($this->linksource) {
         $phpdoc->setGenerateSourcecode($this->linksource);
     }
     if ($this->examplesDir) {
         $phpdoc->setExamplesDir($this->examplesDir->getAbsolutePath());
     }
     if ($this->ignoreTags) {
         $phpdoc->setIgnoreTags($this->ignoreTags);
     }
     if ($this->defaultPackageName) {
         $phpdoc->setDefaultPackageName($this->defaultPackageName);
     }
     if ($this->defaultCategoryName) {
         $phpdoc->setDefaultCategoryName($this->defaultCategoryName);
     }
     if ($this->pear) {
         $phpdoc->setPear($this->pear);
     }
     if ($this->ignore) {
         $phpdoc->setIgnore($this->ignore);
     }
     // append any files in filesets
     $filesToParse = array();
     foreach ($this->filesets as $fs) {
         $files = $fs->getDirectoryScanner($this->project)->getIncludedFiles();
         foreach ($files as $filename) {
             $f = new PhingFile($fs->getDir($this->project), $filename);
             $filesToParse[] = $f->getAbsolutePath();
         }
     }
     //print_r(implode(",", $filesToParse));
     $phpdoc->setFilesToParse(implode(",", $filesToParse));
     // append any files in filesets
     $ricFiles = array();
     foreach ($this->projDocFilesets as $fs) {
         $files = $fs->getDirectoryScanner($this->project)->getIncludedFiles();
         foreach ($files as $filename) {
             $f = new PhingFile($fs->getDir($this->project), $filename);
             $ricFiles[] = $f->getName();
         }
     }
     $phpdoc->setRicFiles($ricFiles);
     if ($this->undocumentedelements) {
         $phpdoc->setUndocumentedelements($this->undocumentedelements);
     }
     if ($this->customtags) {
         $phpdoc->setCustomtags($this->customtags);
     }
 }
Example #16
0
 private function copyToSingleDestination($from, $to, $fromSlot, $fromBasenameSlot, $toSlot, $toBasenameSlot, &$count, &$total)
 {
     if ($from === $to) {
         $this->log("Skipping self-copy of " . $from, $this->verbosity);
         $total--;
         return;
     }
     $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(), $this->mode, $this->preservePermissions);
         $count++;
     } catch (IOException $ioe) {
         $this->logError("Failed to copy " . $from . " to " . $to . ": " . $ioe->getMessage());
     }
 }
Example #17
0
 /**
  * @param PhingFile $f
  * @return int
  */
 public function getBooleanAttributes($f)
 {
     //$rv = getBooleanAttributes0($f);
     $name = $f->getName();
     $hidden = strlen($name) > 0 && $name[0] == '.';
     return $hidden ? $this->BA_HIDDEN : 0;
 }
Example #18
0
 /**
  * Actually copies the files
  *
  * @access  private
  * @return  void
  * @throws  BuildException
  */
 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;
     // handle empty dirs if appropriate
     if ($this->includeEmpty) {
         $count = 0;
         foreach ($this->dirCopyMap as $srcdir => $destdir) {
             $s = new PhingFile((string) $srcdir);
             $d = new PhingFile((string) $destdir);
             if (!$d->exists()) {
                 // Setting source directory permissions to target
                 // (On permissions preservation, the target directory permissions
                 // will be inherited from the source directory, otherwise the 'mode'
                 // will be used)
                 $dirMode = $this->preservePermissions ? $s->getMode() : $this->mode;
                 // Directory creation with specific permission mode
                 if (!$d->mkdirs($dirMode)) {
                     $this->logError("Unable to create directory " . $d->__toString());
                 } else {
                     if ($this->preserveLMT) {
                         $d->setLastModified($s->lastModified());
                     }
                     $count++;
                 }
             }
         }
         if ($count > 0) {
             $this->log("Created " . $count . " empty director" . ($count == 1 ? "y" : "ies") . " in " . $this->destDir->getAbsolutePath());
         }
     }
     if ($mapSize > 0) {
         $this->log("Copying " . $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(), $this->mode, $this->preservePermissions);
                 $count++;
             } catch (IOException $ioe) {
                 $this->logError("Failed to copy " . $from . " to " . $to . ": " . $ioe->getMessage());
             }
         }
     }
 }
Example #19
0
 /**
  * Adds the options that are set via attributes and the nested tags to the options array.
  */
 private function populateOptions()
 {
     // These values could be overridden if explicitly defined using nested tags
     $this->preparedOptions['package'] = $this->package;
     $this->preparedOptions['packagedirectory'] = $this->dir->getAbsolutePath();
     if ($this->packageFile !== null) {
         // create one w/ full path
         $f = new PhingFile($this->packageFile->getAbsolutePath());
         $this->preparedOptions['packagefile'] = $f->getName();
         // must end in trailing slash
         $this->preparedOptions['outputdirectory'] = $f->getParent() . DIRECTORY_SEPARATOR;
         $this->log("Creating package file: " . $f->__toString(), Project::MSG_INFO);
     } else {
         $this->log("Creating [default] package.xml file in base directory.", Project::MSG_INFO);
     }
     // converts option objects and mapping objects into
     // key => value options that can be passed to PEAR_PackageFileManager
     foreach ($this->options as $opt) {
         $this->preparedOptions[$opt->getName()] = $opt->getValue();
         //no arrays yet. preg_split('/\s*,\s*/', $opt->getValue());
     }
     foreach ($this->mappings as $map) {
         $value = $map->getValue();
         // getValue returns complex value
         if ($map->getName() == 'deps') {
             $value = $this->fixDeps($value);
         }
         $this->preparedOptions[$map->getName()] = $value;
     }
 }
Example #20
0
 /**
  * Parse a Phing build file and copy the properties, tasks, data types and 
  * targets it defines into the current project.
  *
  * @return void
  */
 public function main()
 {
     if (!isset($this->file)) {
         throw new BuildException("Missing attribute 'file'");
     }
     $file = new PhingFile($this->file);
     if (!$file->isAbsolute()) {
         $file = new PhingFile($this->project->getBasedir(), $this->file);
     }
     if (!$file->exists()) {
         $msg = "Unable to find build file: {$file->getPath()}";
         if ($this->optional) {
             $this->log($msg . '... skipped');
             return;
         } else {
             throw new BuildException($msg);
         }
     }
     $ctx = $this->project->getReference("phing.parsing.context");
     $cfg = $ctx->getConfigurator();
     if (null !== $cfg && $cfg->isParsing()) {
         // because there isn't a top level implicit target in phing like there is
         // in Ant 1.6, we will be called as soon as our xml is parsed. This isn't
         // really what we want to have happen. Instead we will register ourself
         // with the parse context to be called at the end of the current file's
         // parse phase.
         $cfg->delayTaskUntilParseEnd($this);
     } else {
         // Import xml file into current project scope
         // Since this is delayed until after the importing file has been
         // processed, the properties and targets of this new file may not take
         // effect if they have alreday been defined in the outer scope.
         $this->log("Importing configuration from {$file->getName()}", Project::MSG_VERBOSE);
         ProjectConfigurator::configureProject($this->project, $file);
         $this->log("Configuration imported.", Project::MSG_VERBOSE);
     }
 }
 /**
  * Gets all matching XML schema files and loads them into data models for class.
  * @return     void
  */
 protected function loadDataModels()
 {
     $ads = array();
     // Get all matched files from schemaFilesets
     foreach ($this->schemaFilesets as $fs) {
         $ds = $fs->getDirectoryScanner($this->project);
         $srcDir = $fs->getDir($this->project);
         $dataModelFiles = $ds->getIncludedFiles();
         $platform = $this->getGeneratorConfig()->getConfiguredPlatform();
         // Make a transaction for each file
         foreach ($dataModelFiles as $dmFilename) {
             $this->log("Processing: " . $dmFilename);
             $xmlFile = new PhingFile($srcDir, $dmFilename);
             $dom = new DomDocument('1.0', 'UTF-8');
             $dom->load($xmlFile->getAbsolutePath());
             // normalize (or transform) the XML document using XSLT
             if ($this->xslFile) {
                 $this->log("Transforming " . $xmlFile->getPath() . " using stylesheet " . $this->xslFile->getPath(), Project::MSG_VERBOSE);
                 if (!class_exists('XSLTProcessor')) {
                     $this->log("Could not perform XLST transformation.  Make sure PHP has been compiled/configured to support XSLT.", Project::MSG_ERR);
                 } else {
                     // modify schema to include any external schema's (and remove the external-schema nodes)
                     $this->includeExternalSchemas($dom, $srcDir);
                     // normalize the document using normalizer stylesheet
                     $xsl = new XsltProcessor();
                     $xsl->importStyleSheet(DomDocument::load($this->xslFile->getAbsolutePath()));
                     $transformed = $xsl->transformToDoc($dom);
                     $newXmlFilename = substr($xmlFile->getName(), 0, strrpos($xmlFile->getName(), '.')) . '-transformed.xml';
                     // now overwrite previous vars to point to newly transformed file
                     $xmlFile = new PhingFile($srcDir, $newXmlFilename);
                     $transformed->save($xmlFile->getAbsolutePath());
                     $this->log("\t- Using new (post-transformation) XML file: " . $xmlFile->getPath(), Project::MSG_VERBOSE);
                     $dom = new DomDocument('1.0', 'UTF-8');
                     $dom->load($xmlFile->getAbsolutePath());
                 }
             }
             // validate the XML document using XSD schema
             if ($this->validate && $this->xsdFile) {
                 $this->log("Validating XML doc (" . $xmlFile->getPath() . ") using schema file " . $this->xsdFile->getPath(), Project::MSG_VERBOSE);
                 if (!$dom->schemaValidate($this->xsdFile->getAbsolutePath())) {
                     throw new EngineException("XML schema file (" . $xmlFile->getPath() . ") does not validate. See warnings above for reasons validation failed (make sure error_reporting is set to show E_WARNING if you don't see any).", $this->getLocation());
                 }
             }
             $xmlParser = new XmlToAppData($platform, $this->getTargetPackage(), $this->dbEncoding);
             $ad = $xmlParser->parseFile($xmlFile->getAbsolutePath());
             $ad->setName($dmFilename);
             // <-- Important: use the original name, not the -transformed name.
             $ads[] = $ad;
         }
     }
     if (empty($ads)) {
         throw new BuildException("No schema files were found (matching your schema fileset definition).");
     }
     if (!$this->packageObjectModel) {
         $this->dataModels = $ads;
         $this->databaseNames = array();
         // doesn't seem to be used anywhere
         $this->dataModelDbMap = array();
         // Different datamodels may state the same database
         // names, we just want the unique names of databases.
         foreach ($this->dataModels as $dm) {
             $database = $dm->getDatabase();
             $this->dataModelDbMap[$dm->getName()] = $database->getName();
             $this->databaseNames[$database->getName()] = $database->getName();
             // making list of *unique* dbnames.
         }
     } else {
         $this->joinDatamodels($ads);
         $this->dataModels[0]->getDatabases();
         // calls doFinalInitialization()
     }
     $this->dataModelsLoaded = true;
 }
 /**
  * The mapper implementation. Returns string with source filename
  * but without leading directory information
  *
  * @param  string $sourceFileName The data the mapper works on
  *
  * @return array  The data after the mapper has been applied
  */
 public function main($sourceFileName)
 {
     $f = new PhingFile($sourceFileName);
     return array($f->getName());
 }