Debian Codegraph @

external/nuget-buildtasks/src/Microsoft.NuGet.Build.Tasks/NuGetPackageObject.cs

raw symbols SCIP
1 // Copyright (c) .NET Foundation. All rights reserved.
2 // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
4 using System;
5 using System.Collections.Generic;
6 using System.IO;
7 using System.Linq;
8 using System.Text;
9 using System.Threading.Tasks;
10 using Newtonsoft.Json.Linq;
11
12 namespace Microsoft.NuGet.Build.Tasks
13 {
14 /// <summary>
15 /// Metedata and information for a package listed in the lock file.
16 /// </summary>
17 internal sealed class NuGetPackageObject
18 {
19 /// <summary>
20 /// A Lazy to get the full path to the package. In some cases we want to represent packages where we don't actually have
21 /// a path to it, but we don't care about that fact until we try getting assets to it. Thus we won't force us to have
22 /// a package path until we actually need it.
23 /// </summary>
24 private readonly Lazy<string> _fullPackagePath;
25
26 public NuGetPackageObject(string id, string version, Func<string> fullPackagePathGenerator, JObject targetObject, JObject libraryObject)
27 {
28 Id = id;
29 Version = version;
30 _fullPackagePath = new Lazy<string>(fullPackagePathGenerator);
31 TargetObject = targetObject;
32 LibraryObject = libraryObject;
33 }
34
35 public string Id { get; }
36 public string Version { get; }
37 public string RelativePackagePath => (string)LibraryObject["path"];
38
39 /// <summary>
40 /// The JSON object from the "targets" section in the project.lock.json for this package.
41 /// </summary>
42 public JObject TargetObject { get; }
43
44 /// <summary>
45 /// The JSON object from the "libraries" section in the project.lock.json for this package.
46 /// </summary>
47 public JObject LibraryObject { get; }
48
49 public string GetFullPathToFile(string relativePath)
50 {
51 relativePath = relativePath.Replace('/', Path.DirectorySeparatorChar);
52 return Path.Combine(_fullPackagePath.Value, relativePath);
53 }
54 }
55 }