forked from gabornemeth/StravaSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettingsUtils.cake
177 lines (153 loc) · 5.23 KB
/
settingsUtils.cake
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#addin nuget:?package=Cake.Json&version=1.0.2.13
public class SettingsUtils
{
public static Settings LoadSettings(ICakeContext context, string settingsFile)
{
context.Information("Loading Settings: {0}", settingsFile);
if (!context.FileExists(settingsFile))
{
context.Error("Settings File Does Not Exist");
return null;
}
var settings = context.DeserializeJsonFromFile<Settings>(settingsFile);
var envFeedUrl = context.EnvironmentVariable("NUGET_FEED_URL");
if (!string.IsNullOrEmpty(envFeedUrl))
settings.NuGet.FeedUrl = envFeedUrl;
var envFeedApiKey = context.EnvironmentVariable("NUGET_FEED_APIKEY");
if (!string.IsNullOrEmpty(envFeedApiKey))
settings.NuGet.FeedApiKey = envFeedApiKey;
return settings;
}
}
public class Settings
{
public VersionSettings Version {get;set;}
public BuildSettings Build {get;set;}
public NuGetSettings NuGet {get;set;}
public void Display(ICakeContext context)
{
context.Information("Settings:");
Version.Display(context);
Build.Display(context);
NuGet.Display(context);
}
}
public class VersionSettings
{
public VersionSettings()
{
LoadFrom = "VersionFile";
}
public string VersionFile {get;set;}
public string AssemblyInfoFile {get;set;}
public bool LoadFromGit {get;set;}
public string LoadFrom {get;set;}
public bool AutoIncrementVersion {get;set;}
public string NamespaceBase {get;set;}
public void Display(ICakeContext context)
{
context.Information("Version Settings:");
context.Information("\tVersion File: {0}", VersionFile);
context.Information("\tAssemblyInfo File: {0}", AssemblyInfoFile);
context.Information("\tLoad From: {0}", LoadFrom);
context.Information("\tAutoIncrement Version: {0}", AutoIncrementVersion);
context.Information("\tNamespace Base: {0}", NamespaceBase);
}
}
public class BuildSettings
{
public BuildSettings()
{
SourcePath = "./src";
SolutionFileSpec = "*.sln";
TreatWarningsAsErrors = false;
NugetConfigPath = "./.nuget/NuGet.Config";
}
public string SourcePath {get;set;}
public string SolutionFileSpec {get;set;}
public bool TreatWarningsAsErrors {get;set;}
public string NugetConfigPath {get;set;}
public string SolutionFilePath {
get
{
if (SolutionFileSpec.Contains("/"))
return SolutionFileSpec;
return string.Format("{0}{1}{2}", SourcePath, SolutionFileSpec.Contains("*") ? "/**/" : "", SolutionFileSpec);
}
}
public IEnumerable<FilePath> GetProjectFiles(ICakeContext context)
{
foreach (var solutionFile in context.GetFiles(SolutionFilePath))
{
foreach (var csprojFile in context.GetFiles(solutionFile.GetDirectory() + "/**/*.csproj"))
{
yield return csprojFile;
}
}
}
public void Display(ICakeContext context)
{
context.Information("Build Settings:");
context.Information("\tSource Path: {0}", SourcePath);
context.Information("\tSolution File Spec: {0}", SolutionFileSpec);
context.Information("\tSolution File Path: {0}", SolutionFilePath);
context.Information("\tTreat Warnings As Errors: {0}", TreatWarningsAsErrors);
context.Information("\tNuget Config Path: {0}", NugetConfigPath);
}
}
public class NuGetSettings
{
public NuGetSettings()
{
NuSpecPath = "./nuspec";
NuGetConfig = "./.nuget/NuGet.Config";
ArtifactsPath = "artifacts/packages";
UpdateVersion = false;
VersionDependencyForLibrary = VersionDependencyTypes.none;
}
public string NuGetConfig {get;set;}
public string FeedUrl {get;set;}
public string FeedApiKey {get;set;}
public string NuSpecPath {get;set;}
public string ArtifactsPath {get;set;}
public bool UpdateVersion {get;set;}
public VersionDependencyTypes VersionDependencyForLibrary {get;set;}
public string NuSpecFileSpec {
get {
return string.Format("{0}/*.nuspec", NuSpecPath);
}
}
public string NuGetPackagesSpec {
get {
return string.Format("{0}/*.nupkg", ArtifactsPath);
}
}
public void Display(ICakeContext context)
{
context.Information("NuGet Settings:");
context.Information("\tNuGet Config: {0}", NuGetConfig);
context.Information("\tFeed Url: {0}", FeedUrl);
//context.Information("\tFeed API Key: {0}", FeedApiKey);
context.Information("\tNuSpec Path: {0}", NuSpecPath);
context.Information("\tNuSpec File Spec: {0}", NuSpecFileSpec);
context.Information("\tArtifacts Path: {0}", ArtifactsPath);
context.Information("\tNuGet Packages Spec: {0}", NuGetPackagesSpec);
context.Information("\tUpdate Version: {0}", UpdateVersion);
context.Information("\tForce Version Match: {0}", VersionDependencyForLibrary);
}
}
public class VersionDependencyTypes
{
public string Value { get; set; }
public VersionDependencyTypes(string value)
{
Value = value;
}
public static implicit operator string(VersionDependencyTypes x) {return x.Value;}
public static implicit operator VersionDependencyTypes(String text) {return new VersionDependencyTypes(text);}
public static VersionDependencyTypes none = new VersionDependencyTypes("none");
public static VersionDependencyTypes exact = new VersionDependencyTypes("exact");
public static VersionDependencyTypes greaterthan = new VersionDependencyTypes("greaterthan");
public static VersionDependencyTypes greaterthanorequal = new VersionDependencyTypes("greaterthanorequal");
public static VersionDependencyTypes lessthan = new VersionDependencyTypes("lessthan");
}