From 879ec6dc03f1d2177c7da7a6421bfb3bf9b37c0f Mon Sep 17 00:00:00 2001
From: Helmut Hummel <typo3@helhum.io>
Date: Tue, 12 Dec 2017 15:16:57 +0100
Subject: [PATCH] [!!!][TASK] Upgrade to composer installers 2.0.0

With this step, the typo3/cms package will not be
installable anymore with composer, but only the
single subtree splitted packages like typo3/cms-core.

To ease the usage, a new package typo3/minimal is
introduced, which has dependencies to all required
TYPO3 extensions, so that composer users can't install
an incomplete code base, at least not when using this package.

composer command used:

composer require typo3/cms-composer-installers ^2.0

Releases: master
Resolves: #83302
Change-Id: Ia1009f62d97be611a03cec5dd437b56cd7866eeb
Reviewed-on: https://review.typo3.org/55049
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
---
 composer.json                                 |   2 +-
 composer.lock                                 |  28 +++--
 .../Classes/Composer/InstallerScripts.php     |  42 -------
 .../InstallerScripts/WebDirectory.php         | 103 ------------------
 ...omposerRestrictsInstallationOfTypo3cms.rst |  55 ++++++++++
 typo3/sysext/core/composer.json               |   2 +-
 6 files changed, 70 insertions(+), 162 deletions(-)
 delete mode 100644 typo3/sysext/core/Classes/Composer/InstallerScripts.php
 delete mode 100644 typo3/sysext/core/Classes/Composer/InstallerScripts/WebDirectory.php
 create mode 100644 typo3/sysext/core/Documentation/Changelog/9.0/Breaking-83302-ComposerRestrictsInstallationOfTypo3cms.rst

diff --git a/composer.json b/composer.json
index c760a33a458d..68c9c634eb03 100644
--- a/composer.json
+++ b/composer.json
@@ -45,7 +45,7 @@
 		"doctrine/annotations": "^1.3",
 		"typo3/cms-cli": "^1.0",
 		"typo3/class-alias-loader": "^1.0",
-		"typo3/cms-composer-installers": "^1.4",
+		"typo3/cms-composer-installers": "^2.0",
 		"psr/http-message": "~1.0",
 		"cogpowered/finediff": "~0.3.1",
 		"mso/idna-convert": "^1.1.0",
diff --git a/composer.lock b/composer.lock
index bf4b2b582b02..9878a93408e8 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
         "This file is @generated automatically"
     ],
-    "content-hash": "ee8fd70e59c3f86ff7728b866e54149c",
+    "content-hash": "f97dca50e21002a44cc3ede3fee3f025",
     "packages": [
         {
             "name": "cogpowered/finediff",
@@ -1524,16 +1524,16 @@
         },
         {
             "name": "typo3/cms-composer-installers",
-            "version": "1.4.5",
+            "version": "2.0.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/TYPO3/CmsComposerInstallers.git",
-                "reference": "0ef630f82f12aa611fb44a3e1e5491fc98b97e78"
+                "reference": "68a206451b8d479049a8886bdb0001134bfe03ac"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/TYPO3/CmsComposerInstallers/zipball/0ef630f82f12aa611fb44a3e1e5491fc98b97e78",
-                "reference": "0ef630f82f12aa611fb44a3e1e5491fc98b97e78",
+                "url": "https://api.github.com/repos/TYPO3/CmsComposerInstallers/zipball/68a206451b8d479049a8886bdb0001134bfe03ac",
+                "reference": "68a206451b8d479049a8886bdb0001134bfe03ac",
                 "shasum": ""
             },
             "require": {
@@ -1554,7 +1554,7 @@
             "extra": {
                 "class": "TYPO3\\CMS\\Composer\\Installer\\Plugin",
                 "branch-alias": {
-                    "dev-master": "1.4.x-dev"
+                    "dev-master": "2.0.x-dev"
                 }
             },
             "autoload": {
@@ -1568,16 +1568,14 @@
             ],
             "authors": [
                 {
-                    "name": "Christian Opitz",
-                    "email": "christian.opitz@netresearch.de"
-                },
-                {
-                    "name": "Lars Peipmann",
-                    "email": "lars@peipmann.de"
+                    "name": "The TYPO3 Community",
+                    "homepage": "https://typo3.org/community/",
+                    "role": "Contributor"
                 },
                 {
-                    "name": "Helmut Hummel",
-                    "email": "info@helhum.io"
+                    "name": "TYPO3 CMS Core Team",
+                    "homepage": "https://forge.typo3.org/projects/typo3cms-core",
+                    "role": "Developer"
                 }
             ],
             "description": "TYPO3 CMS Installers",
@@ -1589,7 +1587,7 @@
                 "installer",
                 "typo3"
             ],
-            "time": "2017-11-06T11:44:16+00:00"
+            "time": "2017-12-12T14:04:22+00:00"
         },
         {
             "name": "typo3fluid/fluid",
diff --git a/typo3/sysext/core/Classes/Composer/InstallerScripts.php b/typo3/sysext/core/Classes/Composer/InstallerScripts.php
deleted file mode 100644
index df5d396c30c0..000000000000
--- a/typo3/sysext/core/Classes/Composer/InstallerScripts.php
+++ /dev/null
@@ -1,42 +0,0 @@
-<?php
-declare(strict_types=1);
-namespace TYPO3\CMS\Core\Composer;
-
-/*
- * This file is part of the TYPO3 project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-use Composer\Script\Event;
-use Composer\Semver\Constraint\EmptyConstraint;
-use TYPO3\CMS\Composer\Plugin\Core\InstallerScriptsRegistration;
-use TYPO3\CMS\Composer\Plugin\Core\ScriptDispatcher;
-use TYPO3\CMS\Core\Composer\InstallerScripts\WebDirectory;
-
-/**
- * Hook into Composer build to set up TYPO3 web directory if necessary
- */
-class InstallerScripts implements InstallerScriptsRegistration
-{
-    /**
-     * @param Event $event
-     * @param ScriptDispatcher $scriptDispatcher
-     */
-    public static function register(Event $event, ScriptDispatcher $scriptDispatcher)
-    {
-        if (null !== $event->getComposer()->getRepositoryManager()->getLocalRepository()->findPackage('typo3/cms', new EmptyConstraint())) {
-            $scriptDispatcher->addInstallerScript(
-                new WebDirectory(),
-                60
-            );
-        }
-    }
-}
diff --git a/typo3/sysext/core/Classes/Composer/InstallerScripts/WebDirectory.php b/typo3/sysext/core/Classes/Composer/InstallerScripts/WebDirectory.php
deleted file mode 100644
index 2c7a1dcd690f..000000000000
--- a/typo3/sysext/core/Classes/Composer/InstallerScripts/WebDirectory.php
+++ /dev/null
@@ -1,103 +0,0 @@
-<?php
-declare(strict_types=1);
-namespace TYPO3\CMS\Core\Composer\InstallerScripts;
-
-/*
- * This file is part of the TYPO3 project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-use Composer\Composer;
-use Composer\IO\IOInterface;
-use Composer\Script\Event;
-use Composer\Semver\Constraint\EmptyConstraint;
-use TYPO3\CMS\Composer\Plugin\Config;
-use TYPO3\CMS\Composer\Plugin\Core\InstallerScript;
-use TYPO3\CMS\Composer\Plugin\Util\Filesystem;
-
-/**
- * Setting up TYPO3 web directory
- */
-class WebDirectory implements InstallerScript
-{
-    /**
-     * @var string
-     */
-    private static $typo3Dir = '/typo3';
-
-    /**
-     * @var string
-     */
-    private static $systemExtensionsDir = '/sysext';
-
-    /**
-     * @var IOInterface
-     */
-    private $io;
-
-    /**
-     * @var Composer
-     */
-    private $composer;
-
-    /**
-     * @var Filesystem
-     */
-    private $filesystem;
-
-    /**
-     * @var Config
-     */
-    private $pluginConfig;
-
-    /**
-     * Prepare the web directory with symlinks
-     *
-     * @param Event $event
-     * @return bool
-     */
-    public function run(Event $event): bool
-    {
-        $this->io = $event->getIO();
-        $this->composer = $event->getComposer();
-        $this->filesystem = new Filesystem();
-        $this->pluginConfig = Config::load($this->composer);
-
-        $symlinks = $this->initializeSymlinks();
-        if ($this->filesystem->someFilesExist($symlinks)) {
-            $this->filesystem->removeSymlinks($symlinks);
-        }
-        $this->filesystem->establishSymlinks($symlinks);
-
-        return true;
-    }
-
-    /**
-     * Initialize symlinks from configuration
-     * @return array
-     */
-    private function initializeSymlinks(): array
-    {
-        $webDir = $this->filesystem->normalizePath($this->pluginConfig->get('web-dir'));
-        $backendDir = $webDir . self::$typo3Dir;
-        // Ensure we delete a previously existing symlink to typo3 folder in web directory
-        if ($this->filesystem->isSymlinkedDirectory($backendDir)) {
-            $this->filesystem->removeDirectory($backendDir);
-        }
-        $this->filesystem->ensureDirectoryExists($backendDir);
-        $localRepository = $this->composer->getRepositoryManager()->getLocalRepository();
-        $package = $localRepository->findPackage('typo3/cms', new EmptyConstraint());
-        $sourcesDir = $this->composer->getInstallationManager()->getInstallPath($package);
-        return [
-            $sourcesDir . self::$typo3Dir . self::$systemExtensionsDir => $backendDir . self::$systemExtensionsDir,
-        ];
-    }
-}
diff --git a/typo3/sysext/core/Documentation/Changelog/9.0/Breaking-83302-ComposerRestrictsInstallationOfTypo3cms.rst b/typo3/sysext/core/Documentation/Changelog/9.0/Breaking-83302-ComposerRestrictsInstallationOfTypo3cms.rst
new file mode 100644
index 000000000000..c9d93a881728
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/9.0/Breaking-83302-ComposerRestrictsInstallationOfTypo3cms.rst
@@ -0,0 +1,55 @@
+.. include:: ../../Includes.txt
+
+===============================================================
+Breaking: #83302 - Composer restricts installation of typo3/cms
+===============================================================
+
+See :issue:`83302`
+
+Description
+===========
+
+When running a composer-based TYPO3 instance, it is not possible anymore to require the whole
+TYPO3 Core via `composer require typo3/cms`. This package is solely used for Core-development purposes
+from now on.
+
+Instead, all system extensions maintained by the TYPO3 Core Team must be required individually.
+
+Some examples:
+
+* `composer require typo3/cms-core:^9`
+* `composer require typo3/cms-fluid-styled-content:^9`
+* `composer require typo3/cms-extbase:^9`
+* `composer require typo3/cms-workspaces:^9`
+* `composer require typo3/cms-sys-note:^9`
+
+For convenience, TYPO3 projects can simply require `composer require typo3/minimal` to get the main
+system extensions that are needed for a running TYPO3 instance, and add custom system extensions
+as mentioned above.
+
+
+Impact
+======
+
+Installing or updating the composer package `typo3/cms` will show an error for TYPO3 v9.
+
+
+Affected Installations
+======================
+
+Composer-based TYPO3 installations that previously required `typo3/cms` in the projects'
+`composer.json` file or in any required extension `composer.json` file.
+
+
+Migration
+=========
+
+Extension authors should specifically define their dependencies of system extensions in their
+`composer.json` file, if they have previously added `typo3/cms`.
+
+Site administrators / developers should require only the necessary `typo3/cms-*` packages that they
+have installed in their projects. In order to find out, which system extensions have been installed,
+have a look at `typo3conf/PackageStates.php` and look for all extensions that are located under
+`typo3/sysext/`.
+
+.. index:: CLI, NotScanned
diff --git a/typo3/sysext/core/composer.json b/typo3/sysext/core/composer.json
index ffea89eb1e62..fcb78962ddae 100644
--- a/typo3/sysext/core/composer.json
+++ b/typo3/sysext/core/composer.json
@@ -26,7 +26,7 @@
 		"doctrine/annotations": "^1.3",
 		"typo3/cms-cli": "^1.0",
 		"typo3/class-alias-loader": "^1.0",
-		"typo3/cms-composer-installers": "^1.4",
+		"typo3/cms-composer-installers": "^2.0",
 		"psr/http-message": "~1.0",
 		"cogpowered/finediff": "~0.3.1",
 		"mso/idna-convert": "^1.1.0",
-- 
GitLab