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

Drop composer 1.x support #265

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@ jobs:
sudo apt-add-repository ppa:ondrej/php -y
sudo apt-fast install -y --no-install-recommends php${{ matrix.php }}-ast

- name: Use Composer v1
run: composer require --dev --no-update composer/composer:^1.1

- name: Print Composer version
run: composer --version

- name: composer install
run: composer update --no-interaction --no-progress --ansi

- run: composer test

- name: Use Composer v2
run: composer require --dev --no-update composer/composer:^2.0

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Composer Merge Plugin 1.4.x (and older) requires Composer 1.x.

Composer Merge Plugin 2.0.x (and newer) is compatible with both Composer 2.x and 1.x.

Composer Merge Plugin 3.0.x (and newer) is requires Composer 2.x.

```
$ composer require wikimedia/composer-merge-plugin
```
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"prefer-stable": true,
"require": {
"php": ">=7.4.0",
"composer-plugin-api": "^1.1||^2.0"
"composer-plugin-api": "^2.0"
},
"require-dev": {
"ext-json": "*",
Expand Down
20 changes: 7 additions & 13 deletions src/ExtraPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,7 @@ protected function mergeOrDefer(
}
}

if (!$state->isComposer1()) {
Intervals::clear();
}
Intervals::clear();

return $origin;
}
Expand All @@ -348,18 +346,14 @@ protected function mergeConstraints(Link $origin, Link $merge, PluginState $stat
$oldPrettyString = $origin->getConstraint()->getPrettyString();
$newPrettyString = $merge->getConstraint()->getPrettyString();

if ($state->isComposer1()) {
$constraintClass = MultiConstraint::class;
} else {
$constraintClass = \Composer\Semver\Constraint\MultiConstraint::class;
$constraintClass = \Composer\Semver\Constraint\MultiConstraint::class;

if (Intervals::isSubsetOf($origin->getConstraint(), $merge->getConstraint())) {
return $origin;
}
if (Intervals::isSubsetOf($origin->getConstraint(), $merge->getConstraint())) {
return $origin;
}

if (Intervals::isSubsetOf($merge->getConstraint(), $origin->getConstraint())) {
return $merge;
}
if (Intervals::isSubsetOf($merge->getConstraint(), $origin->getConstraint())) {
return $merge;
}

$newConstraint = $constraintClass::create([
Expand Down
9 changes: 1 addition & 8 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,7 @@ public function warning($message)
*/
public function log($message)
{
if (method_exists($this->inputOutput, 'writeError')) {
$this->inputOutput->writeError($message);
} else {
// @codeCoverageIgnoreStart
// Backwards compatibility for Composer before cb336a5
$this->inputOutput->write($message);
// @codeCoverageIgnoreEnd
}
$this->inputOutput->writeError($message);
}
}
// vim:sw=4:ts=4:sts=4:et:
22 changes: 7 additions & 15 deletions src/MergePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,13 @@ public function onPostInstallOrUpdate(ScriptEvent $event)

$lockBackup = null;
$lock = null;
if (!$this->state->isComposer1()) {
$file = Factory::getComposerFile();
$lock = Factory::getLockFile($file);
if (file_exists($lock)) {
$lockBackup = file_get_contents($lock);
}
$file = Factory::getComposerFile();
$lock = Factory::getLockFile($file);
if (file_exists($lock)) {
$lockBackup = file_get_contents($lock);
}


$config = $this->composer->getConfig();
$preferSource = $config->get('preferred-install') === 'source';
$preferDist = $config->get('preferred-install') === 'dist';
Expand All @@ -371,17 +370,10 @@ public function onPostInstallOrUpdate(ScriptEvent $event)
);

$installer->setUpdate(true);

if ($this->state->isComposer1()) {
// setUpdateWhitelist() only exists in composer 1.x. Configure as to run phan against composer 2.x
// @phan-suppress-next-line PhanUndeclaredMethod
$installer->setUpdateWhitelist($requirements);
} else {
$installer->setUpdateAllowList($requirements);
}
$installer->setUpdateAllowList($requirements);

$status = $installer->run();
if (( $status !== 0 ) && $lockBackup && $lock && !$this->state->isComposer1()) {
if (( $status !== 0 ) && $lockBackup && $lock) {
$this->logger->log(
"\n".'<error>'.
'Update to apply merge settings failed, reverting '.$lock.' to its original content.'.
Expand Down
16 changes: 0 additions & 16 deletions src/PluginState.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ class PluginState
*/
protected $composer;

/**
* @var bool $isComposer1
*/
protected $isComposer1;

/**
* @var array $includes
*/
Expand Down Expand Up @@ -138,17 +133,6 @@ class PluginState
public function __construct(Composer $composer)
{
$this->composer = $composer;
$this->isComposer1 = version_compare(PluginInterface::PLUGIN_API_VERSION, '2.0.0', '<');
}

/**
* Test if this plugin runs within Composer 1.
*
* @return bool
*/
public function isComposer1()
{
return $this->isComposer1;
}

/**
Expand Down
124 changes: 39 additions & 85 deletions tests/phpunit/MergePluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,24 +596,16 @@ function ($args) use ($that, $io) {

$config = new Config();
$mockIO = $io->reveal();
if (version_compare('2.0.0', PluginInterface::PLUGIN_API_VERSION, '>')) {
return new VcsRepository(
$args[1],
$mockIO,
$config
);
} else {
$httpDownloader = new HttpDownloader(
$mockIO,
$config
);
return new VcsRepository(
$args[1],
$mockIO,
$config,
$httpDownloader
);
}
$httpDownloader = new HttpDownloader(
$mockIO,
$config
);
return new VcsRepository(
$args[1],
$mockIO,
$config,
$httpDownloader
);
}
);
$repoManager->prependRepository(Argument::any())->will(
Expand Down Expand Up @@ -688,25 +680,17 @@ function ($args) use ($that, $io) {

$config = new Config();
$mockIO = $io->reveal();
if (version_compare('2.0.0', PluginInterface::PLUGIN_API_VERSION, '>')) {
return new VcsRepository(
$args[1],
$mockIO,
$config
);
} else {
$httpDownloader = new HttpDownloader(
$mockIO,
$config
);

return new VcsRepository(
$args[1],
$mockIO,
$config,
$httpDownloader
);
}
$httpDownloader = new HttpDownloader(
$mockIO,
$config
);

return new VcsRepository(
$args[1],
$mockIO,
$config,
$httpDownloader
);
}
);
$repoManager->prependRepository(Argument::any())->will(
Expand Down Expand Up @@ -1252,13 +1236,6 @@ public function testHasBranchAlias($fireInit)
$io = $this->io;
$dir = $this->fixtureDir(__FUNCTION__);

// RootAliasPackage was updated in 06c44ce to include more setters
// that we take advantage of if available
$haveComposerWithCompleteRootAlias = method_exists(
RootPackageInterface::class,
'setRepositories'
);

$repoManager = $this->prophesize(
RepositoryManager::class
);
Expand All @@ -1268,25 +1245,17 @@ public function testHasBranchAlias($fireInit)
)->will(function ($args) use ($io) {
$config = new Config();
$mockIO = $io->reveal();
if (version_compare('2.0.0', PluginInterface::PLUGIN_API_VERSION, '>')) {
return new VcsRepository(
$args[1],
$mockIO,
$config
);
} else {
$httpDownloader = new HttpDownloader(
$mockIO,
$config
);
$httpDownloader = new HttpDownloader(
$mockIO,
$config
);

return new VcsRepository(
$args[1],
$mockIO,
$config,
$httpDownloader
);
}
return new VcsRepository(
$args[1],
$mockIO,
$config,
$httpDownloader
);
});
$repoManager->prependRepository(Argument::any())->shouldBeCalled();
$this->composer->getRepositoryManager()->will(
Expand All @@ -1306,29 +1275,14 @@ function () use ($repoManager) {
$alias->setDevRequires(Argument::type('array'))->shouldBeCalled();
$alias->setRequires(Argument::type('array'))->shouldBeCalled();

if ($haveComposerWithCompleteRootAlias) {
// When Composer supports it we will apply our changes directly to
// the RootAliasPackage
$alias->setAutoload(Argument::type('array'))->shouldBeCalled();
$alias->setConflicts(Argument::type('array'))->shouldBeCalled();
$alias->setDevAutoload(Argument::type('array'))->shouldBeCalled();
$alias->setProvides(Argument::type('array'))->shouldBeCalled();
$alias->setReplaces(Argument::type('array'))->shouldBeCalled();
$alias->setRepositories(Argument::type('array'))->shouldBeCalled();
$alias->setStabilityFlags(Argument::type('array'))->shouldBeCalled();
$alias->setSuggests(Argument::type('array'))->shouldBeCalled();
} else {
// With older versions of Composer we will fall back to unwrapping
// the aliased RootPackage and make calls to it
$root->setAutoload(Argument::type('array'))->shouldBeCalled();
$root->setConflicts(Argument::type('array'))->shouldBeCalled();
$root->setDevAutoload(Argument::type('array'))->shouldBeCalled();
$root->setProvides(Argument::type('array'))->shouldBeCalled();
$root->setReplaces(Argument::type('array'))->shouldBeCalled();
$root->setRepositories(Argument::type('array'))->shouldBeCalled();
$root->setSuggests(Argument::type('array'))->shouldBeCalled();
$alias->getAliasOf()->shouldBeCalled();
}
$alias->setAutoload(Argument::type('array'))->shouldBeCalled();
$alias->setConflicts(Argument::type('array'))->shouldBeCalled();
$alias->setDevAutoload(Argument::type('array'))->shouldBeCalled();
$alias->setProvides(Argument::type('array'))->shouldBeCalled();
$alias->setReplaces(Argument::type('array'))->shouldBeCalled();
$alias->setRepositories(Argument::type('array'))->shouldBeCalled();
$alias->setStabilityFlags(Argument::type('array'))->shouldBeCalled();
$alias->setSuggests(Argument::type('array'))->shouldBeCalled();

$alias = $alias->reveal();

Expand Down