22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5- // @dart=2.9
6-
75library dartdoc.tool_runner;
86
97import 'dart:io' show Process, ProcessException;
@@ -12,7 +10,6 @@ import 'package:analyzer/file_system/file_system.dart';
1210import 'package:dartdoc/src/dartdoc_options.dart' ;
1311import 'package:dartdoc/src/io_utils.dart' ;
1412import 'package:dartdoc/src/tool_definition.dart' ;
15- import 'package:meta/meta.dart' ;
1613import 'package:path/path.dart' as p;
1714
1815typedef ToolErrorCallback = void Function (String message);
@@ -97,7 +94,7 @@ class ToolRunner {
9794 /// calls [toolErrorCallback] with a detailed error message, and returns `''` .
9895 Future <String > _runProcess (String name, String content, String commandPath,
9996 List <String > args, Map <String , String > environment,
100- {@ required ToolErrorCallback toolErrorCallback}) async {
97+ {required ToolErrorCallback toolErrorCallback}) async {
10198 String commandString () => ([commandPath] + args).join (' ' );
10299 try {
103100 var result =
@@ -128,10 +125,9 @@ class ToolRunner {
128125 /// be sent to to the tool is given in the optional [content] . The stdout of
129126 /// the tool is returned.
130127 Future <String > run (List <String > args,
131- {@required String content,
132- @required ToolErrorCallback toolErrorCallback,
133- Map <String , String > environment}) async {
134- assert (args != null );
128+ {required String content,
129+ required ToolErrorCallback toolErrorCallback,
130+ Map <String , String > environment = const {}}) async {
135131 assert (args.isNotEmpty);
136132 return _toolTracker.add (() {
137133 return _run (args,
@@ -142,13 +138,10 @@ class ToolRunner {
142138 }
143139
144140 Future <String > _run (List <String > args,
145- {@required ToolErrorCallback toolErrorCallback,
146- String content,
147- Map <String , String > environment}) async {
148- assert (args != null );
141+ {required ToolErrorCallback toolErrorCallback,
142+ String content = '' ,
143+ required Map <String , String > environment}) async {
149144 assert (args.isNotEmpty);
150- content ?? = '' ;
151- environment ?? = < String , String > {};
152145 var toolName = args.removeAt (0 );
153146 if (! toolConfiguration.tools.containsKey (toolName)) {
154147 toolErrorCallback (
@@ -157,14 +150,14 @@ class ToolRunner {
157150 return '' ;
158151 }
159152 var toolDefinition = toolConfiguration.tools[toolName];
160- var toolArgs = toolDefinition.command;
153+ var toolArgs = toolDefinition! .command;
161154
162155 // Substitute the temp filename for the "$INPUT" token, and all of the other
163156 // environment variables. Variables are allowed to either be in $(VAR) form,
164157 // or $VAR form.
165158 var envWithInput = {
166159 'INPUT' : _tmpFileWithContent (content),
167- 'TOOL_COMMAND' : toolDefinition.command [0 ],
160+ 'TOOL_COMMAND' : toolArgs [0 ],
168161 ...environment,
169162 };
170163 if (toolDefinition is DartToolDefinition ) {
@@ -176,7 +169,7 @@ class ToolRunner {
176169 // filesystem.
177170 envWithInput['DART_SNAPSHOT_CACHE' ] = pathContext.absolute (
178171 SnapshotCache .instanceFor (resourceProvider).snapshotCache.path);
179- if (toolDefinition.setupCommand != null ) {
172+ if (toolDefinition.setupCommand.isNotEmpty ) {
180173 envWithInput['DART_SETUP_COMMAND' ] = toolDefinition.setupCommand[0 ];
181174 }
182175 }
@@ -186,7 +179,8 @@ class ToolRunner {
186179 ..._substituteInArgs (args, envWithInput),
187180 ];
188181
189- if (toolDefinition.setupCommand != null && ! toolDefinition.setupComplete) {
182+ if (toolDefinition.setupCommand.isNotEmpty &&
183+ ! toolDefinition.setupComplete) {
190184 await _runSetup (
191185 toolName, toolDefinition, envWithInput, toolErrorCallback);
192186 }
0 commit comments