|
1 | | -using System.Collections.Generic; |
2 | 1 | using System; |
| 2 | +using System.Collections.Generic; |
3 | 3 | using System.IO; |
4 | 4 |
|
5 | | -namespace ArtifactBuilder.Artifacts |
| 5 | +namespace ArtifactBuilder.Artifacts; |
| 6 | + |
| 7 | +public class AzureSiteExtension : Artifact |
6 | 8 | { |
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() |
8 | 22 | { |
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 | + } |
12 | 32 |
|
13 | | - private string _version; |
14 | | - private string _nuGetPackageName; |
| 33 | + private string ReadVersionFromFile() |
| 34 | + { |
| 35 | + var versionFile = $@"{RepoRootDirectory}\build\BuildArtifacts\_buildProperties\version_azuresiteextension.txt"; |
15 | 36 |
|
16 | | - public AzureSiteExtension() : base(nameof(AzureSiteExtension)) |
| 37 | + if (!File.Exists(versionFile)) |
17 | 38 | { |
18 | | - ValidateContentAction = ValidateContent; |
| 39 | + throw new PackagingException($"Version file does not exist: {versionFile}"); |
19 | 40 | } |
20 | 41 |
|
21 | | - protected override void InternalBuild() |
| 42 | + try |
22 | 43 | { |
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]; |
31 | 45 | } |
32 | | - |
33 | | - private string ReadVersionFromFile() |
| 46 | + catch |
34 | 47 | { |
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}"); |
50 | 49 | } |
| 50 | + } |
51 | 51 |
|
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(); |
60 | 60 |
|
61 | | - var expectedComponents = GetExpectedComponents(unpackedLocation); |
| 61 | + var expectedComponents = GetExpectedComponents(unpackedLocation); |
62 | 62 |
|
63 | | - var unpackedComponents = GetUnpackedComponents(unpackedLocation); |
| 63 | + var unpackedComponents = GetUnpackedComponents(unpackedLocation); |
64 | 64 |
|
65 | | - ValidationHelpers.ValidateComponents(expectedComponents, unpackedComponents, "Azure Site Extension"); |
| 65 | + ValidationHelpers.ValidateComponents(expectedComponents, unpackedComponents, "Azure Site Extension"); |
66 | 66 |
|
67 | | - FileHelpers.DeleteDirectories(unpackedLocation); |
68 | | - } |
| 67 | + FileHelpers.DeleteDirectories(unpackedLocation); |
| 68 | + } |
69 | 69 |
|
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()?"); |
74 | 74 |
|
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 | + } |
80 | 80 |
|
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 | + } |
104 | 104 |
|
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")); |
110 | 110 |
|
111 | | - return unpackedComponents; |
112 | | - } |
| 111 | + return unpackedComponents; |
113 | 112 | } |
114 | 113 | } |
0 commit comments