forked from cake-build/cake
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for cake-build#2099. Also matches RFC-02 with a few changes.
Differences from RFC-02 1) The cache argument was removed. A new section was added to the cake.config file [Cache] with 2 possible properties Enabled and Path. Enabled defaults to false and Path defaults cache under the tools folder. 2) I originally used a time stamp to determine if the cache was valid or not. I have changed this to use a hash like pull request 2584 used. I did change it to use SHA1CryptoServiceProvider instead of MD5 since MD5 is not FIPS compliant.
- Loading branch information
1 parent
8539b72
commit daeecbe
Showing
8 changed files
with
284 additions
and
54 deletions.
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,45 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Diagnostics; | ||
|
||
using Cake.Core.Diagnostics; | ||
|
||
namespace Cake.Core.Utilities | ||
{ | ||
/// <summary> | ||
/// Disposable Stopwatch used for timing how long a section of code takes and writing the result to the log. | ||
/// </summary> | ||
public class DisposableStopwatch : IDisposable | ||
{ | ||
private readonly Stopwatch _sw; | ||
private readonly ICakeLog _log; | ||
private readonly string _message; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DisposableStopwatch"/> class. | ||
/// </summary> | ||
/// <param name="log">logger.</param> | ||
/// <param name="message">message.</param> | ||
public DisposableStopwatch(ICakeLog log, string message) | ||
{ | ||
_log = log; | ||
_message = message; | ||
_sw = Stopwatch.StartNew(); | ||
} | ||
|
||
/// <summary> | ||
/// Dispose. | ||
/// </summary> | ||
public void Dispose() | ||
{ | ||
if (_sw != null) | ||
{ | ||
_sw.Stop(); | ||
_log.Verbose("{0}: {1}ms", _message, _sw.ElapsedMilliseconds); | ||
} | ||
} | ||
} | ||
} |
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,65 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
|
||
namespace Cake.Core.Utilities | ||
{ | ||
/// <summary> | ||
/// Optimized hash generator. Using SHA1CryptoServiceProvider since it is FIPS compliant. | ||
/// </summary> | ||
public static class FastHash | ||
{ | ||
/// <summary> | ||
/// Generates a hash of the passed byte arrays. | ||
/// </summary> | ||
/// <param name="input">The binary data to hash.</param> | ||
/// <returns>The hash value.</returns> | ||
public static string GenerateHash(byte[] input) | ||
{ | ||
using (var sha1 = new SHA1CryptoServiceProvider()) | ||
{ | ||
sha1.TransformBlock(input, 0, input.Length, input, 0); | ||
|
||
// Just finalize with empty bytes so we don't have to iterate over the enumerable multiple times | ||
sha1.TransformFinalBlock(Encoding.UTF8.GetBytes(string.Empty), 0, 0); | ||
// Convert to hex string; This method is supposedly faster than the usual StringBuilder approach | ||
return ConvertBits(sha1.Hash); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Generates a hash of the passed byte arrays. | ||
/// </summary> | ||
/// <param name="inputs">The binary data to hash.</param> | ||
/// <returns>The hash value.</returns> | ||
public static string GenerateHash(IEnumerable<byte[]> inputs) | ||
{ | ||
using (var sha1 = new SHA1CryptoServiceProvider()) | ||
{ | ||
foreach (var input in inputs) | ||
{ | ||
sha1.TransformBlock(input, 0, input.Length, input, 0); | ||
} | ||
|
||
// Just finalize with empty bytes so we don't have to iterate over the enumerable multiple times | ||
sha1.TransformFinalBlock(Encoding.UTF8.GetBytes(string.Empty), 0, 0); | ||
// Convert to hex string; This method is supposedly faster than the usual StringBuilder approach | ||
return ConvertBits(sha1.Hash); | ||
} | ||
} | ||
|
||
private static string ConvertBits(byte[] hash) | ||
{ | ||
return BitConverter.ToString(hash) | ||
// without dashes | ||
.Replace("-", string.Empty) | ||
// make lowercase | ||
.ToLower(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.