Skip to content

Commit

Permalink
(#509) Get pack compiling
Browse files Browse the repository at this point in the history
This gets pack working, if the package is using the NuGet compatible schema without
the added Chocolatey specific elements
  • Loading branch information
TheCakeIsNaOH committed Jun 17, 2022
1 parent 8d91810 commit 8b2cd72
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace chocolatey.infrastructure.app.nuget

// ReSharper disable InconsistentNaming

public sealed class DictionaryPropertyProvider : IPropertyProvider
public sealed class DictionaryPropertyProvider
{
private readonly IDictionary<string, string> _properties;

Expand All @@ -30,7 +30,7 @@ public DictionaryPropertyProvider(IDictionary<string, string> properties)
_properties = properties;
}

public dynamic GetPropertyValue(string propertyName)
public string GetPropertyValue(string propertyName)
{
string value;
if (_properties.TryGetValue(propertyName, out value))
Expand Down
8 changes: 4 additions & 4 deletions src/chocolatey/infrastructure.app/nuget/NugetPack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace chocolatey.infrastructure.app.nuget
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NuGet;
using IFileSystem = filesystem.IFileSystem;
using chocolatey.infrastructure.platforms;
using NuGet.Common;
Expand All @@ -31,9 +30,10 @@ namespace chocolatey.infrastructure.app.nuget

public sealed class NugetPack
{
public static IPackage BuildPackage(PackageBuilder builder, IFileSystem fileSystem, string outputPath = null)
public static bool BuildPackage(PackageBuilder builder, IFileSystem fileSystem, string outputPath)
{
ExcludeFiles(builder.Files);

// Track if the package file was already present on disk
bool isExistingPackage = fileSystem.file_exists(outputPath);
try
Expand All @@ -57,7 +57,7 @@ public static IPackage BuildPackage(PackageBuilder builder, IFileSystem fileSyst
throw;
}

return new OptimizedZipPackage(outputPath);
return true;
}

private static void ExcludeFiles(ICollection<IPackageFile> packageFiles)
Expand All @@ -67,7 +67,7 @@ private static void ExcludeFiles(ICollection<IPackageFile> packageFiles)
// manifest file.
var filter = Platform.get_platform() == PlatformType.Windows ? @"**\*" : "**/*";
var excludes = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
var wildCards = excludes.Concat(new[] { filter + Constants.ManifestExtension, filter + Constants.PackageExtension });
var wildCards = excludes.Concat(new[] { filter + PackagingConstants.ManifestExtension, filter + NuGetConstants.PackageExtension });

PathResolver.FilterPackageFiles(packageFiles, ResolvePath, wildCards);
}
Expand Down
21 changes: 14 additions & 7 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public virtual string validate_and_return_package_file(ChocolateyConfiguration c

public virtual void pack_run(ChocolateyConfiguration config)
{
var nuspecFilePath = validate_and_return_package_file(config, Constants.ManifestExtension);
var nuspecFilePath = validate_and_return_package_file(config, PackagingConstants.ManifestExtension);
var nuspecDirectory = _fileSystem.get_full_path(_fileSystem.get_directory_name(nuspecFilePath));
if (string.IsNullOrWhiteSpace(nuspecDirectory)) nuspecDirectory = _fileSystem.get_current_directory();

Expand Down Expand Up @@ -292,23 +292,30 @@ public virtual void pack_run(ChocolateyConfiguration config)
// Initialize the property provider based on what was passed in using the properties flag
var propertyProvider = new DictionaryPropertyProvider(properties);

var builder = new PackageBuilder(nuspecFilePath, nuspecDirectory, propertyProvider, includeEmptyDirectories: true);
//Allows empty directories to be distributed in templates via .template packages, issue #1003
bool includeEmptyDirectories = true;
//No need to be deterministic, it's ok to include timestamps
bool deterministic = false;

var builder = new PackageBuilder(nuspecFilePath, nuspecDirectory, propertyProvider.GetPropertyValue, includeEmptyDirectories, deterministic, _nugetLogger);
if (!string.IsNullOrWhiteSpace(config.Version))
{
builder.Version = new SemanticVersion(config.Version);
builder.Version = new NuGetVersion(config.Version);
}

string outputFile = builder.Id + "." + builder.Version + Constants.PackageExtension;
string outputFile = builder.Id + "." + builder.Version + NuGetConstants.PackageExtension;
string outputFolder = config.OutputDirectory ?? _fileSystem.get_current_directory();
string outputPath = _fileSystem.combine_paths(outputFolder, outputFile);

config.Sources = outputFolder;

this.Log().Info(config.QuietOutput ? ChocolateyLoggers.LogFileOnly : ChocolateyLoggers.Normal, () => "Attempting to build package from '{0}'.".format_with(_fileSystem.get_file_name(nuspecFilePath)));

_fileSystem.create_directory_if_not_exists(outputFolder);

IPackage package = NugetPack.BuildPackage(builder, _fileSystem, outputPath);
var createdPackage = NugetPack.BuildPackage(builder, _fileSystem, outputPath);
// package.Validate().Any(v => v.Level == PackageIssueLevel.Error)
if (package == null)
if (!createdPackage)
{
throw new ApplicationException("Unable to create nupkg. See the log for error details.");
}
Expand Down

0 comments on commit 8b2cd72

Please sign in to comment.