Skip to content

Commit

Permalink
Add in default reference libraries in support libraries again. Fix in…
Browse files Browse the repository at this point in the history
…tegration tests
  • Loading branch information
glennawatson committed May 11, 2019
1 parent f906eca commit f089673
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 28 deletions.
12 changes: 6 additions & 6 deletions src/Pharmacist.Core/NuGet/NuGetFrameworkHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ public static NuGetFramework ToFramework(this string frameworkName)
/// <returns>The package details or null if none is available.</returns>
public static IEnumerable<PackageIdentity> GetSupportLibraries(this NuGetFramework framework)
{
if (!framework.IsPackageBased)
{
return null;
}

if (framework.Framework.StartsWith(".NETStandard", StringComparison.OrdinalIgnoreCase))
{
return new[] { new PackageIdentity("NETStandard.Library", new NuGetVersion(framework.Version)) };
Expand All @@ -98,7 +93,12 @@ public static IEnumerable<PackageIdentity> GetSupportLibraries(this NuGetFramewo
}
}

return null;
if (framework.Framework.StartsWith(".NETFramework", StringComparison.OrdinalIgnoreCase))
{
return new[] { new PackageIdentity("Microsoft.NETFramework.ReferenceAssemblies", new NuGetVersion("1.0.0-preview.1")) };
}

return Array.Empty<PackageIdentity>();
}
}
}
31 changes: 25 additions & 6 deletions src/Pharmacist.Core/NuGet/NuGetPackageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ namespace Pharmacist.Core.NuGet
/// </summary>
public static class NuGetPackageHelper
{
private const int ProcessingCount = 32;
private static readonly string[] DefaultFoldersToGrab = { PackagingConstants.Folders.Lib, PackagingConstants.Folders.Build, PackagingConstants.Folders.Ref };

// Bunch of NuGet based objects we can cache and only create once.
private static readonly string _globalPackagesPath = SettingsUtility.GetGlobalPackagesFolder(new XPlatMachineWideSetting().Settings);
private static readonly NuGetLogger _logger = new NuGetLogger();
Expand Down Expand Up @@ -76,7 +79,9 @@ static NuGetPackageHelper()
var packagesToCopy = new Dictionary<string, (PackageIdentity packageIdentity, DownloadResourceResult downloadResourceResult, bool includeFilesInOutput)>(StringComparer.InvariantCultureIgnoreCase);

var stack = new ConcurrentStack<PackageIdentity>(new[] { startingPackage });
var currentItems = new PackageIdentity[32];
stack.PushRange(framework.GetSupportLibraries().ToArray());

var currentItems = new PackageIdentity[ProcessingCount];
while (!stack.IsEmpty)
{
var count = stack.TryPopRange(currentItems);
Expand Down Expand Up @@ -119,9 +124,7 @@ private static (string folder, IEnumerable<string> files) CopyPackageFiles(Packa
EnsureDirectory(directory);

// Get all the folders in our lib and build directory of our nuget. These are the general contents we include in our projects.
var groups = downloadResults.PackageReader.GetFileGroups(PackagingConstants.Folders.Lib).Concat(
downloadResults.PackageReader.GetFileGroups(PackagingConstants.Folders.Build).Concat(
downloadResults.PackageReader.GetFileGroups(PackagingConstants.Folders.Ref)));
var groups = DefaultFoldersToGrab.SelectMany(x => downloadResults.PackageReader.GetFileGroups(x));

// Select our groups that match our selected framework and have content.
var groupFiles = groups.Where(x => !x.HasEmptyFolder && x.TargetFramework.EqualToOrLessThan(framework)).SelectMany(x => x.Items).ToList();
Expand All @@ -136,11 +139,27 @@ private static (string folder, IEnumerable<string> files) CopyPackageFiles(Packa
return (directory, includeFilesInOutput ? outputFiles.Where(x => x.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) : Enumerable.Empty<string>());
}

/// <summary>
/// Gets dependency packages that matches our framework (current version or below).
/// </summary>
/// <param name="downloadResults">The results where to get the dependencies from.</param>
/// <param name="framework">The framework to match dependencies for.</param>
/// <returns>The dependencies, or an empty array if there are no dependencies.</returns>
private static IEnumerable<PackageIdentity> GetDependencyPackages(DownloadResourceResult downloadResults, NuGetFramework framework)
{
return downloadResults.PackageReader.GetPackageDependencies()
// Grab the package dependency group that matches is closest to our framework.
var highestFramework = downloadResults.PackageReader.GetPackageDependencies()
.Where(dependency => dependency.TargetFramework.EqualToOrLessThan(framework))
.SelectMany(x => x.Packages.Select(package => new PackageIdentity(package.Id, package.VersionRange.MinVersion)));
.OrderByDescending(dependency => dependency.TargetFramework.Version)
.FirstOrDefault();

// If no packages match our framework just return an empty array.
if (highestFramework == null)
{
return Array.Empty<PackageIdentity>();
}

return highestFramework.Packages.Select(package => new PackageIdentity(package.Id, package.VersionRange.MinVersion));
}

private static void EnsureDirectory(string packageUnzipPath)
Expand Down
17 changes: 1 addition & 16 deletions src/Pharmacist.Core/TemplateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,10 @@ namespace Pharmacist.Core
{
internal static class TemplateManager
{
/// <summary>
/// Gets the default mustache template file name.
/// </summary>
public const string DefaultMustacheTemplate = "EventBuilder.Core.Templates.DefaultTemplate.mustache";

/// <summary>
/// Gets the template for static based events.
/// </summary>
public const string StaticMustacheTemplate = "EventBuilder.Core.Templates.StaticTemplate.mustache";

/// <summary>
/// Gets the template for the header of the file.
/// </summary>
public const string HeaderTemplate = "EventBuilder.Core.Templates.HeaderTemplate.txt";

/// <summary>
/// Gets the template for the delegate information.
/// </summary>
public const string DelegateTemplate = "EventBuilder.Core.Templates.DelegateTemplate.mustache";
public const string HeaderTemplate = "Pharmacist.Core.Templates.HeaderTemplate.txt";

public static async Task<string> GetTemplateAsync(string templateName)
{
Expand Down
1 change: 1 addition & 0 deletions src/Pharmacist.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public async Task TizenNuGetTest()
await ObservablesForEventGenerator.ExtractEventsFromNuGetPackages(memoryStream, package, framework).ConfigureAwait(false);
memoryStream.Flush();

memoryStream.Position = 0;
using (var sr = new StreamReader(memoryStream))
{
var contents = sr.ReadToEnd();
Expand Down

0 comments on commit f089673

Please sign in to comment.