12
12
13
13
namespace Composer \Satis \Command ;
14
14
15
+ use Composer \Package \Loader \ArrayLoader ;
15
16
use Symfony \Component \Console \Input \InputInterface ;
16
17
use Symfony \Component \Console \Output \OutputInterface ;
17
18
use Symfony \Component \Console \Input \InputArgument ;
@@ -50,6 +51,7 @@ protected function configure()
50
51
->setDefinition (array (
51
52
new InputArgument ('file ' , InputArgument::OPTIONAL , 'Json file to use ' , './satis.json ' ),
52
53
new InputArgument ('output-dir ' , InputArgument::OPTIONAL , 'Location where to output built files ' , null ),
54
+ new InputArgument ('packages ' , InputArgument::IS_ARRAY | InputArgument::OPTIONAL , 'Packages that should be built, if not provided all packages are. ' , null ),
53
55
new InputOption ('no-html-output ' , null , InputOption::VALUE_NONE , 'Turn off HTML view ' ),
54
56
new InputOption ('skip-errors ' , null , InputOption::VALUE_NONE , 'Skip Download or Archive errors ' ),
55
57
))
@@ -101,6 +103,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
101
103
{
102
104
$ verbose = $ input ->getOption ('verbose ' );
103
105
$ configFile = $ input ->getArgument ('file ' );
106
+ $ packagesFilter = $ input ->getArgument ('packages ' );
104
107
$ skipErrors = (bool )$ input ->getOption ('skip-errors ' );
105
108
106
109
if (preg_match ('{^https?://}i ' , $ configFile )) {
@@ -141,7 +144,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
141
144
}
142
145
143
146
$ composer = $ this ->getApplication ()->getComposer (true , $ config );
144
- $ packages = $ this ->selectPackages ($ composer , $ output , $ verbose , $ requireAll , $ requireDependencies , $ requireDevDependencies , $ minimumStability , $ skipErrors );
147
+ $ packages = $ this ->selectPackages ($ composer , $ output , $ verbose , $ requireAll , $ requireDependencies , $ requireDevDependencies , $ minimumStability , $ skipErrors, $ packagesFilter );
145
148
146
149
if ($ htmlView = !$ input ->getOption ('no-html-output ' )) {
147
150
$ htmlView = !isset ($ config ['output-html ' ]) || $ config ['output-html ' ];
@@ -152,14 +155,22 @@ protected function execute(InputInterface $input, OutputInterface $output)
152
155
}
153
156
154
157
$ filenamePrefix = $ outputDir .'/include/all ' ;
158
+ $ filename = $ outputDir .'/packages.json ' ;
159
+ if (!empty ($ packagesFilter )) {
160
+ // in case of an active package filter we need to load the dumped packages.json and merge the
161
+ // updated packages in
162
+ $ oldPackages = $ this ->loadDumpedPackages ($ filename , $ packagesFilter );
163
+ $ packages += $ oldPackages ;
164
+ ksort ($ packages );
165
+ }
166
+
155
167
$ packageFile = $ this ->dumpPackageIncludeJson ($ packages , $ output , $ filenamePrefix );
156
168
$ packageFileHash = hash_file ('sha1 ' , $ packageFile );
157
169
158
170
$ includes = array (
159
171
'include/all$ ' .$ packageFileHash .'.json ' => array ( 'sha1 ' =>$ packageFileHash ),
160
172
);
161
173
162
- $ filename = $ outputDir .'/packages.json ' ;
163
174
$ this ->dumpPackagesJson ($ includes , $ output , $ filename );
164
175
165
176
if ($ htmlView ) {
@@ -176,7 +187,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
176
187
}
177
188
}
178
189
179
- private function selectPackages (Composer $ composer , OutputInterface $ output , $ verbose , $ requireAll , $ requireDependencies , $ requireDevDependencies , $ minimumStability , $ skipErrors )
190
+ private function selectPackages (Composer $ composer , OutputInterface $ output , $ verbose , $ requireAll , $ requireDependencies , $ requireDevDependencies , $ minimumStability , $ skipErrors, array $ packagesFilter = array () )
180
191
{
181
192
$ selected = array ();
182
193
@@ -198,6 +209,7 @@ private function selectPackages(Composer $composer, OutputInterface $output, $ve
198
209
199
210
if ($ requireAll ) {
200
211
$ links = array ();
212
+ $ filterForPackages = count ($ packagesFilter ) > 0 ;
201
213
202
214
foreach ($ repos as $ repo ) {
203
215
// collect links for composer repos with providers
@@ -206,8 +218,18 @@ private function selectPackages(Composer $composer, OutputInterface $output, $ve
206
218
$ links [] = new Link ('__root__ ' , $ name , new MultiConstraint (array ()), 'requires ' , '* ' );
207
219
}
208
220
} else {
209
- // process other repos directly
210
- foreach ($ repo ->getPackages () as $ package ) {
221
+ $ packages = array ();
222
+ if ($ filterForPackages ) {
223
+ // apply package filter if defined
224
+ foreach ($ packagesFilter as $ filter ) {
225
+ $ packages += $ repo ->findPackages ($ filter );
226
+ }
227
+ } else {
228
+ // process other repos directly
229
+ $ packages = $ repo ->getPackages ();
230
+ }
231
+
232
+ foreach ($ packages as $ package ) {
211
233
// skip aliases
212
234
if ($ package instanceof AliasPackage) {
213
235
continue ;
@@ -428,6 +450,45 @@ private function dumpWeb(array $packages, OutputInterface $output, PackageInterf
428
450
file_put_contents ($ directory .'/index.html ' , $ content );
429
451
}
430
452
453
+ private function loadDumpedPackages ($ filename , array $ packagesFilter = array ())
454
+ {
455
+ $ packages = array ();
456
+ $ repoJson = new JsonFile ($ filename );
457
+ $ dirName = dirname ($ filename );
458
+
459
+ if ($ repoJson ->exists ()) {
460
+ $ loader = new ArrayLoader ();
461
+ $ jsonIncludes = $ repoJson ->read ();
462
+ $ jsonIncludes = isset ($ jsonIncludes ['includes ' ]) && is_array ($ jsonIncludes ['includes ' ])
463
+ ? $ jsonIncludes ['includes ' ]
464
+ : array ();
465
+
466
+ foreach ($ jsonIncludes as $ includeFile => $ includeConfig ) {
467
+ $ includeJson = new JsonFile ($ dirName . '/ ' . $ includeFile );
468
+ $ jsonPackages = $ includeJson ->read ();
469
+ $ jsonPackages = isset ($ jsonPackages ['packages ' ]) && is_array ($ jsonPackages ['packages ' ])
470
+ ? $ jsonPackages ['packages ' ]
471
+ : array ();
472
+
473
+ foreach ($ jsonPackages as $ jsonPackage ) {
474
+ if (is_array ($ jsonPackage )) {
475
+ foreach ($ jsonPackage as $ jsonVersion ) {
476
+ if (is_array ($ jsonVersion )) {
477
+ if (isset ($ jsonVersion ['name ' ]) && in_array ($ jsonVersion ['name ' ], $ packagesFilter )) {
478
+ continue ;
479
+ }
480
+ $ package = $ loader ->load ($ jsonVersion );
481
+ $ packages [$ package ->getUniqueName ()] = $ package ;
482
+ }
483
+ }
484
+ }
485
+ }
486
+ }
487
+ }
488
+
489
+ return $ packages ;
490
+ }
491
+
431
492
private function getMappedPackageList (array $ packages )
432
493
{
433
494
$ groupedPackages = $ this ->groupPackagesByName ($ packages );
0 commit comments