Skip to content

Commit 7bcab36

Browse files
committed
Add fileMappings to the DTOs
1 parent 20bd1d8 commit 7bcab36

File tree

8 files changed

+99
-13
lines changed

8 files changed

+99
-13
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#nullable enable
5+
6+
using System.Collections.Generic;
7+
8+
namespace Microsoft.Web.LibraryManager.Contracts
9+
{
10+
/// <summary>
11+
///
12+
/// </summary>
13+
public class FileMapping
14+
{
15+
/// <summary>
16+
/// Root path within the library content for this file mapping entry.
17+
/// </summary>
18+
public string? Root { get; set; }
19+
20+
/// <summary>
21+
/// Destination folder within the project.
22+
/// </summary>
23+
public string? Destination { get; set; }
24+
25+
/// <summary>
26+
/// The file patterns to match for this mapping, relative to <see cref="Root"/>. Accepts glob patterns.
27+
/// </summary>
28+
public IReadOnlyList<string>? Files { get; set; }
29+
}
30+
}

src/LibraryManager.Contracts/ILibraryInstallationState.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public interface ILibraryInstallationState
3030
/// </summary>
3131
IReadOnlyList<string> Files { get; }
3232

33+
/// <summary>
34+
/// List of mappings of a portion of library assets to a unique destination.
35+
/// </summary>
36+
IReadOnlyList<FileMapping> FileMappings { get; }
37+
3338
/// <summary>
3439
/// The path relative to the working directory to copy the files to.
3540
/// </summary>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Collections.Generic;
5+
using Newtonsoft.Json;
6+
7+
#nullable enable
8+
9+
namespace Microsoft.Web.LibraryManager.Json
10+
{
11+
internal class FileMapping
12+
{
13+
[JsonProperty(ManifestConstants.Root)]
14+
public string? Root { get; set; }
15+
16+
[JsonProperty(ManifestConstants.Destination)]
17+
public string? Destination { get; set; }
18+
19+
[JsonProperty(ManifestConstants.Files)]
20+
public IReadOnlyList<string>? Files { get; set; }
21+
}
22+
}

src/LibraryManager/Json/LibraryInstallationStateOnDisk.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System;
54
using System.Collections.Generic;
6-
using System.Text;
75
using Newtonsoft.Json;
86

97
namespace Microsoft.Web.LibraryManager.Json
@@ -21,5 +19,8 @@ internal class LibraryInstallationStateOnDisk
2119

2220
[JsonProperty(ManifestConstants.Files)]
2321
public IReadOnlyList<string> Files { get; set; }
22+
23+
[JsonProperty(ManifestConstants.FileMappings)]
24+
public IReadOnlyList<FileMapping> FileMappings { get; set; }
2425
}
2526
}

src/LibraryManager/Json/LibraryStateToFileConverter.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Linq;
45
using Microsoft.Web.LibraryManager.Contracts;
56
using Microsoft.Web.LibraryManager.LibraryNaming;
67

@@ -33,7 +34,8 @@ public ILibraryInstallationState ConvertToLibraryInstallationState(LibraryInstal
3334
IsUsingDefaultProvider = string.IsNullOrEmpty(stateOnDisk.ProviderId),
3435
ProviderId = provider,
3536
DestinationPath = destination,
36-
Files = stateOnDisk.Files
37+
Files = stateOnDisk.Files,
38+
FileMappings = stateOnDisk.FileMappings.Select(f => new Contracts.FileMapping { Destination = f.Destination, Root = f.Root, Files = f.Files }).ToList(),
3739
};
3840

3941
(state.Name, state.Version) = LibraryIdToNameAndVersionConverter.Instance.GetLibraryNameAndVersion(stateOnDisk.LibraryId, provider);
@@ -49,13 +51,22 @@ public LibraryInstallationStateOnDisk ConvertToLibraryInstallationStateOnDisk(IL
4951
}
5052

5153
string provider = string.IsNullOrEmpty(state.ProviderId) ? _defaultProvider : state.ProviderId;
52-
return new LibraryInstallationStateOnDisk()
54+
var serializeState = new LibraryInstallationStateOnDisk()
5355
{
5456
ProviderId = state.IsUsingDefaultProvider ? null : state.ProviderId,
5557
DestinationPath = state.IsUsingDefaultDestination ? null : state.DestinationPath,
5658
Files = state.Files,
57-
LibraryId = LibraryIdToNameAndVersionConverter.Instance.GetLibraryId(state.Name, state.Version, provider)
59+
LibraryId = LibraryIdToNameAndVersionConverter.Instance.GetLibraryId(state.Name, state.Version, provider),
60+
FileMappings = state.FileMappings?.Select(f => new FileMapping { Destination = f.Destination, Root = f.Root, Files = f.Files }).ToList(),
5861
};
62+
63+
if (serializeState is { FileMappings: { Count: 0} })
64+
{
65+
// if FileMappings is empty, omit it from serialization
66+
serializeState.FileMappings = null;
67+
}
68+
69+
return serializeState;
5970
}
6071
}
6172
}

src/LibraryManager/LibraryInstallationState.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ internal class LibraryInstallationState : ILibraryInstallationState
4646
/// </summary>
4747
public string Version { get; set; }
4848

49+
/// <summary>
50+
/// Mappings for multiple different files within the library to different destinations.
51+
/// </summary>
52+
public IReadOnlyList<FileMapping> FileMappings { get; set; }
53+
4954
/// <summary>Internal use only</summary>
5055
public static LibraryInstallationState FromInterface(ILibraryInstallationState state,
5156
string defaultProviderId = null,

src/LibraryManager/ManifestConstants.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,55 @@ namespace Microsoft.Web.LibraryManager
1313
public static class ManifestConstants
1414
{
1515
/// <summary>
16-
/// libman.json libraries element
16+
/// libman.json libraries element
1717
/// </summary>
1818
public const string Version = "version";
1919

2020
/// <summary>
21-
/// libman.json libraries element
21+
/// libman.json libraries element
2222
/// </summary>
2323
public const string Libraries = "libraries";
2424

2525
/// <summary>
26-
/// libman.json library element
26+
/// libman.json library element
2727
/// </summary>
2828
public const string Library = "library";
2929

3030
/// <summary>
31-
/// libman.json destination element
31+
/// libman.json destination element
3232
/// </summary>
3333
public const string Destination = "destination";
3434

3535
/// <summary>
36-
/// libman.json defaultDestination element
36+
/// libman.json defaultDestination element
3737
/// </summary>
3838
public const string DefaultDestination = "defaultDestination";
3939

4040
/// <summary>
41-
/// libman.json provider element
41+
/// libman.json provider element
4242
/// </summary>
4343
public const string Provider = "provider";
4444

4545
/// <summary>
46-
/// libman.json defaultProvider element
46+
/// libman.json defaultProvider element
4747
/// </summary>
4848
public const string DefaultProvider = "defaultProvider";
4949

5050
/// <summary>
51-
/// libman.json files element
51+
/// libman.json files element
5252
/// </summary>
5353
public const string Files = "files";
5454

55+
/// <summary>
56+
/// libman.json fileMappings element
57+
/// </summary>
58+
public const string FileMappings = "fileMappings";
59+
60+
/// <summary>
61+
/// libman.json root element
62+
/// </summary>
63+
public const string Root = "root";
64+
5565
/// <summary>
5666
/// For providers that support versioned libraries, this represents the evergreen latest version
5767
/// </summary>

test/LibraryManager.Mocks/LibraryInstallationState.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,7 @@ public class LibraryInstallationState : ILibraryInstallationState
4646
/// Indicates whether the library is using the default provider.
4747
/// </summary>
4848
public bool IsUsingDefaultProvider { get; set; }
49+
50+
public IReadOnlyList<FileMapping> FileMappings => throw new System.NotImplementedException();
4951
}
5052
}

0 commit comments

Comments
 (0)