2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- // @dart=2.9
6
-
7
5
library dartdoc.tool_runner;
8
6
9
7
import 'dart:io' show Process, ProcessException;
@@ -12,7 +10,6 @@ import 'package:analyzer/file_system/file_system.dart';
12
10
import 'package:dartdoc/src/dartdoc_options.dart' ;
13
11
import 'package:dartdoc/src/io_utils.dart' ;
14
12
import 'package:dartdoc/src/tool_definition.dart' ;
15
- import 'package:meta/meta.dart' ;
16
13
import 'package:path/path.dart' as p;
17
14
18
15
typedef ToolErrorCallback = void Function (String message);
@@ -97,7 +94,7 @@ class ToolRunner {
97
94
/// calls [toolErrorCallback] with a detailed error message, and returns `''` .
98
95
Future <String > _runProcess (String name, String content, String commandPath,
99
96
List <String > args, Map <String , String > environment,
100
- {@ required ToolErrorCallback toolErrorCallback}) async {
97
+ {required ToolErrorCallback toolErrorCallback}) async {
101
98
String commandString () => ([commandPath] + args).join (' ' );
102
99
try {
103
100
var result =
@@ -128,10 +125,9 @@ class ToolRunner {
128
125
/// be sent to to the tool is given in the optional [content] . The stdout of
129
126
/// the tool is returned.
130
127
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 {
135
131
assert (args.isNotEmpty);
136
132
return _toolTracker.add (() {
137
133
return _run (args,
@@ -142,13 +138,10 @@ class ToolRunner {
142
138
}
143
139
144
140
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 {
149
144
assert (args.isNotEmpty);
150
- content ?? = '' ;
151
- environment ?? = < String , String > {};
152
145
var toolName = args.removeAt (0 );
153
146
if (! toolConfiguration.tools.containsKey (toolName)) {
154
147
toolErrorCallback (
@@ -157,14 +150,14 @@ class ToolRunner {
157
150
return '' ;
158
151
}
159
152
var toolDefinition = toolConfiguration.tools[toolName];
160
- var toolArgs = toolDefinition.command;
153
+ var toolArgs = toolDefinition! .command;
161
154
162
155
// Substitute the temp filename for the "$INPUT" token, and all of the other
163
156
// environment variables. Variables are allowed to either be in $(VAR) form,
164
157
// or $VAR form.
165
158
var envWithInput = {
166
159
'INPUT' : _tmpFileWithContent (content),
167
- 'TOOL_COMMAND' : toolDefinition.command [0 ],
160
+ 'TOOL_COMMAND' : toolArgs [0 ],
168
161
...environment,
169
162
};
170
163
if (toolDefinition is DartToolDefinition ) {
@@ -176,7 +169,7 @@ class ToolRunner {
176
169
// filesystem.
177
170
envWithInput['DART_SNAPSHOT_CACHE' ] = pathContext.absolute (
178
171
SnapshotCache .instanceFor (resourceProvider).snapshotCache.path);
179
- if (toolDefinition.setupCommand != null ) {
172
+ if (toolDefinition.setupCommand.isNotEmpty ) {
180
173
envWithInput['DART_SETUP_COMMAND' ] = toolDefinition.setupCommand[0 ];
181
174
}
182
175
}
@@ -186,7 +179,8 @@ class ToolRunner {
186
179
..._substituteInArgs (args, envWithInput),
187
180
];
188
181
189
- if (toolDefinition.setupCommand != null && ! toolDefinition.setupComplete) {
182
+ if (toolDefinition.setupCommand.isNotEmpty &&
183
+ ! toolDefinition.setupComplete) {
190
184
await _runSetup (
191
185
toolName, toolDefinition, envWithInput, toolErrorCallback);
192
186
}
0 commit comments