/**
  * 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());
     }
 }
Example #2
0
 /**
  * Executes PHPCPD against PhingFile or a FileSet
  *
  * @return void
  */
 public function main()
 {
     if (!isset($this->_file) and count($this->_filesets) == 0) {
         throw new BuildException("Missing either a nested fileset or attribute 'file' set");
     }
     if (count($this->_formatters) == 0) {
         // turn legacy format attribute into formatter
         $fmt = new PHPCPDFormatterElement($this);
         $fmt->setType($this->_format);
         $fmt->setUseFile(false);
         $this->_formatters[] = $fmt;
     }
     $this->validateFormatters();
     $filesToParse = array();
     if ($this->_file instanceof PhingFile) {
         $filesToParse[] = $this->_file->getPath();
     } else {
         // append any files in filesets
         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();
             }
         }
     }
     $this->log('Processing files...');
     $detector = new PHPCPD_Detector(new PHPCPD_Detector_Strategy_Default());
     $clones = $detector->copyPasteDetection($filesToParse, $this->_minLines, $this->_minTokens);
     $this->log('Finished copy/paste detection');
     foreach ($this->_formatters as $fe) {
         $formatter = $fe->getFormatter();
         $formatter->processClones($clones, $this->project, $fe->getUseFile(), $fe->getOutfile());
     }
 }
 /**
  * @throws     BuildException
  */
 public function main()
 {
     if (!$this->getDatabaseName()) {
         throw new BuildException("The databaseName attribute (defined in propel.project property) is required for schema reverse engineering", $this->getLocation());
     }
     //(not yet supported) $this->log("schema : " . $this->dbSchema);
     //DocumentTypeImpl docType = new DocumentTypeImpl(null, "database", null,
     //       "http://jakarta.apache.org/turbine/dtd/database.dtd");
     $this->doc = new DOMDocument('1.0', 'utf-8');
     $this->doc->formatOutput = true;
     // pretty printing
     $this->doc->appendChild($this->doc->createComment("Autogenerated by " . get_class($this) . " class."));
     try {
         $database = $this->buildModel();
         if ($this->validatorBits !== self::VALIDATORS_NONE) {
             $this->addValidators($database);
         }
         $database->appendXml($this->doc);
         $this->log("Writing XML to file: " . $this->xmlSchema->getPath());
         $out = new FileWriter($this->xmlSchema);
         $xmlstr = $this->doc->saveXML();
         $out->write($xmlstr);
         $out->close();
     } catch (Exception $e) {
         $this->log("There was an error building XML from metadata: " . $e->getMessage(), Project::MSG_ERR);
         return false;
     }
     $this->log("Schema reverse engineering finished");
 }
 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
 /**
  * Return the list of files to parse
  *
  * @return string[] list of absolute files to parse
  */
 protected function getFilesToParse()
 {
     $filesToParse = array();
     if ($this->file instanceof PhingFile) {
         $filesToParse[] = $this->file->getPath();
     } else {
         // append any files in filesets
         foreach ($this->filesets as $fs) {
             $dir = $fs->getDir($this->project)->getAbsolutePath();
             foreach ($fs->getDirectoryScanner($this->project)->getIncludedFiles() as $filename) {
                 $fileAbsolutePath = $dir . DIRECTORY_SEPARATOR . $filename;
                 if ($this->cache) {
                     $lastMTime = $this->cache->get($fileAbsolutePath);
                     $currentMTime = filemtime($fileAbsolutePath);
                     if ($lastMTime >= $currentMTime) {
                         continue;
                     } else {
                         $this->cache->put($fileAbsolutePath, $currentMTime);
                     }
                 }
                 $filesToParse[] = $fileAbsolutePath;
             }
         }
     }
     return $filesToParse;
 }
 /**
  * @throws BuildException
  */
 public function main()
 {
     $this->checkPreconditions();
     try {
         $this->log('Building package: ' . $this->destinationFile->__toString(), Project::MSG_INFO);
         /*
          * Delete old package, if exists.
          */
         if ($this->destinationFile->exists()) {
             /*
              * TODO Check operation for errors...
              */
             $this->destinationFile->delete();
         }
         $phar = $this->buildPhar();
         $phar->startBuffering();
         $baseDirectory = realpath($this->baseDirectory->getPath());
         foreach ($this->filesets as $fileset) {
             $this->log('Adding specified files in ' . $fileset->getDir($this->project) . ' to package', Project::MSG_VERBOSE);
             $phar->buildFromIterator($fileset, $baseDirectory);
         }
         $phar->stopBuffering();
         /*
          * File compression, if needed.
          */
         if (Phar::NONE != $this->compression) {
             $phar->compressFiles($this->compression);
         }
     } catch (Exception $e) {
         throw new BuildException('Problem creating package: ' . $e->getMessage(), $e, $this->getLocation());
     }
 }
 /**
  * @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());
     }
 }
Example #8
0
 /**
  * Scans the parameters list for the "lines" parameter and uses
  * it to set the number of lines to be returned in the filtered stream.
  * also scan for skip parameter.
  *
  * @throws BuildException
  */
 private function initialize()
 {
     // get parameters
     $params = $this->getParameters();
     if ($params !== null) {
         /** @var Parameter $param */
         foreach ($params as $param) {
             if ('prepend' === $param->getName()) {
                 $this->setPrepend(new PhingFile($param->getValue()));
                 continue;
             }
             if ('append' === $param->getName()) {
                 $this->setAppend(new PhingFile($param->getValue()));
                 continue;
             }
         }
     }
     if ($this->prepend !== null) {
         if (!$this->prepend->isAbsolute()) {
             $this->prepend = new PhingFile($this->getProject()->getBasedir(), $this->prepend->getPath());
         }
         $this->prependReader = new BufferedReader(new FileReader($this->prepend));
     }
     if ($this->append !== null) {
         if (!$this->append->isAbsolute()) {
             $this->append = new PhingFile($this->getProject()->getBasedir(), $this->append->getPath());
         }
         $this->appendReader = new BufferedReader(new FileReader($this->append));
     }
 }
 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);
 }
 /**
  * Executes PHPMD against PhingFile or a FileSet
  *
  * @throws BuildException - if the phpmd classes can't be loaded.
  */
 public function main()
 {
     /**
      * Find PHPMD
      */
     @(include_once 'PHP/PMD.php');
     if (!class_exists('PHP_PMD')) {
         throw new BuildException('PHPMDTask depends on PHPMD being installed and on include_path.', $this->getLocation());
     }
     require_once 'PHP/PMD/AbstractRule.php';
     if (!$this->minimumPriority) {
         $this->minimumPriority = PHP_PMD_AbstractRule::LOWEST_PRIORITY;
     }
     if (!isset($this->file) and count($this->filesets) == 0) {
         throw new BuildException('Missing either a nested fileset or attribute "file" set');
     }
     if (count($this->formatters) == 0) {
         // turn legacy format attribute into formatter
         $fmt = new PHPMDFormatterElement();
         $fmt->setType($this->format);
         $fmt->setUseFile(false);
         $this->formatters[] = $fmt;
     }
     $reportRenderers = array();
     foreach ($this->formatters as $fe) {
         if ($fe->getType() == '') {
             throw new BuildException('Formatter missing required "type" attribute.');
         }
         if ($fe->getUsefile() && $fe->getOutfile() === null) {
             throw new BuildException('Formatter requires "outfile" attribute when "useFile" is true.');
         }
         $reportRenderers[] = $fe->getRenderer();
     }
     // Create a rule set factory
     $ruleSetFactory = new PHP_PMD_RuleSetFactory();
     $ruleSetFactory->setMinimumPriority($this->minimumPriority);
     $phpmd = new PHP_PMD();
     $phpmd->setFileExtensions($this->allowedFileExtensions);
     $phpmd->setIgnorePattern($this->ignorePatterns);
     $filesToParse = array();
     if ($this->file instanceof PhingFile) {
         $filesToParse[] = $this->file->getPath();
     } else {
         // append any files in filesets
         foreach ($this->filesets as $fs) {
             foreach ($fs->getDirectoryScanner($this->project)->getIncludedFiles() as $filename) {
                 $f = new PhingFile($fs->getDir($this->project), $filename);
                 $filesToParse[] = $f->getAbsolutePath();
             }
         }
     }
     if (count($filesToParse) > 0) {
         $inputPath = implode(',', $filesToParse);
         $this->log('Processing files...');
         $phpmd->processFiles($inputPath, $this->rulesets, $reportRenderers, $ruleSetFactory);
         $this->log('Finished processing files');
     } else {
         $this->log('No files to process');
     }
 }
Example #11
0
 public function checkFileExists()
 {
     //Get the correct path to asset
     switch ($this->type) {
         case Asset::ASSET_TYPE_CSS:
             $this->assetFolder = $this->paths['css'];
             break;
         case Asset::ASSET_TYPE_JS:
             $this->assetFolder = $this->paths['js'];
             break;
         case Asset::ASSET_TYPE_IMAGE:
             $this->assetFolder = $this->paths['images'];
             break;
         default:
             $folder = '';
     }
     //Path to file
     $file = new PhingFile($this->assetsDir . '/' . $this->assetFolder . $this->file);
     //Check file exists
     if (!$file->exists()) {
         throw new BuildException("Unable to find asset file: " . $file->getAbsolutePath());
     }
     //Check we can read it
     if (!$file->canRead()) {
         throw IOException("Unable to read asset file: " . $file->getPath());
     }
     return $file;
 }
 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 #13
0
 /**
  * @throws BuildException
  */
 public function main()
 {
     $this->checkPreconditions();
     try {
         $this->log('Building package: ' . $this->destinationFile->__toString(), Project::MSG_INFO);
         /*
          * Delete old package, if exists.
          */
         if ($this->destinationFile->exists()) {
             /*
              * TODO Check operation for errors...
              */
             $this->destinationFile->delete();
         }
         $phar = $this->buildPhar();
         $phar->startBuffering();
         $baseDirectory = realpath($this->baseDirectory->getPath());
         foreach ($this->filesets as $fileset) {
             foreach ($fileset as $realFileName) {
                 /*
                  * Calculate local file name.
                  */
                 $localFileName = $realFileName;
                 if (0 === strpos($realFileName, $baseDirectory)) {
                     $localFileName = substr($realFileName, strlen($baseDirectory));
                 }
                 $this->log('Adding ' . $realFileName . ' as ' . $localFileName . ' to package', Project::MSG_VERBOSE);
                 $phar->addFile($realFileName, $localFileName);
             }
         }
         $phar->stopBuffering();
     } catch (Exception $e) {
         throw new BuildException('Problem creating package: ' . $e->getMessage(), $e, $this->getLocation());
     }
 }
 /**
  * Executes PHPMD against PhingFile or a FileSet
  *
  * @throws BuildException - if the phpmd classes can't be loaded.
  */
 public function main()
 {
     $className = $this->loadDependencies();
     if (!isset($this->file) and count($this->filesets) == 0) {
         throw new BuildException('Missing either a nested fileset or attribute "file" set');
     }
     if (count($this->formatters) == 0) {
         // turn legacy format attribute into formatter
         $fmt = new PHPMDFormatterElement();
         $fmt->setType($this->format);
         $fmt->setUseFile(false);
         $this->formatters[] = $fmt;
     }
     $reportRenderers = array();
     foreach ($this->formatters as $fe) {
         if ($fe->getType() == '') {
             throw new BuildException('Formatter missing required "type" attribute.');
         }
         if ($fe->getUsefile() && $fe->getOutfile() === null) {
             throw new BuildException('Formatter requires "outfile" attribute when "useFile" is true.');
         }
         $reportRenderers[] = $fe->getRenderer();
     }
     // Create a rule set factory
     if ($this->newVersion) {
         $ruleSetClass = '\\PHPMD\\RuleSetFactory';
         $ruleSetFactory = new $ruleSetClass();
         //php 5.2 parser compatability
     } else {
         if (!class_exists("PHP_PMD_RuleSetFactory")) {
             @(include 'PHP/PMD/RuleSetFactory.php');
         }
         $ruleSetFactory = new PHP_PMD_RuleSetFactory();
     }
     $ruleSetFactory->setMinimumPriority($this->minimumPriority);
     $phpmd = new $className();
     $phpmd->setFileExtensions($this->allowedFileExtensions);
     $phpmd->setIgnorePattern($this->ignorePatterns);
     $filesToParse = array();
     if ($this->file instanceof PhingFile) {
         $filesToParse[] = $this->file->getPath();
     } else {
         // append any files in filesets
         foreach ($this->filesets as $fs) {
             foreach ($fs->getDirectoryScanner($this->project)->getIncludedFiles() as $filename) {
                 $f = new PhingFile($fs->getDir($this->project), $filename);
                 $filesToParse[] = $f->getAbsolutePath();
             }
         }
     }
     if (count($filesToParse) > 0) {
         $inputPath = implode(',', $filesToParse);
         $this->log('Processing files...');
         $phpmd->processFiles($inputPath, $this->rulesets, $reportRenderers, $ruleSetFactory);
         $this->log('Finished processing files');
     } else {
         $this->log('No files to process');
     }
 }
 /**
  * Executes PHPCPD against PhingFile or a FileSet
  *
  * @throws BuildException - if the phpcpd classes can't be loaded.
  */
 public function main()
 {
     if (class_exists('Composer\\Autoload\\ClassLoader', false) && class_exists('\\SebastianBergmann\\PHPCPD\\Detector\\Strategy\\DefaultStrategy')) {
         $oldVersion = false;
     } elseif ($handler = @fopen('SebastianBergmann/PHPCPD/autoload.php', 'r', true)) {
         fclose($handler);
         @(include_once 'SebastianBergmann/PHPCPD/autoload.php');
         if (version_compare(PHP_VERSION, '5.3.0') < 0) {
             throw new BuildException('The PHPCPD task now requires PHP 5.3+');
         }
         $oldVersion = false;
     } elseif ($handler = @fopen('PHPCPD/Autoload.php', 'r', true)) {
         fclose($handler);
         @(include_once 'PHPCPD/Autoload.php');
         $oldVersion = true;
     } else {
         throw new BuildException('PHPCPDTask depends on PHPCPD being installed and on include_path.', $this->getLocation());
     }
     if (!isset($this->file) && count($this->filesets) == 0) {
         throw new BuildException('Missing either a nested fileset or attribute "file" set');
     }
     if (count($this->formatters) == 0) {
         // turn legacy format attribute into formatter
         $fmt = new PHPCPDFormatterElement($this);
         $fmt->setType($this->format);
         $fmt->setUseFile(false);
         $this->formatters[] = $fmt;
     }
     $this->validateFormatters();
     $filesToParse = array();
     if ($this->file instanceof PhingFile) {
         $filesToParse[] = $this->file->getPath();
     } else {
         // append any files in filesets
         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();
             }
         }
     }
     $this->log('Processing files...');
     if ($oldVersion) {
         $detectorClass = 'PHPCPD_Detector';
         $strategyClass = 'PHPCPD_Detector_Strategy_Default';
     } else {
         $detectorClass = '\\SebastianBergmann\\PHPCPD\\Detector\\Detector';
         $strategyClass = '\\SebastianBergmann\\PHPCPD\\Detector\\Strategy\\DefaultStrategy';
     }
     $detector = new $detectorClass(new $strategyClass());
     $clones = $detector->copyPasteDetection($filesToParse, $this->minLines, $this->minTokens);
     $this->log('Finished copy/paste detection');
     foreach ($this->formatters as $fe) {
         $formatter = $fe->getFormatter();
         $formatter->processClones($clones, $this->project, $fe->getUseFile(), $fe->getOutfile());
     }
 }
Example #16
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 #17
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());
         }
     }
 }
 /**
  * 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);
 }
 /**
  * Prepares the command building and execution, i.e.
  * changes to the specified directory.
  *
  * @return void
  */
 protected function prepare()
 {
     if ($this->dir === null) {
         return;
     }
     // expand any symbolic links first
     if (!$this->dir->getCanonicalFile()->isDirectory()) {
         throw new BuildException("'" . (string) $this->dir . "' is not a valid directory");
     }
     $this->currdir = getcwd();
     @chdir($this->dir->getPath());
 }
Example #20
0
 /**
  * @throws BuildException
  */
 public function main()
 {
     $this->checkPreconditions();
     try {
         $this->log('Building package: ' . $this->destinationFile->__toString(), Project::MSG_INFO);
         /**
          * Delete old package, if exists.
          */
         if ($this->destinationFile->exists()) {
             /**
              * TODO Check operation for errors...
              */
             $this->destinationFile->delete();
         }
         $phar = $this->buildPhar();
         $phar->startBuffering();
         $baseDirectory = realpath($this->baseDirectory->getPath());
         foreach ($this->filesets as $fileset) {
             $this->log('Adding specified files in ' . $fileset->getDir($this->project) . ' to package', Project::MSG_VERBOSE);
             $phar->buildFromIterator($fileset, $baseDirectory);
         }
         $phar->stopBuffering();
         /**
          * File compression, if needed.
          */
         if (Phar::NONE != $this->compression) {
             $phar->compressFiles($this->compression);
         }
         if ($this->signatureAlgorithm == Phar::OPENSSL) {
             // Load up the contents of the key
             $keyContents = file_get_contents($this->key);
             // Attempt to load the given key as a PKCS#12 Cert Store first.
             if (openssl_pkcs12_read($keyContents, $certs, $this->keyPassword)) {
                 $private = openssl_pkey_get_private($certs['pkey']);
             } else {
                 // Fall back to a regular PEM-encoded private key.
                 // Setup an OpenSSL resource using the private key
                 // and tell the Phar to sign it using that key.
                 $private = openssl_pkey_get_private($keyContents, $this->keyPassword);
             }
             openssl_pkey_export($private, $pkey);
             $phar->setSignatureAlgorithm(Phar::OPENSSL, $pkey);
             // Get the details so we can get the public key and write that out
             // alongside the phar.
             $details = openssl_pkey_get_details($private);
             file_put_contents($this->destinationFile . '.pubkey', $details['key']);
         } else {
             $phar->setSignatureAlgorithm($this->signatureAlgorithm);
         }
     } catch (Exception $e) {
         throw new BuildException('Problem creating package: ' . $e->getMessage(), $e, $this->getLocation());
     }
 }
Example #21
0
 private function yuiAddFile($file, $is_css = FALSE)
 {
     if (!$is_css) {
         $folder = '/js/';
     } else {
         $folder = '/css/';
     }
     $add = new PhingFile($this->assetDir . $folder . $file->file);
     if ($add->exists() && $add->canRead()) {
         $this->yui->addFile($add->getAbsolutePath());
     } else {
         throw new BuildException("Unable to read asset file: " . $add->getPath(), $this->location);
     }
 }
Example #22
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);
 }
 /**
  * [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);
     }
 }
 /**
  * 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);
     }
 }
 /**
  * @throws BuildException
  */
 public function main()
 {
     $this->checkPreconditions();
     try {
         $this->log('Building package: ' . $this->destinationFile->__toString(), Project::MSG_INFO);
         $baseDirectory = realpath($this->baseDirectory->getPath());
         try {
             $this->compressAllFiles($this->initPhar(), $baseDirectory);
         } catch (\RuntimeException $e) {
             $this->log('Most likely compression failed (known bug): ' . $e->getMessage());
             $this->compressEachFile($this->initPhar(), $baseDirectory);
         }
     } catch (Exception $e) {
         throw new BuildException('Problem creating package: ' . $e->getMessage(), $e, $this->getLocation());
     }
 }
Example #26
0
 /**
  * Executes PHPMD against PhingFile or a FileSet
  *
  * @return void
  */
 public function main()
 {
     if (!isset($this->file) and count($this->filesets) == 0) {
         throw new BuildException("Missing either a nested fileset or attribute 'file' set");
     }
     if (count($this->formatters) == 0) {
         // turn legacy format attribute into formatter
         $fmt = new PHPMDFormatterElement();
         $fmt->setType($this->format);
         $fmt->setUseFile(false);
         $this->formatters[] = $fmt;
     }
     $reportRenderers = array();
     foreach ($this->formatters as $fe) {
         if ($fe->getType() == '') {
             throw new BuildException("Formatter missing required 'type' attribute.");
         }
         if ($fe->getUsefile() && $fe->getOutfile() === null) {
             throw new BuildException("Formatter requires 'outfile' attribute when 'useFile' is true.");
         }
         $reportRenderers[] = $fe->getRenderer();
     }
     // Create a rule set factory
     $ruleSetFactory = new PHP_PMD_RuleSetFactory();
     $ruleSetFactory->setMinimumPriority($this->minimumPriority);
     $phpmd = new PHP_PMD();
     $phpmd->setFileExtensions($this->allowedFileExtensions);
     $phpmd->setIgnorePattern($this->ignorePatterns);
     $filesToParse = array();
     if ($this->file instanceof PhingFile) {
         $filesToParse[] = $this->file->getPath();
     } else {
         // append any files in filesets
         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();
             }
         }
     }
     $inputPath = implode(',', $filesToParse);
     $this->log('Processing files...');
     $phpmd->processFiles($inputPath, $this->rulesets, $reportRenderers, $ruleSetFactory);
     $this->log('Finished processing files');
 }
Example #27
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);
 }
Example #28
0
 /**
  * Executes PHPCPD against PhingFile or a FileSet
  *
  * @throws BuildException
  */
 public function main()
 {
     $this->loadDependencies();
     if (!isset($this->file) && count($this->filesets) == 0) {
         throw new BuildException('Missing either a nested fileset or attribute "file" set');
     }
     if (count($this->formatters) == 0) {
         // turn legacy format attribute into formatter
         $fmt = new PHPCPDFormatterElement($this);
         $fmt->setType($this->format);
         $fmt->setUseFile(false);
         $this->formatters[] = $fmt;
     }
     $this->validateFormatters();
     $filesToParse = array();
     if ($this->file instanceof PhingFile) {
         $filesToParse[] = $this->file->getPath();
     } else {
         // append any files in filesets
         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();
             }
         }
     }
     $this->log('Processing files...');
     if ($this->oldVersion) {
         $detectorClass = 'PHPCPD_Detector';
         $strategyClass = 'PHPCPD_Detector_Strategy_Default';
     } else {
         $detectorClass = '\\SebastianBergmann\\PHPCPD\\Detector\\Detector';
         $strategyClass = '\\SebastianBergmann\\PHPCPD\\Detector\\Strategy\\DefaultStrategy';
     }
     $detector = new $detectorClass(new $strategyClass());
     $clones = $detector->copyPasteDetection($filesToParse, $this->minLines, $this->minTokens);
     $this->log('Finished copy/paste detection');
     foreach ($this->formatters as $fe) {
         $formatter = $fe->getFormatter();
         $formatter->processClones($clones, $this->project, $fe->getUseFile(), $fe->getOutfile());
     }
 }
 private function getStyleSheet()
 {
     $xslname = "checkstyle-" . $this->format . ".xsl";
     if ($this->styleDir) {
         $file = new PhingFile($this->styleDir, $xslname);
     } else {
         $path = Phing::getResourcePath("phing/etc/{$xslname}");
         if ($path === NULL) {
             $path = Phing::getResourcePath("etc/{$xslname}");
             if ($path === NULL) {
                 throw new BuildException("Could not find {$xslname} in resource path");
             }
         }
         $file = new PhingFile($path);
     }
     if (!$file->exists()) {
         throw new BuildException("Could not find file " . $file->getPath());
     }
     return $file;
 }
 /**
  * Perform the resolution & set property.
  */
 public function main()
 {
     if (!$this->propertyName) {
         throw new BuildException("You must specify the propertyName attribute", $this->getLocation());
     }
     // Currently only files are supported
     if ($this->file === null) {
         throw new BuildException("You must specify a path to resolve", $this->getLocation());
     }
     $fs = FileSystem::getFileSystem();
     // if dir attribute was specified then we should
     // use that as basedir to which file was relative.
     // -- unless the file specified is an absolute path
     if ($this->dir !== null && !$fs->isAbsolute(new PhingFile($this->file))) {
         $this->file = new PhingFile($this->dir->getPath(), $this->file);
     }
     $resolved = $this->project->resolveFile($this->file);
     $this->log("Resolved " . $this->file . " to " . $resolved->getAbsolutePath(), $this->logLevel);
     $this->project->setProperty($this->propertyName, $resolved->getAbsolutePath());
 }