This repository was archived by the owner on Feb 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathMergeAllProjectJsonsTask.cs
More file actions
104 lines (85 loc) · 4.44 KB
/
MergeAllProjectJsonsTask.cs
File metadata and controls
104 lines (85 loc) · 4.44 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Newtonsoft.Json;
using System.IO;
using System.Diagnostics;
using System.Windows;
using Newtonsoft.Json.Linq;
namespace stress.codegen
{
// This merge class walks all of the directory tree of InPath and produces a merged project json file. Then we
// 'trim it down' to the type of run we'd like to support, and write that final project.json to disk at OutPath.
public class MergeAllProjectJsonsTask : Task
{
// assumptions:
// we assume that anyos test project.jsons (AND ONLY THESE; any other ones will mess up the merge) are
// present in the directory or subdirectories of InPath
[Required]
public string InPath { get; set; }
// the path to the project.json we are spawning.
[Required]
public string OutPath { get; set; }
// not currently being used, but they exist to allow tests to be 'upgraded' in place.
public string OldPrerelease { get; set; }
public string NewPrerelease { get; set; }
// set this to true when you want to debug. It causes a message box to show with the process id of the executing
// msbuild instance that you can attach your debugger to. The execution of code will sit until you click ok.
public bool Debug { get; set; }
// this method walks the directory tree of inPath and uses the Newtonsoft JObject::Merge to merge together
// our project jsons.
// we require there to be at least ONE project.json present somewhere in the directory tree of inPath
//private JObject MergeProjectJsonsIn(string inPath, string targetFramework)
//{
// //var projectJsons = Directory.EnumerateFiles(InPath, "project.json", SearchOption.AllDirectories).Select(p => JObject.Parse(File.ReadAllText(p)));
// JObject merged = new JObject(projectJsons.First());
// foreach (var file in projectJsons)
// {
// // if (file["frameworks"].Contains(targetFramework))
// // {
// merged.Merge(file);
// //}
// }
// return merged;
//}
// this method:
// strips out test-runtime object if it is present in the dependencies list.
// removes all frameworks except for the one that is to be targeted for the run
private void ProduceAnyOsProjectJson(string outPath, JObject merged, string targetFramework)
{
// Filter out unwanted JObjects.
(merged["dependencies"] as JObject)?.Property("test-runtime")?.Remove();
(merged["dependencies"] as JObject)?.Property("perf")?.Remove();
// remove all supports.
merged["supports"]?.Children<JProperty>().ToList().ForEach(x => x.Remove());
//// remove all frameworks except the specified one
merged["frameworks"]?.Children<JProperty>().ToList().ForEach(x => x.Remove());
merged["frameworks"][targetFramework] = new JObject();
// since we are creating an anyos test launcher we should list all known runtimes here.
merged["runtimes"] = new JObject();
merged["runtimes"]["win10-x64"] = new JObject();
merged["runtimes"]["win7-x64"] = new JObject();
merged["runtimes"]["win7-x86"] = new JObject();
merged["runtimes"]["ubuntu.14.04-x64"] = new JObject();
merged["runtimes"]["osx.10.10-x64"] = new JObject();
merged["runtimes"]["centos.7-x64"] = new JObject();
merged["runtimes"]["rhel.7-x64"] = new JObject();
merged["runtimes"]["debian.8-x64"] = new JObject();
// serialize, then write the project json file to OutPath
File.WriteAllText(OutPath, JsonConvert.SerializeObject(merged));
}
public override bool Execute()
{
if (Debug)
{
MessageBox.Show($"PID:{Process.GetCurrentProcess().Id} Attach debugger now.", "Debug GenerateStressSuiteTask", MessageBoxButton.OK);
}
var x = Directory.EnumerateFiles(InPath, "project.json", SearchOption.AllDirectories).First();
ProduceAnyOsProjectJson(OutPath, JObject.Parse(File.ReadAllText(x)), "netstandard1.7");
return true;
}
}
}