diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2012-01-29 14:32:45 -0800 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2012-01-29 14:32:45 -0800 |
commit | 5fec515095ee10b522f414a03e78f282aaf520dc (patch) | |
tree | 204c75486639c23cdda2ef38b34d7e5050a1a2e3 /src/DotNetOpenAuth.BuildTasks/RegexFileReplace.cs | |
parent | f1a4155398635a4fd9f485eec817152627682704 (diff) | |
parent | 8f4165ee515728aca3faaa26e8354a40612e85e4 (diff) | |
download | DotNetOpenAuth-5fec515095ee10b522f414a03e78f282aaf520dc.zip DotNetOpenAuth-5fec515095ee10b522f414a03e78f282aaf520dc.tar.gz DotNetOpenAuth-5fec515095ee10b522f414a03e78f282aaf520dc.tar.bz2 |
Merge branch 'splitDlls'.
DNOA now builds and (in some cases) ships as many distinct assemblies.
Diffstat (limited to 'src/DotNetOpenAuth.BuildTasks/RegexFileReplace.cs')
-rw-r--r-- | src/DotNetOpenAuth.BuildTasks/RegexFileReplace.cs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.BuildTasks/RegexFileReplace.cs b/src/DotNetOpenAuth.BuildTasks/RegexFileReplace.cs new file mode 100644 index 0000000..294a859 --- /dev/null +++ b/src/DotNetOpenAuth.BuildTasks/RegexFileReplace.cs @@ -0,0 +1,55 @@ +//----------------------------------------------------------------------- +// <copyright file="RegexFileReplace.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.BuildTasks { + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Reflection; + using System.Text; + using Microsoft.Build.BuildEngine; + using Microsoft.Build.Framework; + using Microsoft.Build.Utilities; + using System.Text.RegularExpressions; + + public class RegexFileReplace : Task { + /// <summary> + /// Gets or sets the set of files to search. + /// </summary> + [Required] + public ITaskItem[] Files { get; set; } + + /// <summary> + /// Gets or sets the files to save the changed files to. This may be the same as the input files to make the change in place. + /// </summary> + public ITaskItem[] OutputFiles { get; set; } + + public string Pattern { get; set; } + + public string Replacement { get; set; } + + /// <summary> + /// Executes this instance. + /// </summary> + public override bool Execute() { + if (this.OutputFiles == null || this.OutputFiles.Length == 0) { + this.OutputFiles = this.Files; + } + + foreach (var file in this.Files) { + string[] lines = File.ReadAllLines(file.ItemSpec); + for (int i = 0; i < lines.Length; i++) { + lines[i] = Regex.Replace(lines[i], this.Pattern, this.Replacement); + } + + File.WriteAllLines(file.ItemSpec, lines); + } + + return !this.Log.HasLoggedErrors; + } + } +} |