Skip to content

Commit

Permalink
Merge pull request #2 from rajeshreeputra/issue-1
Browse files Browse the repository at this point in the history
Cleanup plugin and refactor code.
  • Loading branch information
rajeshreeputra authored Mar 10, 2024
2 parents 2220f10 + f4563a8 commit 2b19701
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 268 deletions.
20 changes: 0 additions & 20 deletions src/Capability/Patcher/DynamicPatchesPatcherProvider.php

This file was deleted.

17 changes: 0 additions & 17 deletions src/Patch.php

This file was deleted.

137 changes: 19 additions & 118 deletions src/Plugin/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,135 +6,36 @@
use Composer\Plugin\Capable;
use Composer\Plugin\PluginInterface;
use Composer\IO\IOInterface;
use Composer\Json\JsonFile;
use Composer\Util\ProcessExecutor;
use cweagans\Composer\Capability\Downloader\DownloaderProvider;
use cweagans\Composer\Capability\Patcher\PatcherProvider;
use cweagans\Composer\Capability\Resolver\ResolverProvider;
use cweagans\Composer\ConfigurablePlugin;
use cweagans\Composer\Locker;
use rajeshreeputra\ComposerDynamicPatches\Capability\Resolver\DynamicPatchesResolverProvider;


class Plugin implements PluginInterface, Capable {

use ConfigurablePlugin;

/**
* @var Composer $composer
*/
protected Composer $composer;

/**
* @var IOInterface $io
*/
protected IOInterface $io;

/**
* @var EventDispatcher $eventDispatcher
*/
protected EventDispatcher $eventDispatcher;

/**
* @var ProcessExecutor $executor
*/
protected ProcessExecutor $executor;

/**
* @var array $patches
*/
protected array $patches;

class Plugin implements PluginInterface, Capable
{
/**
* @var array $installedPatches
* Apply plugin modifications to composer
*
* @param Composer $composer
* @param IOInterface $io
*/
protected array $installedPatches;

/**
* @var ?PatchCollection $patchCollection
*/
protected ?PatchCollection $patchCollection;

protected Locker $locker;

protected JsonFile $lockFile;
public function activate(Composer $composer, IOInterface $io): void
{
}

/**
* Get the path to the current patches lock file.
* @inheritDoc
*/
public static function getPatchesLockFilePath(): string
{
$composer_file = \Composer\Factory::getComposerFile();

$dir = dirname(realpath($composer_file));
$base = pathinfo($composer_file, \PATHINFO_FILENAME);

if ($base === 'composer') {
return "$dir/patches.lock.json";
}

return "$dir/$base-patches.lock.json";
}

/**
* Apply plugin modifications to composer
*
* @param Composer $composer
* @param IOInterface $io
*/
public function activate(Composer $composer, IOInterface $io): void {
$this->composer = $composer;
$this->io = $io;
$this->executor = new ProcessExecutor($this->io);
$this->patches = array();
$this->installedPatches = array();
$this->lockFile = new JsonFile(
static::getPatchesLockFilePath(),
null,
$this->io
);
$this->locker = new Locker($this->lockFile);
$this->configuration = [
'disable-resolvers' => [
'type' => 'list',
'default' => [],
],
'disable-downloaders' => [
'type' => 'list',
'default' => [],
],
'disable-patchers' => [
'type' => 'list',
'default' => [],
],
'default-patch-depth' => [
'type' => 'int',
'default' => 1,
],
'package-depths' => [
'type' => 'list',
'default' => [],
],
'patches-file' => [
'type' => 'string',
'default' => 'patches.json',
]
];
$this->configure($this->composer->getPackage()->getExtra(), 'composer-dynamic-patches');
}

/**
* @inheritDoc
*/
public function getCapabilities(): array {
public function getCapabilities(): array
{
return [
ResolverProvider::class => DynamicPatchesResolverProvider::class
ResolverProvider::class => DynamicPatchesResolverProvider::class
];
}

public function deactivate(Composer $composer, IOInterface $io){}

public function uninstall(Composer $composer, IOInterface $io){}

public function deactivate(Composer $composer, IOInterface $io)
{
}

public function uninstall(Composer $composer, IOInterface $io)
{
}
}
Loading

0 comments on commit 2b19701

Please sign in to comment.