diff options
Diffstat (limited to 'src/WixToolset.Core/Compiler.cs')
| -rw-r--r-- | src/WixToolset.Core/Compiler.cs | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/src/WixToolset.Core/Compiler.cs b/src/WixToolset.Core/Compiler.cs index 2dd7da4d..587c24fe 100644 --- a/src/WixToolset.Core/Compiler.cs +++ b/src/WixToolset.Core/Compiler.cs | |||
| @@ -68,10 +68,25 @@ namespace WixToolset.Core | |||
| 68 | Icon, | 68 | Icon, |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | public Compiler(IServiceProvider serviceProvider) | ||
| 72 | { | ||
| 73 | this.ServiceProvider = serviceProvider; | ||
| 74 | } | ||
| 75 | |||
| 76 | private IServiceProvider ServiceProvider { get; } | ||
| 77 | |||
| 71 | private ICompileContext Context { get; set; } | 78 | private ICompileContext Context { get; set; } |
| 72 | 79 | ||
| 73 | private CompilerCore Core { get; set; } | 80 | private CompilerCore Core { get; set; } |
| 74 | 81 | ||
| 82 | public string CompliationId { get; set; } | ||
| 83 | |||
| 84 | public string OutputPath { get; set; } | ||
| 85 | |||
| 86 | public Platform Platform { get; set; } | ||
| 87 | |||
| 88 | public XDocument SourceDocument { get; set; } | ||
| 89 | |||
| 75 | /// <summary> | 90 | /// <summary> |
| 76 | /// Gets or sets the platform which the compiler will use when defaulting 64-bit attributes and elements. | 91 | /// Gets or sets the platform which the compiler will use when defaulting 64-bit attributes and elements. |
| 77 | /// </summary> | 92 | /// </summary> |
| @@ -87,17 +102,21 @@ namespace WixToolset.Core | |||
| 87 | /// <summary> | 102 | /// <summary> |
| 88 | /// Compiles the provided Xml document into an intermediate object | 103 | /// Compiles the provided Xml document into an intermediate object |
| 89 | /// </summary> | 104 | /// </summary> |
| 90 | /// <param name="context">Context for the compile. The BaseURI property | ||
| 91 | /// should be properly set to get messages containing source line information.</param> | ||
| 92 | /// <returns>Intermediate object representing compiled source document.</returns> | 105 | /// <returns>Intermediate object representing compiled source document.</returns> |
| 93 | /// <remarks>This method is not thread-safe.</remarks> | 106 | /// <remarks>This method is not thread-safe.</remarks> |
| 94 | public Intermediate Compile(ICompileContext context) | 107 | public Intermediate Execute() |
| 95 | { | 108 | { |
| 96 | this.Context = context ?? throw new ArgumentNullException(nameof(context)); | 109 | this.Context = this.ServiceProvider.GetService<ICompileContext>(); |
| 110 | this.Context.Messaging = this.ServiceProvider.GetService<IMessaging>(); | ||
| 111 | this.Context.Extensions = this.ServiceProvider.GetService<IExtensionManager>().Create<ICompilerExtension>(); | ||
| 112 | this.Context.CompilationId = this.CompliationId; | ||
| 113 | this.Context.OutputPath = this.OutputPath; | ||
| 114 | this.Context.Platform = this.Platform; | ||
| 115 | this.Context.Source = this.SourceDocument; | ||
| 97 | 116 | ||
| 98 | var target = new Intermediate(); | 117 | var target = new Intermediate(); |
| 99 | 118 | ||
| 100 | if (String.IsNullOrEmpty(context.CompilationId)) | 119 | if (String.IsNullOrEmpty(this.Context.CompilationId)) |
| 101 | { | 120 | { |
| 102 | this.Context.CompilationId = target.Id; | 121 | this.Context.CompilationId = target.Id; |
| 103 | } | 122 | } |
| @@ -115,20 +134,20 @@ namespace WixToolset.Core | |||
| 115 | this.Context.Messaging.Write(ErrorMessages.DuplicateExtensionXmlSchemaNamespace(extension.GetType().ToString(), extension.Namespace.NamespaceName, collidingExtension.GetType().ToString())); | 134 | this.Context.Messaging.Write(ErrorMessages.DuplicateExtensionXmlSchemaNamespace(extension.GetType().ToString(), extension.Namespace.NamespaceName, collidingExtension.GetType().ToString())); |
| 116 | } | 135 | } |
| 117 | 136 | ||
| 118 | extension.PreCompile(context); | 137 | extension.PreCompile(this.Context); |
| 119 | } | 138 | } |
| 120 | 139 | ||
| 121 | // Try to compile it. | 140 | // Try to compile it. |
| 122 | try | 141 | try |
| 123 | { | 142 | { |
| 124 | var parseHelper = context.ServiceProvider.GetService<IParseHelper>(); | 143 | var parseHelper = this.Context.ServiceProvider.GetService<IParseHelper>(); |
| 125 | 144 | ||
| 126 | this.Core = new CompilerCore(target, this.Context.Messaging, parseHelper, extensionsByNamespace); | 145 | this.Core = new CompilerCore(target, this.Context.Messaging, parseHelper, extensionsByNamespace); |
| 127 | this.Core.ShowPedanticMessages = this.ShowPedanticMessages; | 146 | this.Core.ShowPedanticMessages = this.ShowPedanticMessages; |
| 128 | this.componentIdPlaceholdersResolver = new WixVariableResolver(this.Context.Messaging); | 147 | this.componentIdPlaceholdersResolver = new WixVariableResolver(this.Context.Messaging); |
| 129 | 148 | ||
| 130 | // parse the document | 149 | // parse the document |
| 131 | var source = context.Source; | 150 | var source = this.Context.Source; |
| 132 | var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(source.Root); | 151 | var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(source.Root); |
| 133 | if ("Wix" == source.Root.Name.LocalName) | 152 | if ("Wix" == source.Root.Name.LocalName) |
| 134 | { | 153 | { |
| @@ -158,7 +177,7 @@ namespace WixToolset.Core | |||
| 158 | } | 177 | } |
| 159 | finally | 178 | finally |
| 160 | { | 179 | { |
| 161 | foreach (var extension in context.Extensions) | 180 | foreach (var extension in this.Context.Extensions) |
| 162 | { | 181 | { |
| 163 | extension.PostCompile(target); | 182 | extension.PostCompile(target); |
| 164 | } | 183 | } |
