From 27c3268c726e2119e5771c38eddc715792c66ef5 Mon Sep 17 00:00:00 2001 From: Hidde Boomsma Date: Wed, 11 May 2016 11:22:16 +0200 Subject: [PATCH] make install faster Conflicts: composer.json --- A/B/C/D/Hostnet/Sniffs | 1 - composer.json | 11 ++- .../CodeSniffer/CodeSniffer.conf.php | 8 ++ .../Component/CodeSniffer/Installer.php | 88 ++++++------------- 4 files changed, 43 insertions(+), 65 deletions(-) delete mode 120000 A/B/C/D/Hostnet/Sniffs create mode 100644 src/Hostnet/Component/CodeSniffer/CodeSniffer.conf.php diff --git a/A/B/C/D/Hostnet/Sniffs b/A/B/C/D/Hostnet/Sniffs deleted file mode 120000 index 2ed0b71..0000000 --- a/A/B/C/D/Hostnet/Sniffs +++ /dev/null @@ -1 +0,0 @@ -../../../../../src/Hostnet/Sniffs/ \ No newline at end of file diff --git a/composer.json b/composer.json index b69314d..934890b 100644 --- a/composer.json +++ b/composer.json @@ -16,12 +16,12 @@ "minimum-stability": "stable", "autoload": { "psr-0": { - "" : "src/" + "Hostnet": "src/" } }, "autoload-dev": { "psr-0": { - "" : "test/" + "Hostnet": "test/" }, "files" : [ "vendor/squizlabs/php_codesniffer/tests/Standards/AbstractSniffUnitTest.php" @@ -35,6 +35,11 @@ }, "scripts": { "pre-dependencies-solving": "Hostnet\\Component\\CodeSniffer\\Installer::ensureSource", - "post-autoload-dump": "Hostnet\\Component\\CodeSniffer\\Installer::configure" + "post-autoload-dump": "Hostnet\\Component\\CodeSniffer\\Installer::configureAsRoot" + }, + "archive": { + "exclude": [ + "/test" + ] } } diff --git a/src/Hostnet/Component/CodeSniffer/CodeSniffer.conf.php b/src/Hostnet/Component/CodeSniffer/CodeSniffer.conf.php new file mode 100644 index 0000000..dbf4611 --- /dev/null +++ b/src/Hostnet/Component/CodeSniffer/CodeSniffer.conf.php @@ -0,0 +1,8 @@ + 'Hostnet', + 'colors' => '1', + 'installed_paths' => __DIR__ . '/../../hostnet/phpcs-tool/src', +]; +// @codingStandardsIgnoreEnd diff --git a/src/Hostnet/Component/CodeSniffer/Installer.php b/src/Hostnet/Component/CodeSniffer/Installer.php index 1288afb..b25af9e 100644 --- a/src/Hostnet/Component/CodeSniffer/Installer.php +++ b/src/Hostnet/Component/CodeSniffer/Installer.php @@ -6,7 +6,6 @@ use Composer\Installer\InstallerEvent; use Composer\IO\IOInterface; use Composer\Plugin\PluginInterface; -use Composer\Script\Event; use Hostnet\Component\Path\Path; /** @@ -17,13 +16,6 @@ */ class Installer implements PluginInterface, EventSubscriberInterface { - /** - * The configured directory of the vendor/bin. - * - * @var string - */ - private $bin_dir; - /** * @var IOInterface **/ @@ -38,8 +30,22 @@ class Installer implements PluginInterface, EventSubscriberInterface */ public function activate(Composer $composer, IOInterface $io) { - $this->bin_dir = $composer->getConfig()->get('bin-dir'); - $this->io = $io; + $this->io = $io; + } + + /** + * The 'logical'-operation of this Installer. + * PHPCS does not define constants for the config options, + * doing so ourself would only lead to outdated intel. + * + * @see https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options + */ + public function execute() + { + if ($this->io->isVerbose()) { + $this->io->write('Configured phpcs to use Hostnet standard'); + } + self::configure(); } /** @@ -67,62 +73,22 @@ public static function ensureSource(InstallerEvent $event) $download_manager->setPreferSource(true); } - /** - * Allow configuration from script, to use and test phpcs standalone - * @param Event $event the event fired. - */ - public static function configure(Event $event) - { - $root = $event->getComposer()->getPackage()->getName() === 'hostnet/phpcs-tool'; - self::defaultConfig($event->getComposer()->getConfig()->get('bin-dir'), $event->getIo(), $root); - } - - /** - * Use executable of phpcs to configure prefereces - * @param string $setting name of the setting - * @param string $value value of the setting - * @param string $bin_dir location of the phpcs executable - * @param IOInterface $io composer io interface for verbose output - */ - public static function phpcsConfig($setting, $value, $bin_dir, IOInterface $io) + public static function configureAsRoot() { - - $phpcs = escapeshellarg($bin_dir . '/phpcs'); - $setting = escapeshellarg($setting); - $value = escapeshellarg($value); - $output = `2>&1 $phpcs --config-set $setting $value`; - - if ($io->isVerbose()) { - $io->write($output); + $vendor_dir = Path::VENDOR_DIR . '/hostnet/phpcs-tool/src/Hostnet'; + if (!file_exists($vendor_dir)) { + self::configure(); + mkdir($vendor_dir, 0777, true); + symlink(__DIR__ . '/../../Sniffs', $vendor_dir . '/Sniffs'); + copy(__DIR__ . '/../../ruleset.xml', $vendor_dir . '/ruleset.xml'); } } - /** - * Set the default config for phpcs to our desired settings - * @param string $bin_dir - * @param IOInterface $io - */ - public static function defaultConfig($bin_dir, IOInterface $io, $is_root) + public static function configure() { - self::phpcsConfig('default_standard', 'Hostnet', $bin_dir, $io); - self::phpcsConfig('colors', 1, $bin_dir, $io); - if ($is_root) { - copy(__DIR__ . '/../../ruleset.xml', __DIR__ . '/../../../../A/B/C/D/Hostnet/ruleset.xml'); - self::phpcsConfig('installed_paths', realpath(__DIR__ . '/../../../../A/B/C/D'), $bin_dir, $io); - } else { - self::phpcsConfig('installed_paths', realpath(__DIR__ . '/../../..'), $bin_dir, $io); + $file = Path::VENDOR_DIR . '/squizlabs/php_codesniffer/CodeSniffer.conf'; + if (!file_exists($file)) { + copy(__DIR__ . '/CodeSniffer.conf.php', $file); } } - - /** - * The 'logical'-operation of this Installer. - * PHPCS does not define constants for the config options, - * doing so ourself would only lead to outdated intel. - * - * @see https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options - */ - public function execute() - { - self::defaultConfig($this->bin_dir, $this->io, false); - } }