Skip to content

Commit b4fdd4e

Browse files
authored
Merge pull request github#15808 from tamasvajk/buildless/package-source-telemetry
C#: Add package source error count to DB
2 parents edd383a + 2b99b83 commit b4fdd4e

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyManager.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ private void AnalyseProject(FileInfo project)
814814
private IEnumerable<string> RestoreSolutions(IEnumerable<string> solutions, out IEnumerable<string> assets)
815815
{
816816
var successCount = 0;
817+
var nugetSourceFailures = 0;
817818
var assetFiles = new List<string>();
818819
var projects = solutions.SelectMany(solution =>
819820
{
@@ -823,11 +824,16 @@ private IEnumerable<string> RestoreSolutions(IEnumerable<string> solutions, out
823824
{
824825
successCount++;
825826
}
827+
if (res.HasNugetPackageSourceError)
828+
{
829+
nugetSourceFailures++;
830+
}
826831
assetFiles.AddRange(res.AssetsFilePaths);
827832
return res.RestoredProjects;
828833
}).ToList();
829834
assets = assetFiles;
830835
CompilationInfos.Add(("Successfully restored solution files", successCount.ToString()));
836+
CompilationInfos.Add(("Failed solution restore with package source error", nugetSourceFailures.ToString()));
831837
CompilationInfos.Add(("Restored projects through solution files", projects.Count.ToString()));
832838
return projects;
833839
}
@@ -841,6 +847,7 @@ private IEnumerable<string> RestoreSolutions(IEnumerable<string> solutions, out
841847
private void RestoreProjects(IEnumerable<string> projects, out IEnumerable<string> assets)
842848
{
843849
var successCount = 0;
850+
var nugetSourceFailures = 0;
844851
var assetFiles = new List<string>();
845852
var sync = new object();
846853
Parallel.ForEach(projects, new ParallelOptions { MaxDegreeOfParallelism = threads }, project =>
@@ -853,11 +860,16 @@ private void RestoreProjects(IEnumerable<string> projects, out IEnumerable<strin
853860
{
854861
successCount++;
855862
}
863+
if (res.HasNugetPackageSourceError)
864+
{
865+
nugetSourceFailures++;
866+
}
856867
assetFiles.AddRange(res.AssetsFilePaths);
857868
}
858869
});
859870
assets = assetFiles;
860871
CompilationInfos.Add(("Successfully restored project files", successCount.ToString()));
872+
CompilationInfos.Add(("Failed project restore with package source error", nugetSourceFailures.ToString()));
861873
}
862874

863875
[GeneratedRegex(@"^(.+)\.(\d+\.\d+\.\d+(-(.+))?)$", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Singleline)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
| Failed project restore with package source error | 1.0 |
2+
| Failed solution restore with package source error | 0.0 |
3+
| Fallback nuget restore | 1.0 |
4+
| Project files on filesystem | 1.0 |
5+
| Resolved assembly conflicts | 7.0 |
6+
| Restored .NET framework variants | 0.0 |
7+
| Restored projects through solution files | 0.0 |
8+
| Solution files on filesystem | 1.0 |
9+
| Source files generated | 0.0 |
10+
| Source files on filesystem | 1.0 |
11+
| Successfully ran fallback nuget restore | 1.0 |
12+
| Successfully restored project files | 0.0 |
13+
| Successfully restored solution files | 1.0 |
14+
| Unresolved references | 0.0 |
15+
| UseWPF set | 0.0 |
16+
| UseWindowsForms set | 0.0 |
17+
| WebView extraction enabled | 1.0 |
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import csharp
2+
import semmle.code.csharp.commons.Diagnostics
3+
4+
query predicate compilationInfo(string key, float value) {
5+
key != "Resolved references" and
6+
exists(Compilation c, string infoKey, string infoValue | infoValue = c.getInfo(infoKey) |
7+
key = infoKey and
8+
value = infoValue.toFloat()
9+
or
10+
not exists(infoValue.toFloat()) and
11+
key = infoKey + ": " + infoValue and
12+
value = 1
13+
)
14+
}

0 commit comments

Comments
 (0)