Skip to content

Commit 98eea90

Browse files
authored
chore: File-Scoped Namespace refactor, phase 14 (Build Tools) (#3434)
1 parent b465eef commit 98eea90

46 files changed

Lines changed: 4005 additions & 4063 deletions

Some content is hidden

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

build/ArtifactBuilder/AgentComponents.cs

Lines changed: 188 additions & 190 deletions
Large diffs are not rendered by default.

build/ArtifactBuilder/AgentInfo.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
using Newtonsoft.Json;
21
using System.IO;
2+
using Newtonsoft.Json;
3+
4+
namespace ArtifactBuilder;
35

4-
namespace ArtifactBuilder
6+
public class AgentInfo
57
{
6-
public class AgentInfo
7-
{
88

9-
public const string AgentInfoFilename = "agentinfo.json";
9+
public const string AgentInfoFilename = "agentinfo.json";
1010

11-
[JsonProperty(PropertyName = "install_type", NullValueHandling = NullValueHandling.Ignore)]
12-
public string InstallType { get; set; }
11+
[JsonProperty(PropertyName = "install_type", NullValueHandling = NullValueHandling.Ignore)]
12+
public string InstallType { get; set; }
1313

14-
[JsonProperty(PropertyName = "azure_site_extension", NullValueHandling = NullValueHandling.Ignore)]
15-
public bool AzureSiteExtension { get; set; }
14+
[JsonProperty(PropertyName = "azure_site_extension", NullValueHandling = NullValueHandling.Ignore)]
15+
public bool AzureSiteExtension { get; set; }
1616

17-
public void WriteToDisk(string filePath)
17+
public void WriteToDisk(string filePath)
18+
{
19+
using (var file = File.CreateText(Path.Join(filePath, AgentInfoFilename)))
1820
{
19-
using (var file = File.CreateText(Path.Join(filePath, AgentInfoFilename)))
20-
{
21-
var serializer = new JsonSerializer();
22-
serializer.Serialize(file, this);
23-
}
21+
var serializer = new JsonSerializer();
22+
serializer.Serialize(file, this);
2423
}
2524
}
2625
}

build/ArtifactBuilder/AgentType.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
namespace ArtifactBuilder
1+
namespace ArtifactBuilder;
2+
3+
public enum AgentType
24
{
3-
public enum AgentType
4-
{
5-
Framework,
6-
Core
7-
}
8-
}
5+
Framework,
6+
Core
7+
}
Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
11
using System;
22

3-
namespace ArtifactBuilder.Artifacts
3+
namespace ArtifactBuilder.Artifacts;
4+
5+
public abstract class Artifact
46
{
5-
public abstract class Artifact
7+
public Artifact(string name)
8+
{
9+
Name = name;
10+
11+
RepoRootDirectory = FileHelpers.GetRepoRootDirectory();
12+
StagingDirectory = $@"{RepoRootDirectory}\Build\_staging\{Name}";
13+
PackageDirectory = $@"{RepoRootDirectory}\Build\Packaging\{Name}";
14+
OutputDirectory = $@"{RepoRootDirectory}\Build\BuildArtifacts\{Name}";
15+
16+
HomeRootDirectory = FileHelpers.GetHomeRootDirectory();
17+
}
18+
19+
public string RepoRootDirectory { get; }
20+
public string HomeRootDirectory { get; }
21+
public string Name { get; }
22+
23+
protected string StagingDirectory;
24+
protected string PackageDirectory;
25+
protected string OutputDirectory;
26+
protected Action ValidateContentAction;
27+
28+
public void Build(bool clearOutput = true)
629
{
7-
public Artifact(string name)
8-
{
9-
Name = name;
10-
11-
RepoRootDirectory = FileHelpers.GetRepoRootDirectory();
12-
StagingDirectory = $@"{RepoRootDirectory}\Build\_staging\{Name}";
13-
PackageDirectory = $@"{RepoRootDirectory}\Build\Packaging\{Name}";
14-
OutputDirectory = $@"{RepoRootDirectory}\Build\BuildArtifacts\{Name}";
15-
16-
HomeRootDirectory = FileHelpers.GetHomeRootDirectory();
17-
}
18-
19-
public string RepoRootDirectory { get; }
20-
public string HomeRootDirectory { get; }
21-
public string Name { get; }
22-
23-
protected string StagingDirectory;
24-
protected string PackageDirectory;
25-
protected string OutputDirectory;
26-
protected Action ValidateContentAction;
27-
28-
public void Build(bool clearOutput = true)
29-
{
30-
FileHelpers.DeleteDirectories(StagingDirectory);
31-
if (clearOutput)
32-
FileHelpers.DeleteDirectories(OutputDirectory);
33-
34-
InternalBuild();
35-
ValidateContentAction?.Invoke();
36-
}
37-
38-
protected abstract void InternalBuild();
30+
FileHelpers.DeleteDirectories(StagingDirectory);
31+
if (clearOutput)
32+
FileHelpers.DeleteDirectories(OutputDirectory);
33+
34+
InternalBuild();
35+
ValidateContentAction?.Invoke();
3936
}
40-
}
37+
38+
protected abstract void InternalBuild();
39+
}
Lines changed: 87 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,113 @@
1-
using System.Collections.Generic;
21
using System;
2+
using System.Collections.Generic;
33
using System.IO;
44

5-
namespace ArtifactBuilder.Artifacts
5+
namespace ArtifactBuilder.Artifacts;
6+
7+
public class AzureSiteExtension : Artifact
68
{
7-
public class AzureSiteExtension : Artifact
9+
private const string XmlLibraryName = "Microsoft.Web.XmlTransform.dll";
10+
private const string NuGetLibraryName = "NuGet.Core.dll";
11+
private const string NuGetHelperLibraryName = "NewRelic.NuGetHelper.dll";
12+
13+
private string _version;
14+
private string _nuGetPackageName;
15+
16+
public AzureSiteExtension() : base(nameof(AzureSiteExtension))
17+
{
18+
ValidateContentAction = ValidateContent;
19+
}
20+
21+
protected override void InternalBuild()
822
{
9-
private const string XmlLibraryName = "Microsoft.Web.XmlTransform.dll";
10-
private const string NuGetLibraryName = "NuGet.Core.dll";
11-
private const string NuGetHelperLibraryName = "NewRelic.NuGetHelper.dll";
23+
_version = ReadVersionFromFile();
24+
var package = new NugetPackage(StagingDirectory, OutputDirectory);
25+
package.CopyAll($@"{PackageDirectory}");
26+
package.CopyToContent($@"{RepoRootDirectory}\build\NewRelic.NuGetHelper\bin\Release\net462\{NuGetHelperLibraryName}");
27+
package.CopyToContent($@"{RepoRootDirectory}\build\NewRelic.NuGetHelper\bin\Release\net462\{NuGetLibraryName}");
28+
package.CopyToContent($@"{RepoRootDirectory}\build\NewRelic.NuGetHelper\bin\Release\net462\{XmlLibraryName}");
29+
package.SetVersion(_version);
30+
_nuGetPackageName = package.Pack();
31+
}
1232

13-
private string _version;
14-
private string _nuGetPackageName;
33+
private string ReadVersionFromFile()
34+
{
35+
var versionFile = $@"{RepoRootDirectory}\build\BuildArtifacts\_buildProperties\version_azuresiteextension.txt";
1536

16-
public AzureSiteExtension() : base(nameof(AzureSiteExtension))
37+
if (!File.Exists(versionFile))
1738
{
18-
ValidateContentAction = ValidateContent;
39+
throw new PackagingException($"Version file does not exist: {versionFile}");
1940
}
2041

21-
protected override void InternalBuild()
42+
try
2243
{
23-
_version = ReadVersionFromFile();
24-
var package = new NugetPackage(StagingDirectory, OutputDirectory);
25-
package.CopyAll($@"{PackageDirectory}");
26-
package.CopyToContent($@"{RepoRootDirectory}\build\NewRelic.NuGetHelper\bin\Release\net462\{NuGetHelperLibraryName}");
27-
package.CopyToContent($@"{RepoRootDirectory}\build\NewRelic.NuGetHelper\bin\Release\net462\{NuGetLibraryName}");
28-
package.CopyToContent($@"{RepoRootDirectory}\build\NewRelic.NuGetHelper\bin\Release\net462\{XmlLibraryName}");
29-
package.SetVersion(_version);
30-
_nuGetPackageName = package.Pack();
44+
return File.ReadAllLines(versionFile)[0];
3145
}
32-
33-
private string ReadVersionFromFile()
46+
catch
3447
{
35-
var versionFile = $@"{RepoRootDirectory}\build\BuildArtifacts\_buildProperties\version_azuresiteextension.txt";
36-
37-
if (!File.Exists(versionFile))
38-
{
39-
throw new PackagingException($"Version file does not exist: {versionFile}");
40-
}
41-
42-
try
43-
{
44-
return File.ReadAllLines(versionFile)[0];
45-
}
46-
catch
47-
{
48-
throw new PackagingException($"Failed to read version file from: {versionFile}");
49-
}
48+
throw new PackagingException($"Failed to read version file from: {versionFile}");
5049
}
50+
}
5151

52-
/// <summary>
53-
/// This method will not validate the contents of every directory in the unpacked nuget.
54-
/// The validation will focus on the components that we expect to be included in the nuget
55-
/// which aligns with what we expect to be defined in the nuspec file.
56-
/// </summary>
57-
private void ValidateContent()
58-
{
59-
var unpackedLocation = Unpack();
52+
/// <summary>
53+
/// This method will not validate the contents of every directory in the unpacked nuget.
54+
/// The validation will focus on the components that we expect to be included in the nuget
55+
/// which aligns with what we expect to be defined in the nuspec file.
56+
/// </summary>
57+
private void ValidateContent()
58+
{
59+
var unpackedLocation = Unpack();
6060

61-
var expectedComponents = GetExpectedComponents(unpackedLocation);
61+
var expectedComponents = GetExpectedComponents(unpackedLocation);
6262

63-
var unpackedComponents = GetUnpackedComponents(unpackedLocation);
63+
var unpackedComponents = GetUnpackedComponents(unpackedLocation);
6464

65-
ValidationHelpers.ValidateComponents(expectedComponents, unpackedComponents, "Azure Site Extension");
65+
ValidationHelpers.ValidateComponents(expectedComponents, unpackedComponents, "Azure Site Extension");
6666

67-
FileHelpers.DeleteDirectories(unpackedLocation);
68-
}
67+
FileHelpers.DeleteDirectories(unpackedLocation);
68+
}
6969

70-
private string Unpack()
71-
{
72-
if (string.IsNullOrEmpty(_nuGetPackageName))
73-
throw new PackagingException("NuGet package name not found. Did you call InternalBuild()?");
70+
private string Unpack()
71+
{
72+
if (string.IsNullOrEmpty(_nuGetPackageName))
73+
throw new PackagingException("NuGet package name not found. Did you call InternalBuild()?");
7474

75-
var unpackDir = Path.Join(OutputDirectory, "unpacked");
76-
var nugetFile = Path.Join(OutputDirectory, _nuGetPackageName);
77-
NuGetHelpers.Unpack(nugetFile, unpackDir);
78-
return unpackDir;
79-
}
75+
var unpackDir = Path.Join(OutputDirectory, "unpacked");
76+
var nugetFile = Path.Join(OutputDirectory, _nuGetPackageName);
77+
NuGetHelpers.Unpack(nugetFile, unpackDir);
78+
return unpackDir;
79+
}
8080

81-
private SortedSet<string> GetExpectedComponents(string installedFilesRoot)
82-
{
83-
var expectedComponents = new SortedSet<string>(StringComparer.OrdinalIgnoreCase);
84-
85-
// images folder - New Relic icon
86-
ValidationHelpers.AddSingleFileToCollectionWithNewPath(expectedComponents, Path.Combine(installedFilesRoot, "images"), "icon.png");
87-
88-
// README
89-
ValidationHelpers.AddSingleFileToCollectionWithNewPath(expectedComponents, installedFilesRoot, "README.md");
90-
91-
// content folder - installation items
92-
var contentFolder = Path.Combine(installedFilesRoot, "content");
93-
ValidationHelpers.AddSingleFileToCollectionWithNewPath(expectedComponents, contentFolder, "applicationHost.xdt");
94-
ValidationHelpers.AddSingleFileToCollectionWithNewPath(expectedComponents, contentFolder, "install.cmd");
95-
ValidationHelpers.AddSingleFileToCollectionWithNewPath(expectedComponents, contentFolder, "install.ps1");
96-
ValidationHelpers.AddSingleFileToCollectionWithNewPath(expectedComponents, contentFolder, XmlLibraryName);
97-
ValidationHelpers.AddSingleFileToCollectionWithNewPath(expectedComponents, contentFolder, NuGetLibraryName);
98-
ValidationHelpers.AddSingleFileToCollectionWithNewPath(expectedComponents, contentFolder, NuGetHelperLibraryName);
99-
ValidationHelpers.AddSingleFileToCollectionWithNewPath(expectedComponents, contentFolder, "uninstall.cmd");
100-
ValidationHelpers.AddSingleFileToCollectionWithNewPath(expectedComponents, contentFolder, "web.config");
101-
102-
return expectedComponents;
103-
}
81+
private SortedSet<string> GetExpectedComponents(string installedFilesRoot)
82+
{
83+
var expectedComponents = new SortedSet<string>(StringComparer.OrdinalIgnoreCase);
84+
85+
// images folder - New Relic icon
86+
ValidationHelpers.AddSingleFileToCollectionWithNewPath(expectedComponents, Path.Combine(installedFilesRoot, "images"), "icon.png");
87+
88+
// README
89+
ValidationHelpers.AddSingleFileToCollectionWithNewPath(expectedComponents, installedFilesRoot, "README.md");
90+
91+
// content folder - installation items
92+
var contentFolder = Path.Combine(installedFilesRoot, "content");
93+
ValidationHelpers.AddSingleFileToCollectionWithNewPath(expectedComponents, contentFolder, "applicationHost.xdt");
94+
ValidationHelpers.AddSingleFileToCollectionWithNewPath(expectedComponents, contentFolder, "install.cmd");
95+
ValidationHelpers.AddSingleFileToCollectionWithNewPath(expectedComponents, contentFolder, "install.ps1");
96+
ValidationHelpers.AddSingleFileToCollectionWithNewPath(expectedComponents, contentFolder, XmlLibraryName);
97+
ValidationHelpers.AddSingleFileToCollectionWithNewPath(expectedComponents, contentFolder, NuGetLibraryName);
98+
ValidationHelpers.AddSingleFileToCollectionWithNewPath(expectedComponents, contentFolder, NuGetHelperLibraryName);
99+
ValidationHelpers.AddSingleFileToCollectionWithNewPath(expectedComponents, contentFolder, "uninstall.cmd");
100+
ValidationHelpers.AddSingleFileToCollectionWithNewPath(expectedComponents, contentFolder, "web.config");
101+
102+
return expectedComponents;
103+
}
104104

105-
private static SortedSet<string> GetUnpackedComponents(string installedFilesRoot)
106-
{
107-
var unpackedComponents = ValidationHelpers.GetUnpackedComponents(Path.Combine(installedFilesRoot, "content"));
108-
unpackedComponents.UnionWith(ValidationHelpers.GetUnpackedComponents(Path.Combine(installedFilesRoot, "images")));
109-
unpackedComponents.Add(Path.Combine(installedFilesRoot, "README.md"));
105+
private static SortedSet<string> GetUnpackedComponents(string installedFilesRoot)
106+
{
107+
var unpackedComponents = ValidationHelpers.GetUnpackedComponents(Path.Combine(installedFilesRoot, "content"));
108+
unpackedComponents.UnionWith(ValidationHelpers.GetUnpackedComponents(Path.Combine(installedFilesRoot, "images")));
109+
unpackedComponents.Add(Path.Combine(installedFilesRoot, "README.md"));
110110

111-
return unpackedComponents;
112-
}
111+
return unpackedComponents;
113112
}
114113
}

0 commit comments

Comments
 (0)