forked from xamarin/AndroidX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.cake
580 lines (513 loc) · 19.9 KB
/
utilities.cake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
#tool nuget:?package=Cake.CoreCLR
/*
dotnet cake spell-check.cake
dotnet cake spell-check.cake -t=spell-check
*/
#addin nuget:?package=WeCantSpell.Hunspell&version=3.0.1
#addin nuget:?package=Newtonsoft.Json&version=12.0.3
#addin nuget:?package=Cake.FileHelpers&version=3.2.1
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
var TARGET = Argument ("t", Argument ("target", "Default"));
string file_spell_errors = "./output/spell-errors.txt";
List<string> spell_errors = null;
JArray binderator_json_array = null;
Task ("list-artifacts")
.Does
(
() =>
{
using (StreamReader reader = System.IO.File.OpenText(@"./config.json"))
{
JsonTextReader jtr = new JsonTextReader(reader);
binderator_json_array = (JArray)JToken.ReadFrom(jtr);
}
Information("config.json list supported artifacts...");
List<string> lines1 = new List<string>();
List<string> lines2 = new List<string>();
string space = " ";
string dash = "-";
int width1 = 70;
int width2 = 20;
lines1.Add($"# Artifacts supported");
lines2.Add($"# Artifacts with versions supported");
lines1.Add(Environment.NewLine);
lines1.Add(Environment.NewLine);
lines2.Add(Environment.NewLine);
lines2.Add(Environment.NewLine);
lines1.Add($@"|{space.PadRight(width1)}|{space.PadRight(width1)}|");
lines1.Add($@"|{dash.PadRight(width1, '-')}|{dash.PadRight(width1, '-')}|");
lines2.Add($@"|{space.PadRight(width1)}|{space.PadRight(width2)}|{space.PadRight(width1)}|{space.PadRight(width2)}|");
lines2.Add($@"|{dash.PadRight(width1, '-')}|{dash.PadRight(width2, '-')}|{dash.PadRight(width1, '-')}|{dash.PadRight(width2, '-')}|");
foreach(JObject jo in binderator_json_array[0]["artifacts"])
{
bool? dependency_only = (bool?) jo["dependencyOnly"];
if ( dependency_only == true)
{
continue;
}
string group_id = (string) jo["groupId"];
string artifact_id = (string) jo["artifactId"];
string artifact_v = (string) jo["version"];
string nuget_id = (string) jo["nugetId"];
string nuget_v = (string) jo["nugetVersion"];
string maven = $"{group_id}:{artifact_id}";
string nuget = $"{nuget_id}";
string line1 = $@"|{maven.PadRight(width1)}|{nuget.PadRight(width1)}|";
string line2 = $@"|{maven.PadRight(width1)}|{artifact_v.PadRight(width2)}|{nuget.PadRight(width1)}|{nuget_v.PadRight(width2)}|";
lines1.Add(line1);
lines2.Add(line2);
}
EnsureDirectoryExists("./output/");
System.IO.File.WriteAllLines($"./output/artifact-list.md", lines1.ToArray());
System.IO.File.WriteAllLines($"./output/artifact-list-with-versions.md", lines2.ToArray());
System.IO.File.WriteAllLines($"./output/artifact-list-{DateTime.Now.ToString("yyyyMMdd")}.md", lines1.ToArray());
System.IO.File.WriteAllLines($"./output/artifact-list-with-versions-{DateTime.Now.ToString("yyyyMMdd")}.md", lines2.ToArray());
}
);
Task ("spell-check")
.Does
(
() =>
{
if (FileExists(file_spell_errors))
{
DeleteFile(file_spell_errors);
}
EnsureDirectoryExists("./externals/");
string url = "https://raw.githubusercontent.com/titoBouzout/Dictionaries/master/";
string[] files_dictionaries = new[]
{
"English (American).dic",
"English (American).txt",
"English (American).aff",
};
foreach(string file_dictionary in files_dictionaries)
{
string url_full = url + System.Uri.EscapeDataString(file_dictionary);
Information($"Downloading ");
Information($" {url_full}");
if (!FileExists($"./externals/{file_dictionary}"))
{
DownloadFile(url_full, $"./externals/{file_dictionary}");
}
}
var dictionary = WeCantSpell.Hunspell.WordList.CreateFromFiles(@"externals/English (American).dic");
var words = new[]
{
"Xamarin",
"AndroidX",
"IdentifierCommon",
"IdentifierProvider",
"AppCompat",
"AppCompatResources",
"Runtime",
"AsyncLayoutInflater",
"AutoFill",
"Biometric",
"Camera2",
"Lifecycle",
"CardView",
"ConstraintLayout",
"CoordinatorLayout",
"ContentPager",
"CursorAdapter",
"CustomView",
"DataBinding",
"DataBindingAdapters",
"DataBindingCommon",
"DataBindingRuntime",
"ViewBinding",
"DocumentFile",
"DrawerLayout",
"DynamicAnimation",
"Emoji",
"ExifInterface",
"GridLayout",
"HeifWriter",
"Interpolator",
"Leanback",
"V14",
"UI",
"Utils",
"V13",
"V4",
"LiveData",
"ViewModel",
"ViewModelSavedState",
"LocalBroadcastManager",
"Media2",
"MediaRouter",
"MultiDex",
"Runtime",
"PercentLayout",
"RecyclerView",
"SavedState",
"SlidingPaneLayout",
"Sqlite",
"SwipeRefreshLayout",
"TvProvider",
"VectorDrawable",
"VersionedParcelable",
"ViewPager",
"ViewPager2",
"WebKit",
"WindowExtensions",
"SecurityCrypto",
"Java8",
"ReactiveStreams",
"Ktx",
"RxJava2",
"RxJava3",
"GoogleShortcuts",
"WindowJava",
"Startup",
"StartupRuntime",
"Kotlin",
"StdLib",
"Jdk7",
"Jdk8",
"Jetbrains",
"KotlinX",
"Coroutines",
"Jvm",
"GoogleGson",
"Rx2",
"AutoValue",
"ReactiveX",
"RxJava",
"Crypto",
"Tink",
"PhoneInteractions",
"RemoteInteractions",
};
var dictionary_custom = WeCantSpell.Hunspell.WordList.CreateFromWords(words);
using (StreamReader reader = System.IO.File.OpenText(@"./config.json"))
{
JsonTextReader jtr = new JsonTextReader(reader);
binderator_json_array = (JArray)JToken.ReadFrom(jtr);
}
spell_errors = new List<string>();
Information("config.json spell checking...");
foreach(JObject jo in binderator_json_array[0]["artifacts"])
{
bool? dependency_only = (bool?) jo["dependencyOnly"];
if ( dependency_only == true)
{
continue;
}
string nuget_id = (string) jo["nugetId"];
Information($" spell-check {nuget_id}");
string[] nuget_id_parts = nuget_id.Split('.');
foreach(string nuget_id_part in nuget_id_parts)
{
bool check_dictionary_custom = dictionary_custom.Check(nuget_id_part);
Information($" check_dictionary_custom {nuget_id_part} = {check_dictionary_custom}");
if (check_dictionary_custom)
{
Information($" Found in custom dictionary!");
continue;
}
bool check_dictionary = dictionary.Check(nuget_id_part);
Information($" check_dictionary {nuget_id_part} = {check_dictionary}");
if (check_dictionary)
{
Information($" Found in EN-US dictionary!");
continue;
}
Information($"Added {nuget_id_part} from {nuget_id}");
spell_errors.Add(nuget_id_part);
}
}
if (spell_errors.Count > 0)
{
System.IO.File.WriteAllLines(file_spell_errors, spell_errors);
}
}
);
Task ("namespace-check")
.Does
(
() =>
{
// Namespace Checks
FilePath[] files = new FilePath[]{};
FilePath[] files_androidx = GetFiles("./generated/**/Androidx.*.cs").ToArray();
FilePath[] files_com = GetFiles("./generated/**/Com.*.cs").ToArray();
FilePath[] files_org = GetFiles("./generated/**/Org.*.cs").ToArray();
FilePath[] files_io_1 = GetFiles("./generated/**/Io.*.cs").ToArray();
FilePath[] files_io_2 = GetFiles("./generated/**/IO.*.cs").ToArray();
FilePath[] files_kotlinx = GetFiles("./generated/**/Kotlinx*.cs").ToArray();
files = files.Concat(files_androidx.ToArray()).ToArray();
files = files.Concat(files_com.ToArray()).ToArray();
files = files.Concat(files_org.ToArray()).ToArray();
files = files.Concat(files_io_1.ToArray()).ToArray();
files = files.Concat(files_io_2.ToArray()).ToArray();
files = files.Concat(files_kotlinx.ToArray()).ToArray();
if (files.Any())
{
string[] namespaces = Array.ConvertAll(files, x => x.ToString());
System.IO.File.WriteAllLines("./output/namespaces.md", namespaces);
StringBuilder msg = new StringBuilder("Namespaces!!!");
msg.AppendLine();
msg.AppendLine(string.Join(System.Environment.NewLine, namespaces));
throw new Exception(msg.ToString());
}
return;
}
);
Task("binderate-diff")
.Does
(
() =>
{
EnsureDirectoryExists("./output/");
// "git diff -U999999 main:config.json config.json" > ./output/config.json.diff-from-main.txt"
string process = "git";
string process_args = "diff -U999999 main:config.json config.json";
IEnumerable<string> redirectedStandardOutput;
ProcessSettings process_settings = new ProcessSettings ()
{
Arguments = process_args,
RedirectStandardOutput = true
};
int exitCodeWithoutArguments = StartProcess(process, process_settings, out redirectedStandardOutput);
System.IO.File.WriteAllLines("./output/config.json.diff-from-main.txt", redirectedStandardOutput.ToArray());
Information("Exit code: {0}", exitCodeWithoutArguments);
}
);
Task ("api-diff-markdown-info-pr")
.IsDependentOn("binderate-diff")
.Does
(
() =>
{
// TODO: api-diff markdown info based on diff from main
string[] lines_from_file = System.IO.File.ReadAllLines("./output/config.json.diff-from-main.txt");
List<string> lines = new List<string>(lines_from_file);
List<string> changelog = new List<string>();
List<List<string>> changelog_blocks = new List<List<string>>();
List<string> changelog_block = null;
int idx_start = -1;
int idx_stop = -1;
for(int i = 0; i < lines.Count(); i++)
{
string line = lines[i];
if (line.Contains("groupId"))
{
idx_start = i;
}
if(line.Contains("dependencyOnly"))
{
if (line.StartsWith("-"))
{
continue;
}
idx_stop = i;
}
if (idx_start != -1 && idx_stop != -1)
{
changelog_block = lines.GetRange(idx_start, idx_stop - idx_start);
changelog_blocks.Add(changelog_block);
idx_start = -1;
idx_stop = -1;
}
}
foreach (List<string> changelog_block_lines in changelog_blocks)
{
string g = null;
string a = null;
string v_artifact_new = null;
string v_artifact_old = null;
string v_nuget_new = null;
string v_nuget_old = null;
string nuget_id = null;
foreach(string line in changelog_block_lines)
{
if (line.Contains("groupId"))
{
g = ParseDiffLine(line, "groupId");
continue;
}
if (line.Contains("artifactId"))
{
a = ParseDiffLine(line, "artifactId");
continue;
}
if (line.Contains("version"))
{
if (line.StartsWith("+"))
{
v_artifact_new = ParseDiffLine(line, "version");
continue;
}
v_artifact_old = ParseDiffLine(line, "version");
continue;
}
if (line.Contains("nugetVersion"))
{
v_nuget_old = ParseDiffLine(line, "nugetVersion");
continue;
}
if (line.Contains("nugetVersion"))
{
v_nuget_new = ParseDiffLine(line, "nugetVersion");
continue;
}
if (line.Contains("nugetId"))
{
nuget_id = ParseDiffLine(line, "nugetId");
continue;
}
}
if(v_artifact_new == null)
{
continue;
}
string changelog_line = $"- {g}:{a} - {v_artifact_old} -> {v_artifact_new}";
changelog.Add(changelog_line);
}
if (changelog.Count > 0)
{
System.IO.File.WriteAllLines("./output/changelog.md", changelog);
}
return;
}
);
string ParseDiffLine(string line, string name)
{
if (line[0] == '-')
{
StringBuilder sb = new StringBuilder(line);
sb[0] = ' ';
line = sb.ToString();
}
return new string
(
line
.ToCharArray()
.Where(c => !Char.IsWhiteSpace(c))
.ToArray()
)
.Replace("\"", "")
.Replace("+", "")
.Replace("-", "")
.Replace(":", "")
.Replace(name, "")
.Replace(",", "")
;
}
Task ("api-diff-analysis")
.Does
(
() =>
{
using (StreamReader reader = System.IO.File.OpenText(@"./config.json"))
{
JsonTextReader jtr = new JsonTextReader(reader);
binderator_json_array = (JArray)JToken.ReadFrom(jtr);
}
DirectoryPathCollection directories = GetSubDirectories("./output/api-diff");
Dictionary<string, string> nugets_modified = new Dictionary<string, string>();
foreach(DirectoryPath d in directories)
{
string d_name = d.GetDirectoryName();
Information( $"Directory = {d}");
Information( $" nugetId = {d.GetDirectoryName()}");
string groupId = null;
string artifactId = null;
string nugetId = null;
string nugetVersion = null;
// no guarantees thta config.json is sorted, so linear "search"
// TODO: sort + (LINQ or binary serch)
foreach(JObject jo in binderator_json_array[0]["artifacts"])
{
groupId = (string) jo["groupId"];
artifactId = (string) jo["artifactId"];
nugetId = (string) jo["nugetId"];
nugetVersion = (string) jo["nugetVersion"];
if (nugetId == d_name)
{
Information( $" groupId = {groupId}");
Information( $" artifactId = {artifactId}");
Information( $" artifactId fully qualified = {groupId}.{artifactId}");
nugets_modified.Add(d_name, $"{groupId}.{artifactId}");
}
}
}
string[] lines = nugets_modified.Select(kv => kv.Key + Environment.NewLine + "\t" + kv.Value).ToArray();
System.IO.File.WriteAllLines("./output/nugets-with-changed-APIs.md", lines);
return;
}
);
Task ("read-analysis-files")
.IsDependentOn ("binderate-diff")
.IsDependentOn ("api-diff-markdown-info-pr")
.IsDependentOn ("namespace-check")
.IsDependentOn ("spell-check")
.IsDependentOn ("api-diff-analysis")
.IsDependentOn ("list-artifacts")
.Does
(
() =>
{
List<string> files = new List<string>
{
"./output/spell-errors.txt",
"./output/changelog.md",
"./output/config.json.diff-from-main.txt",
"./output/missing_dotnet_override_type.csv",
"./output/missing_dotnet_type.csv",
"./output/missing_java_type.csv",
"./output/nugets-with-changed-APIs.md",
};
if ( ! FileExists("./output/spell-errors.txt") )
{
files.Remove("./output/spell-errors.txt");
}
string process = "code";
string process_args = $"-n {string.Join(" ", files)}";
IEnumerable<string> redirectedStandardOutput;
ProcessSettings process_settings = new ProcessSettings ()
{
Arguments = process_args,
RedirectStandardOutput = true
};
int exitCodeWithoutArguments = StartProcess(process, process_settings, out redirectedStandardOutput);
Information("Exit code: {0}", exitCodeWithoutArguments);
}
);
Task("dependencies")
.Does
(
() =>
{
if (!(binderator_json_array?.Count > 0))
{
using (StreamReader reader = System.IO.File.OpenText(@"./config.json"))
{
JsonTextReader jtr = new JsonTextReader(reader);
binderator_json_array = (JArray)JToken.ReadFrom(jtr);
}
}
Warning("config.json dependencies ...");
foreach(JObject jo in binderator_json_array[0]["artifacts"])
{
string groupId = (string) jo["groupId"];
string artifactId = (string) jo["artifactId"];
string nugetId = (string) jo["nugetId"];
string nugetVersion = (string) jo["nugetVersion"];
}
}
);
Task ("Default")
.IsDependentOn ("read-analysis-files")
;
if (System.IO.File.Exists(file_spell_errors))
{
string separator = System.Environment.NewLine + "\t" + "\t";
string msg = "Spell Errors:" + System.Environment.NewLine + "\t" + "\t"
+ string.Join(separator, System.IO.File.ReadAllLines(file_spell_errors));
throw new Exception(msg);
}
RunTarget (TARGET);