Skip to content

Commit

Permalink
make install faster
Browse files Browse the repository at this point in the history
Conflicts:
	composer.json
  • Loading branch information
Hidde Boomsma committed May 11, 2016
1 parent 3aa18d9 commit 27c3268
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 65 deletions.
1 change: 0 additions & 1 deletion A/B/C/D/Hostnet/Sniffs

This file was deleted.

11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
]
}
}
8 changes: 8 additions & 0 deletions src/Hostnet/Component/CodeSniffer/CodeSniffer.conf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
// @codingStandardsIgnoreStart
$phpCodeSnifferConfig = [
'default_standard' => 'Hostnet',
'colors' => '1',
'installed_paths' => __DIR__ . '/../../hostnet/phpcs-tool/src',
];
// @codingStandardsIgnoreEnd
88 changes: 27 additions & 61 deletions src/Hostnet/Component/CodeSniffer/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -17,13 +16,6 @@
*/
class Installer implements PluginInterface, EventSubscriberInterface
{
/**
* The configured directory of the vendor/bin.
*
* @var string
*/
private $bin_dir;

/**
* @var IOInterface
**/
Expand All @@ -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();
}

/**
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 27c3268

Please sign in to comment.