@@ -9,6 +9,7 @@ import 'package:logging/logging.dart';
9
9
import 'package:openapi_generator/src/determine_flutter_project_status.dart' ;
10
10
import 'package:openapi_generator/src/gen_on_spec_changes.dart' ;
11
11
import 'package:openapi_generator/src/models/output_message.dart' ;
12
+ import 'package:openapi_generator/src/process_runner.dart' ;
12
13
import 'package:openapi_generator/src/utils.dart' ;
13
14
import 'package:openapi_generator_annotations/openapi_generator_annotations.dart'
14
15
as annots;
@@ -18,10 +19,9 @@ import 'models/command.dart';
18
19
import 'models/generator_arguments.dart' ;
19
20
20
21
class OpenapiGenerator extends GeneratorForAnnotation <annots.Openapi > {
21
- @Deprecated ('To be removed in next major version' )
22
- final bool testMode;
22
+ final ProcessRunner _processRunner;
23
23
24
- OpenapiGenerator ({ this .testMode = false } );
24
+ OpenapiGenerator (this ._processRunner );
25
25
26
26
@override
27
27
FutureOr <String > generateForAnnotatedElement (
@@ -98,21 +98,17 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
98
98
var javaOpts = Platform .environment['JAVA_OPTS' ] ?? '' ;
99
99
100
100
ProcessResult result;
101
- if (! testMode) {
102
- result = await Process .run (
103
- 'java' ,
104
- [
105
- if (javaOpts.isNotEmpty) javaOpts,
106
- '-jar' ,
107
- binPath,
108
- ...args,
109
- ],
110
- workingDirectory: Directory .current.path,
111
- runInShell: Platform .isWindows,
112
- );
113
- } else {
114
- result = ProcessResult (999999 , 0 , null , null );
115
- }
101
+ result = await _processRunner.run (
102
+ 'java' ,
103
+ [
104
+ if (javaOpts.isNotEmpty) javaOpts,
105
+ '-jar' ,
106
+ binPath,
107
+ ...args,
108
+ ],
109
+ workingDirectory: Directory .current.path,
110
+ runInShell: Platform .isWindows,
111
+ );
116
112
117
113
if (result.exitCode != 0 ) {
118
114
return Future .error (
@@ -342,16 +338,12 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
342
338
);
343
339
344
340
ProcessResult results;
345
- if (! testMode) {
346
- results = await Process .run (
347
- command.executable,
348
- command.arguments,
349
- runInShell: Platform .isWindows,
350
- workingDirectory: args.outputDirectory,
351
- );
352
- } else {
353
- results = ProcessResult (99999 , 0 , null , null );
354
- }
341
+ results = await _processRunner.run (
342
+ command.executable,
343
+ command.arguments,
344
+ runInShell: Platform .isWindows,
345
+ workingDirectory: args.outputDirectory,
346
+ );
355
347
356
348
if (results.exitCode != 0 ) {
357
349
return Future .error (
@@ -398,16 +390,12 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
398
390
);
399
391
400
392
ProcessResult results;
401
- if (! testMode) {
402
- results = await Process .run (
403
- command.executable,
404
- command.arguments,
405
- runInShell: Platform .isWindows,
406
- workingDirectory: args.outputDirectory,
407
- );
408
- } else {
409
- results = ProcessResult (999999 , 0 , null , null );
410
- }
393
+ results = await _processRunner.run (
394
+ command.executable,
395
+ command.arguments,
396
+ runInShell: Platform .isWindows,
397
+ workingDirectory: args.outputDirectory,
398
+ );
411
399
412
400
if (results.exitCode != 0 ) {
413
401
return Future .error (
@@ -482,16 +470,13 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
482
470
Future <void > formatCode ({required GeneratorArguments args}) async {
483
471
final command = Command (executable: 'dart' , arguments: ['format' , './' ]);
484
472
ProcessResult result;
485
- if (! testMode) {
486
- result = await Process .run (
487
- command.executable,
488
- command.arguments,
489
- workingDirectory: args.outputDirectory,
490
- runInShell: Platform .isWindows,
491
- );
492
- } else {
493
- result = ProcessResult (99999 , 0 , null , null );
494
- }
473
+
474
+ result = await _processRunner.run (
475
+ command.executable,
476
+ command.arguments,
477
+ workingDirectory: args.outputDirectory,
478
+ runInShell: Platform .isWindows,
479
+ );
495
480
496
481
if (result.exitCode != 0 ) {
497
482
return Future .error (
0 commit comments