From 47187cc6f57e3ed9cb7e268d7909c02a690609c2 Mon Sep 17 00:00:00 2001 From: Alex Verbruggen Date: Tue, 23 Jan 2018 04:41:11 -0800 Subject: [PATCH 01/12] Fixes first round for toolkit --- bin/qa | 4 +-- .../Command/CheckCodingStandardsCommand.php | 14 ++++---- .../Command/CheckStarterkitCommand.php | 8 ++--- src/Console/Command/ReviewThemeCommand.php | 4 +-- src/Console/Command/ReviewThisCommand.php | 2 +- .../Command/ScanCommentedCodeCommand.php | 10 +++--- src/Console/Command/ScanThemeNameConflict.php | 6 ++-- src/Console/Helper/PhingPropertiesHelper.php | 36 +++++++++++-------- src/Console/Helper/ReviewCommandHelper.php | 31 ++++++++-------- 9 files changed, 61 insertions(+), 54 deletions(-) diff --git a/bin/qa b/bin/qa index cd22918..d46a6f2 100755 --- a/bin/qa +++ b/bin/qa @@ -44,9 +44,9 @@ $commands[] = new ScanCronCommand(); $commands[] = new ScanCommentedCodeCommand(); $commands[] = new ScanTodosCommand(); $commands[] = new ScanThemeNameConflict(); -$commands[] = new CheckStarterkitCommand(); +//$commands[] = new CheckStarterkitCommand(); $commands[] = new ScanPlatformProvidedCommand(); $commands[] = new DiffUpdateHooksCommand(); $commands[] = new DiffMakeFilesCommand(); $application->addCommands($commands); -$application->run(); \ No newline at end of file +$application->run(); diff --git a/src/Console/Command/CheckCodingStandardsCommand.php b/src/Console/Command/CheckCodingStandardsCommand.php index 33435f8..719bc70 100644 --- a/src/Console/Command/CheckCodingStandardsCommand.php +++ b/src/Console/Command/CheckCodingStandardsCommand.php @@ -26,8 +26,8 @@ protected function configure() { $phingPropertiesHelper = new PhingPropertiesHelper(new NullOutput()); $properties = $phingPropertiesHelper->requestSettings(array( - 'phpcs-config' => 'phpcs.config', - 'basedir' => 'project.basedir', + 'phpcs.config' => 'phpcs.config', + 'project.basedir' => 'project.basedir', )); // @codingStandardsIgnoreStart @@ -35,11 +35,11 @@ protected function configure() ->setName('phpcs:run') ->setDescription('Perform a phpcs run with provided phpcs.xml standard.') ->addOption('directory', null, InputOption::VALUE_OPTIONAL, 'Path to run PHPCS on.') - ->addOption('standard', null, InputOption::VALUE_OPTIONAL, 'PHPCS standard.', $properties['phpcs-config']) + ->addOption('standard', null, InputOption::VALUE_OPTIONAL, 'PHPCS standard.', $properties['phpcs.config']) ->addOption('exclude-dirs', null, InputOption::VALUE_OPTIONAL, 'Directories to exclude.') ->addOption('width', null, InputOption::VALUE_OPTIONAL, 'Width of the report.') ->addOption('show', null, InputOption::VALUE_NONE, 'If option is given description is shown.') - ->addOption('basedir', null, InputOption::VALUE_REQUIRED, 'The project basedir to find phpcs.', $properties['basedir']); + ->addOption('project.basedir', null, InputOption::VALUE_REQUIRED, 'The project basedir to find phpcs.', $properties['project.basedir']); // @codingStandardsIgnoreEnd } @@ -48,13 +48,13 @@ protected function execute(InputInterface $input, OutputInterface $output) $dirname = !empty($input->getOption('directory')) ? $input->getOption('directory') : getcwd(); // @codingStandardsIgnoreLine $exclude_dirs = !empty($input->getOption('exclude-dirs')) ? '--ignore=' . $input->getOption('exclude-dirs') . ' ' : ''; - $standard = !empty($input->getOption('standard')) ? $input->getOption('standard') : $properties['phpcs-config']; - $basedir = $input->getOption('basedir'); + $standard = !empty($input->getOption('standard')) ? $input->getOption('standard') : $properties['phpcs.config']; + $basedir = $input->getOption('project.basedir'); //$width = !empty($input->getOption('width')) ? $input->getOption('width') : 80; $show = $input->getOption('show') ? true : false; ob_start(); - $executable = $basedir . "/ssk/phpcs"; + $executable = $basedir . "/toolkit/phpcs"; passthru($executable . " --standard=$standard $exclude_dirs --report=emacs -qvs " . $dirname, $error); $phpcs = ob_get_contents(); ob_end_clean(); diff --git a/src/Console/Command/CheckStarterkitCommand.php b/src/Console/Command/CheckStarterkitCommand.php index dab0866..c1802c2 100644 --- a/src/Console/Command/CheckStarterkitCommand.php +++ b/src/Console/Command/CheckStarterkitCommand.php @@ -31,7 +31,7 @@ protected function configure() ->addOption('branch', null, InputOption::VALUE_OPTIONAL, 'Starterkit branch.') ->addOption('remote', null, InputOption::VALUE_OPTIONAL, 'Starterkit remote.') ->addOption('repository', null, InputOption::VALUE_OPTIONAL, 'Starterkit repository on github.') - ->addOption('basedir', null, InputOption::VALUE_OPTIONAL, 'Project base directory.') + ->addOption('project.basedir', null, InputOption::VALUE_OPTIONAL, 'Project base directory.') ; } @@ -44,7 +44,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if (empty($input->getOption('branch')) || empty($input->getOption('remote')) || empty($input->getOption('repository')) - || empty($input->getOption('basedir')) + || empty($input->getOption('project.basedir')) ) { // Get the needed options for if the call came from console and not from phing. $phingPropertiesHelper = new PhingPropertiesHelper($output); @@ -52,7 +52,7 @@ protected function execute(InputInterface $input, OutputInterface $output) 'branch' => 'starterkit.branch', 'remote' => 'starterkit.remote', 'repository' => 'starterkit.repository', - 'basedir' => 'project.basedir', + 'project.basedir' => 'project.basedir', )); } @@ -61,7 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $remote = !empty($input->getOption('remote')) ? $input->getOption('remote') : $options['remote']; // @codingStandardsIgnoreLine $repository = !empty($input->getOption('repository')) ? $input->getOption('repository') : $options['repository']; - $basedir = !empty($input->getOption('basedir')) ? $input->getOption('basedir') : $options['basedir']; + $basedir = !empty($input->getOption('project.basedir')) ? $input->getOption('project.basedir') : $options['project.basedir']; $subsiteRepository = $this->getGitWrapper()->workingCopy($basedir); // Add the remote for the starterkit if it doesn't exist yet. diff --git a/src/Console/Command/ReviewThemeCommand.php b/src/Console/Command/ReviewThemeCommand.php index 8180bc0..97c63d6 100644 --- a/src/Console/Command/ReviewThemeCommand.php +++ b/src/Console/Command/ReviewThemeCommand.php @@ -43,14 +43,14 @@ protected function execute(InputInterface $input, OutputInterface $output) { $phingPropertiesHelper = new PhingPropertiesHelper($output); $properties = $phingPropertiesHelper->requestSettings(array( - 'lib' => 'subsite.resources.lib.dir', + 'lib.dir' => 'lib.dir', )); // Get the application $application = $this->getApplication(); // Setup the reviewCommandHelper. $reviewCommandHelper = new ReviewCommandThemeHelper($input, $output, $application); // Change the lib property to the current folder. - $reviewCommandHelper->setProperties(array('lib' => $properties['lib'])); + $reviewCommandHelper->setProperties(array('lib.dir' => $properties['lib.dir'])); // Start the review. $reviewCommandHelper->startReview('theme'); } diff --git a/src/Console/Command/ReviewThisCommand.php b/src/Console/Command/ReviewThisCommand.php index 2299e29..48154d8 100644 --- a/src/Console/Command/ReviewThisCommand.php +++ b/src/Console/Command/ReviewThisCommand.php @@ -44,7 +44,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // Setup the reviewCommandHelper. $reviewCommandHelper = new ReviewCommandHelper($input, $output, $application); // Change the lib property to the current folder. - $reviewCommandHelper->setProperties(array('lib' => getcwd())); + $reviewCommandHelper->setProperties(array('lib.dir' => getcwd())); // Start the review. $reviewCommandHelper->startReview(); } diff --git a/src/Console/Command/ScanCommentedCodeCommand.php b/src/Console/Command/ScanCommentedCodeCommand.php index 6e65810..e6bf1fc 100644 --- a/src/Console/Command/ScanCommentedCodeCommand.php +++ b/src/Console/Command/ScanCommentedCodeCommand.php @@ -26,7 +26,7 @@ protected function configure() { $phingPropertiesHelper = new PhingPropertiesHelper(new NullOutput()); $properties = $phingPropertiesHelper->requestSettings(array( - 'basedir' => 'project.basedir', + 'project.basedir' => 'project.basedir', )); // @codingStandardsIgnoreStart $this @@ -36,23 +36,23 @@ protected function configure() ->addOption('exclude-dirs', null, InputOption::VALUE_OPTIONAL, 'Directories to exclude.') ->addOption('width', null, InputOption::VALUE_OPTIONAL, 'Width of the report.') ->addOption('show', null, InputOption::VALUE_NONE, 'If option is given description is shown.') - ->addOption('basedir', null, InputOption::VALUE_REQUIRED, 'The project basedir to find phpcs.', $properties['basedir']); + ->addOption('project.basedir', null, InputOption::VALUE_REQUIRED, 'The project basedir to find phpcs.', $properties['project.basedir']); // @codingStandardsIgnoreEnd } protected function execute(InputInterface $input, OutputInterface $output) { $properties = array( - 'basedir' => 'todo', + 'project.basedir' => 'todo', ); $dirname = !empty($input->getOption('directory')) ? $input->getOption('directory') : getcwd(); // @codingStandardsIgnoreLine $exclude_dirs = !empty($input->getOption('exclude-dirs')) ? '--ignore=' . $input->getOption('exclude-dirs') . ' ' : ''; - $basedir = !empty($input->getOption('basedir')) ? $input->getOption('basedir') : $properties['basedir']; + $basedir = !empty($input->getOption('project.basedir')) ? $input->getOption('project.basedir') : $properties['project.basedir']; //$width = !empty($input->getOption('width')) ? $input->getOption('width') : 80; $show = $input->getOption('show') ? true : false; ob_start(); - $executable = $basedir . "/ssk/phpcs"; + $executable = $basedir . "/toolkit/phpcs"; // @codingStandardsIgnoreLine passthru($executable . " --standard=" . $basedir . "/resources/custom-rulesets/coco-50.xml $exclude_dirs --report=emacs -qvs " . $dirname, $error); $phpcs = ob_get_contents(); diff --git a/src/Console/Command/ScanThemeNameConflict.php b/src/Console/Command/ScanThemeNameConflict.php index 19e9757..d6e4791 100644 --- a/src/Console/Command/ScanThemeNameConflict.php +++ b/src/Console/Command/ScanThemeNameConflict.php @@ -42,7 +42,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $phingPropertiesHelper = new PhingPropertiesHelper($output); $properties = $phingPropertiesHelper->requestSettings(array( - 'lib' => 'subsite.resources.lib.dir', + 'lib.dir' => 'lib.dir', )); // Get the current theme name. @@ -50,7 +50,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if (!$theme_name) { $application = $this->getApplication(); $reviewCommandHelper = new ReviewCommandThemeHelper($input, $output, $application); - $options = $reviewCommandHelper->getThemeFiles($properties['lib']); + $options = $reviewCommandHelper->getThemeFiles($properties['lib.dir']); } else { $options[] = $theme_name; @@ -65,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $finder = new Finder(); $finder->files() ->name($theme_name . '.info') - ->in($properties['lib']) + ->in($properties['lib.dir']) ->exclude(array('themes')) ->sortByName(); diff --git a/src/Console/Helper/PhingPropertiesHelper.php b/src/Console/Helper/PhingPropertiesHelper.php index 584be57..400e57d 100644 --- a/src/Console/Helper/PhingPropertiesHelper.php +++ b/src/Console/Helper/PhingPropertiesHelper.php @@ -9,6 +9,11 @@ use Symfony\Component\Console\Output\OutputInterface; +require_once 'vendor/ec-europa/toolkit/vendor/phing/phing/classes/phing/Phing.php'; +require_once 'vendor/ec-europa/toolkit/vendor/phing/phing/classes/phing/Project.php'; +require_once 'vendor/ec-europa/toolkit/vendor/phing/phing/classes/phing/parser/ProjectConfigurator.php'; +require_once 'vendor/ec-europa/toolkit/vendor/phing/phing/classes/phing/system/io/PhingFile.php'; + /** * Class PhingPropertiesHelper * @package QualityAssurance\Component\Console\Helper @@ -161,7 +166,7 @@ private function setBuildProperties($contents, $settings, &$buildproperties) { // Replace root paths. $contents = str_replace('${project.basedir}', $settings['project.basedir'], $contents); - $contents = str_replace('${project.starterkit.root}', $settings['project.starterkit.root'], $contents); + $contents = str_replace('${toolkit.dir}', $settings['toolkit.dir'], $contents); if ($xml = simplexml_load_string($contents)) { $json = json_encode($xml); @@ -188,16 +193,26 @@ private function getAllSettings($buildfile = '') $buildfile = $this->findPhingBuildFile(); } if ($buildfile) { + \Phing::startup(); + $project = new \Project(); + $project->setUserProperty("phing.file", $buildfile); + $project->setUserProperty("phing.dir", dirname($buildfile)); + $project->fireBuildStarted(); + $project->init(); + \ProjectConfigurator::configureProject($project, new \PhingFile($buildfile)); + $settings = $project->getProperties(); + + /* $root = dirname($buildfile); - $sskRoot = $root . '/vendor/ec-europa/ssk'; + $tkRoot = $root . '/vendor/ec-europa/toolkit'; $settings = array( 'project.basedir' => $root, - 'project.starterkit.root' => $sskRoot, + 'toolkit.dir' => $tkRoot, ); // Array that will gather the build.properties files. $buildproperties = array(); // Start by parsing the main build file. - $contents = file_get_contents($sskRoot . '/build.xml'); + $contents = file_get_contents($tkRoot . '/includes/phing/build/boot/properties.xml'); // Gather build properties from within found files. $this->setBuildProperties($contents, $settings, $buildproperties); @@ -215,9 +230,9 @@ private function getAllSettings($buildfile = '') if (is_file($propertiesfile)) { $settings += $this->parsefile($propertiesfile); } - } + } */ } - $this->resolveProperties($settings); +// $this->resolveProperties($settings); return $settings; } @@ -236,14 +251,7 @@ public function requestSettings($options) { $settings = $this->getAllSettings(); $selection = array(); foreach ($options as $key => $value) { - if (isset($settings[$value])) { - $selection[$key] = $settings[$value]; - } - else { - throw new \Symfony\Component\Debug\Exception\FatalErrorException( - "Requested property ' . $value . ' not found.", 0, 1, __FILE__, __LINE__ - ); - } + $selection[$key] = $settings[$key]; } return $selection; } diff --git a/src/Console/Helper/ReviewCommandHelper.php b/src/Console/Helper/ReviewCommandHelper.php index 2c3a1c3..3efceb8 100644 --- a/src/Console/Helper/ReviewCommandHelper.php +++ b/src/Console/Helper/ReviewCommandHelper.php @@ -156,8 +156,8 @@ protected function buildCommandlines($absolute_path) 'directory' => $directory, 'filename' => $filename, 'profile' => $this->properties['profile'], - 'standard' => $this->properties['phpcs-config'], - 'basedir' => $this->properties['basedir'], + 'standard' => $this->properties['phpcs.config'], + 'project.basedir' => $this->properties['project.basedir'], ); if ($exclude_directories = $this->getSubmoduleDirectories($filename, $directory)) { $command_options['exclude-dirs'] = implode(',', $exclude_directories); @@ -288,14 +288,14 @@ protected function setOptions($section = false) switch ($section) { case 'theme': // Fetch all modules, features and themes into an array. - $options = $this->getThemeFiles($properties['lib']); + $options = $this->getThemeFiles($properties['lib.dir']); break; default: // Fetch all modules, features and themes into an array. - $info_files = $this->getInfoFiles($properties['lib']); + $info_files = $this->getInfoFiles($properties['lib.dir']); // Fetch all make files into an array. - $make_files = $this->getMakeFiles($properties['resources']); + $make_files = $this->getMakeFiles($properties['resources.dir']); // Merge makes and infos into options. $options = array_merge($make_files, $info_files); // Add the "Select all" option. @@ -354,20 +354,19 @@ protected function getPhingProperties($type) $properties = array(); if ($this->input->getOption('type') == 'subsite') { $properties = $phingPropertiesHelper->requestSettings(array( - 'lib' => 'subsite.resources.lib.dir', - 'resources' => 'subsite.resources.dir', - 'phpcs-config' => 'phpcs.config', - 'profile' => 'platform.profile.name', - 'basedir' => 'project.basedir', - 'check-ssk' => 'qa.check.ssk', + 'lib.dir' => 'lib.dir', + 'resources.dir' => 'resources.dir', + 'phpcs.config' => 'phpcs.config', + 'profile' => 'profile', + 'project.basedir' => 'project.basedir', )); } else { $properties = $phingPropertiesHelper->requestSettings(array( - 'lib' => 'platform.resources.profiles.dir', - 'resources' => 'platform.resources.dir', - 'phpcs-config' => 'phpcs.config', - 'profile' => 'platform.profile.name', - 'basedir' => 'project.basedir', + 'lib.dir' => 'lib.dir', + 'resources.dir' => 'resources.dir', + 'phpcs.config' => 'phpcs.config', + 'profile' => 'profile', + 'project.basedir' => 'project.basedir', )); } return $properties; From 3f190665dc4f3aefc0335e9d63b37ade108ea5bd Mon Sep 17 00:00:00 2001 From: Alex Verbruggen Date: Tue, 23 Jan 2018 05:12:16 -0800 Subject: [PATCH 02/12] Set defaults --- src/Console/Command/ScanPlatformProvidedCommand.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Console/Command/ScanPlatformProvidedCommand.php b/src/Console/Command/ScanPlatformProvidedCommand.php index 6ea3bb7..ec0eafc 100644 --- a/src/Console/Command/ScanPlatformProvidedCommand.php +++ b/src/Console/Command/ScanPlatformProvidedCommand.php @@ -7,11 +7,13 @@ namespace QualityAssurance\Component\Console\Command; +use QualityAssurance\Component\Console\Helper\PhingPropertiesHelper; use QualityAssurance\Component\Console\Helper\DrupalInfoFormatHelper; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Question\ChoiceQuestion; use Symfony\Component\Console\Style\SymfonyStyle; @@ -23,13 +25,20 @@ class ScanPlatformProvidedCommand extends Command { protected function configure() { + $phingPropertiesHelper = new PhingPropertiesHelper(new NullOutput()); + $properties = $phingPropertiesHelper->requestSettings(array( + 'profile' => 'profile', + 'resources.dir.site.make' => 'resources.dir.site.make', + 'project.basedir' => 'project.basedir', + )); + $this ->setName('scan:mkpd') ->setDescription('Scan for platform provided modules.') ->addOption('directory', null, InputOption::VALUE_OPTIONAL, 'Path to recursively check.') ->addOption('exclude-dirs', null, InputOption::VALUE_OPTIONAL, 'Directories to exclude.') - ->addOption('filename', null, InputOption::VALUE_OPTIONAL, 'Modulename.') - ->addOption('profile', null, InputOption::VALUE_OPTIONAL, 'Profile.'); + ->addOption('filename', null, InputOption::VALUE_OPTIONAL, 'Modulename.', $properties['resources.dir.site.make']) + ->addOption('profile', null, InputOption::VALUE_OPTIONAL, 'Profile.', $properties['profile']); } protected function execute(InputInterface $input, OutputInterface $output) From 5ee22366132c4d655360c28e76d786d88b7279c2 Mon Sep 17 00:00:00 2001 From: Alex Verbruggen Date: Tue, 23 Jan 2018 07:38:38 -0800 Subject: [PATCH 03/12] Add php compat --- bin/qa | 9 ++- composer.json | 10 +++- phpcs/SubStandards/Subsite/ruleset.xml | 5 -- src/Console/Application.php | 44 +++++++++++++++ .../Command/CheckCodingStandardsCommand.php | 24 +++++--- .../Command/ScanCommentedCodeCommand.php | 9 +-- .../Command/ScanPlatformProvidedCommand.php | 6 +- src/Console/Helper/PhingPropertiesHelper.php | 56 +------------------ src/Console/Helper/ReviewCommandHelper.php | 2 +- 9 files changed, 83 insertions(+), 82 deletions(-) create mode 100755 src/Console/Application.php diff --git a/bin/qa b/bin/qa index d46a6f2..a010041 100755 --- a/bin/qa +++ b/bin/qa @@ -1,7 +1,6 @@ #!/usr/bin/env php setApplication($application); +} + $application->addCommands($commands); + $application->run(); diff --git a/composer.json b/composer.json index 565d8e4..1bfad6e 100755 --- a/composer.json +++ b/composer.json @@ -7,7 +7,9 @@ "drupal/coder": "8.2.12", "php": ">=5.2.0", "symfony/console": "~2.3.10|^2.4.2|~3.0", - "symfony/finder": "^3.2" + "symfony/finder": "^3.2", + "squizlabs/php_codesniffer": "2.9.0", + "wimg/php-compatibility": "^8.1" }, "require-dev": { "phpunit/phpunit": ">=3.7 <5.0" @@ -22,5 +24,9 @@ }, "bin": [ "bin/qa" - ] + ], + "scripts": { + "post-install-cmd": "\"vendor/bin/phpcs\" --config-set installed_paths '../../drupal/coder/coder_sniffer,../../wimg/php-compatibility,../../ec-europa/qa-automation/phpcs/SubStandards'", + "post-update-cmd" : "\"vendor/bin/phpcs\" --config-set installed_paths '../../drupal/coder/coder_sniffer,../../wimg/php-compatibility,../../ec-europa/qa-automation/phpcs/SubStandards'" + } } diff --git a/phpcs/SubStandards/Subsite/ruleset.xml b/phpcs/SubStandards/Subsite/ruleset.xml index fd72437..aa9713c 100644 --- a/phpcs/SubStandards/Subsite/ruleset.xml +++ b/phpcs/SubStandards/Subsite/ruleset.xml @@ -12,11 +12,6 @@ contrib contributed - - **/example_module - **/myproject_core - **/example_theme - diff --git a/src/Console/Application.php b/src/Console/Application.php new file mode 100755 index 0000000..efa0cb6 --- /dev/null +++ b/src/Console/Application.php @@ -0,0 +1,44 @@ +getAllSettings(); + $this->properties = $properties; + } + + public function getProperties() + { + return $this->properties; + } +} diff --git a/src/Console/Command/CheckCodingStandardsCommand.php b/src/Console/Command/CheckCodingStandardsCommand.php index 719bc70..c706d4b 100644 --- a/src/Console/Command/CheckCodingStandardsCommand.php +++ b/src/Console/Command/CheckCodingStandardsCommand.php @@ -8,7 +8,8 @@ namespace QualityAssurance\Component\Console\Command; use QualityAssurance\Component\Console\Helper\PhingPropertiesHelper; -use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Application; +use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -20,15 +21,19 @@ * Class CheckCodingStandardsCommand * @package QualityAssurance\Component\Console\Command */ -class CheckCodingStandardsCommand extends Command +class CheckCodingStandardsCommand extends ContainerAwareCommand { + public function __construct($name = null) + { + parent::__construct(); + } + protected function configure() { $phingPropertiesHelper = new PhingPropertiesHelper(new NullOutput()); - $properties = $phingPropertiesHelper->requestSettings(array( - 'phpcs.config' => 'phpcs.config', - 'project.basedir' => 'project.basedir', - )); + $properties = $phingPropertiesHelper->getAllSettings(); + $app = $this->getApplication(); + var_dump($app); // @codingStandardsIgnoreStart $this @@ -39,22 +44,23 @@ protected function configure() ->addOption('exclude-dirs', null, InputOption::VALUE_OPTIONAL, 'Directories to exclude.') ->addOption('width', null, InputOption::VALUE_OPTIONAL, 'Width of the report.') ->addOption('show', null, InputOption::VALUE_NONE, 'If option is given description is shown.') + ->addOption('toolkit.dir.bin', null, InputOption::VALUE_REQUIRED, 'The binary to phpcs.', $properties['toolkit.dir.bin']) ->addOption('project.basedir', null, InputOption::VALUE_REQUIRED, 'The project basedir to find phpcs.', $properties['project.basedir']); // @codingStandardsIgnoreEnd } protected function execute(InputInterface $input, OutputInterface $output) { - $dirname = !empty($input->getOption('directory')) ? $input->getOption('directory') : getcwd(); + $dirname = !empty($input->getOption('directory')) ? $input->getOption('directory') : ''; // @codingStandardsIgnoreLine $exclude_dirs = !empty($input->getOption('exclude-dirs')) ? '--ignore=' . $input->getOption('exclude-dirs') . ' ' : ''; - $standard = !empty($input->getOption('standard')) ? $input->getOption('standard') : $properties['phpcs.config']; + $standard = !empty($input->getOption('standard')) ? $input->getOption('standard') : ''; $basedir = $input->getOption('project.basedir'); + $executable = $input->getOption('toolkit.dir.bin') . '/phpcs'; //$width = !empty($input->getOption('width')) ? $input->getOption('width') : 80; $show = $input->getOption('show') ? true : false; ob_start(); - $executable = $basedir . "/toolkit/phpcs"; passthru($executable . " --standard=$standard $exclude_dirs --report=emacs -qvs " . $dirname, $error); $phpcs = ob_get_contents(); ob_end_clean(); diff --git a/src/Console/Command/ScanCommentedCodeCommand.php b/src/Console/Command/ScanCommentedCodeCommand.php index e6bf1fc..f8085f3 100644 --- a/src/Console/Command/ScanCommentedCodeCommand.php +++ b/src/Console/Command/ScanCommentedCodeCommand.php @@ -8,6 +8,7 @@ namespace QualityAssurance\Component\Console\Command; use QualityAssurance\Component\Console\Helper\PhingPropertiesHelper; +use QualityAssurance\Component\Console\Application\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -25,9 +26,8 @@ class ScanCommentedCodeCommand extends Command protected function configure() { $phingPropertiesHelper = new PhingPropertiesHelper(new NullOutput()); - $properties = $phingPropertiesHelper->requestSettings(array( - 'project.basedir' => 'project.basedir', - )); + $properties = $phingPropertiesHelper->getAllSettings(); + // @codingStandardsIgnoreStart $this ->setName('scan:coco') @@ -36,6 +36,7 @@ protected function configure() ->addOption('exclude-dirs', null, InputOption::VALUE_OPTIONAL, 'Directories to exclude.') ->addOption('width', null, InputOption::VALUE_OPTIONAL, 'Width of the report.') ->addOption('show', null, InputOption::VALUE_NONE, 'If option is given description is shown.') + ->addOption('toolkit.dir.bin', null, InputOption::VALUE_REQUIRED, 'The binary to phpcs.', $properties['toolkit.dir.bin']) ->addOption('project.basedir', null, InputOption::VALUE_REQUIRED, 'The project basedir to find phpcs.', $properties['project.basedir']); // @codingStandardsIgnoreEnd } @@ -52,7 +53,7 @@ protected function execute(InputInterface $input, OutputInterface $output) //$width = !empty($input->getOption('width')) ? $input->getOption('width') : 80; $show = $input->getOption('show') ? true : false; ob_start(); - $executable = $basedir . "/toolkit/phpcs"; + $executable = $input->getOption('toolkit.dir.bin') . '/phpcs'; // @codingStandardsIgnoreLine passthru($executable . " --standard=" . $basedir . "/resources/custom-rulesets/coco-50.xml $exclude_dirs --report=emacs -qvs " . $dirname, $error); $phpcs = ob_get_contents(); diff --git a/src/Console/Command/ScanPlatformProvidedCommand.php b/src/Console/Command/ScanPlatformProvidedCommand.php index ec0eafc..1716e3c 100644 --- a/src/Console/Command/ScanPlatformProvidedCommand.php +++ b/src/Console/Command/ScanPlatformProvidedCommand.php @@ -26,11 +26,7 @@ class ScanPlatformProvidedCommand extends Command protected function configure() { $phingPropertiesHelper = new PhingPropertiesHelper(new NullOutput()); - $properties = $phingPropertiesHelper->requestSettings(array( - 'profile' => 'profile', - 'resources.dir.site.make' => 'resources.dir.site.make', - 'project.basedir' => 'project.basedir', - )); + $properties = $phingPropertiesHelper->getAllSettings(); $this ->setName('scan:mkpd') diff --git a/src/Console/Helper/PhingPropertiesHelper.php b/src/Console/Helper/PhingPropertiesHelper.php index 400e57d..0e77ea1 100644 --- a/src/Console/Helper/PhingPropertiesHelper.php +++ b/src/Console/Helper/PhingPropertiesHelper.php @@ -129,29 +129,6 @@ private function inVal($val) return $val; } - /** - * Helper function to resolve all variable references in the properties array. - * - * @param array $properties - */ - private function resolveProperties(&$properties) - { - foreach ($properties as $key => $value) { - if (preg_match_all('/\$\{([^\$}]+)\}/', $value, $matches)) { - if (!empty($matches)) { - foreach ($matches[0] as $subkey => $match) { - if (isset($properties[$matches[1][$subkey]])) { - $properties[$key] = preg_replace("~" . preg_quote($match, "~") . "~", $properties[$matches[1][$subkey]], $properties[$key]); - if (preg_match_all('/\$\{([^\$}]+)\}/', $properties[$key], $submatches)) { - $this->resolveProperties($properties); - } - } - } - } - } - } - } - /** * Helper function to extract the build properties files from the build xml files. * @@ -187,7 +164,7 @@ private function setBuildProperties($contents, $settings, &$buildproperties) { * @param $buildfile * Absolute path to the main build file (build.xml). */ - private function getAllSettings($buildfile = '') + public function getAllSettings($buildfile = '') { if (empty($buildfile)) { $buildfile = $this->findPhingBuildFile(); @@ -201,38 +178,7 @@ private function getAllSettings($buildfile = '') $project->init(); \ProjectConfigurator::configureProject($project, new \PhingFile($buildfile)); $settings = $project->getProperties(); - - /* - $root = dirname($buildfile); - $tkRoot = $root . '/vendor/ec-europa/toolkit'; - $settings = array( - 'project.basedir' => $root, - 'toolkit.dir' => $tkRoot, - ); - // Array that will gather the build.properties files. - $buildproperties = array(); - // Start by parsing the main build file. - $contents = file_get_contents($tkRoot . '/includes/phing/build/boot/properties.xml'); - // Gather build properties from within found files. - $this->setBuildProperties($contents, $settings, $buildproperties); - - // This also needs to be recursified. - if (isset($buildproperties['import'])) { - foreach($buildproperties['import'] as $import) { - if (isset($import['@attributes']['file'])) { - $contents = file_get_contents($import['@attributes']['file']); - $this->setBuildProperties($contents, $settings, $buildproperties); - } - } - } - - foreach ($buildproperties as $propertiesfile) { - if (is_file($propertiesfile)) { - $settings += $this->parsefile($propertiesfile); - } - } */ } -// $this->resolveProperties($settings); return $settings; } diff --git a/src/Console/Helper/ReviewCommandHelper.php b/src/Console/Helper/ReviewCommandHelper.php index 3efceb8..95dd5f5 100644 --- a/src/Console/Helper/ReviewCommandHelper.php +++ b/src/Console/Helper/ReviewCommandHelper.php @@ -58,7 +58,7 @@ public function setProperties($overrides = array()) $this->properties = $phingProperties; } } - + /** * Start a review process. */ From 44b3d8ccd9d8202b44810dc211b781eafbd78f3b Mon Sep 17 00:00:00 2001 From: Alex Verbruggen Date: Tue, 23 Jan 2018 07:48:18 -0800 Subject: [PATCH 04/12] Fix location script --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 1bfad6e..37be8c9 100755 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "bin/qa" ], "scripts": { - "post-install-cmd": "\"vendor/bin/phpcs\" --config-set installed_paths '../../drupal/coder/coder_sniffer,../../wimg/php-compatibility,../../ec-europa/qa-automation/phpcs/SubStandards'", - "post-update-cmd" : "\"vendor/bin/phpcs\" --config-set installed_paths '../../drupal/coder/coder_sniffer,../../wimg/php-compatibility,../../ec-europa/qa-automation/phpcs/SubStandards'" + "post-install-cmd": "../../../bin/phpcs --config-set installed_paths '../../drupal/coder/coder_sniffer,../../wimg/php-compatibility,../../ec-europa/qa-automation/phpcs/SubStandards'", + "post-update-cmd" : "../../../bin/phpcs --config-set installed_paths '../../drupal/coder/coder_sniffer,../../wimg/php-compatibility,../../ec-europa/qa-automation/phpcs/SubStandards'" } } From bed5fe69e3f574ec6f4eb4f4c54e3ca09e3522af Mon Sep 17 00:00:00 2001 From: Alex Verbruggen Date: Tue, 23 Jan 2018 09:50:10 -0800 Subject: [PATCH 05/12] Add bundle --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 37be8c9..8344517 100755 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ "symfony/console": "~2.3.10|^2.4.2|~3.0", "symfony/finder": "^3.2", "squizlabs/php_codesniffer": "2.9.0", - "wimg/php-compatibility": "^8.1" + "wimg/php-compatibility": "^8.1", + "symfony/framework-bundle": "^4.0" }, "require-dev": { "phpunit/phpunit": ">=3.7 <5.0" From e577d52df0992004fbaddc93f66d09174773173b Mon Sep 17 00:00:00 2001 From: Alex Verbruggen Date: Tue, 23 Jan 2018 21:35:08 -0800 Subject: [PATCH 06/12] Fixes --- composer.json | 3 +- src/Console/Application.php | 44 ------------------- .../Command/CheckCodingStandardsCommand.php | 12 ++--- 3 files changed, 5 insertions(+), 54 deletions(-) delete mode 100755 src/Console/Application.php diff --git a/composer.json b/composer.json index 8344517..cf219d9 100755 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ "symfony/finder": "^3.2", "squizlabs/php_codesniffer": "2.9.0", "wimg/php-compatibility": "^8.1", - "symfony/framework-bundle": "^4.0" + "symfony/framework-bundle": "^4.0", + "symfony/web-server-bundle": "^4.0" }, "require-dev": { "phpunit/phpunit": ">=3.7 <5.0" diff --git a/src/Console/Application.php b/src/Console/Application.php deleted file mode 100755 index efa0cb6..0000000 --- a/src/Console/Application.php +++ /dev/null @@ -1,44 +0,0 @@ -getAllSettings(); - $this->properties = $properties; - } - - public function getProperties() - { - return $this->properties; - } -} diff --git a/src/Console/Command/CheckCodingStandardsCommand.php b/src/Console/Command/CheckCodingStandardsCommand.php index c706d4b..d7b737b 100644 --- a/src/Console/Command/CheckCodingStandardsCommand.php +++ b/src/Console/Command/CheckCodingStandardsCommand.php @@ -9,7 +9,7 @@ use QualityAssurance\Component\Console\Helper\PhingPropertiesHelper; use Symfony\Component\Console\Application; -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -21,19 +21,12 @@ * Class CheckCodingStandardsCommand * @package QualityAssurance\Component\Console\Command */ -class CheckCodingStandardsCommand extends ContainerAwareCommand +class CheckCodingStandardsCommand extends Command { - public function __construct($name = null) - { - parent::__construct(); - } - protected function configure() { $phingPropertiesHelper = new PhingPropertiesHelper(new NullOutput()); $properties = $phingPropertiesHelper->getAllSettings(); - $app = $this->getApplication(); - var_dump($app); // @codingStandardsIgnoreStart $this @@ -51,6 +44,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { + $dirname = !empty($input->getOption('directory')) ? $input->getOption('directory') : ''; // @codingStandardsIgnoreLine $exclude_dirs = !empty($input->getOption('exclude-dirs')) ? '--ignore=' . $input->getOption('exclude-dirs') . ' ' : ''; From f22893ced22b1d299a46c431bb48e786c234e696 Mon Sep 17 00:00:00 2001 From: Alex Verbruggen Date: Tue, 23 Jan 2018 21:39:12 -0800 Subject: [PATCH 07/12] Fix --- bin/qa | 11 ++--------- composer.json | 3 +-- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/bin/qa b/bin/qa index a010041..8a84ce5 100755 --- a/bin/qa +++ b/bin/qa @@ -14,8 +14,7 @@ use QualityAssurance\Component\Console\Command\DiffMakeFilesCommand; use QualityAssurance\Component\Console\Command\ReviewThisCommand; use QualityAssurance\Component\Console\Command\ReviewThemeCommand; use QualityAssurance\Component\Console\Command\ReviewFullCommand; -use QualityAssurance\Component\Console\Application; - +use Symfony\Component\Console\Application; if (is_file($autoload = getcwd() . '/vendor/autoload.php')) { require $autoload; @@ -33,8 +32,7 @@ if (is_file($autoload = __DIR__ . '/../vendor/autoload.php')) { ); exit(1); } - -$application = new Application('Quality Assurance', '@package_version@'); +$application = new Application(); $commands = array(); $commands[] = new ReviewThisCommand(); $commands[] = new ReviewThemeCommand(); @@ -49,11 +47,6 @@ $commands[] = new ScanThemeNameConflict(); $commands[] = new ScanPlatformProvidedCommand(); $commands[] = new DiffUpdateHooksCommand(); $commands[] = new DiffMakeFilesCommand(); - -foreach ($commands as $command) { - $command->setApplication($application); -} - $application->addCommands($commands); $application->run(); diff --git a/composer.json b/composer.json index cf219d9..8344517 100755 --- a/composer.json +++ b/composer.json @@ -10,8 +10,7 @@ "symfony/finder": "^3.2", "squizlabs/php_codesniffer": "2.9.0", "wimg/php-compatibility": "^8.1", - "symfony/framework-bundle": "^4.0", - "symfony/web-server-bundle": "^4.0" + "symfony/framework-bundle": "^4.0" }, "require-dev": { "phpunit/phpunit": ">=3.7 <5.0" From e34190b5f43245f355cbf7c363e8c03aa038b2e7 Mon Sep 17 00:00:00 2001 From: Alex Verbruggen Date: Tue, 23 Jan 2018 21:43:44 -0800 Subject: [PATCH 08/12] Remove package --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 8344517..37be8c9 100755 --- a/composer.json +++ b/composer.json @@ -9,8 +9,7 @@ "symfony/console": "~2.3.10|^2.4.2|~3.0", "symfony/finder": "^3.2", "squizlabs/php_codesniffer": "2.9.0", - "wimg/php-compatibility": "^8.1", - "symfony/framework-bundle": "^4.0" + "wimg/php-compatibility": "^8.1" }, "require-dev": { "phpunit/phpunit": ">=3.7 <5.0" From 54bddec3883c66f8a6149cd7a00d065eb74416f9 Mon Sep 17 00:00:00 2001 From: Alex Verbruggen Date: Tue, 23 Jan 2018 21:53:43 -0800 Subject: [PATCH 09/12] Add path --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 37be8c9..a1ef0b4 100755 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "bin/qa" ], "scripts": { - "post-install-cmd": "../../../bin/phpcs --config-set installed_paths '../../drupal/coder/coder_sniffer,../../wimg/php-compatibility,../../ec-europa/qa-automation/phpcs/SubStandards'", - "post-update-cmd" : "../../../bin/phpcs --config-set installed_paths '../../drupal/coder/coder_sniffer,../../wimg/php-compatibility,../../ec-europa/qa-automation/phpcs/SubStandards'" + "post-install-cmd": "$(pwd)/bin/phpcs --config-set installed_paths '../../drupal/coder/coder_sniffer,../../wimg/php-compatibility,../../ec-europa/qa-automation/phpcs/SubStandards'", + "post-update-cmd" : "$(pwd)/bin/phpcs --config-set installed_paths '../../drupal/coder/coder_sniffer,../../wimg/php-compatibility,../../ec-europa/qa-automation/phpcs/SubStandards'" } } From 194dbdcc9048cd6cda7861243683b4e4a0f1ebd9 Mon Sep 17 00:00:00 2001 From: Alex Verbruggen Date: Tue, 23 Jan 2018 22:32:43 -0800 Subject: [PATCH 10/12] Re-add exclusion --- phpcs/SubStandards/Subsite/ruleset.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpcs/SubStandards/Subsite/ruleset.xml b/phpcs/SubStandards/Subsite/ruleset.xml index aa9713c..fd72437 100644 --- a/phpcs/SubStandards/Subsite/ruleset.xml +++ b/phpcs/SubStandards/Subsite/ruleset.xml @@ -12,6 +12,11 @@ contrib contributed + + **/example_module + **/myproject_core + **/example_theme + From db20c9eeda27ff963dd9a5080591f010e9f9ba4d Mon Sep 17 00:00:00 2001 From: Joao Santos Date: Fri, 26 Jan 2018 09:56:45 +0100 Subject: [PATCH 11/12] MULTISITE-19240: Include phing/phing into project. --- .gitignore | 1 + composer.json | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c2e8a87..8658bab 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ bin/phpcbf bin/phpcs bin/phpunit +bin/phing composer.lock vendor/ diff --git a/composer.json b/composer.json index a1ef0b4..45c7ce4 100755 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ "symfony/console": "~2.3.10|^2.4.2|~3.0", "symfony/finder": "^3.2", "squizlabs/php_codesniffer": "2.9.0", - "wimg/php-compatibility": "^8.1" + "wimg/php-compatibility": "^8.1", + "phing/phing": "~2.16.0" }, "require-dev": { "phpunit/phpunit": ">=3.7 <5.0" From 3424cc2b608668f34d3570b1687d18cc215c60ae Mon Sep 17 00:00:00 2001 From: Joao Santos Date: Fri, 26 Jan 2018 13:44:13 +0100 Subject: [PATCH 12/12] Switch from hardcoded load to vendor autoload. --- src/Console/Helper/PhingPropertiesHelper.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Console/Helper/PhingPropertiesHelper.php b/src/Console/Helper/PhingPropertiesHelper.php index 0e77ea1..cd3165f 100644 --- a/src/Console/Helper/PhingPropertiesHelper.php +++ b/src/Console/Helper/PhingPropertiesHelper.php @@ -9,10 +9,11 @@ use Symfony\Component\Console\Output\OutputInterface; -require_once 'vendor/ec-europa/toolkit/vendor/phing/phing/classes/phing/Phing.php'; -require_once 'vendor/ec-europa/toolkit/vendor/phing/phing/classes/phing/Project.php'; -require_once 'vendor/ec-europa/toolkit/vendor/phing/phing/classes/phing/parser/ProjectConfigurator.php'; -require_once 'vendor/ec-europa/toolkit/vendor/phing/phing/classes/phing/system/io/PhingFile.php'; +// turn off html errors +ini_set('html_errors', 'off'); + +// Require composer autoload. +require_once dirname(__FILE__) . '/../../../../../autoload.php'; /** * Class PhingPropertiesHelper