Skip to content

Commit

Permalink
merged in changes from release/3
Browse files Browse the repository at this point in the history
  • Loading branch information
Allan Paiste committed Sep 2, 2018
2 parents a2f3eef + 0bf5729 commit 1478201
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 66 deletions.
8 changes: 7 additions & 1 deletion changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
],
"fix": [
"forward-port(3.34.0): patches queue generator sometimes generated lists that did not queue proper re-applying of patches when dealing with bundles and indirect targets so that 'patch:redo' == 'patch:undo' + 'patch:apply'",
"forward-port(3.34.0): make sure that the removal od 'dev' bundle (or any other type with indirect targets) patches cause proper re-patching of related targets when running with --no-dev"
"forward-port(3.34.0): make sure that the removal od 'dev' bundle (or any other type with indirect targets) patches cause proper re-patching of related targets when running with --no-dev",
"forward-port(3.34.1): conflicting project applied patches state when doing a --no-dev call and a filtered undo/redo after that"
]
},
"4.2.1": {
Expand Down Expand Up @@ -51,6 +52,11 @@
"allow patch failures to be passed over gracefully with extra/patcher/graceful configuration in root package"
]
},
"3.34.1": {
"fix": [
"conflicting project applied patches state when doing a --no-dev call and a filtered undo/redo after that"
]
},
"3.34.0": {
"feature": [
"allow patch path strip level to be defined in patch's embedded target-info declaration (@level <int>)"
Expand Down
8 changes: 4 additions & 4 deletions src/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Bootstrap
* @var \Vaimo\ComposerPatches\Patch\DefinitionList\Loader\ComponentPool
*/
private $loaderComponents;

/**
* @var \Vaimo\ComposerPatches\Managers\LockerManager
*/
Expand Down Expand Up @@ -68,20 +68,20 @@ public function __construct(
$composer,
$logger
);

$this->repositoryProcessor = new \Vaimo\ComposerPatches\Repository\Processor($logger);

$this->lockerManager = new \Vaimo\ComposerPatches\Managers\LockerManager();
}

public function applyPatches($devMode = false, array $filters = array())
public function applyPatches($devMode = false, array $filters = array(), array $resets = array())
{
$repository = $this->composer->getRepositoryManager()->getLocalRepository();

$config = $this->configFactory->create();

$patchesLoader = $this->loaderFactory->create($this->loaderComponents, $config, $devMode);
$patchesApplier = $this->applierFactory->create($config, $filters);
$patchesApplier = $this->applierFactory->create($config, $filters, $resets);

$this->repositoryProcessor->process($repository, $patchesLoader, $patchesApplier);
}
Expand Down
7 changes: 6 additions & 1 deletion src/Composer/Commands/PatchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
);
}

$bootstrap->applyPatches($isDevMode, array_filter($filters));
$bootstrap->applyPatches(
$isDevMode,
array_filter($filters),
$behaviourFlags['redo'] ? array('related') : array('direct', 'related')
);

$bootstrap->sanitizeLocker($composer->getLocker());
}

Expand Down
1 change: 1 addition & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Config
const PATCHER_SOURCES = 'sources';
const PATCHER_SECURE_HTTP = 'secure-http';
const PATCHER_GRACEFUL = 'graceful';

const PATCHER_FORCE_RESET = 'force-reset';

const PATCHES_DEPENDS = 'patches-depend';
Expand Down
40 changes: 14 additions & 26 deletions src/Factories/PatchesApplierFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

use Vaimo\ComposerPatches\Config as PluginConfig;
use Vaimo\ComposerPatches\Patch\FailureHandlers;
use Vaimo\ComposerPatches\Patch\PackageResolvers;
use Vaimo\ComposerPatches\Strategies;

class PatchesApplierFactory
Expand All @@ -22,6 +21,11 @@ class PatchesApplierFactory
*/
private $logger;

/**
* @var \Vaimo\ComposerPatches\Factories\QueueGeneratorFactory
*/
private $queueGeneratorFactory;

/**
* @param \Composer\Composer $composer
* @param \Vaimo\ComposerPatches\Logger $logger
Expand All @@ -32,9 +36,13 @@ public function __construct(
) {
$this->composer = $composer;
$this->logger = $logger;

$this->queueGeneratorFactory = new \Vaimo\ComposerPatches\Factories\QueueGeneratorFactory(
$this->composer
);
}

public function create(PluginConfig $pluginConfig, $filters = array())
public function create(PluginConfig $pluginConfig, array $filters = array(), array $resets = array())
{
$composer = $this->composer;

Expand Down Expand Up @@ -71,31 +79,11 @@ public function create(PluginConfig $pluginConfig, $filters = array())

$packageCollector = new \Vaimo\ComposerPatches\Package\Collector(array($rootPackage));

if ($pluginConfig->shouldResetEverything()) {
$packagesResolver = new PackageResolvers\FullResetResolver();
} else {
$packagesResolver = new PackageResolvers\MissingPatchesResolver();
}

$repositoryAnalyser = new \Vaimo\ComposerPatches\Repository\Analyser(
$packageCollector,
$packagesResolver
);

$missingItemsAnalyser = new \Vaimo\ComposerPatches\Repository\Analyser(
$packageCollector,
new \Vaimo\ComposerPatches\Patch\PackageResolvers\MissingPatchesResolver()
);
$this->queueGeneratorFactory->create($pluginConfig, $filters, $resets);

$listResolver = new \Vaimo\ComposerPatches\Repository\PatchesApplier\ListResolver(
$repositoryAnalyser,
$missingItemsAnalyser
);

$queueGenerator = new \Vaimo\ComposerPatches\Repository\PatchesApplier\QueueGenerator(
$listResolver,
$filters
);
$queueGeneratorFactory = new \Vaimo\ComposerPatches\Factories\QueueGeneratorFactory($composer);

$queueGenerator = $queueGeneratorFactory->create($pluginConfig, $filters, $resets);

$patcherStateManager = new \Vaimo\ComposerPatches\Managers\PatcherStateManager();

Expand Down
67 changes: 67 additions & 0 deletions src/Factories/QueueGeneratorFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* Copyright © Vaimo Group. All rights reserved.
* See LICENSE_VAIMO.txt for license details.
*/
namespace Vaimo\ComposerPatches\Factories;

use Vaimo\ComposerPatches\Repository\ResetsResolvers;
use Vaimo\ComposerPatches\Patch\PackageResolvers;
use Vaimo\ComposerPatches\Config as Config;

class QueueGeneratorFactory
{
/**
* @var \Composer\Composer
*/
private $composer;

/**
* @param \Composer\Composer $composer
*/
public function __construct(
\Composer\Composer $composer
) {
$this->composer = $composer;
}

public function create(Config $pluginConfig, array $filters = array(), $resets = array())
{
$rootPackage = $this->composer->getPackage();

$packageCollector = new \Vaimo\ComposerPatches\Package\Collector(array($rootPackage));

$resolvers = array(
'full' => new PackageResolvers\FullResetResolver(),
'missing' => new PackageResolvers\MissingPatchesResolver()
);

$repositoryAnalyser = new \Vaimo\ComposerPatches\Repository\Analyser(
$packageCollector,
$resolvers[$pluginConfig->shouldResetEverything() ? 'full' : 'missing']
);

$missingItemsAnalyser = new \Vaimo\ComposerPatches\Repository\Analyser(
$packageCollector,
$resolvers['missing']
);

$resetsResolvers = array(
'direct' => new ResetsResolvers\DirectResetsResolver($missingItemsAnalyser),
'related' => new ResetsResolvers\RelatedResetsResolver($repositoryAnalyser)
);

$listResolver = new \Vaimo\ComposerPatches\Repository\PatchesApplier\ListResolver(
$repositoryAnalyser,
$missingItemsAnalyser
);

return new \Vaimo\ComposerPatches\Repository\PatchesApplier\QueueGenerator(
$listResolver,
!$resets
? $resetsResolvers
: array_intersect_key($resetsResolvers, array_flip($resets)),
$filters
);
}
}
19 changes: 19 additions & 0 deletions src/Interfaces/PatchesResetsResolverInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Copyright © Vaimo Group. All rights reserved.
* See LICENSE_VAIMO.txt for license details.
*/
namespace Vaimo\ComposerPatches\Interfaces;

use Composer\Repository\WritableRepositoryInterface as PackageRepository;

interface PatchesResetsResolverInterface
{
/**
* @param PackageRepository $repository
* @param array $patches
* @param array $filters
* @return array
*/
public function resolvePatchesResets(PackageRepository $repository, array $patches, array $filters);
}
28 changes: 0 additions & 28 deletions src/Repository/PatchesApplier/ListResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,34 +67,6 @@ public function resolveRelatedQueue(PackageRepository $repository, array $patche
return $relatedPatchesQueue;
}

public function resolvePatchesResets(PackageRepository $repository, array $patches, array $filters)
{
$resets = $this->repositoryAnalyser->determinePackageResets($repository, $patches);

$fullResets = array_keys(array_filter($resets, 'is_bool'));

$resets = array_diff_key($resets, array_flip($fullResets));

$targets = array_replace_recursive(
$resets,
$this->patchListUtils->createSimplifiedList(array_intersect_key($patches, $resets))
);

$resetPatches = $this->patchListUtils->createDetailedList($targets);

foreach ($filters as $key => $filter) {
$resetPatches = $this->patchListUtils->applyDefinitionFilter(
$resetPatches,
$this->filterUtils->composeRegex($this->filterUtils->trimRules($filter), '/'),
$key
);
}

return array_unique(
array_merge($this->patchListUtils->getAllTargets($resetPatches), $fullResets)
);
}

public function resolvePatchesQueue(array $patches, array $filters)
{
$patches = array_filter($patches);
Expand Down
26 changes: 20 additions & 6 deletions src/Repository/PatchesApplier/QueueGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Vaimo\ComposerPatches\Repository\PatchesApplier;

use Composer\Repository\WritableRepositoryInterface as PackageRepository;
use Vaimo\ComposerPatches\Interfaces\PatchesResetsResolverInterface;

class QueueGenerator
{
Expand All @@ -14,20 +15,28 @@ class QueueGenerator
*/
private $listResolver;

/**
* @var \Vaimo\ComposerPatches\Interfaces\PatchesResetsResolverInterface[]
*/
private $resetResolvers;

/**
* @var array
*/
private $filters;

/**
* @param \Vaimo\ComposerPatches\Repository\PatchesApplier\ListResolver $listResolver,
* @param PatchesResetsResolverInterface[] $resetResolvers
* @param array $filters
*/
public function __construct(
\Vaimo\ComposerPatches\Repository\PatchesApplier\ListResolver $listResolver,
array $resetResolvers,
array $filters
) {
$this->listResolver = $listResolver;
$this->resetResolvers = $resetResolvers;
$this->filters = $filters;
}

Expand All @@ -37,12 +46,17 @@ public function generate(PackageRepository $repository, array $patches)
$patches,
$this->filters
);

$resetsQueue = $this->listResolver->resolvePatchesResets(
$repository,
$patchesQueue,
$this->filters
);

$resetsQueue = array();

foreach ($this->resetResolvers as $resolver) {
$resetsQueue = array_unique(
array_merge(
$resetsQueue,
$resolver->resolvePatchesResets($repository, $patchesQueue, $this->filters)
)
);
}

$relatedQueue = $this->listResolver->resolveRelatedQueue(
$repository,
Expand Down
32 changes: 32 additions & 0 deletions src/Repository/ResetsResolvers/DirectResetsResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Copyright © Vaimo Group. All rights reserved.
* See LICENSE_VAIMO.txt for license details.
*/
namespace Vaimo\ComposerPatches\Repository\ResetsResolvers;

use Composer\Repository\WritableRepositoryInterface as PackageRepository;

class DirectResetsResolver implements \Vaimo\ComposerPatches\Interfaces\PatchesResetsResolverInterface
{
/**
* @var \Vaimo\ComposerPatches\Repository\Analyser
*/
private $itemsAnalyser;

/**
* @param \Vaimo\ComposerPatches\Repository\Analyser $itemsAnalyser
*/
public function __construct(
\Vaimo\ComposerPatches\Repository\Analyser $itemsAnalyser
) {
$this->itemsAnalyser = $itemsAnalyser;
}

public function resolvePatchesResets(PackageRepository $repository, array $patches, array $filters)
{
return array_keys(
$this->itemsAnalyser->determinePackageResets($repository, $patches)
);
}
}
Loading

0 comments on commit 1478201

Please sign in to comment.