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");
 }
 /**
  * Set the sqldbmap.
  * @param      PhingFile $sqldbmap The db map.
  */
 public function setOutputDirectory(PhingFile $out)
 {
     if (!$out->exists()) {
         $out->mkdirs();
     }
     $this->outDir = $out;
 }
Example #3
0
 public function main()
 {
     /**
      * Find PHPLoc
      */
     if (!@(include_once 'SebastianBergmann/PHPLOC/Analyser.php')) {
         throw new BuildException('PHPLocTask depends on PHPLoc being installed ' . 'and on include_path.', $this->getLocation());
     }
     $this->_validateProperties();
     if (!is_null($this->reportDirectory) && !is_dir($this->reportDirectory)) {
         $reportOutputDir = new PhingFile($this->reportDirectory);
         $logMessage = "Report output directory doesn't exist, creating: " . $reportOutputDir->getAbsolutePath() . '.';
         $this->log($logMessage);
         $reportOutputDir->mkdirs();
     }
     if ($this->reportType !== 'cli') {
         $this->reportFileName .= '.' . trim($this->reportType);
     }
     if (count($this->fileSets) > 0) {
         $project = $this->getProject();
         foreach ($this->fileSets as $fileSet) {
             $directoryScanner = $fileSet->getDirectoryScanner($project);
             $files = $directoryScanner->getIncludedFiles();
             $directory = $fileSet->getDir($this->project)->getPath();
             foreach ($files as $file) {
                 if ($this->isFileSuffixSet($file)) {
                     $this->filesToCheck[] = $directory . DIRECTORY_SEPARATOR . $file;
                 }
             }
         }
         $this->filesToCheck = array_unique($this->filesToCheck);
     }
     $this->runPhpLocCheck();
 }
Example #4
0
 public function setTmpDir(PhingFile $dir)
 {
     if (!$dir->exists()) {
         $dir->mkdirs();
     }
     $this->tmpDir = $dir->getAbsolutePath();
 }
Example #5
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;
 }
Example #7
0
 /**
  * Utility method to create directory for package if it doesn't already exist.
  * @param      string $path The [relative] package path.
  * @throws     BuildException - if there is an error creating directories
  */
 protected function ensureDirExists($path)
 {
     $f = new PhingFile($this->getOutputDirectory(), $path);
     if (!$f->exists()) {
         if (!$f->mkdirs()) {
             throw new BuildException("Error creating directories: " . $f->getPath());
         }
     }
 }
Example #8
0
 /**
  * create the directory and all parents
  *
  * @throws BuildException if dir is somehow invalid, or creation failed.
  */
 public function main()
 {
     if ($this->dir === null) {
         throw new BuildException("dir attribute is required", $this->location);
     }
     if ($this->dir->isFile()) {
         throw new BuildException("Unable to create directory as a file already exists with that name: " . $this->dir->getAbsolutePath());
     }
     if (!$this->dir->exists()) {
         $result = $this->dir->mkdirs($this->mode);
         if (!$result) {
             if ($this->dir->exists()) {
                 $this->log("A different process or task has already created " . $this->dir->getAbsolutePath());
                 return;
             }
             $msg = "Directory " . $this->dir->getAbsolutePath() . " creation was not successful for an unknown reason";
             throw new BuildException($msg, $this->location);
         }
         $this->log("Created dir: " . $this->dir->getAbsolutePath());
     }
 }
 /**
  * [REQUIRED] Set the output directory. It will be
  * created if it doesn't exist.
  * @param  PhingFile $outputDirectory
  * @return void
  * @throws Exception
  */
 public function setOutputDirectory(PhingFile $outputDirectory)
 {
     try {
         if (!$outputDirectory->exists()) {
             $this->log("Output directory does not exist, creating: " . $outputDirectory->getPath(), Project::MSG_VERBOSE);
             if (!$outputDirectory->mkdirs()) {
                 throw new IOException("Unable to create Ouptut directory: " . $outputDirectory->getAbsolutePath());
             }
         }
         $this->outputDirectory = $outputDirectory->getCanonicalPath();
     } catch (IOException $ioe) {
         throw new BuildException($ioe);
     }
 }
    /**
     * @return void
     */
    public function main()
    {
        $this->_checkTargetDir();

        /* @var $fileSet FileSet */
        foreach ($this->_fileSets as $fileSet) {

            $files = $fileSet->getDirectoryScanner($this->project)
                ->getIncludedFiles();

            foreach ($files as $file) {

                $targetDir = new PhingFile($this->_targetDir, dirname($file));
                if (!$targetDir->exists()) {
                    $targetDir->mkdirs();
                }
                unset ($targetDir);

                $source = new PhingFile(
                    $fileSet->getDir($this->project),
                    $file
                );
                $target = new PhingFile(
                    $this->_targetDir,
                    str_replace('.less', '.css', $file)
                );

                $this->log("Processing ${file}");
                try {
                    $lessc = new lessc($source->getAbsolutePath());
                    file_put_contents(
                        $target->getAbsolutePath(),
                        $lessc->parse()
                    );
                } catch (Exception $e) {
                    $this->log("Failed processing ${file}!", Project::MSG_ERR);
                    $this->log($e->getMessage(), Project::MSG_DEBUG);
                }

            }

        }
    }
 private function transform(DOMDocument $document)
 {
     $dir = new PhingFile($this->toDir);
     if (!$dir->exists() && !$dir->mkdirs()) {
         throw new BuildException("Unable to create '" . $this->toDir . "'");
     }
     $xslfile = $this->getStyleSheet();
     $xsl = new DOMDocument();
     $xsl->load($xslfile->getAbsolutePath());
     $proc = new XSLTProcessor();
     $proc->importStyleSheet($xsl);
     if ($this->format == "noframes") {
         $writer = new FileWriter(new PhingFile($this->toDir, "checkstyle-noframes.html"));
         $writer->write($proc->transformToXML($document));
         $writer->close();
     } else {
         ExtendedFileStream::registerStream();
         // no output for the framed report
         // it's all done by extension...
         $dir = new PhingFile($this->toDir);
         $proc->setParameter('', 'output.dir', $dir->getAbsolutePath());
         $proc->transformToXML($document);
     }
 }
Example #12
0
 /**
  * @throws BuildException
  */
 private function validateProperties()
 {
     if ($this->fileToCheck === null && count($this->fileSets) === 0) {
         throw new BuildException('Missing either a nested fileset or the attribute "file" set.');
     }
     if ($this->fileToCheck !== null) {
         if (!file_exists($this->fileToCheck)) {
             throw new BuildException("File to check doesn't exist.");
         }
         if (!$this->isFileSuffixSet($this->fileToCheck)) {
             throw new BuildException('Suffix of file to check is not defined in "suffixes" attribute.');
         }
         if (count($this->fileSets) > 0) {
             throw new BuildException('Either use a nested fileset or "file" attribute; not both.');
         }
     }
     if (count($this->suffixesToCheck) === 0) {
         throw new BuildException('No file suffix defined.');
     }
     if (count($this->formatterElements) == 0) {
         if ($this->reportType === null) {
             throw new BuildException('No report type or formatters defined.');
         }
         if ($this->reportType !== null && !in_array($this->reportType, $this->acceptedReportTypes)) {
             throw new BuildException('Unaccepted report type defined.');
         }
         if ($this->reportType !== 'cli' && $this->reportDirectory === null) {
             throw new BuildException('No report output directory defined.');
         }
         if ($this->reportDirectory !== null && !is_dir($this->reportDirectory)) {
             $reportOutputDir = new PhingFile($this->reportDirectory);
             $logMessage = "Report output directory doesn't exist, creating: " . $reportOutputDir->getAbsolutePath() . '.';
             $this->log($logMessage);
             $reportOutputDir->mkdirs();
         }
         if ($this->reportType !== 'cli') {
             $this->reportFileName .= '.' . $this->reportType;
         }
         $formatterElement = new PHPLocFormatterElement();
         $formatterElement->setType($this->reportType);
         $formatterElement->setUseFile($this->reportDirectory !== null);
         $formatterElement->setToDir($this->reportDirectory);
         $formatterElement->setOutfile($this->reportFileName);
         $this->formatterElements[] = $formatterElement;
     }
 }
 public function main()
 {
     $this->loadDependencies();
     $this->validateProperties();
     if ($this->reportDirectory !== null && !is_dir($this->reportDirectory)) {
         $reportOutputDir = new PhingFile($this->reportDirectory);
         $logMessage = "Report output directory doesn't exist, creating: " . $reportOutputDir->getAbsolutePath() . '.';
         $this->log($logMessage);
         $reportOutputDir->mkdirs();
     }
     if ($this->reportType !== 'cli') {
         $this->reportFileName .= '.' . $this->reportType;
     }
     if (count($this->fileSets) > 0) {
         foreach ($this->fileSets as $fileSet) {
             $directoryScanner = $fileSet->getDirectoryScanner($this->project);
             $files = $directoryScanner->getIncludedFiles();
             $directory = $fileSet->getDir($this->project)->getPath();
             foreach ($files as $file) {
                 if ($this->isFileSuffixSet($file)) {
                     $this->filesToCheck[] = $directory . DIRECTORY_SEPARATOR . $file;
                 }
             }
         }
         $this->filesToCheck = array_unique($this->filesToCheck);
     }
     $this->runPhpLocCheck();
 }
Example #14
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 #15
0
 /**
  * Execute the input script with Velocity
  *
  * @throws BuildException
  *                        BuildExceptions are thrown when required attributes are missing.
  *                        Exceptions thrown by Velocity are rethrown as BuildExceptions.
  */
 public function main()
 {
     // Make sure the template path is set.
     if (empty($this->templatePath)) {
         throw new BuildException("The template path needs to be defined!");
     }
     // Make sure the control template is set.
     if ($this->controlTemplate === null) {
         throw new BuildException("The control template needs to be defined!");
     }
     // Make sure the output directory is set.
     if ($this->outputDirectory === null) {
         throw new BuildException("The output directory needs to be defined!");
     }
     // Make sure there is an output file.
     if ($this->outputFile === null) {
         throw new BuildException("The output file needs to be defined!");
     }
     // Setup Smarty runtime.
     // Smarty uses one object to store properties and to store
     // the context for the template (unlike Velocity).  We setup this object, calling it
     // $this->context, and then initControlContext simply zeros out
     // any assigned variables.
     //
     // Use the smarty backwards compatibility layer if existent.
     if (class_exists('SmartyBC')) {
         $this->context = new SmartyBC();
     } else {
         $this->context = new Smarty();
     }
     if ($this->compilePath !== null) {
         $this->log("Using compilePath: " . $this->compilePath);
         $this->context->compile_dir = $this->compilePath;
     }
     if ($this->configPath !== null) {
         $this->log("Using configPath: " . $this->configPath);
         $this->context->config_dir = $this->configPath;
     }
     if ($this->forceCompile !== null) {
         $this->context->force_compile = $this->forceCompile;
     }
     if ($this->leftDelimiter !== null) {
         $this->context->left_delimiter = $this->leftDelimiter;
     }
     if ($this->rightDelimiter !== null) {
         $this->context->right_delimiter = $this->rightDelimiter;
     }
     if ($this->templatePath !== null) {
         $this->log("Using templatePath: " . $this->templatePath);
         $this->context->template_dir = $this->templatePath;
     }
     $smartyCompilePath = new PhingFile($this->context->compile_dir);
     if (!$smartyCompilePath->exists()) {
         $this->log("Compile directory does not exist, creating: " . $smartyCompilePath->getPath(), Project::MSG_VERBOSE);
         if (!$smartyCompilePath->mkdirs()) {
             throw new BuildException("Smarty needs a place to compile templates; specify a 'compilePath' or create " . $this->context->compile_dir);
         }
     }
     // Make sure the output directory exists, if it doesn't
     // then create it.
     $file = new PhingFile($this->outputDirectory);
     if (!$file->exists()) {
         $this->log("Output directory does not exist, creating: " . $file->getAbsolutePath());
         $file->mkdirs();
     }
     $path = $this->outputDirectory . DIRECTORY_SEPARATOR . $this->outputFile;
     $this->log("Generating to file " . $path);
     $writer = new FileWriter($path);
     // The generator and the output path should
     // be placed in the init context here and
     // not in the generator class itself.
     $c = $this->initControlContext();
     // Set any variables that need to always
     // be loaded
     $this->populateInitialContext($c);
     // Feed all the options into the initial
     // control context so they are available
     // in the control/worker templates.
     if ($this->contextProperties !== null) {
         foreach ($this->contextProperties->keys() as $property) {
             $value = $this->contextProperties->getProperty($property);
             // Special exception (from Texen)
             // for properties ending in file.contents:
             // in that case we dump the contents of the file
             // as the "value" for the Property.
             if (StringHelper::endsWith("file.contents", $property)) {
                 // pull in contents of file specified
                 $property = substr($property, 0, strpos($property, "file.contents") - 1);
                 // reset value, and then
                 // read in teh contents of the file into that var
                 $value = "";
                 $f = new PhingFile($this->project->resolveFile($value)->getCanonicalPath());
                 if ($f->exists()) {
                     try {
                         $fr = new FileReader($f);
                         $fr->readInto($value);
                     } catch (Exception $e) {
                         throw $e;
                     }
                 }
             }
             // if ends with file.contents
             if (StringHelper::isBoolean($value)) {
                 $value = StringHelper::booleanValue($value);
             }
             $c->assign($property, $value);
         }
         // foreach property
     }
     // if contextProperties !== null
     try {
         //$c->display($this->controlTemplate);
         $writer->write($c->fetch($this->controlTemplate));
         $writer->close();
     } catch (IOException $ioe) {
         $writer->close();
         throw new BuildException("Cannot write parsed template.");
     }
     $this->cleanup();
 }
    /**
     * @return void
     */
    public function main()
    {
        $this->_checkJarPath();
        $this->_checkTargetDir();

        /* @var $fileSet FileSet */
        foreach ($this->_fileSets as $fileSet) {

            $files = $fileSet->getDirectoryScanner($this->project)
                ->getIncludedFiles();

            foreach ($files as $file) {

                $targetDir = new PhingFile($this->_targetDir, dirname($file));
                if (!$targetDir->exists()) {
                    $targetDir->mkdirs();
                }
                unset ($targetDir);

                $source = new PhingFile($fileSet->getDir($this->project), $file);
                $target = new PhingFile($this->_targetDir, $file);

                $this->log("Processing ${file}");
                $cmd = escapeshellcmd($this->_javaPath)
                    . ' -jar ' . escapeshellarg($this->_jarPath)
                    . ' -o ' . escapeshellarg($target->getAbsolutePath())
                    . ' ' . escapeshellarg($source->getAbsolutePath());
                $this->log('Executing: ' . $cmd, Project::MSG_DEBUG);
                @exec($cmd, $output, $return);

                if ($return !== 0) {
                    $this->log("Failed processing ${file}!", Project::MSG_ERR);
                }
            }
        }
    }
Example #17
0
 /**
  * Actually copies the files
  *
  * @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) {
         return;
     }
     $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 => $toFiles) {
         if (is_array($toFiles)) {
             foreach ($toFiles as $to) {
                 $this->copyToSingleDestination($from, $to, $fromSlot, $fromBasenameSlot, $toSlot, $toBasenameSlot, $count, $total);
             }
         } else {
             $this->copyToSingleDestination($from, $toFiles, $fromSlot, $fromBasenameSlot, $toSlot, $toBasenameSlot, $count, $total);
         }
     }
 }
Example #18
0
 protected function doWork()
 {
     if (count($this->completeDirMap) > 0) {
         foreach ($this->completeDirMap as $from => $to) {
             $f = new PhingFile($from);
             $d = new PhingFile($to);
             $moved = false;
             try {
                 // try to rename
                 $this->log("Attempting to rename {$from} to {$to}", $this->verbosity);
                 $this->fileUtils->copyFile($f, $d, $this->forceOverwrite, $this->preserveLMT, $this->filterChains, $this->getProject(), $this->mode);
                 $f->delete(true);
                 $moved = true;
             } catch (IOException $ioe) {
                 $moved = false;
                 $this->log("Failed to rename {$from} to {$to}: " . $ioe->getMessage(), $this->verbosity);
             }
         }
     }
     $copyMapSize = count($this->fileCopyMap);
     if ($copyMapSize > 0) {
         // files to move
         $this->log("Moving {$copyMapSize} files to " . $this->destDir->getAbsolutePath());
         foreach ($this->fileCopyMap as $from => $to) {
             if ($from == $to) {
                 $this->log("Skipping self-move of {$from}", $this->verbosity);
                 continue;
             }
             $f = new PhingFile($from);
             $d = new PhingFile($to);
             try {
                 // try to move
                 $this->log("Moving {$from} to {$to}", $this->verbosity);
                 $this->fileUtils->copyFile($f, $d, $this->forceOverwrite, $this->preserveLMT, $this->filterChains, $this->getProject(), $this->mode);
                 $f->delete();
             } catch (IOException $ioe) {
                 $msg = "Failed to move {$from} to {$to}: " . $ioe->getMessage();
                 throw new BuildException($msg, $this->location);
             }
         }
         // foreach fileCopyMap
     }
     // if copyMapSize
     // handle empty dirs if appropriate
     if ($this->includeEmpty) {
         $e = array_keys($this->dirCopyMap);
         $count = 0;
         foreach ($e as $dir) {
             $d = new PhingFile((string) $dir);
             if (!$d->exists()) {
                 if (!$d->mkdirs()) {
                     $this->log("Unable to create directory " . $d->getAbsolutePath(), Project::MSG_ERR);
                 } else {
                     $count++;
                 }
             }
         }
         if ($count > 0) {
             $this->log("moved {$count} empty director" . ($count == 1 ? "y" : "ies") . " to " . $this->destDir->getAbsolutePath());
         }
     }
     if (count($this->filesets) > 0) {
         // process filesets
         foreach ($this->filesets as $fs) {
             $dir = $fs->getDir($this->project);
             if ($this->okToDelete($dir)) {
                 $this->deleteDir($dir);
             }
         }
     }
 }
 public function main()
 {
     /**
      * Find PHPLoc
      */
     if (!class_exists('\\SebastianBergmann\\PHPLOC\\Analyser')) {
         if (!@(include_once 'SebastianBergmann/PHPLOC/autoload.php')) {
             if (!@(include_once 'PHPLOC/Analyser.php')) {
                 throw new BuildException('PHPLocTask depends on PHPLoc being installed and on include_path.', $this->getLocation());
             } else {
                 $this->oldVersion = true;
             }
         }
     }
     $versionClass = '\\SebastianBergmann\\PHPLOC\\Version';
     if (class_exists($versionClass) && version_compare(constant($versionClass . '::VERSION'), '1.7.0') >= 0 && version_compare(constant($versionClass . '::VERSION'), '2.0.0beta1') == -1) {
         $this->isOneSevenVersion = true;
     }
     $this->validateProperties();
     if ($this->reportDirectory !== null && !is_dir($this->reportDirectory)) {
         $reportOutputDir = new PhingFile($this->reportDirectory);
         $logMessage = "Report output directory doesn't exist, creating: " . $reportOutputDir->getAbsolutePath() . '.';
         $this->log($logMessage);
         $reportOutputDir->mkdirs();
     }
     if ($this->reportType !== 'cli') {
         $this->reportFileName .= '.' . $this->reportType;
     }
     if (count($this->fileSets) > 0) {
         foreach ($this->fileSets as $fileSet) {
             $directoryScanner = $fileSet->getDirectoryScanner($this->project);
             $files = $directoryScanner->getIncludedFiles();
             $directory = $fileSet->getDir($this->project)->getPath();
             foreach ($files as $file) {
                 if ($this->isFileSuffixSet($file)) {
                     $this->filesToCheck[] = $directory . DIRECTORY_SEPARATOR . $file;
                 }
             }
         }
         $this->filesToCheck = array_unique($this->filesToCheck);
     }
     $this->runPhpLocCheck();
 }
 /**
  * Creates a new Capsule context with some basic properties set.
  * (Capsule is a simple PHP encapsulation system -- aka a php "template" class.)
  * @return Capsule
  */
 protected function createContext()
 {
     $context = new Capsule();
     // Make sure the output directory exists, if it doesn't
     // then create it.
     $outputDir = new PhingFile($this->outputDirectory);
     if (!$outputDir->exists()) {
         $this->log("Output directory does not exist, creating: " . $outputDir->getAbsolutePath());
         $outputDir->mkdirs();
     }
     // Place our set of data models into the context along
     // with the names of the databases as a convenience for now.
     $context->put("targetDatabase", $this->targetDatabase);
     $context->put("targetPackage", $this->targetPackage);
     $context->put("now", strftime("%c"));
     $this->log("Target database type: " . $this->targetDatabase);
     $this->log("Target package: " . $this->targetPackage);
     $this->log("Using template path: " . $this->templatePath);
     $this->log("Output directory: " . $this->outputDirectory);
     $context->setTemplatePath($this->templatePath);
     $context->setOutputDirectory($this->outputDirectory);
     $this->populateContextProperties($context);
     return $context;
 }
Example #21
0
 public function main()
 {
     // check to make sure task received all correct params
     $this->validate();
     $basepath = $this->getOutputDirectory();
     // Get new Capsule context
     $generator = $this->createContext();
     $generator->put("basepath", $basepath);
     // make available to other templates
     $targetPlatform = $this->getTargetPlatform();
     // convenience for embedding in strings below
     // we need some values that were loaded into the template context
     $basePrefix = $generator->get('basePrefix');
     $project = $generator->get('project');
     foreach ($this->getDataModels() as $dataModel) {
         $this->log("Processing Datamodel : " . $dataModel->getName());
         foreach ($dataModel->getDatabases() as $database) {
             $this->log("  - processing database : " . $database->getName());
             $generator->put("platform", $database->getPlatform());
             foreach ($database->getTables() as $table) {
                 if (!$table->isForReferenceOnly()) {
                     if ($table->getPackage()) {
                         $package = $table->getPackage();
                     } else {
                         $package = $this->targetPackage;
                     }
                     $pkbase = "{$package}.om";
                     $pkpeer = "{$package}";
                     $pkmap = "{$package}.map";
                     // make these available
                     $generator->put("package", $package);
                     $generator->put("pkbase", $pkbase);
                     //$generator->put("pkpeer", $pkpeer); -- we're not using this yet
                     $generator->put("pkmap", $pkmap);
                     foreach (array($pkpeer, $pkmap, $pkbase) as $pk) {
                         $path = strtr($pk, '.', '/');
                         $f = new PhingFile($this->getOutputDirectory(), $path);
                         if (!$f->exists()) {
                             if (!$f->mkdirs()) {
                                 throw new Exception("Error creating directories: " . $f->getPath());
                             }
                         }
                     }
                     // for each package
                     $this->log("\t+ " . $table->getName());
                     $generator->put("table", $table);
                     // Create the Base Peer class
                     $this->log("\t\t-> " . $basePrefix . $table->getPhpName() . "Peer");
                     $path = ClassTools::getFilePath($pkbase, $basePrefix . $table->getPhpName() . "Peer");
                     $generator->parse("om/{$targetPlatform}/Peer.tpl", $path);
                     // Create the Base object class
                     $this->log("\t\t-> " . $basePrefix . $table->getPhpName());
                     $path = ClassTools::getFilePath($pkbase, $basePrefix . $table->getPhpName());
                     $generator->parse("om/{$targetPlatform}/Object.tpl", $path);
                     if ($table->isTree()) {
                         // Create the Base NodePeer class
                         $this->log("\t\t-> " . $basePrefix . $table->getPhpName() . "NodePeer");
                         $path = ClassTools::getFilePath($pkbase, $basePrefix . $table->getPhpName() . "NodePeer");
                         $generator->parse("om/{$targetPlatform}/NodePeer.tpl", $path);
                         // Create the Base Node class if the table is a tree
                         $this->log("\t\t-> " . $basePrefix . $table->getPhpName() . "Node");
                         $path = ClassTools::getFilePath($pkbase, $basePrefix . $table->getPhpName() . "Node");
                         $generator->parse("om/{$targetPlatform}/Node.tpl", $path);
                     }
                     // Create MapBuilder class if this table is not an alias
                     if (!$table->isAlias()) {
                         $this->log("\t\t-> " . $table->getPhpName() . "MapBuilder");
                         $path = ClassTools::getFilePath($pkmap, $table->getPhpName() . "MapBuilder");
                         $generator->parse("om/{$targetPlatform}/MapBuilder.tpl", $path);
                     }
                     // if !$table->isAlias()
                     // Create [empty] stub Peer class if it does not already exist
                     $path = ClassTools::getFilePath($package, $table->getPhpName() . "Peer");
                     $_f = new PhingFile($basepath, $path);
                     if (!$_f->exists()) {
                         $this->log("\t\t-> " . $table->getPhpName() . "Peer");
                         $generator->parse("om/{$targetPlatform}/ExtensionPeer.tpl", $path);
                     } else {
                         $this->log("\t\t-> (exists) " . $table->getPhpName() . "Peer");
                     }
                     // Create [empty] stub object class if it does not already exist
                     $path = ClassTools::getFilePath($package, $table->getPhpName());
                     $_f = new PhingFile($basepath, $path);
                     if (!$_f->exists()) {
                         $this->log("\t\t-> " . $table->getPhpName());
                         $generator->parse("om/{$targetPlatform}/ExtensionObject.tpl", $path);
                     } else {
                         $this->log("\t\t-> (exists) " . $table->getPhpName());
                     }
                     if ($table->isTree()) {
                         // Create [empty] stub Node Peer class if it does not already exist
                         $path = ClassTools::getFilePath($package, $table->getPhpName() . "NodePeer");
                         $_f = new PhingFile($basepath, $path);
                         if (!$_f->exists()) {
                             $this->log("\t\t-> " . $table->getPhpName() . "NodePeer");
                             $generator->parse("om/{$targetPlatform}/ExtensionNodePeer.tpl", $path);
                         } else {
                             $this->log("\t\t-> (exists) " . $table->getPhpName() . "NodePeer");
                         }
                         // Create [empty] stub Node class if it does not already exist
                         $path = ClassTools::getFilePath($package, $table->getPhpName() . "Node");
                         $_f = new PhingFile($basepath, $path);
                         if (!$_f->exists()) {
                             $this->log("\t\t-> " . $table->getPhpName() . "Node");
                             $generator->parse("om/{$targetPlatform}/ExtensionNode.tpl", $path);
                         } else {
                             $this->log("\t\t-> (exists) " . $table->getPhpName() . "Node");
                         }
                     }
                     // Create [empty] interface if it does not already exist
                     if ($table->getInterface()) {
                         $path = ClassTools::getFilePath($table->getInterface());
                         $_f = new PhingFile($basepath, $path);
                         if (!$_f->exists()) {
                             $_dir = new PhingFile(dirname($_f->getAbsolutePath()));
                             $_dir->mkdirs();
                             $this->log("\t\t-> " . $table->getInterface());
                             $generator->parse("om/{$targetPlatform}/Interface.tpl", $path);
                         } else {
                             $this->log("\t\t-> (exists) " . $table->getInterface());
                         }
                     }
                     // If table has enumerated children (uses inheritance) then create the empty child stub classes
                     // if they don't already exist.
                     if ($table->getChildrenColumn()) {
                         $col = $table->getChildrenColumn();
                         if ($col->isEnumeratedClasses()) {
                             foreach ($col->getChildren() as $child) {
                                 $childpkg = $child->getPackage() ? $child->getPackage() : $package;
                                 $generator->put("child", $child);
                                 $generator->put("package", $childpkg);
                                 $path = ClassTools::getFilePath($childpkg, $child->getClassName());
                                 $_f = new PhingFile($basepath, $path);
                                 if (!$_f->exists()) {
                                     $this->log("\t\t-> " . $child->getClassName());
                                     $generator->parse("om/{$targetPlatform}/MultiExtendObject.tpl", $path);
                                 } else {
                                     $this->log("\t\t-> (exists) " . $child->getClassName());
                                 }
                             }
                             // foreach
                         }
                         // if col->is enumerated
                     }
                     // if tbl->getChildrenCol
                 }
                 // if !$table->isForReferenceOnly()
             }
             // foreach table
         }
         // foreach database
     }
     // foreach dataModel
 }
Example #22
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;
     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());
                 $count++;
             } catch (IOException $ioe) {
                 $this->log("Failed to copy " . $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 #23
0
 /**
  * Execute the input script with Velocity
  *
  * @throws BuildException
  *                        BuildExceptions are thrown when required attributes are missing.
  *                        Exceptions thrown by Velocity are rethrown as BuildExceptions.
  */
 public function main()
 {
     // Make sure the template path is set.
     if (empty($this->templatePath)) {
         throw new BuildException("The template path needs to be defined!");
     }
     // Make sure the control template is set.
     if ($this->controlTemplate === null) {
         throw new BuildException("The control template needs to be defined!");
     }
     // Make sure the output directory is set.
     if ($this->outputDirectory === null) {
         throw new BuildException("The output directory needs to be defined!");
     }
     // Make sure there is an output file.
     if ($this->outputFile === null) {
         throw new BuildException("The output file needs to be defined!");
     }
     // Setup Smarty runtime.
     // Smarty uses one object to store properties and to store
     // the context for the template (unlike Velocity).  We setup this object, calling it
     // $this->context, and then initControlContext simply zeros out
     // any assigned variables.
     $this->context = new Capsule();
     if ($this->templatePath !== null) {
         $this->log("Using templatePath: " . $this->templatePath);
         $this->context->setTemplatePath($this->templatePath);
     }
     // Make sure the output directory exists, if it doesn't
     // then create it.
     $outputDir = new PhingFile($this->outputDirectory);
     if (!$outputDir->exists()) {
         $this->log("Output directory does not exist, creating: " . $outputDir->getAbsolutePath());
         $outputDir->mkdirs();
     }
     $this->context->setOutputDirectory($outputDir->getAbsolutePath());
     $path = $this->outputDirectory . DIRECTORY_SEPARATOR . $this->outputFile;
     $this->log("Generating to file " . $path);
     //$writer = new FileWriter($path);
     // The generator and the output path should
     // be placed in the init context here and
     // not in the generator class itself.
     $c = $this->initControlContext();
     // Set any variables that need to always
     // be loaded
     $this->populateInitialContext($c);
     // Feed all the options into the initial
     // control context so they are available
     // in the control/worker templates.
     if ($this->contextProperties !== null) {
         foreach ($this->contextProperties->keys() as $property) {
             $value = $this->contextProperties->getProperty($property);
             // Special exception (from Texen)
             // for properties ending in file.contents:
             // in that case we dump the contents of the file
             // as the "value" for the Property.
             if (preg_match('/file\\.contents$/', $property)) {
                 // pull in contents of file specified
                 $property = substr($property, 0, strpos($property, "file.contents") - 1);
                 // reset value, and then
                 // read in the contents of the file into that var
                 $value = "";
                 $f = new PhingFile($this->project->resolveFile($value)->getCanonicalPath());
                 if ($f->exists()) {
                     $fr = new FileReader($f);
                     $fr->readInto($value);
                 }
             }
             // if ends with file.contents
             if (StringHelper::isBoolean($value)) {
                 $value = StringHelper::booleanValue($value);
             }
             $c->put($property, $value);
         }
         // foreach property
     }
     // if contextProperties !== null
     try {
         $this->log("Parsing control template: " . $this->controlTemplate);
         $c->parse($this->controlTemplate, $path);
     } catch (Exception $ioe) {
         throw new BuildException("Cannot write parsed template: " . $ioe->getMessage());
     }
     $this->cleanup();
 }