forked from ChilliCream/graphql-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Helpers.cs
110 lines (94 loc) · 3.78 KB
/
Helpers.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
class Helpers
{
static readonly string[] Directories =
{
"GreenDonut",
Path.Combine("HotChocolate", "Analyzers"),
Path.Combine("HotChocolate", "ApolloFederation"),
Path.Combine("HotChocolate", "AspNetCore"),
Path.Combine("HotChocolate", "AzureFunctions"),
Path.Combine("HotChocolate", "Core"),
Path.Combine("HotChocolate", "CodeGeneration"),
Path.Combine("HotChocolate", "Diagnostics"),
Path.Combine("HotChocolate", "Language"),
Path.Combine("HotChocolate", "PersistedQueries"),
Path.Combine("HotChocolate", "Utilities"),
Path.Combine("HotChocolate", "Data"),
Path.Combine("HotChocolate", "Filters"),
Path.Combine("HotChocolate", "MongoDb"),
Path.Combine("HotChocolate", "Neo4J"),
Path.Combine("HotChocolate", "Stitching"),
Path.Combine("HotChocolate", "Spatial"),
Path.Combine("StrawberryShake", "Client"),
Path.Combine("StrawberryShake", "CodeGeneration"),
Path.Combine("StrawberryShake", "Tooling")
};
static IEnumerable<string> GetAllProjects(
string sourceDirectory,
IEnumerable<string> directories,
Func<string, bool> include = null)
{
foreach (var directory in directories)
{
var fullDirectory = Path.Combine(sourceDirectory, directory);
foreach (var file in Directory.EnumerateFiles(fullDirectory, "*.csproj", SearchOption.AllDirectories))
{
if (!(include?.Invoke(file) ?? true)
|| file.Contains("benchmark", StringComparison.OrdinalIgnoreCase)
|| file.Contains("demo", StringComparison.OrdinalIgnoreCase)
|| file.Contains("sample", StringComparison.OrdinalIgnoreCase))
{
continue;
}
yield return file;
}
}
}
public static IReadOnlyCollection<Output> DotNetBuildSonarSolution(
string solutionFile,
IEnumerable<string> directories = null,
Func<string, bool> include = null)
{
if (File.Exists(solutionFile))
{
return Array.Empty<Output>();
}
directories ??= Directories;
IEnumerable<string> projects = GetAllProjects(Path.GetDirectoryName(solutionFile), directories, include);
var workingDirectory = Path.GetDirectoryName(solutionFile);
var list = new List<Output>();
list.AddRange(DotNetTasks.DotNet($"new sln -n {Path.GetFileNameWithoutExtension(solutionFile)}", workingDirectory));
var projectsArg = string.Join(" ", projects.Select(t => $"\"{t}\""));
list.AddRange(DotNetTasks.DotNet($"sln \"{solutionFile}\" add {projectsArg}", workingDirectory));
return list;
}
public static IReadOnlyCollection<Output> DotNetBuildTestSolution(
string solutionFile,
IEnumerable<Project> projects)
{
if (File.Exists(solutionFile))
{
return Array.Empty<Output>();
}
var workingDirectory = Path.GetDirectoryName(solutionFile);
var list = new List<Output>();
list.AddRange(DotNetTasks.DotNet($"new sln -n {Path.GetFileNameWithoutExtension(solutionFile)}", workingDirectory));
var projectsArg = string.Join(" ", projects.Select(t => $"\"{t}\""));
list.AddRange(DotNetTasks.DotNet($"sln \"{solutionFile}\" add {projectsArg}", workingDirectory));
return list;
}
public static void TryDelete(string fileName)
{
if(File.Exists(fileName))
{
File.Delete(fileName);
}
}
}