-
-
Notifications
You must be signed in to change notification settings - Fork 200
/
Copy pathTarget.cs
130 lines (111 loc) · 3.88 KB
/
Target.cs
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
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Build.Framework;
namespace Microsoft.Build.Logging.StructuredLogger
{
public class Target : TimedNode, IHasSourceFile, IHasRelevance
{
public bool Succeeded { get; internal set; }
public string DependsOnTargets { get; set; }
public Project Project => GetNearestParent<Project>();
public string SourceFilePath { get; set; }
public string ParentTarget { get; set; }
public TargetBuiltReason TargetBuiltReason { get; set; }
public TimedNode OriginalNode { get; set; }
public override string TypeName => nameof(Target);
public string ParentTargetTooltip
{
get
{
if (string.IsNullOrEmpty(ParentTarget))
{
return string.Empty;
}
if (OriginalNode != null)
{
return "Navigate to where the target was built originally";
}
if (TargetBuiltReason == TargetBuiltReason.None)
{
return $"{Name} was built because of {ParentTarget}";
}
var cause = TargetBuiltReason switch
{
TargetBuiltReason.AfterTargets => $"Target '{Name}' had AfterTargets='{ParentTarget}' directly or indirectly",
TargetBuiltReason.BeforeTargets => $"Target '{Name}' had BeforeTargets='{ParentTarget}'",
TargetBuiltReason.DependsOn => $"Target '{ParentTarget}' had DependsOnTargets='{Name}'",
_ => ""
};
return cause;
}
}
public string ParentTargetText
{
get
{
if (string.IsNullOrEmpty(ParentTarget))
{
return string.Empty;
}
if (OriginalNode != null)
{
return ParentTarget;
}
var connectingSymbol = TargetBuiltReason switch
{
TargetBuiltReason.AfterTargets => "↑",
TargetBuiltReason.BeforeTargets => "↓",
TargetBuiltReason.DependsOn => "→",
_ => "→",
};
return $" {connectingSymbol} " + ParentTarget;
}
}
public Target()
{
Id = -1;
}
public void TryAddTarget(Target target)
{
if (target.Parent == null)
{
AddChild(target);
}
}
private Dictionary<int, Task> tasksById;
public Task GetTaskById(int taskId)
{
if (tasksById == null)
{
tasksById = new Dictionary<int, Task>();
}
if (!tasksById.TryGetValue(taskId, out var task))
{
var children = Children;
for (int i = 0; i < children.Count; i++)
{
if (children[i] is Task t && t.Id == taskId)
{
task = t;
break;
}
}
if (task != null)
{
tasksById[taskId] = task;
}
}
return task;
}
public override string ToString()
{
return $"Target Name={Name} Project={Path.GetFileName(Project?.ProjectFile)}";
}
public bool IsLowRelevance
{
get => HasFlag(NodeFlags.LowRelevance) && !IsSelected;
set => SetFlag(NodeFlags.LowRelevance, value);
}
}
}