Skip to content

Commit 12597c5

Browse files
authored
Merge pull request #36 from JParkinson1991/release/2.0.0
Release/2.0.0 - Composer 2 Compatibility
2 parents d31aed5 + 00bfc3f commit 12597c5

File tree

4 files changed

+50
-21
lines changed

4 files changed

+50
-21
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/composer.lock
2+
/vendor

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
"psr-0": { "": "src/"}
1919
},
2020
"require": {
21-
"composer-plugin-api": "^1.0"
21+
"composer-plugin-api": "^2.0"
2222
},
2323
"require-dev": {
24-
"composer/composer": "1.*"
24+
"composer/composer": "^2.0"
2525
},
2626
"extra": {
2727
"class": "Netresearch\\Composer\\Patches\\Plugin",

src/Netresearch/Composer/Patches/Downloader/Composer.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class Composer implements DownloaderInterface
3030
*
3131
* @param \Composer\IO\IOInterface $io
3232
*/
33-
public function __construct(\Composer\IO\IOInterface $io)
33+
public function __construct(\Composer\IO\IOInterface $io, \Composer\Config $config)
3434
{
35-
$this->remoteFileSystem = new RemoteFilesystem($io);
35+
$this->remoteFileSystem = new RemoteFilesystem($io, $config);
3636
}
3737

3838
/**

src/Netresearch/Composer/Patches/Plugin.php

+44-17
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use Composer\Composer;
1717
use Composer\Downloader\DownloaderInterface;
18+
use Composer\Factory;
1819
use Composer\Installer\PackageEvents;
1920
use Composer\IO\IOInterface;
2021
use Composer\Plugin\PluginInterface;
@@ -54,20 +55,46 @@ class Plugin implements PluginInterface, EventSubscriberInterface
5455
/**
5556
* Activate the plugin (called from {@see \Composer\Plugin\PluginManager})
5657
*
57-
* @param \Composer\Composer $composer
58+
* @param \Composer\Composer $composer
5859
* @param \Composer\IO\IOInterface $io
5960
*/
6061
public function activate(Composer $composer, IOInterface $io)
6162
{
6263
$this->io = $io;
6364
$this->composer = $composer;
64-
$this->downloader = new Downloader\Composer($io);
65+
$this->downloader = new Downloader\Composer($io, Factory::createConfig($io));
6566

6667
// Add the installer
6768
$noopInstaller = new Installer($io);
6869
$composer->getInstallationManager()->addInstaller($noopInstaller);
6970
}
7071

72+
/**
73+
* Remove any hooks from Composer
74+
*
75+
* This will be called when a plugin is deactivated before being
76+
* uninstalled, but also before it gets upgraded to a new version
77+
* so the old one can be deactivated and the new one activated.
78+
*
79+
* @param Composer $composer
80+
* @param IOInterface $io
81+
*/
82+
public function deactivate(Composer $composer, IOInterface $io)
83+
{
84+
}
85+
86+
/**
87+
* Prepare the plugin to be uninstalled
88+
*
89+
* This will be called after deactivate.
90+
*
91+
* @param Composer $composer
92+
* @param IOInterface $io
93+
*/
94+
public function uninstall(Composer $composer, IOInterface $io)
95+
{
96+
}
97+
7198
/**
7299
* Get the events, this {@see \Composer\EventDispatcher\EventSubscriberInterface}
73100
* subscribes to
@@ -77,17 +104,17 @@ public function activate(Composer $composer, IOInterface $io)
77104
public static function getSubscribedEvents()
78105
{
79106
return array(
80-
PackageEvents::PRE_PACKAGE_UNINSTALL => array('restore'),
81-
PackageEvents::PRE_PACKAGE_UPDATE => array('restore'),
82-
ScriptEvents::POST_UPDATE_CMD => array('apply'),
83-
ScriptEvents::POST_INSTALL_CMD => array('apply'),
107+
PackageEvents::PRE_PACKAGE_UNINSTALL => array('restore'),
108+
PackageEvents::PRE_PACKAGE_UPDATE => array('restore'),
109+
ScriptEvents::POST_UPDATE_CMD => array('apply'),
110+
ScriptEvents::POST_INSTALL_CMD => array('apply'),
84111
);
85112
}
86113

87114
/**
88115
* Revert patches on/from packages that are going to be removed
89116
*
90-
* @param PackageEvent $event
117+
* @param PackageEvent $event
91118
* @throws Exception
92119
*
93120
* @return void
@@ -147,11 +174,11 @@ public function apply(Event $event)
147174
$patch->apply($packagePath, true);
148175
} catch (PatchCommandException $applyException) {
149176
try {
150-
// If this won't fail, patch was already applied
151-
$patch->revert($packagePath, true);
177+
// If this won't fail, patch was already applied
178+
$patch->revert($packagePath, true);
152179
} catch (PatchCommandException $revertException) {
153-
// Patch seems not to be applied and fails as well
154-
$this->writePatchNotice('apply', $patch, $package, $applyException);
180+
// Patch seems not to be applied and fails as well
181+
$this->writePatchNotice('apply', $patch, $package, $applyException);
155182
}
156183
continue;
157184
}
@@ -165,8 +192,8 @@ public function apply(Event $event)
165192
/**
166193
* Get the patches and packages that are not already in $history
167194
*
168-
* @param \Composer\Package\PackageInterface $initialPackage
169-
* @param array &$history
195+
* @param \Composer\Package\PackageInterface $initialPackage
196+
* @param array &$history
170197
* @return array
171198
*/
172199
protected function getPatches(PackageInterface $initialPackage, array &$history)
@@ -204,7 +231,7 @@ protected function getPatches(PackageInterface $initialPackage, array &$history)
204231
/**
205232
* Get the install path for a package
206233
*
207-
* @param \Composer\Package\PackageInterface $package
234+
* @param \Composer\Package\PackageInterface $package
208235
* @return string
209236
*/
210237
protected function getPackagePath(PackageInterface $package)
@@ -215,9 +242,9 @@ protected function getPackagePath(PackageInterface $package)
215242
/**
216243
* Write a notice to IO
217244
*
218-
* @param string $action
219-
* @param \Netresearch\Composer\Patches\Patch $patch
220-
* @param \Composer\Package\PackageInterface $package
245+
* @param string $action
246+
* @param \Netresearch\Composer\Patches\Patch $patch
247+
* @param \Composer\Package\PackageInterface $package
221248
* @param \Netresearch\Composer\Patches\Exception $exception
222249
*/
223250
protected function writePatchNotice($action, Patch $patch, PackageInterface $package, $exception = null)

0 commit comments

Comments
 (0)