@@ -154,6 +154,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
154
154
$ this ->dumpDownloads ($ config , $ packages , $ input , $ output , $ outputDir , $ skipErrors );
155
155
}
156
156
157
+ $ filenamePrefix = $ outputDir .'/include/all ' ;
157
158
$ filename = $ outputDir .'/packages.json ' ;
158
159
if (!empty ($ packagesFilter )) {
159
160
// 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)
162
163
$ packages += $ oldPackages ;
163
164
ksort ($ packages );
164
165
}
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 );
166
175
167
176
if ($ htmlView ) {
168
177
$ dependencies = array ();
@@ -198,10 +207,10 @@ private function selectPackages(Composer $composer, OutputInterface $output, $ve
198
207
}
199
208
}
200
209
201
- $ links = array ();
202
-
203
210
if ($ requireAll ) {
211
+ $ links = array ();
204
212
$ filterForPackages = count ($ packagesFilter ) > 0 ;
213
+
205
214
foreach ($ repos as $ repo ) {
206
215
// collect links for composer repos with providers
207
216
if ($ repo instanceof ComposerRepository && $ repo ->hasProviders ()) {
@@ -231,29 +240,20 @@ private function selectPackages(Composer $composer, OutputInterface $output, $ve
231
240
}
232
241
233
242
// add matching package if not yet selected
234
- if (!isset ($ selected [$ package ->getName ()])) {
243
+ if (!isset ($ selected [$ package ->getUniqueName ()])) {
235
244
if ($ verbose ) {
236
245
$ output ->writeln ('Selected ' .$ package ->getPrettyName ().' ( ' .$ package ->getPrettyVersion ().') ' );
237
246
}
238
-
239
247
$ selected [$ package ->getUniqueName ()] = $ package ;
240
248
}
241
249
}
242
250
}
243
251
}
244
252
} 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 ());
255
254
}
256
255
256
+
257
257
// process links if any
258
258
$ depsLinks = array ();
259
259
@@ -388,51 +388,32 @@ private function dumpDownloads(array $config, array &$packages, InputInterface
388
388
}
389
389
}
390
390
391
- private function dumpJson (array $ packages , OutputInterface $ output , $ filename , $ update = false )
391
+
392
+ private function dumpPackageIncludeJson (array $ packages , OutputInterface $ output , $ filename )
392
393
{
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 ;
401
396
foreach ($ packages as $ package ) {
402
397
$ repo ['packages ' ][$ package ->getPrettyName ()][$ package ->getPrettyVersion ()] = $ dumper ->dump ($ package );
403
398
}
404
- $ output -> writeln ( ' <info>Writing packages.json</info> ' );
399
+ $ repoJson = new JsonFile ( $ filename );
405
400
$ 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 ;
406
406
}
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 );
436
417
}
437
418
438
419
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
466
447
file_put_contents ($ directory .'/index.html ' , $ content );
467
448
}
468
449
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
+
469
489
private function getMappedPackageList (array $ packages )
470
490
{
471
491
$ groupedPackages = $ this ->groupPackagesByName ($ packages );
0 commit comments