@@ -13,6 +13,7 @@ import 'package:platform/platform.dart';
13
13
import 'core.dart' ;
14
14
import 'plugin_command.dart' ;
15
15
import 'process_runner.dart' ;
16
+ import 'repository_package.dart' ;
16
17
17
18
/// Possible outcomes of a command run for a package.
18
19
enum RunState {
@@ -84,7 +85,7 @@ abstract class PackageLoopingCommand extends PluginCommand {
84
85
int _otherWarningCount = 0 ;
85
86
86
87
/// The package currently being run by [runForPackage] .
87
- PackageEnumerationEntry ? _currentPackage ;
88
+ PackageEnumerationEntry ? _currentPackageEntry ;
88
89
89
90
/// Called during [run] before any calls to [runForPackage] . This provides an
90
91
/// opportunity to fail early if the command can't be run (e.g., because the
@@ -97,7 +98,7 @@ abstract class PackageLoopingCommand extends PluginCommand {
97
98
/// be included in the final error summary (e.g., a command that only has a
98
99
/// single failure mode), or strings that should be listed for that package
99
100
/// in the final summary. An empty list indicates success.
100
- Future <PackageResult > runForPackage (Directory package);
101
+ Future <PackageResult > runForPackage (RepositoryPackage package);
101
102
102
103
/// Called during [run] after all calls to [runForPackage] . This provides an
103
104
/// opportunity to do any cleanup of run-level state.
@@ -155,31 +156,13 @@ abstract class PackageLoopingCommand extends PluginCommand {
155
156
/// things that might be useful to someone debugging an unexpected result.
156
157
void logWarning (String warningMessage) {
157
158
print (Colorize (warningMessage)..yellow ());
158
- if (_currentPackage != null ) {
159
- _packagesWithWarnings.add (_currentPackage ! );
159
+ if (_currentPackageEntry != null ) {
160
+ _packagesWithWarnings.add (_currentPackageEntry ! );
160
161
} else {
161
162
++ _otherWarningCount;
162
163
}
163
164
}
164
165
165
- /// Returns the identifying name to use for [package] .
166
- ///
167
- /// Implementations should not expect a specific format for this string, since
168
- /// it uses heuristics to try to be precise without being overly verbose. If
169
- /// an exact format (e.g., published name, or basename) is required, that
170
- /// should be used instead.
171
- String getPackageDescription (Directory package) {
172
- String packageName = getRelativePosixPath (package, from: packagesDir);
173
- final List <String > components = p.posix.split (packageName);
174
- // For the common federated plugin pattern of `foo/foo_subpackage`, drop
175
- // the first part since it's not useful.
176
- if (components.length >= 2 &&
177
- components[1 ].startsWith ('${components [0 ]}_' )) {
178
- packageName = p.posix.joinAll (components.sublist (1 ));
179
- }
180
- return packageName;
181
- }
182
-
183
166
/// Returns the relative path from [from] to [entity] in Posix style.
184
167
///
185
168
/// This should be used when, for example, printing package-relative paths in
@@ -219,50 +202,50 @@ abstract class PackageLoopingCommand extends PluginCommand {
219
202
Future <bool > _runInternal () async {
220
203
_packagesWithWarnings.clear ();
221
204
_otherWarningCount = 0 ;
222
- _currentPackage = null ;
205
+ _currentPackageEntry = null ;
223
206
224
207
await initializeRun ();
225
208
226
- final List <PackageEnumerationEntry > packages = includeSubpackages
209
+ final List <PackageEnumerationEntry > targetPackages = includeSubpackages
227
210
? await getTargetPackagesAndSubpackages (filterExcluded: false ).toList ()
228
211
: await getTargetPackages (filterExcluded: false ).toList ();
229
212
230
213
final Map <PackageEnumerationEntry , PackageResult > results =
231
214
< PackageEnumerationEntry , PackageResult > {};
232
- for (final PackageEnumerationEntry package in packages ) {
233
- _currentPackage = package ;
234
- _printPackageHeading (package );
215
+ for (final PackageEnumerationEntry entry in targetPackages ) {
216
+ _currentPackageEntry = entry ;
217
+ _printPackageHeading (entry );
235
218
236
219
// Command implementations should never see excluded packages; they are
237
220
// included at this level only for logging.
238
- if (package .excluded) {
239
- results[package ] = PackageResult .exclude ();
221
+ if (entry .excluded) {
222
+ results[entry ] = PackageResult .exclude ();
240
223
continue ;
241
224
}
242
225
243
- final PackageResult result = await runForPackage (package.directory );
226
+ final PackageResult result = await runForPackage (entry.package );
244
227
if (result.state == RunState .skipped) {
245
228
final String message =
246
229
'${indentation }SKIPPING: ${result .details .first }' ;
247
230
captureOutput ? print (message) : print (Colorize (message)..darkGray ());
248
231
}
249
- results[package ] = result;
232
+ results[entry ] = result;
250
233
}
251
- _currentPackage = null ;
234
+ _currentPackageEntry = null ;
252
235
253
236
completeRun ();
254
237
255
238
print ('\n ' );
256
239
// If there were any errors reported, summarize them and exit.
257
240
if (results.values
258
241
.any ((PackageResult result) => result.state == RunState .failed)) {
259
- _printFailureSummary (packages , results);
242
+ _printFailureSummary (targetPackages , results);
260
243
return false ;
261
244
}
262
245
263
246
// Otherwise, print a summary of what ran for ease of auditing that all the
264
247
// expected tests ran.
265
- _printRunSummary (packages , results);
248
+ _printRunSummary (targetPackages , results);
266
249
267
250
print ('\n ' );
268
251
_printSuccess ('No issues found!' );
@@ -283,9 +266,9 @@ abstract class PackageLoopingCommand extends PluginCommand {
283
266
/// Something is always printed to make it easier to distinguish between
284
267
/// a command running for a package and producing no output, and a command
285
268
/// not having been run for a package.
286
- void _printPackageHeading (PackageEnumerationEntry package ) {
287
- final String packageDisplayName = getPackageDescription ( package.directory) ;
288
- String heading = package .excluded
269
+ void _printPackageHeading (PackageEnumerationEntry entry ) {
270
+ final String packageDisplayName = entry. package.displayName ;
271
+ String heading = entry .excluded
289
272
? 'Not running for $packageDisplayName ; excluded'
290
273
: 'Running for $packageDisplayName ' ;
291
274
if (hasLongOutput) {
@@ -295,16 +278,15 @@ abstract class PackageLoopingCommand extends PluginCommand {
295
278
|| $heading
296
279
============================================================
297
280
''' ;
298
- } else if (! package .excluded) {
281
+ } else if (! entry .excluded) {
299
282
heading = '$heading ...' ;
300
283
}
301
284
if (captureOutput) {
302
285
print (heading);
303
286
} else {
304
287
final Colorize colorizeHeading = Colorize (heading);
305
- print (package.excluded
306
- ? colorizeHeading.darkGray ()
307
- : colorizeHeading.cyan ());
288
+ print (
289
+ entry.excluded ? colorizeHeading.darkGray () : colorizeHeading.cyan ());
308
290
}
309
291
}
310
292
@@ -349,17 +331,18 @@ abstract class PackageLoopingCommand extends PluginCommand {
349
331
350
332
/// Prints a one-line-per-package overview of the run results for each
351
333
/// package.
352
- void _printPerPackageRunOverview (List <PackageEnumerationEntry > packages,
334
+ void _printPerPackageRunOverview (
335
+ List <PackageEnumerationEntry > packageEnumeration,
353
336
{required Set <PackageEnumerationEntry > skipped}) {
354
337
print ('Run overview:' );
355
- for (final PackageEnumerationEntry package in packages ) {
356
- final bool hadWarning = _packagesWithWarnings.contains (package );
338
+ for (final PackageEnumerationEntry entry in packageEnumeration ) {
339
+ final bool hadWarning = _packagesWithWarnings.contains (entry );
357
340
Styles style;
358
341
String summary;
359
- if (package .excluded) {
342
+ if (entry .excluded) {
360
343
summary = 'excluded' ;
361
344
style = Styles .DARK_GRAY ;
362
- } else if (skipped.contains (package )) {
345
+ } else if (skipped.contains (entry )) {
363
346
summary = 'skipped' ;
364
347
style = hadWarning ? Styles .LIGHT_YELLOW : Styles .DARK_GRAY ;
365
348
} else {
@@ -373,27 +356,26 @@ abstract class PackageLoopingCommand extends PluginCommand {
373
356
if (! captureOutput) {
374
357
summary = (Colorize (summary)..apply (style)).toString ();
375
358
}
376
- print (' ${getPackageDescription ( package .directory ) } - $summary ' );
359
+ print (' ${entry . package .displayName } - $summary ' );
377
360
}
378
361
print ('' );
379
362
}
380
363
381
364
/// Prints a summary of all of the failures from [results] .
382
- void _printFailureSummary (List <PackageEnumerationEntry > packages ,
365
+ void _printFailureSummary (List <PackageEnumerationEntry > packageEnumeration ,
383
366
Map <PackageEnumerationEntry , PackageResult > results) {
384
367
const String indentation = ' ' ;
385
368
_printError (failureListHeader);
386
- for (final PackageEnumerationEntry package in packages ) {
387
- final PackageResult result = results[package ]! ;
369
+ for (final PackageEnumerationEntry entry in packageEnumeration ) {
370
+ final PackageResult result = results[entry ]! ;
388
371
if (result.state == RunState .failed) {
389
372
final String errorIndentation = indentation * 2 ;
390
373
String errorDetails = '' ;
391
374
if (result.details.isNotEmpty) {
392
375
errorDetails =
393
376
':\n $errorIndentation ${result .details .join ('\n $errorIndentation ' )}' ;
394
377
}
395
- _printError (
396
- '$indentation ${getPackageDescription (package .directory )}$errorDetails ' );
378
+ _printError ('$indentation ${entry .package .displayName }$errorDetails ' );
397
379
}
398
380
}
399
381
_printError (failureListFooter);
0 commit comments