diff --git a/lib/src/dartdoc_options.dart b/lib/src/dartdoc_options.dart index f4e8da6326..c3e0d09254 100644 --- a/lib/src/dartdoc_options.dart +++ b/lib/src/dartdoc_options.dart @@ -242,7 +242,10 @@ class ToolConfiguration { setupCommand; } newToolDefinitions[name] = ToolDefinition.fromCommand( - [executable] + command, setupCommand, description, resourceProvider, + [executable] + command, + setupCommand ?? const [], + description, + resourceProvider, compileArgs: compileArgs ?? const []); } return ToolConfiguration._(newToolDefinitions, resourceProvider); diff --git a/lib/src/tool_definition.dart b/lib/src/tool_definition.dart index fe37380c34..44ec3116e2 100644 --- a/lib/src/tool_definition.dart +++ b/lib/src/tool_definition.dart @@ -23,8 +23,8 @@ class ToolDefinition { /// A list containing the command and options to setup phase for this tool. /// The first argument in the command is the tool executable, and will have /// its path evaluated relative to the `dartdoc_options.yaml` location. May - /// be null or empty, in which case it will be ignored at setup time. - final List? setupCommand; + /// be empty, in which case it will be ignored at setup time. + final List setupCommand; /// A description of the defined tool. Must not be null. final String description; @@ -43,7 +43,7 @@ class ToolDefinition { /// given. factory ToolDefinition.fromCommand( List command, - List? setupCommand, + List setupCommand, String description, ResourceProvider resourceProvider, {List? compileArgs}) { @@ -68,10 +68,9 @@ class ToolDefinition { @override String toString() { - var setupCommand = this.setupCommand; final commandString = '${this is DartToolDefinition ? '(Dart) ' : ''}"${command.join(' ')}"'; - if (setupCommand == null) { + if (setupCommand.isEmpty) { return '$runtimeType: $commandString ($description)'; } else { return '$runtimeType: $commandString, with setup command ' @@ -140,7 +139,7 @@ class DartToolDefinition extends ToolDefinition { } } - DartToolDefinition(List command, List? setupCommand, + DartToolDefinition(List command, List setupCommand, String description, this._resourceProvider, {this.compileArgs = const []}) : super(command, setupCommand, description); diff --git a/lib/src/tool_runner.dart b/lib/src/tool_runner.dart index 47010b2813..1b214f12be 100644 --- a/lib/src/tool_runner.dart +++ b/lib/src/tool_runner.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.9 - library dartdoc.tool_runner; import 'dart:io' show Process, ProcessException; @@ -12,7 +10,6 @@ import 'package:analyzer/file_system/file_system.dart'; import 'package:dartdoc/src/dartdoc_options.dart'; import 'package:dartdoc/src/io_utils.dart'; import 'package:dartdoc/src/tool_definition.dart'; -import 'package:meta/meta.dart'; import 'package:path/path.dart' as p; typedef ToolErrorCallback = void Function(String message); @@ -97,7 +94,7 @@ class ToolRunner { /// calls [toolErrorCallback] with a detailed error message, and returns `''`. Future _runProcess(String name, String content, String commandPath, List args, Map environment, - {@required ToolErrorCallback toolErrorCallback}) async { + {required ToolErrorCallback toolErrorCallback}) async { String commandString() => ([commandPath] + args).join(' '); try { var result = @@ -128,10 +125,9 @@ class ToolRunner { /// be sent to to the tool is given in the optional [content]. The stdout of /// the tool is returned. Future run(List args, - {@required String content, - @required ToolErrorCallback toolErrorCallback, - Map environment}) async { - assert(args != null); + {required String content, + required ToolErrorCallback toolErrorCallback, + Map environment = const {}}) async { assert(args.isNotEmpty); return _toolTracker.add(() { return _run(args, @@ -142,13 +138,10 @@ class ToolRunner { } Future _run(List args, - {@required ToolErrorCallback toolErrorCallback, - String content, - Map environment}) async { - assert(args != null); + {required ToolErrorCallback toolErrorCallback, + String content = '', + required Map environment}) async { assert(args.isNotEmpty); - content ??= ''; - environment ??= {}; var toolName = args.removeAt(0); if (!toolConfiguration.tools.containsKey(toolName)) { toolErrorCallback( @@ -157,14 +150,14 @@ class ToolRunner { return ''; } var toolDefinition = toolConfiguration.tools[toolName]; - var toolArgs = toolDefinition.command; + var toolArgs = toolDefinition!.command; // Substitute the temp filename for the "$INPUT" token, and all of the other // environment variables. Variables are allowed to either be in $(VAR) form, // or $VAR form. var envWithInput = { 'INPUT': _tmpFileWithContent(content), - 'TOOL_COMMAND': toolDefinition.command[0], + 'TOOL_COMMAND': toolArgs[0], ...environment, }; if (toolDefinition is DartToolDefinition) { @@ -176,7 +169,7 @@ class ToolRunner { // filesystem. envWithInput['DART_SNAPSHOT_CACHE'] = pathContext.absolute( SnapshotCache.instanceFor(resourceProvider).snapshotCache.path); - if (toolDefinition.setupCommand != null) { + if (toolDefinition.setupCommand.isNotEmpty) { envWithInput['DART_SETUP_COMMAND'] = toolDefinition.setupCommand[0]; } } @@ -186,7 +179,8 @@ class ToolRunner { ..._substituteInArgs(args, envWithInput), ]; - if (toolDefinition.setupCommand != null && !toolDefinition.setupComplete) { + if (toolDefinition.setupCommand.isNotEmpty && + !toolDefinition.setupComplete) { await _runSetup( toolName, toolDefinition, envWithInput, toolErrorCallback); } diff --git a/test/tool_runner_test.dart b/test/tool_runner_test.dart index afacb3deba..20985b7d99 100644 --- a/test/tool_runner_test.dart +++ b/test/tool_runner_test.dart @@ -88,7 +88,7 @@ echo: // yaml map (which would fail on a missing executable), or a file is deleted // during execution,it might, so we test it. toolMap.tools.addAll({ - 'missing': ToolDefinition(['/a/missing/executable'], null, 'missing'), + 'missing': ToolDefinition(['/a/missing/executable'], [], 'missing'), }); runner = ToolRunner(toolMap);