From 6c6f6a3f31d7df657c32d634c9fa8fdf4723ae9a Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Fri, 1 Jul 2022 09:32:39 +0100
Subject: [PATCH] =?UTF-8?q?Issue=20#3284420=20by=20longwave,=20G=C3=A1bor?=
 =?UTF-8?q?=20Hojtsy,=20Spokje:=20Remove=20Composer=201=20specific=20code?=
 =?UTF-8?q?=20paths=20from=20Drupal=2010?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 composer.lock                                 |  8 +++----
 composer/Composer.php                         |  4 ++--
 composer/Plugin/ProjectMessage/composer.json  |  2 +-
 composer/Plugin/Scaffold/AllowedPackages.php  | 24 +------------------
 composer/Plugin/Scaffold/composer.json        |  2 +-
 composer/Plugin/VendorHardening/composer.json |  2 +-
 .../Drupal/Tests/Composer/ComposerTest.php    |  2 +-
 7 files changed, 11 insertions(+), 33 deletions(-)

diff --git a/composer.lock b/composer.lock
index bafbb7624587..c6a3d01245bb 100644
--- a/composer.lock
+++ b/composer.lock
@@ -681,10 +681,10 @@
             "dist": {
                 "type": "path",
                 "url": "composer/Plugin/ProjectMessage",
-                "reference": "b4efdbe26634b41a1b89e4f3770a8074769088a6"
+                "reference": "56ffb5a4a8cab53a97554862ce1003541af3438d"
             },
             "require": {
-                "composer-plugin-api": "^1.1 || ^2",
+                "composer-plugin-api": "^2",
                 "php": ">=7.3.0"
             },
             "type": "composer-plugin",
@@ -714,10 +714,10 @@
             "dist": {
                 "type": "path",
                 "url": "composer/Plugin/VendorHardening",
-                "reference": "d54f0b3cc8b4237f3a41a0860a808db242f9da9e"
+                "reference": "db4c3ed9b83937aa292951593a8e35176ef5f907"
             },
             "require": {
-                "composer-plugin-api": "^1.1 || ^2",
+                "composer-plugin-api": "^2",
                 "php": ">=7.3.0"
             },
             "type": "composer-plugin",
diff --git a/composer/Composer.php b/composer/Composer.php
index d3a87090bfde..8b8de87b95d2 100644
--- a/composer/Composer.php
+++ b/composer/Composer.php
@@ -91,8 +91,8 @@ protected static function setTemplateProjectStability(string $root, string $vers
   public static function ensureComposerVersion(): void {
     $composerVersion = method_exists(ComposerApp::class, 'getVersion') ?
       ComposerApp::getVersion() : ComposerApp::VERSION;
-    if (Comparator::lessThan($composerVersion, '1.9.0')) {
-      throw new \RuntimeException("Drupal core development requires Composer 1.9.0, but Composer $composerVersion is installed. Please run 'composer self-update'.");
+    if (Comparator::lessThan($composerVersion, '2.0.0')) {
+      throw new \RuntimeException("Drupal core development requires Composer 2.0.0, but Composer $composerVersion is installed. Please run 'composer self-update'.");
     }
   }
 
diff --git a/composer/Plugin/ProjectMessage/composer.json b/composer/Plugin/ProjectMessage/composer.json
index 3741b3160010..3fbcd711100b 100644
--- a/composer/Plugin/ProjectMessage/composer.json
+++ b/composer/Plugin/ProjectMessage/composer.json
@@ -15,6 +15,6 @@
   },
   "require": {
     "php": ">=7.3.0",
-    "composer-plugin-api": "^1.1 || ^2"
+    "composer-plugin-api": "^2"
   }
 }
diff --git a/composer/Plugin/Scaffold/AllowedPackages.php b/composer/Plugin/Scaffold/AllowedPackages.php
index 481492f009ab..988c379139ea 100644
--- a/composer/Plugin/Scaffold/AllowedPackages.php
+++ b/composer/Plugin/Scaffold/AllowedPackages.php
@@ -3,7 +3,6 @@
 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;
@@ -101,8 +100,7 @@ public function event(PackageEvent $event) {
     // 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();
+    $package = $operation->getOperationType() === 'update' ? $operation->getTargetPackage() : $operation->getPackage();
     if (ScaffoldOptions::hasOptions($package->getExtra())) {
       $this->newPackages[$package->getName()] = $package;
     }
@@ -181,26 +179,6 @@ protected function evaluateNewPackages(array $allowed_packages) {
     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.
    *
diff --git a/composer/Plugin/Scaffold/composer.json b/composer/Plugin/Scaffold/composer.json
index ca9d6d7b48d2..cde1fac25476 100644
--- a/composer/Plugin/Scaffold/composer.json
+++ b/composer/Plugin/Scaffold/composer.json
@@ -6,7 +6,7 @@
   "homepage": "https://www.drupal.org/project/drupal",
   "license": "GPL-2.0-or-later",
   "require": {
-    "composer-plugin-api": "^1 || ^2",
+    "composer-plugin-api": "^2",
     "php": ">=7.3.0"
   },
   "conflict": {
diff --git a/composer/Plugin/VendorHardening/composer.json b/composer/Plugin/VendorHardening/composer.json
index 5f78bc6abdaa..6179219996ba 100644
--- a/composer/Plugin/VendorHardening/composer.json
+++ b/composer/Plugin/VendorHardening/composer.json
@@ -15,6 +15,6 @@
   },
   "require": {
     "php": ">=7.3.0",
-    "composer-plugin-api": "^1.1 || ^2"
+    "composer-plugin-api": "^2"
   }
 }
diff --git a/core/tests/Drupal/Tests/Composer/ComposerTest.php b/core/tests/Drupal/Tests/Composer/ComposerTest.php
index ec7b385f3bc8..9854c14efd21 100644
--- a/core/tests/Drupal/Tests/Composer/ComposerTest.php
+++ b/core/tests/Drupal/Tests/Composer/ComposerTest.php
@@ -21,7 +21,7 @@ public function testEnsureComposerVersion() {
       $this->assertNull(Composer::ensureComposerVersion());
     }
     catch (\RuntimeException $e) {
-      $this->assertMatchesRegularExpression('/Drupal core development requires Composer 1.9.0, but Composer /', $e->getMessage());
+      $this->assertMatchesRegularExpression('/Drupal core development requires Composer 2.0.0, but Composer /', $e->getMessage());
     }
   }
 
-- 
GitLab