Skip to content

Commit

Permalink
Merge pull request #3 from magento-trigger/MC-39996
Browse files Browse the repository at this point in the history
MC-39996: Add composer2 support
  • Loading branch information
fascinosum authored Dec 17, 2020
2 parents 9fc7b89 + 50318ac commit 4adc8a9
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 74 deletions.
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"repositories": [
{
"type": "vcs",
"url": "[email protected]:Flyingmana/phpcs.git"

This comment has been minimized.

Copy link
@ihor-sviziev

ihor-sviziev Mar 9, 2021

@fascinosum it's really strange that this commit was tagged with "0.2.1-beta1" tag, but it's not as part of master branch. Could you push it?
/CC @sidolov @sivaschenko

This comment has been minimized.

Copy link
@fascinosum

fascinosum Mar 9, 2021

Author Collaborator

@ihor-sviziev, we are working on it. There was a sync issue

"url": "[email protected]:firegento/phpcs.git"
}
],
"authors":[
Expand Down Expand Up @@ -39,16 +39,16 @@
}
],
"require":{
"composer-plugin-api": "^1.0"
"composer-plugin-api": "^1.1 || ^2.0",
"composer/composer": "^1.9 || ^2.0"
},
"require-dev":{
"phpunit/phpunit":"*",
"phpunit/phpunit-mock-objects": "dev-master",
"squizlabs/php_codesniffer": "1.4.7",
"firegento/phpcs": "dev-patch-1",
"composer/composer":"*@dev",
"symfony/process":"*",
"mikey179/vfsStream":"*"
"firegento/phpcs": "~1.1.0",
"symfony/process": "*",
"mikey179/vfsstream": "*"
},
"replace": {
"magento-hackathon/magento-composer-installer": "*"
Expand All @@ -64,7 +64,6 @@
"/tests/FullStackTest/"
]
},
"test_version":"999.0.0",
"extra":{
"composer-command-registry": [ "MagentoHackathon\\Composer\\Magento\\Command\\DeployCommand" ],
"class":"MagentoHackathon\\Composer\\Magento\\Plugin"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @author Tiago Ribeiro <[email protected]>
* @author Rui Marinho <[email protected]>
*/
class DeployCommand extends \Composer\Command\Command
class DeployCommand extends \Composer\Command\BaseCommand
{
protected function configure()
{
Expand Down
134 changes: 68 additions & 66 deletions src/MagentoHackathon/Composer/Magento/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Composer\Installer\InstallerInterface;
use Composer\Package\PackageInterface;
use MagentoHackathon\Composer\Magento\Deploy\Manager\Entry;
use React\Promise\PromiseInterface;

/**
* Composer Magento Installer
Expand Down Expand Up @@ -99,7 +100,7 @@ class Installer extends LibraryInstaller implements InstallerInterface
* @var bool
*/
protected $appendGitIgnore = false;

/**
* @var array Path mapping prefixes that need to be translated (i.e. to
* use a public directory as the web server root).
Expand Down Expand Up @@ -201,7 +202,7 @@ public function setDeployManager( DeployManager $deployManager)
$this->deployManager = $deployManager;
}


public function setConfig( ProjectConfig $config )
{
$this->config = $config;
Expand Down Expand Up @@ -329,7 +330,7 @@ public function getDeployStrategy(PackageInterface $package, $strategy = null)
}
if( isset($extra['magento-deploy-ignore'][$package->getName()]) ){
$moduleSpecificDeployIgnores = array_merge(
$moduleSpecificDeployIgnores,
$moduleSpecificDeployIgnores,
$extra['magento-deploy-ignore'][$package->getName()]
);
}
Expand Down Expand Up @@ -394,35 +395,39 @@ public function getTargetDir()
}

/**
* Installs specific package
*
* @param InstalledRepositoryInterface $repo repository in which to check
* @param PackageInterface $package package instance
* @inheritdoc
*/
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
{

if ($package->getType() === 'magento-core' && !$this->preInstallMagentoCore()) {
return;
}

parent::install($repo, $package);
$afterInstall = function () use ($package) {
// skip marshal and apply default behavior if extra->map does not exist
if ($this->hasExtraMap($package)) {
$strategy = $this->getDeployStrategy($package);
$strategy->setMappings($this->getParser($package)->getMappings());
$deployManagerEntry = new Entry();
$deployManagerEntry->setPackageName($package->getName());
$deployManagerEntry->setDeployStrategy($strategy);
$this->deployManager->addPackage($deployManagerEntry);

// skip marshal and apply default behavior if extra->map does not exist
if (!$this->hasExtraMap($package)) {
return;
}
if ($this->appendGitIgnore) {
$this->appendGitIgnore($package, $this->getGitIgnoreFileLocation());
}
}
};

$strategy = $this->getDeployStrategy($package);
$strategy->setMappings($this->getParser($package)->getMappings());
$deployManagerEntry = new Entry();
$deployManagerEntry->setPackageName($package->getName());
$deployManagerEntry->setDeployStrategy($strategy);
$this->deployManager->addPackage($deployManagerEntry);
$promise = parent::install($repo, $package);

if ($this->appendGitIgnore) {
$this->appendGitIgnore($package, $this->getGitIgnoreFileLocation());
// Composer v2 might return a promise here
if ($promise instanceof PromiseInterface) {
return $promise->then($afterInstall);
}

// If not, execute the code right away as parent::install executed synchronously (composer v1, or v2 without async)
$afterInstall();
}

/**
Expand Down Expand Up @@ -464,7 +469,7 @@ public function appendGitIgnore(PackageInterface $package, $ignoreFile)
if( in_array($ignore, $ignoredMappings) ){
continue;
}

$additions[] = $ignore;
}
}
Expand All @@ -474,7 +479,7 @@ public function appendGitIgnore(PackageInterface $package, $ignoreFile)
$contents = array_merge($contents, $additions);
file_put_contents($ignoreFile, implode("\n", $contents));
}

if ($package->getType() === 'magento-core') {
$this->prepareMagentoCore();
}
Expand Down Expand Up @@ -590,17 +595,10 @@ protected function redeployProject() {
}

/**
* Updates specific package
*
* @param InstalledRepositoryInterface $repo repository in which to check
* @param PackageInterface $initial already installed package version
* @param PackageInterface $target updated version
*
* @throws InvalidArgumentException if $from package is not installed
* @inheritdoc
*/
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
{

if ($target->getType() === 'magento-core' && !$this->preUpdateMagentoCore()) {
return;
}
Expand All @@ -618,25 +616,35 @@ public function update(InstalledRepositoryInterface $repo, PackageInterface $ini
}
}

parent::update($repo, $initial, $target);
$afterUpdate = function () use ($target) {
// marshal files for new package version if extra->map exist
if ($this->hasExtraMap($target)) {
$targetStrategy = $this->getDeployStrategy($target);
$targetStrategy->setMappings($this->getParser($target)->getMappings());
$deployManagerEntry = new Entry();
$deployManagerEntry->setPackageName($target->getName());
$deployManagerEntry->setDeployStrategy($targetStrategy);
$this->deployManager->addPackage($deployManagerEntry);
}

// marshal files for new package version if extra->map exist
if ($this->hasExtraMap($target)) {
$targetStrategy = $this->getDeployStrategy($target);
$targetStrategy->setMappings($this->getParser($target)->getMappings());
$deployManagerEntry = new Entry();
$deployManagerEntry->setPackageName($target->getName());
$deployManagerEntry->setDeployStrategy($targetStrategy);
$this->deployManager->addPackage($deployManagerEntry);
}
if($this->appendGitIgnore) {
$this->appendGitIgnore($target, $this->getGitIgnoreFileLocation());
}

if($this->appendGitIgnore) {
$this->appendGitIgnore($target, $this->getGitIgnoreFileLocation());
}
if ($target->getType() === 'magento-core') {
$this->postUpdateMagentoCore();
}
};

$promise = parent::update($repo, $initial, $target);

if ($target->getType() === 'magento-core') {
$this->postUpdateMagentoCore();
// Composer v2 might return a promise here
if ($promise instanceof PromiseInterface) {
return $promise->then($afterUpdate);
}

// If not, execute the code right away as parent::update executed synchronously (composer v1, or v2 without async)
$afterUpdate();
}


Expand Down Expand Up @@ -707,30 +715,24 @@ public function clearMagentoCache() {
}

/**
* Uninstalls specific package.
*
* @param InstalledRepositoryInterface $repo repository in which to check
* @param PackageInterface $package package instance
* @inheritdoc
*/
public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
{
// skip marshal and apply default behavior if extra->map does not exist
if (!$this->hasExtraMap($package)) {
parent::uninstall($repo, $package);
return;
}

$strategy = $this->getDeployStrategy($package);
$strategy->setMappings($this->getParser($package)->getMappings());
try {
$strategy->clean();
} catch (\ErrorException $e) {
if ($this->io->isDebug()) {
$this->io->write($e->getMessage());
if ($this->hasExtraMap($package)) {
$strategy = $this->getDeployStrategy($package);
$strategy->setMappings($this->getParser($package)->getMappings());
try {
$strategy->clean();
} catch (\ErrorException $e) {
if ($this->io->isDebug()) {
$this->io->write($e->getMessage());
}
}
}

parent::uninstall($repo, $package);
return parent::uninstall($repo, $package);
}

/**
Expand Down Expand Up @@ -792,7 +794,7 @@ public function getInstallPath(PackageInterface $package)

return $installPath;
}

public function transformArrayKeysToLowerCase($array)
{
$arrayNew = array();
Expand All @@ -806,7 +808,7 @@ public function transformArrayKeysToLowerCase($array)
* this function is for annoying people with messages.
*
* First usage: get people to vote about the future release of composer so later I can say "you wanted it this way"
*
*
* @param IOInterface $io
*/
public function annoy(IOInterface $io)
Expand All @@ -819,7 +821,7 @@ public function annoy(IOInterface $io)
$io->write('<comment> time for voting about the future of the #magento #composer installer. </comment>', true);
$io->write('<comment> https://github.com/magento-hackathon/magento-composer-installer/blob/discussion-master/Milestone/2/index.md </comment>', true);
$io->write('<error> For the case you don\'t vote, I will ignore your problems till iam finished with the resulting release. </error>', true);
*
*
**/
}

Expand Down
14 changes: 14 additions & 0 deletions src/MagentoHackathon/Composer/Magento/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,18 @@ private function requestRegeneration()
touch($filename);
}
}

/**
* @inheritdoc
*/
public function deactivate(Composer $composer, IOInterface $io)
{
}

/**
* @inheritdoc
*/
public function uninstall(Composer $composer, IOInterface $io)
{
}
}

0 comments on commit 4adc8a9

Please sign in to comment.