ProjectContext provides access to Lockfile; Lockfile knows its path
This commit is contained in:
parent
7555793363
commit
0ddf493f1d
4 changed files with 25 additions and 12 deletions
|
@ -15,12 +15,19 @@ namespace Microsoft.DotNet.ProjectModel.Graph
|
||||||
public static readonly int CurrentVersion = 2;
|
public static readonly int CurrentVersion = 2;
|
||||||
public static readonly string FileName = "project.lock.json";
|
public static readonly string FileName = "project.lock.json";
|
||||||
|
|
||||||
|
public string LockFilePath { get; }
|
||||||
|
|
||||||
public int Version { get; set; }
|
public int Version { get; set; }
|
||||||
public IList<ProjectFileDependencyGroup> ProjectFileDependencyGroups { get; set; } = new List<ProjectFileDependencyGroup>();
|
public IList<ProjectFileDependencyGroup> ProjectFileDependencyGroups { get; set; } = new List<ProjectFileDependencyGroup>();
|
||||||
public IList<LockFilePackageLibrary> PackageLibraries { get; set; } = new List<LockFilePackageLibrary>();
|
public IList<LockFilePackageLibrary> PackageLibraries { get; set; } = new List<LockFilePackageLibrary>();
|
||||||
public IList<LockFileProjectLibrary> ProjectLibraries { get; set; } = new List<LockFileProjectLibrary>();
|
public IList<LockFileProjectLibrary> ProjectLibraries { get; set; } = new List<LockFileProjectLibrary>();
|
||||||
public IList<LockFileTarget> Targets { get; set; } = new List<LockFileTarget>();
|
public IList<LockFileTarget> Targets { get; set; } = new List<LockFileTarget>();
|
||||||
|
|
||||||
|
public LockFile(string lockFilePath)
|
||||||
|
{
|
||||||
|
LockFilePath = lockFilePath;
|
||||||
|
}
|
||||||
|
|
||||||
public bool IsValidForProject(Project project)
|
public bool IsValidForProject(Project project)
|
||||||
{
|
{
|
||||||
string message;
|
string message;
|
||||||
|
|
|
@ -15,26 +15,26 @@ namespace Microsoft.DotNet.ProjectModel.Graph
|
||||||
{
|
{
|
||||||
public static class LockFileReader
|
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
|
try
|
||||||
{
|
{
|
||||||
return Read(stream);
|
return Read(lockFilePath, stream);
|
||||||
}
|
}
|
||||||
catch (FileFormatException ex)
|
catch (FileFormatException ex)
|
||||||
{
|
{
|
||||||
throw ex.WithFilePath(filePath);
|
throw ex.WithFilePath(lockFilePath);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
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
|
try
|
||||||
{
|
{
|
||||||
|
@ -43,7 +43,7 @@ namespace Microsoft.DotNet.ProjectModel.Graph
|
||||||
|
|
||||||
if (jobject != null)
|
if (jobject != null)
|
||||||
{
|
{
|
||||||
return ReadLockFile(jobject);
|
return ReadLockFile(lockFilePath, jobject);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -53,16 +53,16 @@ namespace Microsoft.DotNet.ProjectModel.Graph
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
// Ran into parsing errors, mark it as unlocked and out-of-date
|
// Ran into parsing errors, mark it as unlocked and out-of-date
|
||||||
return new LockFile
|
return new LockFile(lockFilePath)
|
||||||
{
|
{
|
||||||
Version = int.MinValue
|
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.Version = ReadInt(cursor, "version", defaultValue: int.MinValue);
|
||||||
lockFile.Targets = ReadObject(cursor.ValueAsJsonObject("targets"), ReadTarget);
|
lockFile.Targets = ReadObject(cursor.ValueAsJsonObject("targets"), ReadTarget);
|
||||||
lockFile.ProjectFileDependencyGroups = ReadObject(cursor.ValueAsJsonObject("projectFileDependencyGroups"), ReadProjectFileDependencyGroup);
|
lockFile.ProjectFileDependencyGroups = ReadObject(cursor.ValueAsJsonObject("projectFileDependencyGroups"), ReadProjectFileDependencyGroup);
|
||||||
|
|
|
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.DotNet.ProjectModel.Compilation;
|
using Microsoft.DotNet.ProjectModel.Compilation;
|
||||||
|
using Microsoft.DotNet.ProjectModel.Graph;
|
||||||
using Microsoft.DotNet.ProjectModel.Resolution;
|
using Microsoft.DotNet.ProjectModel.Resolution;
|
||||||
using NuGet.Frameworks;
|
using NuGet.Frameworks;
|
||||||
|
|
||||||
|
@ -22,6 +23,8 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
|
|
||||||
public Project ProjectFile => RootProject.Project;
|
public Project ProjectFile => RootProject.Project;
|
||||||
|
|
||||||
|
public LockFile LockFile { get; }
|
||||||
|
|
||||||
public string RootDirectory => GlobalSettings.DirectoryPath;
|
public string RootDirectory => GlobalSettings.DirectoryPath;
|
||||||
|
|
||||||
public string ProjectDirectory => ProjectFile.ProjectDirectory;
|
public string ProjectDirectory => ProjectFile.ProjectDirectory;
|
||||||
|
@ -36,7 +39,8 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
NuGetFramework targetFramework,
|
NuGetFramework targetFramework,
|
||||||
string runtimeIdentifier,
|
string runtimeIdentifier,
|
||||||
string packagesDirectory,
|
string packagesDirectory,
|
||||||
LibraryManager libraryManager)
|
LibraryManager libraryManager,
|
||||||
|
LockFile lockfile)
|
||||||
{
|
{
|
||||||
GlobalSettings = globalSettings;
|
GlobalSettings = globalSettings;
|
||||||
RootProject = rootProject;
|
RootProject = rootProject;
|
||||||
|
@ -44,6 +48,7 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
RuntimeIdentifier = runtimeIdentifier;
|
RuntimeIdentifier = runtimeIdentifier;
|
||||||
PackagesDirectory = packagesDirectory;
|
PackagesDirectory = packagesDirectory;
|
||||||
LibraryManager = libraryManager;
|
LibraryManager = libraryManager;
|
||||||
|
LockFile = lockfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LibraryExporter CreateExporter(string configuration)
|
public LibraryExporter CreateExporter(string configuration)
|
||||||
|
|
|
@ -259,7 +259,8 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
TargetFramework,
|
TargetFramework,
|
||||||
target?.RuntimeIdentifier,
|
target?.RuntimeIdentifier,
|
||||||
PackagesDirectory,
|
PackagesDirectory,
|
||||||
libraryManager);
|
libraryManager,
|
||||||
|
LockFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ResolveDependencies(Dictionary<LibraryKey, LibraryDescription> libraries,
|
private void ResolveDependencies(Dictionary<LibraryKey, LibraryDescription> libraries,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue