Add install-path to the installed.json for every package, fixes #2174, closes #2424

main
Jordi Boggiano 5 years ago
parent 203f972ed7
commit 63da7c6b2d
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

@ -618,7 +618,7 @@ class Installer
} }
if ($this->executeOperations || $this->writeLock) { if ($this->executeOperations || $this->writeLock) {
$localRepo->write($this->devMode); $localRepo->write($this->devMode, $this->installationManager);
} }
$event = 'Composer\Installer\PackageEvents::POST_PACKAGE_'.strtoupper($jobType); $event = 'Composer\Installer\PackageEvents::POST_PACKAGE_'.strtoupper($jobType);
@ -630,7 +630,7 @@ class Installer
if ($this->executeOperations) { if ($this->executeOperations) {
// force source/dist urls to be updated for all packages // force source/dist urls to be updated for all packages
$this->processPackageUrls($pool, $policy, $localRepo, $repositories); $this->processPackageUrls($pool, $policy, $localRepo, $repositories);
$localRepo->write($this->devMode); $localRepo->write($this->devMode, $this->installationManager);
} }
return array(0, $devPackages); return array(0, $devPackages);

@ -15,6 +15,8 @@ namespace Composer\Repository;
use Composer\Json\JsonFile; use Composer\Json\JsonFile;
use Composer\Package\Loader\ArrayLoader; use Composer\Package\Loader\ArrayLoader;
use Composer\Package\Dumper\ArrayDumper; use Composer\Package\Dumper\ArrayDumper;
use Composer\Installer\InstallationManager;
use Composer\Util\Filesystem;
/** /**
* Filesystem repository. * Filesystem repository.
@ -84,13 +86,18 @@ class FilesystemRepository extends WritableArrayRepository
/** /**
* Writes writable repository. * Writes writable repository.
*/ */
public function write($devMode) public function write($devMode, InstallationManager $installationManager)
{ {
$data = array('packages' => array(), 'dev' => $devMode); $data = array('packages' => array(), 'dev' => $devMode);
$dumper = new ArrayDumper(); $dumper = new ArrayDumper();
$fs = new Filesystem();
$repoDir = dirname($fs->normalizePath($this->file->getPath()));
foreach ($this->getCanonicalPackages() as $package) { foreach ($this->getCanonicalPackages() as $package) {
$data['packages'][] = $dumper->dump($package); $pkgArray = $dumper->dump($package);
$path = $installationManager->getInstallPath($package);
$pkgArray['install-path'] = ('' !== $path && null !== $path) ? $fs->findShortestPath($repoDir, $path, true) : null;
$data['packages'][] = $pkgArray;
} }
usort($data['packages'], function ($a, $b) { usort($data['packages'], function ($a, $b) {

@ -13,6 +13,7 @@
namespace Composer\Repository; namespace Composer\Repository;
use Composer\Package\AliasPackage; use Composer\Package\AliasPackage;
use Composer\Installer\InstallationManager;
/** /**
* Writable array repository. * Writable array repository.
@ -24,7 +25,7 @@ class WritableArrayRepository extends ArrayRepository implements WritableReposit
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function write($devMode) public function write($devMode, InstallationManager $installationManager)
{ {
} }

@ -13,6 +13,7 @@
namespace Composer\Repository; namespace Composer\Repository;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
use Composer\Installer\InstallationManager;
/** /**
* Writable repository interface. * Writable repository interface.
@ -26,7 +27,7 @@ interface WritableRepositoryInterface extends RepositoryInterface
* *
* @param bool $devMode Whether dev requirements were included or not in this installation * @param bool $devMode Whether dev requirements were included or not in this installation
*/ */
public function write($devMode); public function write($devMode, InstallationManager $installationManager);
/** /**
* Adds package to the repository. * Adds package to the repository.

@ -13,6 +13,7 @@
namespace Composer\Test\Mock; namespace Composer\Test\Mock;
use Composer\Repository\InstalledFilesystemRepository; use Composer\Repository\InstalledFilesystemRepository;
use Composer\Installer\InstallationManager;
class InstalledFilesystemRepositoryMock extends InstalledFilesystemRepository class InstalledFilesystemRepositoryMock extends InstalledFilesystemRepository
{ {
@ -20,7 +21,7 @@ class InstalledFilesystemRepositoryMock extends InstalledFilesystemRepository
{ {
} }
public function write($devMode) public function write($devMode, InstallationManager $installationManager)
{ {
} }
} }

@ -24,7 +24,7 @@ class LockerTest extends TestCase
$locker = new Locker( $locker = new Locker(
new NullIO, new NullIO,
$json, $json,
$this->createRepositoryManagerMock(), $this->createInstallationManagerMock(),
$this->getJsonContent() $this->getJsonContent()
); );
@ -259,7 +259,7 @@ class LockerTest extends TestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
} }
private function createInstallationManagerMock() private function createInstallationManagerMock()
{ {
$mock = $this->getMockBuilder('Composer\Installer\InstallationManager') $mock = $this->getMockBuilder('Composer\Installer\InstallationManager')

@ -82,11 +82,21 @@ class FilesystemRepositoryTest extends TestCase
$json = $this->createJsonFileMock(); $json = $this->createJsonFileMock();
$repository = new FilesystemRepository($json); $repository = new FilesystemRepository($json);
$im = $this->getMockBuilder('Composer\Installer\InstallationManager')
->disableOriginalConstructor()
->getMock();
$im->expects($this->once())
->method('getInstallPath')
->will($this->returnValue('/foo/bar/vendor/woop/woop'));
$json $json
->expects($this->once()) ->expects($this->once())
->method('read') ->method('read')
->will($this->returnValue(array())); ->will($this->returnValue(array()));
$json
->expects($this->once())
->method('getPath')
->will($this->returnValue('/foo/bar/vendor/composer/installed.json'));
$json $json
->expects($this->once()) ->expects($this->once())
->method('exists') ->method('exists')
@ -95,12 +105,12 @@ class FilesystemRepositoryTest extends TestCase
->expects($this->once()) ->expects($this->once())
->method('write') ->method('write')
->with(array( ->with(array(
'packages' => array(array('name' => 'mypkg', 'type' => 'library', 'version' => '0.1.10', 'version_normalized' => '0.1.10.0')), 'packages' => array(array('name' => 'mypkg', 'type' => 'library', 'version' => '0.1.10', 'version_normalized' => '0.1.10.0', 'install-path' => '../woop/woop')),
'dev' => true, 'dev' => true,
)); ));
$repository->addPackage($this->getPackage('mypkg', '0.1.10')); $repository->addPackage($this->getPackage('mypkg', '0.1.10'));
$repository->write(true); $repository->write(true, $im);
} }
private function createJsonFileMock() private function createJsonFileMock()

Loading…
Cancel
Save