Skip to content
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 26 commits into from
Oct 27, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
96e34f5
Add XDTHelper
brianary Oct 6, 2014
db4afb0
Add XDTHelper
brianary Oct 6, 2014
5918412
Merge branch 'XDTHelper' of https://github.com/brianary/FAKE into XDT…
brianary Oct 8, 2014
c28ed40
Add XDTHelper
brianary Oct 6, 2014
5ca6c9d
Merge branch 'XDTHelper' of https://github.com/brianary/FAKE into XDT…
brianary Oct 9, 2014
b3fa2bd
Add XDTHelper
brianary Oct 6, 2014
abd4d10
Add XDTHelper
brianary Oct 6, 2014
f5d8d82
Add XDTHelper
brianary Oct 6, 2014
629b7d4
Merge branch 'XDTHelper' of https://github.com/brianary/FAKE into XDT…
brianary Oct 17, 2014
00c965a
Fix proj file, remove autoload.
brianary Oct 24, 2014
f02eb8f
Update packages
forki Oct 20, 2014
6d3d55b
Bump version to 3.7.2
forki Oct 20, 2014
0f14f77
Replace list mode in command line with option -lt
ovu Oct 21, 2014
2fb7308
Add option in the command line option to list targets
ovu Oct 21, 2014
26e2139
Use priority list for nuget.exe selection - fixes #572
forki Oct 22, 2014
01b2f96
RELEASE_NOTES
forki Oct 22, 2014
1d380e6
Bump version to 3.7.3
forki Oct 22, 2014
93762a8
Bump version to 3.7.4
forki Oct 22, 2014
ad0cb94
Document the option -lt to list targets.
ovu Oct 22, 2014
9b36c17
RELEASE_NOTES
forki Oct 23, 2014
9265756
Bump version to 3.7.5
forki Oct 23, 2014
0dcf88e
Add XDTHelper
brianary Oct 6, 2014
f56430f
Add XDTHelper
brianary Oct 6, 2014
43338d9
Fix proj file, remove autoload.
brianary Oct 24, 2014
8d6f70c
More tolerance for missing XDT files, added simple tests.
brianary Oct 27, 2014
a90f397
Fix test reference file.
brianary Oct 27, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions FAKE.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30501.0
# Visual Studio Express 2013 for Windows Desktop
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0F0488CC-2580-4C07-9E16-3997480F0221}"
ProjectSection(SolutionItems) = preProject
Expand Down
3 changes: 2 additions & 1 deletion src/app/FakeLib/FakeLib.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
<Compile Include="FscHelper.fs" />
<Compile Include="HipChatNotificationHelper.fs" />
<Compile Include="XamarinHelper.fs" />
<Compile Include="XDTHelper.fs" />
<None Include="app.config" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -206,4 +207,4 @@
</Target>
-->
<Import Project="$(FSharpTargetsPath)" />
</Project>
</Project>
84 changes: 84 additions & 0 deletions src/app/FakeLib/XDTHelper.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
[<AutoOpen>]
Copy link
Member

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.

/// 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