Issue #3126566 by greg.1.anderson, jungle, tedbow, hussainweb, Kristen Pol, alexpott: Allow Drupal to work with Composer 2

merge-requests/64/head
catch 2020-05-06 10:13:47 +01:00
parent f75a4b42cb
commit 53e445bf42
10 changed files with 79 additions and 9 deletions

8
composer.lock generated
View File

@ -884,10 +884,10 @@
"dist": {
"type": "path",
"url": "composer/Plugin/ProjectMessage",
"reference": "3b795f469441eb27854798f70cb38e717d80bbfc"
"reference": "ed6afc20bfed583e5325ca86f78d07a653d6045c"
},
"require": {
"composer-plugin-api": "^1.1",
"composer-plugin-api": "^1.1 || ^2",
"php": ">=7.0.8"
},
"type": "composer-plugin",
@ -914,10 +914,10 @@
"dist": {
"type": "path",
"url": "composer/Plugin/VendorHardening",
"reference": "2db54f089065dedbe4a040b01f7b527f2bad68f6"
"reference": "6773d713a655ec8a5ac8c29cd5df653cfec6d3cc"
},
"require": {
"composer-plugin-api": "^1.1",
"composer-plugin-api": "^1.1 || ^2",
"php": ">=7.0.8"
},
"type": "composer-plugin",

View File

@ -45,6 +45,18 @@ class MessagePlugin implements PluginInterface, EventSubscriberInterface {
$this->io = $io;
}
/**
* {@inheritdoc}
*/
public function deactivate(Composer $composer, IOInterface $io) {
}
/**
* {@inheritdoc}
*/
public function uninstall(Composer $composer, IOInterface $io) {
}
/**
* {@inheritdoc}
*/

View File

@ -15,6 +15,6 @@
},
"require": {
"php": ">=7.0.8",
"composer-plugin-api": "^1.1"
"composer-plugin-api": "^1.1 || ^2"
}
}

View File

@ -3,6 +3,7 @@
namespace Drupal\Composer\Plugin\Scaffold;
use Composer\Composer;
use Composer\DependencyResolver\Operation\OperationInterface;
use Composer\Installer\PackageEvent;
use Composer\IO\IOInterface;
use Composer\Package\PackageInterface;
@ -96,8 +97,12 @@ class AllowedPackages implements PostPackageEventListenerInterface {
*/
public function event(PackageEvent $event) {
$operation = $event->getOperation();
// Determine the package.
$package = $operation->getJobType() == 'update' ? $operation->getTargetPackage() : $operation->getPackage();
// Determine the package. Later, in evaluateNewPackages(), we will report
// which of the newly-installed packages have scaffold operations, and
// whether or not they are allowed to scaffold by the allowed-packages
// option in the root-level composer.json file.
$operationType = $this->getOperationType($operation);
$package = $operationType === 'update' ? $operation->getTargetPackage() : $operation->getPackage();
if (ScaffoldOptions::hasOptions($package->getExtra())) {
$this->newPackages[$package->getName()] = $package;
}
@ -176,6 +181,26 @@ class AllowedPackages implements PostPackageEventListenerInterface {
return $allowed_packages;
}
/**
* Determine the type of the provided operation.
*
* Adjusts API used for Composer 1 or Composer 2.
*
* @param \Composer\DependencyResolver\Operation\OperationInterface $operation
* The operation object.
*
* @return string
* The operation type.
*/
protected function getOperationType(OperationInterface $operation) {
// Use Composer 2 method.
if (method_exists($operation, 'getOperationType')) {
return $operation->getOperationType();
}
// Fallback to Composer 1 method.
return $operation->getJobType();
}
/**
* Retrieves a package from the current composer process.
*

View File

@ -60,6 +60,18 @@ class Plugin implements PluginInterface, EventSubscriberInterface, Capable {
$this->requireWasCalled = FALSE;
}
/**
* {@inheritdoc}
*/
public function deactivate(Composer $composer, IOInterface $io) {
}
/**
* {@inheritdoc}
*/
public function uninstall(Composer $composer, IOInterface $io) {
}
/**
* {@inheritdoc}
*/

View File

@ -6,7 +6,7 @@
"homepage": "https://www.drupal.org/project/drupal",
"license": "GPL-2.0-or-later",
"require": {
"composer-plugin-api": "^1.0.0",
"composer-plugin-api": "^1 || ^2",
"php": ">=7.0.8"
},
"conflict": {

View File

@ -65,6 +65,18 @@ class VendorHardeningPlugin implements PluginInterface, EventSubscriberInterface
$this->config = new Config($this->composer->getPackage());
}
/**
* {@inheritdoc}
*/
public function deactivate(Composer $composer, IOInterface $io) {
}
/**
* {@inheritdoc}
*/
public function uninstall(Composer $composer, IOInterface $io) {
}
/**
* {@inheritdoc}
*/

View File

@ -15,6 +15,6 @@
},
"require": {
"php": ">=7.0.8",
"composer-plugin-api": "^1.1"
"composer-plugin-api": "^1.1 || ^2"
}
}

View File

@ -104,6 +104,11 @@ class ComposerProjectTemplatesTest extends BuildTestBase {
* @dataProvider provideTemplateCreateProject
*/
public function testTemplateCreateProject($project, $package_dir, $docroot_dir) {
$composerVersionLine = exec('composer --version');
if (strpos($composerVersionLine, 'Composer version 2') !== FALSE) {
$this->markTestSkipped('We cannot run the template create project test with Composer 2 until we have a stable version of composer/semver 2.x. The create project test installs drupal/core-recommended and the Drupal Composer plugins from Packagist, so these must also be compatible with Composer 2.x in order for this test to work.');
}
$this->copyCodebase();
// Get the Drupal core version branch. For instance, this should be

View File

@ -44,6 +44,10 @@ class ScaffoldUpgradeTest extends TestCase {
* Test upgrading the Composer Scaffold plugin.
*/
public function testScaffoldUpgrade() {
$composerVersionLine = exec('composer --version');
if (strpos($composerVersionLine, 'Composer version 2') !== FALSE) {
$this->markTestSkipped('We cannot run the scaffold upgrade test with Composer 2 until we have a stable version of drupal/core-composer-scaffold to start from that we can install with Composer 2.x.');
}
$this->fixturesDir = $this->fixtures->tmpDir($this->getName());
$replacements = ['SYMLINK' => 'false', 'PROJECT_ROOT' => $this->fixtures->projectRoot()];
$this->fixtures->cloneFixtureProjects($this->fixturesDir, $replacements);