@@ -25,14 +25,16 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
25
25
FutureOr <String > generateForAnnotatedElement (
26
26
Element element, ConstantReader annotations, BuildStep buildStep) async {
27
27
logOutputMessage (
28
- log: log,
29
- communication: OutputMessage (
30
- message: [
28
+ log: log,
29
+ communication: OutputMessage (
30
+ message: [
31
31
'' ,
32
32
' - :::::::::::::::::::::::::::::::::::::::::::' ,
33
33
' - :: Openapi generator for dart ::' ,
34
34
' - :::::::::::::::::::::::::::::::::::::::::::' ,
35
- ].join ('\n ' )));
35
+ ].join ('\n ' ),
36
+ ),
37
+ );
36
38
37
39
try {
38
40
if (element is ! ClassElement ) {
@@ -85,35 +87,37 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
85
87
return generatorV2 (args: args, baseCommand: baseCommand);
86
88
}
87
89
88
- await runOpenApiJar (arguments: args.jarArgs);
89
- await generateSources (baseCommand: baseCommand, args: args);
90
+ await runOpenApiJar (arguments: args);
90
91
await fetchDependencies (baseCommand: baseCommand, args: args);
92
+ await generateSources (baseCommand: baseCommand, args: args);
91
93
} catch (e, st) {
92
94
late OutputMessage communication;
93
95
if (e is ! OutputMessage ) {
94
96
communication = OutputMessage (
95
- message: '- :: There was an error generating the spec. ::' ,
96
- level: Level .SEVERE ,
97
- additionalContext: e,
98
- stackTrace: st);
97
+ message: '- :: There was an error generating the spec. ::' ,
98
+ level: Level .SEVERE ,
99
+ additionalContext: e,
100
+ stackTrace: st,
101
+ );
99
102
} else {
100
103
communication = e;
101
104
}
102
105
103
106
logOutputMessage (log: log, communication: communication);
104
107
} finally {
105
108
logOutputMessage (
106
- log: log,
107
- communication: OutputMessage (
108
- message: ' - :::::::::::::::::::::::::::::::::::::::::::' ));
109
+ log: log,
110
+ communication: OutputMessage (
111
+ message: ' - :::::::::::::::::::::::::::::::::::::::::::' ,
112
+ ),
113
+ );
109
114
}
110
115
return '' ;
111
116
}
112
117
113
118
/// Runs the OpenAPI compiler with the given [args] .
114
- Future <void > runOpenApiJar (
115
- {required FutureOr <List <String >> arguments}) async {
116
- final args = await arguments;
119
+ Future <void > runOpenApiJar ({required GeneratorArguments arguments}) async {
120
+ final args = await arguments.jarArgs;
117
121
logOutputMessage (
118
122
log: log,
119
123
communication: OutputMessage (
@@ -128,17 +132,22 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
128
132
// Include java environment variables in openApiCliCommand
129
133
var javaOpts = Platform .environment['JAVA_OPTS' ] ?? '' ;
130
134
131
- final result = await Process .run (
132
- 'java' ,
133
- [
134
- if (javaOpts.isNotEmpty) javaOpts,
135
- '-jar' ,
136
- binPath,
137
- ...args,
138
- ],
139
- workingDirectory: Directory .current.path,
140
- runInShell: Platform .isWindows,
141
- );
135
+ ProcessResult result;
136
+ if (! testMode) {
137
+ result = await Process .run (
138
+ 'java' ,
139
+ [
140
+ if (javaOpts.isNotEmpty) javaOpts,
141
+ '-jar' ,
142
+ binPath,
143
+ ...args,
144
+ ],
145
+ workingDirectory: Directory .current.path,
146
+ runInShell: Platform .isWindows,
147
+ );
148
+ } else {
149
+ result = ProcessResult (999999 , 0 , null , null );
150
+ }
142
151
143
152
if (result.exitCode != 0 ) {
144
153
return Future .error (
@@ -154,7 +163,7 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
154
163
log: log,
155
164
communication: OutputMessage (
156
165
message: [
157
- // result.stdout,
166
+ if (arguments.isDebug) result.stdout,
158
167
' - :: Codegen completed successfully. ::' ,
159
168
].join ('\n ' ),
160
169
),
@@ -172,35 +181,42 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
172
181
{required GeneratorArguments args, required String baseCommand}) async {
173
182
if (args.isRemote) {
174
183
logOutputMessage (
175
- log: log,
176
- communication: OutputMessage (
177
- message:
178
- ' - :: Using a remote specification, a cache will still be create but may be outdated. ::' ,
179
- level: Level .WARNING ));
184
+ log: log,
185
+ communication: OutputMessage (
186
+ message:
187
+ ' - :: Using a remote specification, a cache will still be create but may be outdated. ::' ,
188
+ level: Level .WARNING ,
189
+ ),
190
+ );
180
191
}
181
192
try {
182
193
if (await hasDiff (
183
194
cachedPath: args.cachePath,
184
195
loadPath: await args.inputFileOrFetch,
185
196
)) {
186
197
logOutputMessage (
187
- log: log,
188
- communication: OutputMessage (
189
- message: ' - :: Dirty Spec found. Running generation. ::' ));
190
- await runOpenApiJar (arguments: args.jarArgs);
191
- await generateSources (baseCommand: baseCommand, args: args);
198
+ log: log,
199
+ communication: OutputMessage (
200
+ message: ' - :: Dirty Spec found. Running generation. ::' ,
201
+ ),
202
+ );
203
+ await runOpenApiJar (arguments: args);
192
204
await fetchDependencies (baseCommand: baseCommand, args: args);
205
+ await generateSources (baseCommand: baseCommand, args: args);
193
206
if (! args.hasLocalCache) {
194
207
logOutputMessage (
195
- log: log,
196
- communication: OutputMessage (
197
- message: ' - :: No local cache found. Creating one. ::' ));
208
+ log: log,
209
+ communication: OutputMessage (
210
+ message: ' - :: No local cache found. Creating one. ::' ,
211
+ ),
212
+ );
198
213
} else {
199
214
logOutputMessage (
200
- log: log,
201
- communication: OutputMessage (
202
- message:
203
- ' - :: Local cache found. Overwriting existing one. ::' ));
215
+ log: log,
216
+ communication: OutputMessage (
217
+ message: ' - :: Local cache found. Overwriting existing one. ::' ,
218
+ ),
219
+ );
204
220
}
205
221
await cacheSpec (
206
222
outputLocation: args.cachePath,
@@ -253,21 +269,25 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
253
269
logOutputMessage (
254
270
log: log,
255
271
communication: OutputMessage (
256
- message: ' - :: Skipping source gen step due to flag being set. ::' ,
257
- level: Level .WARNING ),
272
+ message: ' - :: Skipping source gen step due to flag being set. ::' ,
273
+ level: Level .WARNING ,
274
+ ),
258
275
);
259
276
} else if (! args.shouldGenerateSources) {
260
277
logOutputMessage (
261
- log: log,
262
- communication: OutputMessage (
263
- message:
264
- ' - :: Skipping source gen because generator does not need it. ::' ));
278
+ log: log,
279
+ communication: OutputMessage (
280
+ message:
281
+ ' - :: Skipping source gen because generator does not need it. ::' ,
282
+ ),
283
+ );
265
284
} else {
266
- return runSourceGen (baseCommand: baseCommand, args: args).then (
285
+ return await runSourceGen (baseCommand: baseCommand, args: args).then (
267
286
(_) => logOutputMessage (
268
287
log: log,
269
288
communication: OutputMessage (
270
- message: ' - :: Sources generated successfully. ::' ),
289
+ message: ' - :: Sources generated successfully. ::' ,
290
+ ),
271
291
),
272
292
onError: (e, st) => Future .error (
273
293
OutputMessage (
@@ -285,9 +305,11 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
285
305
Future <void > runSourceGen (
286
306
{required String baseCommand, required GeneratorArguments args}) async {
287
307
logOutputMessage (
288
- log: log,
289
- communication:
290
- OutputMessage (message: ' - :: Running source code generation. ::' ));
308
+ log: log,
309
+ communication: OutputMessage (
310
+ message: ' - :: Running source code generation. ::' ,
311
+ ),
312
+ );
291
313
final command = Command (
292
314
executable: baseCommand,
293
315
arguments: 'pub run build_runner build --delete-conflicting-outputs'
@@ -303,12 +325,17 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
303
325
),
304
326
);
305
327
306
- final results = await Process .run (
307
- command.executable,
308
- command.arguments,
309
- runInShell: Platform .isWindows,
310
- workingDirectory: args.outputDirectory,
311
- );
328
+ ProcessResult results;
329
+ if (! testMode) {
330
+ results = await Process .run (
331
+ command.executable,
332
+ command.arguments,
333
+ runInShell: Platform .isWindows,
334
+ workingDirectory: args.outputDirectory,
335
+ );
336
+ } else {
337
+ results = ProcessResult (99999 , 0 , null , null );
338
+ }
312
339
313
340
if (results.exitCode != 0 ) {
314
341
return Future .error (
@@ -335,10 +362,12 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
335
362
{required String baseCommand, required GeneratorArguments args}) async {
336
363
if (! args.shouldFetchDependencies) {
337
364
logOutputMessage (
338
- log: log,
339
- communication: OutputMessage (
340
- message: ' - :: Skipping install step because flag was set. ::' ,
341
- level: Level .WARNING ));
365
+ log: log,
366
+ communication: OutputMessage (
367
+ message: ' - :: Skipping install step because flag was set. ::' ,
368
+ level: Level .WARNING ,
369
+ ),
370
+ );
342
371
} else {
343
372
final command = Command (
344
373
executable: baseCommand,
@@ -354,15 +383,24 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
354
383
),
355
384
);
356
385
357
- final result = await Process .run (command.executable, command.arguments,
386
+ ProcessResult results;
387
+ if (! testMode) {
388
+ results = await Process .run (
389
+ command.executable,
390
+ command.arguments,
358
391
runInShell: Platform .isWindows,
359
- workingDirectory: args.outputDirectory);
360
- if (result.exitCode != 0 ) {
392
+ workingDirectory: args.outputDirectory,
393
+ );
394
+ } else {
395
+ results = ProcessResult (999999 , 0 , null , null );
396
+ }
397
+
398
+ if (results.exitCode != 0 ) {
361
399
return Future .error (
362
400
OutputMessage (
363
401
message: ' - :: Install within generated sources failed. ::' ,
364
402
level: Level .SEVERE ,
365
- additionalContext: result .stderr,
403
+ additionalContext: results .stderr,
366
404
stackTrace: StackTrace .current,
367
405
),
368
406
);
@@ -371,7 +409,7 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
371
409
log: log,
372
410
communication: OutputMessage (
373
411
message: [
374
- result .stdout,
412
+ if (args.isDebug) results .stdout,
375
413
' - :: Install completed successfully. ::' ,
376
414
].join ('\n ' ),
377
415
),
0 commit comments