protected function findFiles() { $ds = new DirectoryScanner(); $ds->setBasedir($this->dir); $ds->setIncludes(array('**/composer.json')); $ds->scan(); return $ds->getIncludedFiles(); }
function scan($scanners = array('checks', 'analyzers')) { // Run the scan $scan_pass = parent::scan($scanners); // Get the results $results = $this->get_results(); // Get the previously scanned files $scanned_files = $this->get_scanned_files($this->directory); $directory = $this->get_normalized_dir_path($this->directory); // Save the results foreach ($this->files as $file_group_type => $files) { foreach ($files as $file => $file_contents) { // Get the post id to update if (array_key_exists($file, $scanned_files)) { $post_id = $scanned_files[$file]['post_id']; } else { // This file does not already have a db entry, insert one $post_id = wp_insert_post(array('post_type' => self::ASYNC_SCAN_CPT, 'post_title' => $file)); if (is_wp_error($post_id)) { continue; } update_post_meta($post_id, 'vip_scanner_dir', $directory); } // Save the scan results for this file update_post_meta($post_id, 'vip_scanner_async_results', $results); update_post_meta($post_id, 'vip_scanner_async_pass', $scan_pass); } } return $scan_pass; }
/** * Perform checks on a directory * * [<dir>] * : Directory to scan. Defaults to current. * * [--scan_type=<scan_type>] * : Type of scan to perform. Defaults to "WP.org Theme Review" * * [--summary] * : Summarize the results. * * [--format=<format>] * : Output results to a given format: table, JSON, CSV. Defaults to table. * * @subcommand scan */ public function scan($args, $assoc_args) { if (empty($args[0])) { $dir = getcwd(); } else { $dir = realpath($args[0]); } $defaults = array('scan_type' => 'VIP Theme Review', 'format' => 'table'); $args = wp_parse_args($assoc_args, $defaults); $review = VIP_Scanner::get_instance()->get_review($args['scan_type']); if (!$review) { WP_CLI::error(sprintf('Scanning of %s failed', $dir)); } $scanner = new DirectoryScanner($dir, $review); $scanner->scan(array('checks', 'analyzers')); if (!$scanner) { WP_CLI::error(sprintf('Scanning of %s failed', $dir)); } self::scan_dir($scanner, $args); }
function __construct($theme, $review) { if (!function_exists('get_theme_root')) { return $this->add_error('wp-load', sprintf('%s requires WordPress to be loaded.', get_class($this)), 'blocker'); } // decide whether to interpret theme as a path by checking if the path exists $potential_file_path = realpath($theme); if ($potential_file_path) { $path = $potential_file_path; } else { $path = sprintf('%s/%s', get_theme_root(), $theme); } // Call Parent Constructor parent::__construct($path, $review); }
/** * Returns the excluded files * * @return array */ public function getExcludedFiles() { $includes = array(); foreach ($this->files as $file) { $includes[] = $file->getName(); } $this->directoryScanner->setIncludes($includes); $this->directoryScanner->scan(); $files = $this->directoryScanner->getIncludedFiles(); $dir = $this->directoryScanner->getBasedir(); $fileList = array(); foreach ($files as $file) { $fileList[] = $dir . DIRECTORY_SEPARATOR . $file; } return $fileList; }
/** * Tests whether a name matches against at least one exclude pattern. * * @param string $_name the name to match * @return bool <code>true</code> when the name matches against at least one * exclude pattern, <code>false</code> otherwise. */ protected function isExcluded($_name) { for ($i = 0; $i < count($this->excludes); $i++) { if (DirectoryScanner::matchPath($this->excludes[$i], $_name, $this->isCaseSensitive)) { return true; } } return false; }
protected function findSplits() { $this->log("checking heads for subsplits"); $repo = $this->getRepository(); $base = $this->getBase(); $splits = array(); $heads = $this->getHeads(); if (!empty($base)) { $base = '/' . ltrim($base, '/'); } else { $base = '/'; } chdir($repo . '/.subsplit'); foreach ($heads as $head) { $splits[$head] = array(); passthru("git checkout '{$head}'"); $ds = new DirectoryScanner(); $ds->setBasedir($repo . '/.subsplit' . $base); $ds->setIncludes(array('**/' . $this->subIndicatorFile)); $ds->scan(); $files = $ds->getIncludedFiles(); foreach ($files as $file) { $pkg = file_get_contents($repo . '/.subsplit' . $base . '/' . $file); $pkg_json = json_decode($pkg, true); $name = $pkg_json['name']; $component = str_replace('/composer.json', '', $file); $tmpreponame = explode('/', $name); $reponame = $tmpreponame[1]; $splits[$head][$component]['repo'] = $reponame; $nscomponent = str_replace('/', '\\', $component); $splits[$head][$component]['desc'] = "[READ ONLY] Subtree split of {$nscomponent}: " . $pkg_json['description']; } } passthru("git checkout master"); chdir($repo); $this->splits = $splits; }
/** feed dirscanner with infos defined by this fileset */ protected function setupDirectoryScanner(DirectoryScanner $ds, Project $p) { if ($ds === null) { throw new Exception("DirectoryScanner cannot be null"); } // FIXME - pass dir directly wehn dirscanner supports File $ds->setBasedir($this->dir->getPath()); foreach ($this->additionalPatterns as $addPattern) { $this->defaultPatterns->append($addPattern, $p); } $ds->setIncludes($this->defaultPatterns->getIncludePatterns($p)); $ds->setExcludes($this->defaultPatterns->getExcludePatterns($p)); $p->log("FileSet: Setup file scanner in dir " . $this->dir->__toString() . " with " . $this->defaultPatterns->toString(), Project::MSG_DEBUG); if ($ds instanceof SelectorScanner) { $ds->setSelectors($this->getSelectors($p)); } if ($this->useDefaultExcludes) { $ds->addDefaultExcludes(); } $ds->setCaseSensitive($this->isCaseSensitive); }
private function makeEntityNames($dirnames, PhingFile $rootDir) { if (empty($dirnames)) { return; } foreach ($dirnames as $dirname) { $this->output .= "<!-- dir: {$dirname} -->\n"; $ds = new DirectoryScanner(); $ds->setIncludes(array("**/*.xml")); $futil = new FileUtils(); $baseDir = $futil->resolveFile($rootDir, $dirname); $ds->setBasedir($baseDir->getPath()); $ds->scan(); $xmlFiles = $ds->getIncludedFiles(); $allEntities = ''; foreach ($xmlFiles as $xmlFilename) { $xmlFile = $futil->resolveFile($baseDir, $xmlFilename); $entityName = $this->fileToEntity($xmlFile, $rootDir); $this->output .= "<!-- {$dirname}/{$xmlFilename}-->\n"; $this->output .= "<!ENTITY {$entityName} SYSTEM \"{$dirname}/{$xmlFilename}\">\n"; $allEntities .= "&{$entityName};"; } $this->output .= "<!-- {$dirname} -->\n"; $this->output .= "<!ENTITY {$dirname}.all \"{$allEntities}\">\n"; } }
public function findComponents() { $ds = new DirectoryScanner(); $ds->setBasedir((string) $this->basedir . '/.subsplit/src'); $ds->setIncludes(array('**/composer.json')); $ds->scan(); $files = $ds->getIncludedFiles(); $this->subpackages = $files; }
/** * Tests whether a name matches the start of at least one include pattern. * * @param string $_name the name to match * * @return bool <code>true</code> when the name matches against at least one * include pattern, <code>false</code> otherwise. */ protected function couldHoldIncluded($_name) { for ($i = 0; $i < count($this->includes); $i++) { if (DirectoryScanner::matchPatternStart($this->includes[$i], $_name, $this->isCaseSensitive)) { return true; } } return false; }
protected function compareFiles(DirectoryScanner $ds, $expectedFiles, $expectedDirectories) { $includedFiles = $ds->getIncludedFiles(); $includedDirectories = $ds->getIncludedDirectories(); if (count($includedFiles)) { $includedFiles = array_map(array($this, 'replaceSeparator'), $includedFiles); natsort($includedFiles); $includedFiles = array_values($includedFiles); } if (count($includedDirectories)) { $includedDirectories = array_map(array($this, 'replaceSeparator'), $includedDirectories); natsort($includedDirectories); $includedDirectories = array_values($includedDirectories); } $this->assertEquals($includedFiles, $expectedFiles); $this->assertEquals($includedDirectories, $expectedDirectories); }
/** * Helper to get instance of DirectoryScanner with cli options applied * * @param ezcConsoleInput $input CLI Options pased to app * * @return Theseer\Tools\IncludeExcludeFilterIterator */ protected function getScanner(\ezcConsoleInput $input) { $scanner = new DirectoryScanner(); $include = $input->getOption('include'); if (is_array($include->value)) { $scanner->setIncludes($include->value); } else { $scanner->addInclude($include->value); } $exclude = $input->getOption('exclude'); if ($exclude->value) { if (is_array($exclude->value)) { $scanner->setExcludes($exclude->value); } else { $scanner->addExclude($exclude->value); } } $args = $input->getArguments(); return $scanner($args[0]); }
/** * Perform analysis on a directory * * [<dir>] * : Directory to scan. Defaults to current. * * [--scan_type=<scan_type>] * : Type of scan to perform. Defaults to "WP.org Theme Review" * * [--depth=<depth>] * : Number of levels of hierarchy to output. 0 outputs everything. * Defaults to 1. * @subcommand analyze */ public function analyze($args, $assoc_args) { if (empty($args[0])) { $dir = getcwd(); } else { $dir = realpath($args[0]); } $defaults = array('scan_type' => 'VIP Theme Review', 'depth' => 1); $args = wp_parse_args($assoc_args, $defaults); $scanner = VIP_Scanner::get_instance()->get_review($args['scan_type'], array('analyzers')); if (!$scanner) { WP_CLI::error(sprintf('Scanning of %s failed', $args['theme'])); } $scanner = new DirectoryScanner($dir, $scanner); $scanner->scan(array('analyzers')); $errors = $scanner->get_errors(); if (!empty($errors)) { self::display_errors($scanner, 'table'); } $empty = array(); $display_args = array('bare' => true, 'depth' => intval($args['depth'])); foreach ($scanner->elements as $element) { // Display empty elements after the others if ($element->is_empty()) { $empty[] = $element; continue; } if ($element->name() !== 'Files') { $element->analyze_prefixes(); } $r = new ElementRenderer($element); WP_CLI::line($r->display(false, $display_args)); } foreach ($empty as $element) { $r = new ElementRenderer($element); $r->display(true, $display_args); } }