Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc updates #494

Merged
merged 3 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Capability/Downloader/CoreDownloaderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CoreDownloaderProvider extends BaseDownloaderProvider
public function getDownloaders(): array
{
return [
new ComposerDownloader($this->composer, $this->io),
new ComposerDownloader($this->composer, $this->io, $this->plugin),
];
}
}
6 changes: 3 additions & 3 deletions src/Capability/Patcher/CorePatcherProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class CorePatcherProvider extends BasePatcherProvider
public function getPatchers(): array
{
return [
new GitPatcher($this->composer, $this->io),
new GitInitPatcher($this->composer, $this->io),
new FreeformPatcher($this->composer, $this->io)
new GitPatcher($this->composer, $this->io, $this->plugin),
new GitInitPatcher($this->composer, $this->io, $this->plugin),
new FreeformPatcher($this->composer, $this->io, $this->plugin)
];
}
}
5 changes: 3 additions & 2 deletions src/Capability/Resolver/CoreResolverProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace cweagans\Composer\Capability\Resolver;

use cweagans\Composer\Resolver\Dependencies;
use cweagans\Composer\Resolver\PatchesFile;
use cweagans\Composer\Resolver\RootComposer;

Expand All @@ -13,8 +14,8 @@ class CoreResolverProvider extends BaseResolverProvider
public function getResolvers(): array
{
return [
new RootComposer($this->composer, $this->io),
new PatchesFile($this->composer, $this->io),
new RootComposer($this->composer, $this->io, $this->plugin),
new PatchesFile($this->composer, $this->io, $this->plugin),
];
}
}
11 changes: 10 additions & 1 deletion src/Downloader/DownloaderBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
use cweagans\Composer\Downloader\Exception\HashMismatchException;
use cweagans\Composer\Patch;

Expand All @@ -23,13 +24,21 @@ abstract class DownloaderBase implements DownloaderInterface
*/
protected IOInterface $io;

/**
* An instance of the main plugin class.
*
* @var PluginInterface
*/
protected PluginInterface $plugin;

/**
* @inheritDoc
*/
public function __construct(Composer $composer, IOInterface $io)
public function __construct(Composer $composer, IOInterface $io, PluginInterface $plugin)
{
$this->composer = $composer;
$this->io = $io;
$this->plugin = $plugin;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/Downloader/DownloaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
use cweagans\Composer\Patch;

interface DownloaderInterface
Expand All @@ -21,8 +22,10 @@ interface DownloaderInterface
* package metadata and configuration.
* @param IOInterface $io
* IO object to use for resolver input/output.
* @param PluginInterface $plugin
* The main plugin class.
*/
public function __construct(Composer $composer, IOInterface $io);
public function __construct(Composer $composer, IOInterface $io, PluginInterface $plugin);

/**
* Apply a patch.
Expand Down
11 changes: 10 additions & 1 deletion src/Patcher/PatcherBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
use Composer\Util\ProcessExecutor;
use cweagans\Composer\Patch;
use Symfony\Component\Process\Process;
Expand All @@ -24,6 +25,13 @@ abstract class PatcherBase implements PatcherInterface
*/
protected IOInterface $io;

/**
* An instance of the main plugin class.
*
* @var PluginInterface
*/
protected PluginInterface $plugin;

/**
* If set, the Patcher object will use this path instead of a $PATH lookup to execute the appropriate tool.
*
Expand All @@ -48,10 +56,11 @@ abstract class PatcherBase implements PatcherInterface
/**
* {@inheritDoc}
*/
public function __construct(Composer $composer, IOInterface $io)
public function __construct(Composer $composer, IOInterface $io, PluginInterface $plugin)
{
$this->composer = $composer;
$this->io = $io;
$this->plugin = $plugin;
$this->executor = new ProcessExecutor($io);
}

Expand Down
5 changes: 4 additions & 1 deletion src/Patcher/PatcherInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
use cweagans\Composer\Patch;

interface PatcherInterface
Expand All @@ -16,8 +17,10 @@ interface PatcherInterface
* package metadata and configuration.
* @param IOInterface $io
* IO object to use for resolver input/output.
* @param PluginInterface $plugin
* The main plugin class.
*/
public function __construct(Composer $composer, IOInterface $io);
public function __construct(Composer $composer, IOInterface $io, PluginInterface $plugin);

/**
* Apply a patch.
Expand Down
23 changes: 16 additions & 7 deletions src/Resolver/PatchesFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace cweagans\Composer\Resolver;

use Composer\Installer\PackageEvent;
use cweagans\Composer\Patch;
use cweagans\Composer\Plugin\Patches;
use cweagans\Composer\PatchCollection;
use InvalidArgumentException;

Expand All @@ -19,18 +19,23 @@ class PatchesFile extends ResolverBase
*/
public function resolve(PatchCollection $collection): void
{
$extra = $this->composer->getPackage()->getExtra();
$valid_patches_file = array_key_exists('patches-file', $extra) &&
file_exists(realpath($extra['patches-file'])) &&
is_readable(realpath($extra['patches-file']));
$patches_file = $this->plugin->getConfig('patches-file');

$valid_patches_file = file_exists(realpath($patches_file)) && is_readable(realpath($patches_file));

// $extra = $this->composer->getPackage()->getExtra();
// $valid_patches_file = array_key_exists('composer-patches', $extra) &&
// array_key_exists('patches-file', $extra['composer-patches']) &&
// file_exists(realpath($extra['composer-patches']['patches-file'])) &&
// is_readable(realpath($extra['composer-patches']['patches-file']));

// If we don't have a valid patches file, exit early.
if (!$valid_patches_file) {
return;
}

$this->io->write(' - <info>Gathering patches from patches file.</info>');
$patches_file = $this->readPatchesFile($extra['patches-file']);
$this->io->write(' - <info>Resolving patches from patches file.</info>');
$patches_file = $this->readPatchesFile($patches_file);

foreach ($this->findPatchesInJson($patches_file) as $package => $patches) {
foreach ($patches as $patch) {
Expand All @@ -51,6 +56,10 @@ public function resolve(PatchCollection $collection): void
*/
protected function readPatchesFile($patches_file): array
{
if ($patches_file === '') {
return [];
}

$patches = file_get_contents($patches_file);
$patches = json_decode($patches, true);

Expand Down
12 changes: 10 additions & 2 deletions src/Resolver/ResolverBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
namespace cweagans\Composer\Resolver;

use Composer\Composer;
use Composer\Installer\PackageEvent;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
use cweagans\Composer\Patch;
use cweagans\Composer\PatchCollection;

Expand All @@ -29,13 +29,21 @@ abstract class ResolverBase implements ResolverInterface
*/
protected IOInterface $io;

/**
* An instance of the main plugin class.
*
* @var PluginInterface
*/
protected PluginInterface $plugin;

/**
* {@inheritDoc}
*/
public function __construct(Composer $composer, IOInterface $io)
public function __construct(Composer $composer, IOInterface $io, PluginInterface $plugin)
{
$this->composer = $composer;
$this->io = $io;
$this->plugin = $plugin;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/Resolver/ResolverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
use cweagans\Composer\PatchCollection;

interface ResolverInterface
Expand All @@ -21,8 +22,10 @@ interface ResolverInterface
* package metadata and configuration.
* @param IOInterface $io
* IO object to use for resolver input/output.
* @param PluginInterface $plugin
* The main plugin class.
*/
public function __construct(Composer $composer, IOInterface $io);
public function __construct(Composer $composer, IOInterface $io, PluginInterface $plugin);

/**
* Find and add patches to the supplied PatchCollection.
Expand Down
3 changes: 1 addition & 2 deletions src/Resolver/RootComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace cweagans\Composer\Resolver;

use Composer\Installer\PackageEvent;
use cweagans\Composer\Patch;
use cweagans\Composer\PatchCollection;

Expand All @@ -23,7 +22,7 @@ public function resolve(PatchCollection $collection): void
return;
}

$this->io->write(' - <info>Gathering patches from root package</info>');
$this->io->write(' - <info>Resolving patches from root package.</info>');

foreach ($this->findPatchesInJson($extra['patches']) as $package => $patches) {
foreach ($patches as $patch) {
Expand Down
9 changes: 7 additions & 2 deletions tests/unit/ComposerDownloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
namespace cweagans\Composer\Tests\Unit;

use Codeception\Test\Unit;
use Codeception\Util\Stub;
use Composer\Composer;
use Composer\Config;
use Composer\IO\NullIO;
use Composer\Plugin\PluginInterface;
use cweagans\Composer\Downloader\ComposerDownloader;
use cweagans\Composer\Downloader\Exception\HashMismatchException;
use cweagans\Composer\Patch;
use cweagans\Composer\Plugin\Patches;

class ComposerDownloaderTest extends Unit
{
Expand All @@ -34,8 +37,9 @@ public function testDownloader()
$composer = new Composer();
$composer->setConfig(new Config());
$io = new NullIO();
$plugin = Stub::makeEmpty(PluginInterface::class);

$downloader = new ComposerDownloader($composer, $io);
$downloader = new ComposerDownloader($composer, $io, $plugin);

$patch = new Patch();
$patch->package = "placeholder";
Expand Down Expand Up @@ -73,8 +77,9 @@ public function testLocalFile()
$composer = new Composer();
$composer->setConfig(new Config());
$io = new NullIO();
$plugin = Stub::makeEmpty(PluginInterface::class);

$downloader = new ComposerDownloader($composer, $io);
$downloader = new ComposerDownloader($composer, $io, $plugin);

$patch = new Patch();
$patch->package = "placeholder";
Expand Down
14 changes: 8 additions & 6 deletions tests/unit/PatcherAvailabilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
namespace cweagans\Composer\Tests\Unit;

use Codeception\Test\Unit;
use Codeception\Util\Stub;
use Composer\Composer;
use Composer\IO\NullIO;
use cweagans\Composer\Patcher\BsdPatchPatcher;
use cweagans\Composer\Patcher\GnuPatchPatcher;
use Composer\Plugin\PluginInterface;
use cweagans\Composer\Patcher\GitPatcher;

class PatcherAvailabilityTest extends Unit
Expand All @@ -28,19 +28,21 @@ public function testMissingOrBrokenToolBehaviors($patcher, $expected)

public function missingOrBrokenToolBehaviorsDataProvider()
{
$patcher = new GitPatcher(new Composer(), new NullIO());
$plugin = Stub::makeEmpty(PluginInterface::class);

$patcher = new GitPatcher(new Composer(), new NullIO(), $plugin);
$patcher->toolPathOverride = codecept_data_dir('testtools/intentionally-missing-executable');
yield 'missing git' => [$patcher, false];

$patcher = new GitPatcher(new Composer(), new NullIO());
$patcher = new GitPatcher(new Composer(), new NullIO(), $plugin);
$patcher->toolPathOverride = codecept_data_dir('testtools/broken-git.sh');
yield 'broken git' => [$patcher, false];

$patcher = new GitPatcher(new Composer(), new NullIO());
$patcher = new GitPatcher(new Composer(), new NullIO(), $plugin);
$patcher->toolPathOverride = codecept_data_dir('testtools/git.sh');
yield 'working git' => [$patcher, true];

$patcher = new GitPatcher(new Composer(), new NullIO());
$patcher = new GitPatcher(new Composer(), new NullIO(), $plugin);
yield 'working (real) git' => [$patcher, true];
}
}