-
Notifications
You must be signed in to change notification settings - Fork 585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add XDTHelper #556
Merged
Merged
Add XDTHelper #556
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
96e34f5
Add XDTHelper
brianary db4afb0
Add XDTHelper
brianary 5918412
Merge branch 'XDTHelper' of https://github.com/brianary/FAKE into XDT…
brianary c28ed40
Add XDTHelper
brianary 5ca6c9d
Merge branch 'XDTHelper' of https://github.com/brianary/FAKE into XDT…
brianary b3fa2bd
Add XDTHelper
brianary abd4d10
Add XDTHelper
brianary f5d8d82
Add XDTHelper
brianary 629b7d4
Merge branch 'XDTHelper' of https://github.com/brianary/FAKE into XDT…
brianary 00c965a
Fix proj file, remove autoload.
brianary f02eb8f
Update packages
forki 6d3d55b
Bump version to 3.7.2
forki 0f14f77
Replace list mode in command line with option -lt
ovu 2fb7308
Add option in the command line option to list targets
ovu 26e2139
Use priority list for nuget.exe selection - fixes #572
forki 01b2f96
RELEASE_NOTES
forki 1d380e6
Bump version to 3.7.3
forki 93762a8
Bump version to 3.7.4
forki ad0cb94
Document the option -lt to list targets.
ovu 9b36c17
RELEASE_NOTES
forki 9265756
Bump version to 3.7.5
forki 0dcf88e
Add XDTHelper
brianary f56430f
Add XDTHelper
brianary 43338d9
Fix proj file, remove autoload.
brianary 8d6f70c
More tolerance for missing XDT files, added simple tests.
brianary a90f397
Fix test reference file.
brianary File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
[<AutoOpen>] | ||
/// Contains functions used to transform config (or any XML) files using Microsoft's XML Document Transformations. | ||
module Fake.XDTHelper | ||
|
||
open System | ||
open System.IO | ||
open System.Xml | ||
open Microsoft.Web.XmlTransform | ||
|
||
/// Integrates XDT logging into FAKE logging. | ||
type FakeXmlTransformationLogger() = | ||
interface IXmlTransformationLogger with | ||
member x.EndSection(message, messageArgs) = | ||
postMessage <| LogMessage(String.Format(message, messageArgs), true) | ||
postMessage <| CloseTag("XDT") | ||
member x.EndSection(``type``, message, messageArgs) = | ||
match ``type`` with | ||
| MessageType.Verbose -> | ||
postMessage <| TraceMessage(String.Format(message, messageArgs), true) | ||
postMessage <| CloseTag("XDT") | ||
| _ -> | ||
postMessage <| LogMessage(String.Format(message, messageArgs), true) | ||
postMessage <| CloseTag("XDT") | ||
member x.LogError(message, messageArgs) = | ||
postMessage <| ErrorMessage(String.Format(message, messageArgs)) | ||
member x.LogError(file, message, messageArgs) = | ||
postMessage <| ErrorMessage(sprintf "File: %s" file) | ||
postMessage <| ErrorMessage(String.Format(message, messageArgs)) | ||
member x.LogError(file, lineNumber, linePosition, message, messageArgs) = | ||
postMessage <| ErrorMessage(sprintf "File: %s:%d:%d" file lineNumber linePosition) | ||
postMessage <| ErrorMessage(String.Format(message, messageArgs)) | ||
member x.LogErrorFromException(ex) = | ||
postMessage <| ErrorMessage(string ex) | ||
member x.LogErrorFromException(ex, file) = | ||
postMessage <| ErrorMessage(sprintf "File: %s" file) | ||
postMessage <| ErrorMessage(string ex) | ||
member x.LogErrorFromException(ex, file, lineNumber, linePosition) = | ||
postMessage <| ErrorMessage(sprintf "File: %s:%d:%d" file lineNumber linePosition) | ||
postMessage <| ErrorMessage(string ex) | ||
member x.LogMessage(message, messageArgs) = | ||
postMessage <| LogMessage(String.Format(message, messageArgs), true) | ||
member x.LogMessage(``type``, message, messageArgs) = | ||
match ``type`` with | ||
| MessageType.Verbose -> postMessage <| TraceMessage(String.Format(message, messageArgs), true) | ||
| _ -> postMessage <| LogMessage(String.Format(message, messageArgs), true) | ||
member x.LogWarning(message, messageArgs) = | ||
postMessage <| ImportantMessage(String.Format(message, messageArgs)) | ||
member x.LogWarning(file, message, messageArgs) = | ||
postMessage <| ImportantMessage(sprintf "File: %s" file) | ||
postMessage <| ImportantMessage(String.Format(message, messageArgs)) | ||
member x.LogWarning(file, lineNumber, linePosition, message, messageArgs) = | ||
postMessage <| ImportantMessage(sprintf "File: %s:%d:%d" file lineNumber linePosition) | ||
postMessage <| ImportantMessage(String.Format(message, messageArgs)) | ||
member x.StartSection(message, messageArgs) = | ||
postMessage <| OpenTag("XDT","StartSection") | ||
postMessage <| LogMessage(String.Format(message, messageArgs), true) | ||
member x.StartSection(``type``, message, messageArgs) = | ||
match ``type`` with | ||
| MessageType.Verbose -> | ||
postMessage <| OpenTag("XDT","StartSectionVerbose") | ||
postMessage <| TraceMessage(String.Format(message, messageArgs), true) | ||
| _ -> | ||
postMessage <| OpenTag("XDT","StartSectionNormal") | ||
postMessage <| LogMessage(String.Format(message, messageArgs), true) | ||
|
||
/// Reads XML file (typically a config file), makes changes according to XDT transform syntax, saves result. | ||
let TransformFile (inXmlFile:string) (transformFile:string) (outXmlFile:string) = | ||
if not <| File.Exists inXmlFile then new FileNotFoundException(sprintf "XML file %s does not exist." inXmlFile) |> raise | ||
if not <| File.Exists transformFile then new FileNotFoundException(sprintf "XML Document Transform file %s does not exist." transformFile) |> raise | ||
use xdtStream = new FileStream(Path.GetFullPath transformFile, FileMode.Open, FileAccess.Read) | ||
let fakeLogger = new FakeXmlTransformationLogger() | ||
use xdt = new XmlTransformation(xdtStream, fakeLogger) | ||
let xml = new XmlDocument() | ||
xml.Load(Path.GetFullPath inXmlFile) | ||
if not <| xdt.Apply(xml) then new InvalidOperationException(sprintf "Unable to transform %s with %s." inXmlFile transformFile) |> raise | ||
xml.Save(outXmlFile) | ||
|
||
/// Modifies an XML file in place using an XDT file named by inserting a .configName in between the filename and .extension. | ||
let TransformFileWithConfigName (configName:string) (xmlFile:string) = | ||
TransformFile xmlFile (Path.ChangeExtension(xmlFile, configName + (Path.GetExtension(xmlFile)))) xmlFile | ||
|
||
/// Modifies XML files in place using an XDT file named by inserting a .configName in between each filename and .extension. | ||
let TransformFilesWithConfigName (configName:string) (files:FileIncludes) = | ||
Seq.iter (TransformFileWithConfigName configName) files |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove auto open. We try to get rid of this.