aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/Librarian.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core/Librarian.cs')
-rw-r--r--src/WixToolset.Core/Librarian.cs52
1 files changed, 19 insertions, 33 deletions
diff --git a/src/WixToolset.Core/Librarian.cs b/src/WixToolset.Core/Librarian.cs
index abd6c844..5db4b219 100644
--- a/src/WixToolset.Core/Librarian.cs
+++ b/src/WixToolset.Core/Librarian.cs
@@ -8,14 +8,13 @@ namespace WixToolset.Core
8 using WixToolset.Core.Bind; 8 using WixToolset.Core.Bind;
9 using WixToolset.Core.Link; 9 using WixToolset.Core.Link;
10 using WixToolset.Data; 10 using WixToolset.Data;
11 using WixToolset.Extensibility;
12 using WixToolset.Extensibility.Data; 11 using WixToolset.Extensibility.Data;
13 using WixToolset.Extensibility.Services; 12 using WixToolset.Extensibility.Services;
14 13
15 /// <summary> 14 /// <summary>
16 /// Core librarian tool. 15 /// Core librarian tool.
17 /// </summary> 16 /// </summary>
18 internal class Librarian 17 internal class Librarian : ILibrarian
19 { 18 {
20 internal Librarian(IServiceProvider serviceProvider) 19 internal Librarian(IServiceProvider serviceProvider)
21 { 20 {
@@ -28,42 +27,29 @@ namespace WixToolset.Core
28 27
29 private IMessaging Messaging { get; } 28 private IMessaging Messaging { get; }
30 29
31 private ILibraryContext Context { get; set; }
32
33 public bool BindFiles { get; set; }
34
35 public IEnumerable<BindPath> BindPaths { get; set; }
36
37 public IEnumerable<Localization> Localizations { get; set; }
38
39 public IEnumerable<Intermediate> Intermediates { get; set; }
40
41 /// <summary> 30 /// <summary>
42 /// Create a library by combining several intermediates (objects). 31 /// Create a library by combining several intermediates (objects).
43 /// </summary> 32 /// </summary>
44 /// <param name="sections">The sections to combine into a library.</param> 33 /// <param name="sections">The sections to combine into a library.</param>
45 /// <returns>Returns the new library.</returns> 34 /// <returns>Returns the new library.</returns>
46 public Intermediate Execute() 35 public Intermediate Combine(ILibraryContext context)
47 { 36 {
48 this.Context = new LibraryContext(this.ServiceProvider); 37 if (String.IsNullOrEmpty(context.LibraryId))
49 this.Context.BindFiles = this.BindFiles; 38 {
50 this.Context.BindPaths = this.BindPaths; 39 context.LibraryId = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).TrimEnd('=').Replace('+', '.').Replace('/', '_');
51 this.Context.Extensions = this.ServiceProvider.GetService<IExtensionManager>().Create<ILibrarianExtension>(); 40 }
52 this.Context.Localizations = this.Localizations; 41
53 this.Context.LibraryId = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).TrimEnd('=').Replace('+', '.').Replace('/', '_'); 42 foreach (var extension in context.Extensions)
54 this.Context.Intermediates = this.Intermediates;
55
56 foreach (var extension in this.Context.Extensions)
57 { 43 {
58 extension.PreCombine(this.Context); 44 extension.PreCombine(context);
59 } 45 }
60 46
61 Intermediate library = null; 47 Intermediate library = null;
62 try 48 try
63 { 49 {
64 var sections = this.Context.Intermediates.SelectMany(i => i.Sections).ToList(); 50 var sections = context.Intermediates.SelectMany(i => i.Sections).ToList();
65 51
66 var collate = new CollateLocalizationsCommand(this.Messaging, this.Context.Localizations); 52 var collate = new CollateLocalizationsCommand(this.Messaging, context.Localizations);
67 var localizationsByCulture = collate.Execute(); 53 var localizationsByCulture = collate.Execute();
68 54
69 if (this.Messaging.EncounteredError) 55 if (this.Messaging.EncounteredError)
@@ -71,20 +57,20 @@ namespace WixToolset.Core
71 return null; 57 return null;
72 } 58 }
73 59
74 var embedFilePaths = this.ResolveFilePathsToEmbed(sections); 60 var embedFilePaths = this.ResolveFilePathsToEmbed(context, sections);
75 61
76 foreach (var section in sections) 62 foreach (var section in sections)
77 { 63 {
78 section.LibraryId = this.Context.LibraryId; 64 section.LibraryId = context.LibraryId;
79 } 65 }
80 66
81 library = new Intermediate(this.Context.LibraryId, sections, localizationsByCulture, embedFilePaths); 67 library = new Intermediate(context.LibraryId, sections, localizationsByCulture, embedFilePaths);
82 68
83 this.Validate(library); 69 this.Validate(library);
84 } 70 }
85 finally 71 finally
86 { 72 {
87 foreach (var extension in this.Context.Extensions) 73 foreach (var extension in context.Extensions)
88 { 74 {
89 extension.PostCombine(library); 75 extension.PostCombine(library);
90 } 76 }
@@ -99,7 +85,7 @@ namespace WixToolset.Core
99 /// <param name="library">Library to validate.</param> 85 /// <param name="library">Library to validate.</param>
100 private void Validate(Intermediate library) 86 private void Validate(Intermediate library)
101 { 87 {
102 FindEntrySectionAndLoadSymbolsCommand find = new FindEntrySectionAndLoadSymbolsCommand(this.Messaging, library.Sections); 88 var find = new FindEntrySectionAndLoadSymbolsCommand(this.Messaging, library.Sections);
103 find.Execute(); 89 find.Execute();
104 90
105 // TODO: Consider bringing this sort of verification back. 91 // TODO: Consider bringing this sort of verification back.
@@ -113,16 +99,16 @@ namespace WixToolset.Core
113 // } 99 // }
114 } 100 }
115 101
116 private List<string> ResolveFilePathsToEmbed(IEnumerable<IntermediateSection> sections) 102 private List<string> ResolveFilePathsToEmbed(ILibraryContext context, IEnumerable<IntermediateSection> sections)
117 { 103 {
118 var embedFilePaths = new List<string>(); 104 var embedFilePaths = new List<string>();
119 105
120 // Resolve paths to files that are to be embedded in the library. 106 // Resolve paths to files that are to be embedded in the library.
121 if (this.Context.BindFiles) 107 if (context.BindFiles)
122 { 108 {
123 var variableResolver = new WixVariableResolver(this.Messaging); 109 var variableResolver = new WixVariableResolver(this.Messaging);
124 110
125 var fileResolver = new FileResolver(this.Context.BindPaths, this.Context.Extensions); 111 var fileResolver = new FileResolver(context.BindPaths, context.Extensions);
126 112
127 foreach (var tuple in sections.SelectMany(s => s.Tuples)) 113 foreach (var tuple in sections.SelectMany(s => s.Tuples))
128 { 114 {