11public class ChocolateyPackage : PackageDefinition
22{
33 public ChocolateyPackage (
4- string id ,
5- string source ,
4+ string id ,
5+ string title = null ,
6+ string summary = null ,
7+ string description = null ,
8+ string [ ] releaseNotes = null ,
9+ string [ ] tags = null ,
10+ string source = null ,
611 string packageVersion = null ,
712 IPackageTestRunner testRunner = null ,
813 IPackageTestRunner [ ] testRunners = null ,
914 PackageCheck [ ] checks = null ,
10- IEnumerable < PackageTest > tests = null )
15+ IEnumerable < PackageTest > tests = null ,
16+ PackageContent packageContent = null )
1117 : base (
1218 PackageType . Chocolatey ,
1319 id ,
14- source ,
20+ title : title ,
21+ summary : summary ,
22+ description : description ,
23+ releaseNotes : releaseNotes ,
24+ tags : tags ,
25+ source : source ,
1526 packageVersion : packageVersion ,
1627 testRunner : testRunner ,
1728 testRunners : testRunners ,
1829 checks : checks ,
19- tests : tests )
30+ tests : tests ,
31+ packageContent : packageContent )
2032 {
21- if ( ! source . EndsWith ( ".nuspec" ) )
22- throw new ArgumentException ( "Source must be a nuspec file" , nameof ( source ) ) ;
2333 }
2434
2535 // The file name of this package, including extension
@@ -33,15 +43,70 @@ public class ChocolateyPackage : PackageDefinition
3343 // The directory into which extensions to the test runner are installed
3444 public override string ExtensionInstallDirectory => BuildSettings . ChocolateyTestDirectory ;
3545
36- public override void BuildPackage ( )
46+ protected virtual ChocolateyPackSettings ChocolateyPackSettings
3747 {
38- _context . ChocolateyPack ( PackageSource ,
39- new ChocolateyPackSettings ( )
48+ get
49+ {
50+ var repositoryUrl = NUNIT_GITHUB_URL + BuildSettings . GitHubRepository + "/" ;
51+ var rawGitHubUserContent = "https://raw.githubusercontent.com/" + BuildSettings . GitHubRepository + "/main/" ;
52+
53+ // NOTE: Because of how Cake build works, these settings will
54+ // override any settings in a nuspec file. Therefore, no settings
55+ // should be initialized unless they either
56+ // 1) are taken from the PackageDefinition itself.
57+ // 2) are taken from the BuildSettings, which apply to all packages being built.
58+ // 3) are defined to be the same for all TestCentric packages.
59+
60+ var settings = new ChocolateyPackSettings
4061 {
62+ // From PackageDefinition
63+ Id = PackageId ,
4164 Version = PackageVersion ,
65+ Title = PackageTitle ?? PackageId ,
66+ Summary = PackageSummary ,
67+ Description = PackageDescription ,
68+ ReleaseNotes = ReleaseNotes ,
69+ Tags = Tags ,
70+ // From BuildSettings
71+ LicenseUrl = new Uri ( $ "{ NUNIT_RAW_URL } { BuildSettings . GitHubRepository } /main/LICENSE.txt") ,
72+ Verbose = BuildSettings . ChocolateyVerbosity ,
4273 OutputDirectory = BuildSettings . PackageDirectory ,
74+ ProjectSourceUrl = new Uri ( repositoryUrl ) ,
75+ PackageSourceUrl = new Uri ( repositoryUrl ) ,
76+ BugTrackerUrl = new Uri ( repositoryUrl + "issues" ) ,
77+ // Common to all packages
78+ Authors = NUNIT_PACKAGE_AUTHORS ,
79+ Owners = NUNIT_PACKAGE_OWNERS ,
80+ Copyright = NUNIT_COPYRIGHT ,
81+ ProjectUrl = new Uri ( NUNIT_PROJECT_URL ) ,
82+ RequireLicenseAcceptance = false ,
83+ DocsUrl = new Uri ( NUNIT_PROJECT_URL ) ,
84+ MailingListUrl = new Uri ( NUNIT_MAILING_LIST_URL ) ,
4385 ArgumentCustomization = args => args . Append ( $ "BIN_DIR={ BuildSettings . OutputDirectory } ")
44- } ) ;
86+ } ;
87+
88+ if ( PackageContent != null )
89+ {
90+ foreach ( var item in PackageContent . GetChocolateyNuSpecContent ( BasePath ) )
91+ settings . Files . Add ( item ) ;
92+
93+ foreach ( PackageReference dependency in PackageContent . Dependencies )
94+ settings . Dependencies . Add ( new ChocolateyNuSpecDependency { Id = dependency . Id , Version = dependency . Version } ) ;
95+ }
96+
97+ return settings ;
98+ }
99+ }
100+
101+ public override void BuildPackage ( )
102+ {
103+ if ( string . IsNullOrEmpty ( PackageSource ) )
104+ _context . ChocolateyPack ( ChocolateyPackSettings ) ;
105+ else if ( PackageSource . EndsWith ( ".nuspec" ) )
106+ _context . ChocolateyPack ( PackageSource , ChocolateyPackSettings ) ;
107+ else
108+ throw new ArgumentException (
109+ $ "Invalid package source specified: { PackageSource } ", "source" ) ;
45110 }
46111
47112 protected override bool IsRemovableExtension ( string id )
0 commit comments