ProjectContext provides access to Lockfile; Lockfile knows its path

This commit is contained in:
Mihai Codoban 2016-01-14 11:52:03 -08:00
parent 7555793363
commit 0ddf493f1d
4 changed files with 25 additions and 12 deletions

View file

@ -15,12 +15,19 @@ namespace Microsoft.DotNet.ProjectModel.Graph
public static readonly int CurrentVersion = 2;
public static readonly string FileName = "project.lock.json";
public string LockFilePath { get; }
public int Version { get; set; }
public IList<ProjectFileDependencyGroup> ProjectFileDependencyGroups { get; set; } = new List<ProjectFileDependencyGroup>();
public IList<LockFilePackageLibrary> PackageLibraries { get; set; } = new List<LockFilePackageLibrary>();
public IList<LockFileProjectLibrary> ProjectLibraries { get; set; } = new List<LockFileProjectLibrary>();
public IList<LockFileTarget> Targets { get; set; } = new List<LockFileTarget>();
public LockFile(string lockFilePath)
{
LockFilePath = lockFilePath;
}
public bool IsValidForProject(Project project)
{
string message;

View file

@ -15,26 +15,26 @@ namespace Microsoft.DotNet.ProjectModel.Graph
{
public static class LockFileReader
{
public static LockFile Read(string filePath)
public static LockFile Read(string lockFilePath)
{
using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
using (var stream = new FileStream(lockFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
try
{
return Read(stream);
return Read(lockFilePath, stream);
}
catch (FileFormatException ex)
{
throw ex.WithFilePath(filePath);
throw ex.WithFilePath(lockFilePath);
}
catch (Exception ex)
{
throw FileFormatException.Create(ex, filePath);
throw FileFormatException.Create(ex, lockFilePath);
}
}
}
internal static LockFile Read(Stream stream)
internal static LockFile Read(string lockFilePath, Stream stream)
{
try
{
@ -43,7 +43,7 @@ namespace Microsoft.DotNet.ProjectModel.Graph
if (jobject != null)
{
return ReadLockFile(jobject);
return ReadLockFile(lockFilePath, jobject);
}
else
{
@ -53,16 +53,16 @@ namespace Microsoft.DotNet.ProjectModel.Graph
catch
{
// Ran into parsing errors, mark it as unlocked and out-of-date
return new LockFile
return new LockFile(lockFilePath)
{
Version = int.MinValue
};
}
}
private static LockFile ReadLockFile(JsonObject cursor)
private static LockFile ReadLockFile(string lockFilePath, JsonObject cursor)
{
var lockFile = new LockFile();
var lockFile = new LockFile(lockFilePath);
lockFile.Version = ReadInt(cursor, "version", defaultValue: int.MinValue);
lockFile.Targets = ReadObject(cursor.ValueAsJsonObject("targets"), ReadTarget);
lockFile.ProjectFileDependencyGroups = ReadObject(cursor.ValueAsJsonObject("projectFileDependencyGroups"), ReadProjectFileDependencyGroup);

View file

@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.DotNet.ProjectModel.Compilation;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.ProjectModel.Resolution;
using NuGet.Frameworks;
@ -22,6 +23,8 @@ namespace Microsoft.DotNet.ProjectModel
public Project ProjectFile => RootProject.Project;
public LockFile LockFile { get; }
public string RootDirectory => GlobalSettings.DirectoryPath;
public string ProjectDirectory => ProjectFile.ProjectDirectory;
@ -36,7 +39,8 @@ namespace Microsoft.DotNet.ProjectModel
NuGetFramework targetFramework,
string runtimeIdentifier,
string packagesDirectory,
LibraryManager libraryManager)
LibraryManager libraryManager,
LockFile lockfile)
{
GlobalSettings = globalSettings;
RootProject = rootProject;
@ -44,6 +48,7 @@ namespace Microsoft.DotNet.ProjectModel
RuntimeIdentifier = runtimeIdentifier;
PackagesDirectory = packagesDirectory;
LibraryManager = libraryManager;
LockFile = lockfile;
}
public LibraryExporter CreateExporter(string configuration)

View file

@ -259,7 +259,8 @@ namespace Microsoft.DotNet.ProjectModel
TargetFramework,
target?.RuntimeIdentifier,
PackagesDirectory,
libraryManager);
libraryManager,
LockFile);
}
private void ResolveDependencies(Dictionary<LibraryKey, LibraryDescription> libraries,