Skip to content

Commit e84d7e0

Browse files
committed
Validate suppressions
1 parent 86db944 commit e84d7e0

File tree

71 files changed

+755
-187
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+755
-187
lines changed

src/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/CommonResources.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@
126126
<data name="NoBreakingChangesFound" xml:space="preserve">
127127
<value>APICompat ran successfully without finding any breaking changes.</value>
128128
</data>
129+
<data name="ObsoleteBaselineSuppressionsFound" xml:space="preserve">
130+
<value>Obsolete suppressions found that should be removed from suppression files:</value>
131+
</data>
129132
<data name="SuppressionsFileNotSpecified" xml:space="preserve">
130133
<value>A file path must be passed in to successfully generate a compatibility suppression file.</value>
131134
</data>
@@ -135,4 +138,4 @@
135138
<data name="WroteSuppressions" xml:space="preserve">
136139
<value>Successfully wrote compatibility suppressions to '{0}'.</value>
137140
</data>
138-
</root>
141+
</root>

src/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/SuppressionFileHelper.cs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System;
4+
using System.Collections.Generic;
55
using Microsoft.DotNet.ApiCompatibility.Logging;
66
using Microsoft.DotNet.ApiSymbolExtensions.Logging;
77

@@ -14,6 +14,7 @@ internal static class SuppressionFileHelper
1414
/// </summary>
1515
public static void GenerateSuppressionFile(ISuppressionEngine suppressionEngine,
1616
ISuppressableLog log,
17+
bool removeObsoleteSuppressions,
1718
string[]? suppressionFiles,
1819
string? suppressionOutputFile)
1920
{
@@ -25,14 +26,14 @@ public static void GenerateSuppressionFile(ISuppressionEngine suppressionEngine,
2526

2627
if (suppressionOutputFile == null)
2728
{
28-
throw new ArgumentException(CommonResources.SuppressionsFileNotSpecified, nameof(suppressionOutputFile));
29+
log.LogError(CommonResources.SuppressionsFileNotSpecified);
30+
return;
2931
}
3032

31-
if (suppressionEngine.WriteSuppressionsToFile(suppressionOutputFile))
33+
if (suppressionEngine.WriteSuppressionsToFile(suppressionOutputFile, removeObsoleteSuppressions))
3234
{
3335
log.LogMessage(MessageImportance.High,
34-
string.Format(CommonResources.WroteSuppressions,
35-
suppressionOutputFile));
36+
string.Format(CommonResources.WroteSuppressions, suppressionOutputFile));
3637
}
3738
}
3839

@@ -50,8 +51,25 @@ public static void LogApiCompatSuccessOrFailure(bool generateSuppressionFile, IS
5051
}
5152
else
5253
{
53-
log.LogMessage(MessageImportance.Normal,
54-
CommonResources.NoBreakingChangesFound);
54+
log.LogMessage(MessageImportance.Normal, CommonResources.NoBreakingChangesFound);
55+
}
56+
}
57+
58+
/// <summary>
59+
/// Validate whether obsolete baseline suppressions exist and log those.
60+
/// </summary>
61+
public static void ValidateSuppressions(ISuppressionEngine suppressionEngine, ISuppressableLog log)
62+
{
63+
IReadOnlyCollection<Suppression> obsoleteBaselineSuppressions = suppressionEngine.GetObsoleteSuppressions();
64+
if (obsoleteBaselineSuppressions.Count == 0)
65+
{
66+
return;
67+
}
68+
69+
log.LogError(Resources.ObsoleteSuppressionsFoundRegenerateSuppressionFileCommandHelp);
70+
foreach (Suppression obsoleteBaselineSuppression in obsoleteBaselineSuppressions)
71+
{
72+
log.LogMessage(MessageImportance.Normal, "- " + obsoleteBaselineSuppression.ToString());
5573
}
5674
}
5775
}

src/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/ValidateAssemblies.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ internal static class ValidateAssemblies
1515
{
1616
public static void Run(Func<ISuppressionEngine, ISuppressableLog> logFactory,
1717
bool generateSuppressionFile,
18+
bool removeObsoleteSuppressions,
19+
bool validateSuppressions,
1820
string[]? suppressionFiles,
1921
string? suppressionOutputFile,
2022
string? noWarn,
@@ -93,9 +95,14 @@ public static void Run(Func<ISuppressionEngine, ISuppressableLog> logFactory,
9395
{
9496
SuppressionFileHelper.GenerateSuppressionFile(serviceProvider.SuppressionEngine,
9597
serviceProvider.SuppressableLog,
98+
removeObsoleteSuppressions,
9699
suppressionFiles,
97100
suppressionOutputFile);
98101
}
102+
else if (validateSuppressions)
103+
{
104+
SuppressionFileHelper.ValidateSuppressions(serviceProvider.SuppressionEngine, serviceProvider.SuppressableLog);
105+
}
99106
}
100107

101108
private static string[]? GetAssemblyReferences(string[][]? assemblyReferences, int counter)

src/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/ValidatePackage.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ internal static class ValidatePackage
1414
{
1515
public static void Run(Func<ISuppressionEngine, ISuppressableLog> logFactory,
1616
bool generateSuppressionFile,
17+
bool removeObsoleteSuppressions,
18+
bool validateSuppressions,
1719
string[]? suppressionFiles,
1820
string? suppressionOutputFile,
1921
string? noWarn,
@@ -84,9 +86,14 @@ public static void Run(Func<ISuppressionEngine, ISuppressableLog> logFactory,
8486
{
8587
SuppressionFileHelper.GenerateSuppressionFile(serviceProvider.SuppressionEngine,
8688
serviceProvider.SuppressableLog,
89+
removeObsoleteSuppressions,
8790
suppressionFiles,
8891
suppressionOutputFile);
8992
}
93+
else if (validateSuppressions)
94+
{
95+
SuppressionFileHelper.ValidateSuppressions(serviceProvider.SuppressionEngine, serviceProvider.SuppressableLog);
96+
}
9097
}
9198
}
9299
}

src/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/xlf/CommonResources.cs.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
<target state="new">APICompat ran successfully without finding any breaking changes.</target>
1818
<note />
1919
</trans-unit>
20+
<trans-unit id="ObsoleteBaselineSuppressionsFound">
21+
<source>Obsolete suppressions found that should be removed from suppression files:</source>
22+
<target state="new">Obsolete suppressions found that should be removed from suppression files:</target>
23+
<note />
24+
</trans-unit>
2025
<trans-unit id="SuppressionsFileNotSpecified">
2126
<source>A file path must be passed in to successfully generate a compatibility suppression file.</source>
2227
<target state="translated">Aby bylo možné úspěšně vygenerovat soubor potlačení kompatibility, musí být předána cesta k souboru.</target>

src/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/xlf/CommonResources.de.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
<target state="new">APICompat ran successfully without finding any breaking changes.</target>
1818
<note />
1919
</trans-unit>
20+
<trans-unit id="ObsoleteBaselineSuppressionsFound">
21+
<source>Obsolete suppressions found that should be removed from suppression files:</source>
22+
<target state="new">Obsolete suppressions found that should be removed from suppression files:</target>
23+
<note />
24+
</trans-unit>
2025
<trans-unit id="SuppressionsFileNotSpecified">
2126
<source>A file path must be passed in to successfully generate a compatibility suppression file.</source>
2227
<target state="translated">Ein Dateipfad muss übergeben werden, um erfolgreich eine Kompatibilitätsunterdrückungsdatei zu generieren.</target>

src/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/xlf/CommonResources.es.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
<target state="new">APICompat ran successfully without finding any breaking changes.</target>
1818
<note />
1919
</trans-unit>
20+
<trans-unit id="ObsoleteBaselineSuppressionsFound">
21+
<source>Obsolete suppressions found that should be removed from suppression files:</source>
22+
<target state="new">Obsolete suppressions found that should be removed from suppression files:</target>
23+
<note />
24+
</trans-unit>
2025
<trans-unit id="SuppressionsFileNotSpecified">
2126
<source>A file path must be passed in to successfully generate a compatibility suppression file.</source>
2227
<target state="translated">Se debe pasar una ruta de acceso de archivo para generar correctamente un archivo de supresión de compatibilidad.</target>

src/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/xlf/CommonResources.fr.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
<target state="new">APICompat ran successfully without finding any breaking changes.</target>
1818
<note />
1919
</trans-unit>
20+
<trans-unit id="ObsoleteBaselineSuppressionsFound">
21+
<source>Obsolete suppressions found that should be removed from suppression files:</source>
22+
<target state="new">Obsolete suppressions found that should be removed from suppression files:</target>
23+
<note />
24+
</trans-unit>
2025
<trans-unit id="SuppressionsFileNotSpecified">
2126
<source>A file path must be passed in to successfully generate a compatibility suppression file.</source>
2227
<target state="translated">Un chemin de fichier doit être transmis pour générer avec succès un fichier de suppression de compatibilité.</target>

src/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/xlf/CommonResources.it.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
<target state="new">APICompat ran successfully without finding any breaking changes.</target>
1818
<note />
1919
</trans-unit>
20+
<trans-unit id="ObsoleteBaselineSuppressionsFound">
21+
<source>Obsolete suppressions found that should be removed from suppression files:</source>
22+
<target state="new">Obsolete suppressions found that should be removed from suppression files:</target>
23+
<note />
24+
</trans-unit>
2025
<trans-unit id="SuppressionsFileNotSpecified">
2126
<source>A file path must be passed in to successfully generate a compatibility suppression file.</source>
2227
<target state="translated">È necessario passare un percorso di file per generare un file di eliminazione della compatibilità.</target>

src/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/xlf/CommonResources.ja.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
<target state="new">APICompat ran successfully without finding any breaking changes.</target>
1818
<note />
1919
</trans-unit>
20+
<trans-unit id="ObsoleteBaselineSuppressionsFound">
21+
<source>Obsolete suppressions found that should be removed from suppression files:</source>
22+
<target state="new">Obsolete suppressions found that should be removed from suppression files:</target>
23+
<note />
24+
</trans-unit>
2025
<trans-unit id="SuppressionsFileNotSpecified">
2126
<source>A file path must be passed in to successfully generate a compatibility suppression file.</source>
2227
<target state="translated">互換性抑制ファイルを正常に生成するには、ファイル パスを渡す必要があります。</target>

0 commit comments

Comments
 (0)