Skip to content

Commit 9b49181

Browse files
committed
Merged in the latest changes from master and changed the logic to rely on the includes functionality introduced by composer#132.
2 parents 1929e44 + f44c455 commit 9b49181

File tree

3 files changed

+145
-89
lines changed

3 files changed

+145
-89
lines changed

composer.lock

+43-29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Composer/Satis/Command/BuildCommand.php

+74-54
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
154154
$this->dumpDownloads($config, $packages, $input, $output, $outputDir, $skipErrors);
155155
}
156156

157+
$filenamePrefix = $outputDir.'/include/all';
157158
$filename = $outputDir.'/packages.json';
158159
if(!empty($packagesFilter)) {
159160
// in case of an active package filter we need to load the dumped packages.json and merge the
@@ -162,7 +163,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
162163
$packages += $oldPackages;
163164
ksort($packages);
164165
}
165-
$this->dumpJson($packages, $output, $filename);
166+
167+
$packageFile = $this->dumpPackageIncludeJson($packages, $output, $filenamePrefix);
168+
$packageFileHash = hash_file('sha1', $packageFile);
169+
170+
$includes = array(
171+
'include/all$'.$packageFileHash.'.json' => array( 'sha1'=>$packageFileHash ),
172+
);
173+
174+
$this->dumpPackagesJson($includes, $output, $filename);
166175

167176
if ($htmlView) {
168177
$dependencies = array();
@@ -198,10 +207,10 @@ private function selectPackages(Composer $composer, OutputInterface $output, $ve
198207
}
199208
}
200209

201-
$links = array();
202-
203210
if ($requireAll) {
211+
$links = array();
204212
$filterForPackages = count($packagesFilter) > 0;
213+
205214
foreach ($repos as $repo) {
206215
// collect links for composer repos with providers
207216
if ($repo instanceof ComposerRepository && $repo->hasProviders()) {
@@ -231,29 +240,20 @@ private function selectPackages(Composer $composer, OutputInterface $output, $ve
231240
}
232241

233242
// add matching package if not yet selected
234-
if (!isset($selected[$package->getName()])) {
243+
if (!isset($selected[$package->getUniqueName()])) {
235244
if ($verbose) {
236245
$output->writeln('Selected '.$package->getPrettyName().' ('.$package->getPrettyVersion().')');
237246
}
238-
239247
$selected[$package->getUniqueName()] = $package;
240248
}
241249
}
242250
}
243251
}
244252
} else {
245-
$links = $composer->getPackage()->getRequires();
246-
247-
// only pick up packages in our filter, if a filter has been set.
248-
if (count($packagesFilter) > 0) {
249-
$links = array_filter($links, function(Link $link) use ($packagesFilter) {
250-
return in_array($link->getTarget(), $packagesFilter);
251-
});
252-
}
253-
254-
$links = array_values($links);
253+
$links = array_values($composer->getPackage()->getRequires());
255254
}
256255

256+
257257
// process links if any
258258
$depsLinks = array();
259259

@@ -388,51 +388,32 @@ private function dumpDownloads(array $config, array &$packages, InputInterface
388388
}
389389
}
390390

391-
private function dumpJson(array $packages, OutputInterface $output, $filename, $update = false)
391+
392+
private function dumpPackageIncludeJson(array $packages, OutputInterface $output, $filename)
392393
{
393-
$repoJson = new JsonFile($filename);
394-
395-
// decide if we should do an update or override.
396-
$repo = $update && $repoJson->exists()
397-
? $repoJson->read()
398-
: array('packages' => array());
399-
400-
$dumper = new ArrayDumper;
394+
$repo = array('packages' => array());
395+
$dumper = new ArrayDumper;
401396
foreach ($packages as $package) {
402397
$repo['packages'][$package->getPrettyName()][$package->getPrettyVersion()] = $dumper->dump($package);
403398
}
404-
$output->writeln('<info>Writing packages.json</info>');
399+
$repoJson = new JsonFile($filename);
405400
$repoJson->write($repo);
401+
$hash = hash_file('sha1', $filename);
402+
$filenameWithHash = $filename.'$'.$hash.'.json';
403+
rename($filename, $filenameWithHash);
404+
$output->writeln("<info>wrote packages json $filenameWithHash</info>");
405+
return $filenameWithHash;
406406
}
407-
408-
private function loadDumpedPackages($filename, array $packagesFilter = array())
409-
{
410-
$packages = array();
411-
$repoJson = new JsonFile($filename);
412-
413-
if ($repoJson->exists()) {
414-
$loader = new ArrayLoader();
415-
$jsonPackages = $repoJson->read();
416-
$jsonPackages = isset($jsonPackages['packages']) && is_array($jsonPackages['packages'])
417-
? $jsonPackages['packages']
418-
: array();
419-
420-
foreach ($jsonPackages as $jsonPackage) {
421-
if (is_array($jsonPackage)) {
422-
foreach ($jsonPackage as $jsonVersion) {
423-
if (is_array($jsonVersion)) {
424-
if(isset($jsonVersion['name']) && in_array($jsonVersion['name'], $packagesFilter)) {
425-
continue;
426-
}
427-
$package = $loader->load($jsonVersion);
428-
$packages[$package->getUniqueName()] = $package;
429-
}
430-
}
431-
}
432-
}
433-
}
434-
435-
return $packages;
407+
408+
private function dumpPackagesJson($includes, OutputInterface $output, $filename){
409+
$repo = array(
410+
'packages' => array(),
411+
'includes' => $includes,
412+
);
413+
414+
$output->writeln('<info>Writing packages.json</info>');
415+
$repoJson = new JsonFile($filename);
416+
$repoJson->write($repo);
436417
}
437418

438419
private function dumpWeb(array $packages, OutputInterface $output, PackageInterface $rootPackage, $directory, $template = null, array $dependencies = array())
@@ -466,6 +447,45 @@ private function dumpWeb(array $packages, OutputInterface $output, PackageInterf
466447
file_put_contents($directory.'/index.html', $content);
467448
}
468449

450+
private function loadDumpedPackages($filename, array $packagesFilter = array())
451+
{
452+
$packages = array();
453+
$repoJson = new JsonFile($filename);
454+
$dirName = dirname($filename);
455+
456+
if ($repoJson->exists()) {
457+
$loader = new ArrayLoader();
458+
$jsonIncludes = $repoJson->read();
459+
$jsonIncludes = isset($jsonIncludes['includes']) && is_array($jsonIncludes['includes'])
460+
? $jsonIncludes['includes']
461+
: array();
462+
463+
foreach ($jsonIncludes as $includeFile => $includeConfig) {
464+
$includeJson = new JsonFile($dirName . '/' . $includeFile);
465+
$jsonPackages = $includeJson->read();
466+
$jsonPackages = isset($jsonPackages['packages']) && is_array($jsonPackages['packages'])
467+
? $jsonPackages['packages']
468+
: array();
469+
470+
foreach ($jsonPackages as $jsonPackage) {
471+
if (is_array($jsonPackage)) {
472+
foreach ($jsonPackage as $jsonVersion) {
473+
if (is_array($jsonVersion)) {
474+
if(isset($jsonVersion['name']) && in_array($jsonVersion['name'], $packagesFilter)) {
475+
continue;
476+
}
477+
$package = $loader->load($jsonVersion);
478+
$packages[$package->getUniqueName()] = $package;
479+
}
480+
}
481+
}
482+
}
483+
}
484+
}
485+
486+
return $packages;
487+
}
488+
469489
private function getMappedPackageList(array $packages)
470490
{
471491
$groupedPackages = $this->groupPackagesByName($packages);

0 commit comments

Comments
 (0)