Skip to content

Commit

Permalink
Remove tools from package spec (no longer used)
Browse files Browse the repository at this point in the history
  • Loading branch information
joelverhagen committed Nov 21, 2016
1 parent eb9ca47 commit 81491a5
Show file tree
Hide file tree
Showing 15 changed files with 17 additions and 917 deletions.
15 changes: 0 additions & 15 deletions src/NuGet.Core/NuGet.Commands/RestoreCommand/LockFileBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,6 @@ public LockFile CreateLockFile(
lockFile.Targets.Add(target);
}

PopulateProjectFileToolGroups(project, lockFile);

PopulatePackageFolders(localRepositories.Select(repo => repo.RepositoryRoot).Distinct(), lockFile);

// Add the original package spec to the lock file.
Expand Down Expand Up @@ -380,19 +378,6 @@ private static void AddProjectFileDependenciesForNETCore(PackageSpec project, Lo
}
}

private static void PopulateProjectFileToolGroups(PackageSpec project, LockFile lockFile)
{
// Add the tool dependencies (this states what the project requires)
if (project.Tools.Any())
{
lockFile.ProjectFileToolGroups.Add(new ProjectFileDependencyGroup(
LockFile.ToolFramework.ToString(),
project.Tools
.Select(x => x.LibraryRange.ToLockFileDependencyGroupString())
.OrderBy(dependency => dependency, StringComparer.Ordinal)));
}
}

private static void PopulatePackageFolders(IEnumerable<string> packageFolders, LockFile lockFile)
{
lockFile.PackageFolders.AddRange(packageFolders.Select(path => new LockFileItem(path)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using NuGet.Client;
using NuGet.Common;
using NuGet.ContentModel;
using NuGet.DependencyResolver;
using NuGet.Frameworks;
using NuGet.LibraryModel;
using NuGet.Packaging;
using NuGet.Packaging.Core;
using NuGet.ProjectModel;
using NuGet.Repositories;
Expand Down Expand Up @@ -598,10 +594,6 @@ private void DowngradeLockFileToV1(LockFile lockFile)
library.Type = null;
}

// Remove tools
lockFile.Tools.Clear();
lockFile.ProjectFileToolGroups.Clear();

// Remove the package spec
lockFile.PackageSpec = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public static PackageSpec GetSpec(string projectFilePath, string id, VersionRang
Name = name, // make sure this package never collides with a dependency
FilePath = projectFilePath,
Dependencies = new List<LibraryDependency>(),
Tools = new List<ToolDependency>(),
TargetFrameworks =
{
new TargetFrameworkInformation
Expand Down
47 changes: 0 additions & 47 deletions src/NuGet.Core/NuGet.LibraryModel/ToolDependency.cs

This file was deleted.

75 changes: 0 additions & 75 deletions src/NuGet.Core/NuGet.ProjectModel/JsonPackageSpecReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ public static PackageSpec GetPackageSpec(JObject rawPackageSpec, string name, st
"dependencies",
isGacOrFrameworkReference: false);

packageSpec.Tools = ReadTools(packageSpec, rawPackageSpec).ToList();

packageSpec.PackOptions = GetPackOptions(packageSpec, rawPackageSpec);

packageSpec.RestoreMetadata = GetMSBuildMetadata(packageSpec, rawPackageSpec);
Expand Down Expand Up @@ -573,79 +571,6 @@ private static void PopulateDependencies(
}
}

private static IEnumerable<ToolDependency> ReadTools(PackageSpec packageSpec, JObject rawPackageSpec)
{
var tools = rawPackageSpec["tools"] as JObject;
if (tools != null)
{
foreach (var tool in tools)
{
if (string.IsNullOrEmpty(tool.Key))
{
throw FileFormatException.Create(
Strings.MissingToolName,
tool.Value,
packageSpec.FilePath);
}

var value = tool.Value;
JToken versionToken = null;
string versionValue = null;
var imports = new List<NuGetFramework>();
if (value.Type == JTokenType.String)
{
versionToken = value;
versionValue = value.Value<string>();
}
else
{
if (value.Type == JTokenType.Object)
{
versionToken = value["version"];
if (versionToken != null && versionToken.Type == JTokenType.String)
{
versionValue = versionToken.Value<string>();
}

imports.AddRange(GetImports((JObject)value, packageSpec));
}
}

if (versionValue == null)
{
throw FileFormatException.Create(
Strings.MissingVersionOnTool,
tool.Value,
packageSpec.FilePath);
}

VersionRange versionRange;
try
{
versionRange = VersionRange.Parse(versionValue);
}
catch (Exception ex)
{
throw FileFormatException.Create(
ex,
versionToken,
packageSpec.FilePath);
}

yield return new ToolDependency
{
LibraryRange = new LibraryRange
{
Name = tool.Key,
TypeConstraint = LibraryDependencyTarget.Package,
VersionRange = versionRange
},
Imports = imports
};
}
}
}

private static bool TryGetStringEnumerable(JToken token, out IEnumerable<string> result)
{
IEnumerable<string> values;
Expand Down
49 changes: 0 additions & 49 deletions src/NuGet.Core/NuGet.ProjectModel/LockFile/LockFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ public class LockFile : IEquatable<LockFile>
public IList<ProjectFileDependencyGroup> ProjectFileDependencyGroups { get; set; } = new List<ProjectFileDependencyGroup>();
public IList<LockFileLibrary> Libraries { get; set; } = new List<LockFileLibrary>();
public IList<LockFileTarget> Targets { get; set; } = new List<LockFileTarget>();
public IList<LockFileTarget> Tools { get; set; } = new List<LockFileTarget>();
public IList<ProjectFileDependencyGroup> ProjectFileToolGroups { get; set; } = new List<ProjectFileDependencyGroup>();
public IList<LockFileItem> PackageFolders { get; set; } = new List<LockFileItem>();
public PackageSpec PackageSpec { get; set; }

Expand All @@ -45,11 +43,6 @@ public bool IsValidForPackageSpec(PackageSpec spec, int requestLockFileVersion)
return false;
}

if (!ValidateTools(spec))
{
return false;
}

return true;
}

Expand Down Expand Up @@ -101,44 +94,6 @@ private bool ValidateDependencies(PackageSpec spec)
return true;
}

private bool ValidateTools(PackageSpec spec)
{
// Skip this check if there are no tools at all.
if (ProjectFileToolGroups.Count == 0 && spec.Tools.Count == 0)
{
return true;
}

// The lock file should only contain tools for a single framework
if (ProjectFileToolGroups.Count != 1)
{
return false;
}

var group = ProjectFileToolGroups.First();
if (!StringComparer.OrdinalIgnoreCase.Equals(
group.FrameworkName,
ToolFramework.ToString()))
{
return false;
}

var lockDependencies = group
.Dependencies
.OrderBy(x => x, StringComparer.Ordinal);

var specDependencies = spec.Tools
.Select(x => x.LibraryRange.ToLockFileDependencyGroupString())
.OrderBy(x => x, StringComparer.Ordinal);

if (!specDependencies.SequenceEqual(lockDependencies))
{
return false;
}

return true;
}

public LockFileTarget GetTarget(NuGetFramework framework, string runtimeIdentifier)
{
return Targets.FirstOrDefault(t =>
Expand Down Expand Up @@ -170,8 +125,6 @@ public bool Equals(LockFile other)
&& ProjectFileDependencyGroups.OrderedEquals(other.ProjectFileDependencyGroups, group => group.FrameworkName, StringComparer.OrdinalIgnoreCase)
&& Libraries.OrderedEquals(other.Libraries, library => library.Name, StringComparer.OrdinalIgnoreCase)
&& Targets.OrderedEquals(other.Targets, target => target.Name, StringComparer.Ordinal)
&& ProjectFileToolGroups.OrderedEquals(other.ProjectFileToolGroups, group => group.FrameworkName, StringComparer.OrdinalIgnoreCase)
&& Tools.OrderedEquals(other.Tools, target => target.Name, StringComparer.Ordinal)
&& PackageFolders.SequenceEqual(other.PackageFolders)
&& EqualityUtility.EqualsWithNullCheck(PackageSpec, other.PackageSpec);
}
Expand All @@ -195,8 +148,6 @@ public override int GetHashCode()
}

HashLockFileTargets(combiner, Targets);
HashProjectFileDependencyGroups(combiner, ProjectFileToolGroups);
HashLockFileTargets(combiner, Tools);

foreach (var item in PackageFolders)
{
Expand Down
18 changes: 1 addition & 17 deletions src/NuGet.Core/NuGet.ProjectModel/LockFile/LockFileFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ private static LockFile ReadLockFile(JObject cursor)
lockFile.Libraries = ReadObject(cursor[LibrariesProperty] as JObject, ReadLibrary);
lockFile.Targets = ReadObject(cursor[TargetsProperty] as JObject, ReadTarget);
lockFile.ProjectFileDependencyGroups = ReadObject(cursor[ProjectFileDependencyGroupsProperty] as JObject, ReadProjectFileDependencyGroup);
lockFile.Tools = ReadObject(cursor[ToolsProperty] as JObject, ReadTarget);
lockFile.ProjectFileToolGroups = ReadObject(cursor[ProjectFileToolGroupsProperty] as JObject, ReadProjectFileDependencyGroup);
lockFile.PackageFolders = ReadObject(cursor[PackageFoldersProperty] as JObject, ReadFileItem);
lockFile.PackageSpec = ReadPackageSpec(cursor[PackageSpecProperty] as JObject);
return lockFile;
Expand All @@ -192,21 +190,7 @@ private static JObject WriteLockFile(LockFile lockFile)
json[TargetsProperty] = WriteObject(lockFile.Targets, WriteTarget);
json[LibrariesProperty] = WriteObject(lockFile.Libraries, WriteLibrary);
json[ProjectFileDependencyGroupsProperty] = WriteObject(lockFile.ProjectFileDependencyGroups, WriteProjectFileDependencyGroup);

// Avoid writing out the tools section for v1 lock files
if (lockFile.Version >= 2)
{
if (lockFile.Tools != null)
{
json[ToolsProperty] = WriteObject(lockFile.Tools, WriteTarget);
}

if (lockFile.ProjectFileToolGroups != null)
{
json[ProjectFileToolGroupsProperty] = WriteObject(lockFile.ProjectFileToolGroups, WriteProjectFileDependencyGroup);
}
}


if (lockFile.PackageFolders?.Any() == true)
{
json[PackageFoldersProperty] = WriteObject(lockFile.PackageFolders, WriteFileItem);
Expand Down
4 changes: 0 additions & 4 deletions src/NuGet.Core/NuGet.ProjectModel/PackageSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ public NuGetVersion Version

public IList<LibraryDependency> Dependencies { get; set; } = new List<LibraryDependency>();

public IList<ToolDependency> Tools { get; set; } = new List<ToolDependency>();

public IDictionary<string, IEnumerable<string>> Scripts { get; private set; } = new Dictionary<string, IEnumerable<string>>(StringComparer.OrdinalIgnoreCase);

public IDictionary<string, string> PackInclude { get; private set; } = new Dictionary<string, string>();
Expand Down Expand Up @@ -128,7 +126,6 @@ public override int GetHashCode()
hashCode.AddSequence(Tags);
hashCode.AddSequence(ContentFiles);
hashCode.AddSequence(Dependencies);
hashCode.AddSequence(Tools);
hashCode.AddDictionary(Scripts);
hashCode.AddDictionary(PackInclude);
hashCode.AddObject(PackOptions);
Expand Down Expand Up @@ -177,7 +174,6 @@ public bool Equals(PackageSpec other)
EqualityUtility.SequenceEqualWithNullCheck(Tags, other.Tags) &&
EqualityUtility.SequenceEqualWithNullCheck(ContentFiles, other.ContentFiles) &&
EqualityUtility.SequenceEqualWithNullCheck(Dependencies, other.Dependencies) &&
EqualityUtility.SequenceEqualWithNullCheck(Tools, other.Tools) &&
EqualityUtility.DictionaryOfSequenceEquals(Scripts, other.Scripts) &&
EqualityUtility.DictionaryEquals(PackInclude, other.PackInclude, (s, o) => StringComparer.Ordinal.Equals(s, o)) &&
EqualityUtility.EqualsWithNullCheck(PackOptions, other.PackOptions) &&
Expand Down
24 changes: 0 additions & 24 deletions src/NuGet.Core/NuGet.ProjectModel/PackageSpecWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public static void Write(PackageSpec packageSpec, IObjectWriter writer)
SetDependencies(writer, packageSpec.Dependencies);
}

SetTools(writer, packageSpec.Tools);
SetFrameworks(writer, packageSpec.TargetFrameworks);

JsonRuntimeFormat.WriteRuntimeGraph(writer, packageSpec.RuntimeGraph);
Expand Down Expand Up @@ -365,29 +364,6 @@ private static void SetFrameworks(IObjectWriter writer, IList<TargetFrameworkInf
}
}

private static void SetTools(IObjectWriter writer, IList<ToolDependency> tools)
{
if (tools.Any())
{
writer.WriteObjectStart("tools");

foreach (var tool in tools)
{
writer.WriteObjectStart(tool.LibraryRange.Name);
writer.WriteNameValue("version", tool.LibraryRange.VersionRange.ToNormalizedString());

if (tool.Imports.Any())
{
SetImports(writer, tool.Imports);
}

writer.WriteObjectEnd();
}

writer.WriteObjectEnd();
}
}

private static void SetValue(IObjectWriter writer, string name, string value)
{
if (value != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15485,8 +15485,6 @@
],
"UAP,Version=v10.0": []
},
"tools": {},
"projectFileToolGroups": {},
"packageSpec": {
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0"
Expand Down
Loading

0 comments on commit 81491a5

Please sign in to comment.