-
Notifications
You must be signed in to change notification settings - Fork 692
/
WarningProperties.cs
141 lines (120 loc) · 5.71 KB
/
WarningProperties.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
131
132
133
134
135
136
137
138
139
140
141
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using NuGet.Common;
using NuGet.Shared;
namespace NuGet.ProjectModel
{
/// <summary>
/// Class to hold warning properties given by project system.
/// </summary>
public class WarningProperties : IEquatable<WarningProperties>
{
/// <summary>
/// List of Warning Codes that should be treated as Errors.
/// </summary>
public ISet<NuGetLogCode> WarningsAsErrors { get; }
/// <summary>
/// List of Warning Codes that should be ignored.
/// </summary>
public ISet<NuGetLogCode> NoWarn { get; }
/// <summary>
/// Indicates if all warnings should be ignored.
/// </summary>
public bool AllWarningsAsErrors { get; set; }
/// <summary>
/// List of Warning Codes that should not be treated as Errors.
/// </summary>
public ISet<NuGetLogCode> WarningsNotAsErrors { get; }
public WarningProperties()
{
WarningsAsErrors = new HashSet<NuGetLogCode>();
NoWarn = new HashSet<NuGetLogCode>();
AllWarningsAsErrors = false;
WarningsNotAsErrors = new HashSet<NuGetLogCode>();
}
[Obsolete("Use the constructor with 4 instead.")]
public WarningProperties(ISet<NuGetLogCode> warningsAsErrors, ISet<NuGetLogCode> noWarn, bool allWarningsAsErrors)
: this(warningsAsErrors, noWarn, allWarningsAsErrors, new HashSet<NuGetLogCode>())
{
}
public WarningProperties(ISet<NuGetLogCode> warningsAsErrors, ISet<NuGetLogCode> noWarn, bool allWarningsAsErrors, ISet<NuGetLogCode> warningsNotAsErrors)
{
WarningsAsErrors = warningsAsErrors ?? throw new ArgumentNullException(nameof(warningsAsErrors));
NoWarn = noWarn ?? throw new ArgumentNullException(nameof(noWarn));
AllWarningsAsErrors = allWarningsAsErrors;
WarningsNotAsErrors = warningsNotAsErrors ?? throw new ArgumentNullException(nameof(warningsNotAsErrors));
}
public override int GetHashCode()
{
var hashCode = new HashCodeCombiner();
hashCode.AddObject(AllWarningsAsErrors);
hashCode.AddUnorderedSequence(WarningsAsErrors);
hashCode.AddUnorderedSequence(NoWarn);
hashCode.AddUnorderedSequence(WarningsNotAsErrors);
return hashCode.CombinedHash;
}
public override bool Equals(object obj)
{
return Equals(obj as WarningProperties);
}
public bool Equals(WarningProperties other)
{
if (other == null)
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return AllWarningsAsErrors == other.AllWarningsAsErrors &&
EqualityUtility.SetEqualsWithNullCheck(WarningsAsErrors, other.WarningsAsErrors) &&
EqualityUtility.SetEqualsWithNullCheck(NoWarn, other.NoWarn) &&
EqualityUtility.SetEqualsWithNullCheck(WarningsNotAsErrors, other.WarningsNotAsErrors);
}
public WarningProperties Clone()
{
return new WarningProperties(warningsAsErrors: new HashSet<NuGetLogCode>(WarningsAsErrors), noWarn: new HashSet<NuGetLogCode>(NoWarn), allWarningsAsErrors: AllWarningsAsErrors, warningsNotAsErrors: WarningsNotAsErrors);
}
/// <summary>
/// Create warning properties from the msbuild property strings.
/// </summary>
public static WarningProperties GetWarningProperties(string treatWarningsAsErrors, string warningsAsErrors, string noWarn, string warningsNotAsErrors)
{
return GetWarningProperties(treatWarningsAsErrors, MSBuildStringUtility.GetNuGetLogCodes(warningsAsErrors), MSBuildStringUtility.GetNuGetLogCodes(noWarn), MSBuildStringUtility.GetNuGetLogCodes(warningsNotAsErrors));
}
/// <summary>
/// Create warning properties from the msbuild property strings.
/// </summary>
[Obsolete]
public static WarningProperties GetWarningProperties(string treatWarningsAsErrors, string warningsAsErrors, string noWarn)
{
return GetWarningProperties(treatWarningsAsErrors, MSBuildStringUtility.GetNuGetLogCodes(warningsAsErrors), MSBuildStringUtility.GetNuGetLogCodes(noWarn));
}
/// <summary>
/// Create warning properties from NuGetLogCode collection.
/// </summary>
public static WarningProperties GetWarningProperties(string treatWarningsAsErrors, ImmutableArray<NuGetLogCode> warningsAsErrors, ImmutableArray<NuGetLogCode> noWarn, ImmutableArray<NuGetLogCode> warningsNotAsErrors)
{
var props = new WarningProperties()
{
AllWarningsAsErrors = MSBuildStringUtility.IsTrue(treatWarningsAsErrors)
};
props.WarningsAsErrors.UnionWith(warningsAsErrors);
props.NoWarn.UnionWith(noWarn);
props.WarningsNotAsErrors.UnionWith(warningsNotAsErrors);
return props;
}
/// <summary>
/// Create warning properties from NuGetLogCode collection.
/// </summary>
[Obsolete]
public static WarningProperties GetWarningProperties(string treatWarningsAsErrors, ImmutableArray<NuGetLogCode> warningsAsErrors, ImmutableArray<NuGetLogCode> noWarn)
{
return GetWarningProperties(treatWarningsAsErrors, warningsAsErrors, noWarn, []);
}
}
}