Skip to content

Commit

Permalink
Code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierdecoster committed Mar 27, 2017
1 parent 5113343 commit 0a35c93
Showing 1 changed file with 40 additions and 48 deletions.
88 changes: 40 additions & 48 deletions src/NuGet.Core/NuGet.Packaging/NuspecReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -107,15 +106,53 @@ public NuspecReader(XDocument xml, IFrameworkNameProvider frameworkProvider)
/// </summary>
public IEnumerable<PackageDependencyGroup> GetDependencyGroups()
{
return GetAllDependencyGroups(useStrictVersionCheck: false);
return GetDependencyGroups(useStrictVersionCheck: false);
}

/// <summary>
/// Read package dependencies for all frameworks
/// </summary>
public IEnumerable<PackageDependencyGroup> GetDependencyGroups(bool useStrictVersionCheck)
{
return GetAllDependencyGroups(useStrictVersionCheck);
var ns = MetadataNode.GetDefaultNamespace().NamespaceName;
var dependencyNode = MetadataNode
.Elements(XName.Get(Dependencies, ns));

var groupFound = false;
var dependencyGroups = dependencyNode
.Elements(XName.Get(Group, ns));

foreach (var depGroup in dependencyGroups)
{
groupFound = true;

var groupFramework = GetAttributeValue(depGroup, TargetFramework);

var dependencies = depGroup
.Elements(XName.Get(Dependency, ns));

var packages = GetPackageDependencies(dependencies, useStrictVersionCheck);

var framework = string.IsNullOrEmpty(groupFramework)
? NuGetFramework.AnyFramework
: NuGetFramework.Parse(groupFramework, _frameworkProvider);

yield return new PackageDependencyGroup(framework, packages);
}

// legacy behavior
if (!groupFound)
{
var legacyDependencies = dependencyNode
.Elements(XName.Get(Dependency, ns));

var packages = GetPackageDependencies(legacyDependencies, useStrictVersionCheck);

if (packages.Any())
{
yield return new PackageDependencyGroup(NuGetFramework.AnyFramework, packages);
}
}
}

/// <summary>
Expand Down Expand Up @@ -415,51 +452,6 @@ private static List<string> GetFlags(string flags)
return set.OrderBy(s => s, StringComparer.OrdinalIgnoreCase).ToList();
}

private IEnumerable<PackageDependencyGroup> GetAllDependencyGroups(bool useStrictVersionCheck)
{
var ns = MetadataNode.GetDefaultNamespace().NamespaceName;
var dependencyNode = MetadataNode
.Elements(XName.Get(Dependencies, ns));

var groupFound = false;
var dependencyGroups = dependencyNode
.Elements(XName.Get(Group, ns));

foreach (var depGroup in dependencyGroups)
{
groupFound = true;

var groupFramework = GetAttributeValue(depGroup, TargetFramework);

var dependencies = depGroup
.Elements(XName.Get(Dependency, ns));

var packages = GetPackageDependencies(dependencies, useStrictVersionCheck);

var framework = string.IsNullOrEmpty(groupFramework)
? NuGetFramework.AnyFramework
: NuGetFramework.Parse(groupFramework, _frameworkProvider);

yield return new PackageDependencyGroup(framework, packages);
}

// legacy behavior
if (!groupFound)
{
var legacyDependencies = dependencyNode
.Elements(XName.Get(Dependency, ns));

var packages = GetPackageDependencies(legacyDependencies, useStrictVersionCheck);

if (packages.Any())
{
yield return new PackageDependencyGroup(NuGetFramework.AnyFramework, packages);
}
}

yield break;
}

private HashSet<PackageDependency> GetPackageDependencies(IEnumerable<XElement> nodes, bool useStrictVersionCheck)
{
var packages = new HashSet<PackageDependency>();
Expand Down

0 comments on commit 0a35c93

Please sign in to comment.