-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow manually provided function.json file. Closes #50
- Loading branch information
1 parent
68ef61c
commit 7ae75e6
Showing
2 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
src/Microsoft.NET.Sdk.Functions/MakeFunction/BuildArtifactsLog.cs
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,74 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace MakeFunctionJson | ||
{ | ||
internal class BuildArtifactsLog | ||
{ | ||
private const string buildArtifactsLogName = "functionsSdk.out"; | ||
private readonly HashSet<string> _artifacts; | ||
private readonly FakeLogger _logger; | ||
private readonly string _logPath; | ||
|
||
public BuildArtifactsLog(string outputPath, FakeLogger logger) | ||
{ | ||
_logger = logger; | ||
_artifacts = new HashSet<string>(StringComparer.OrdinalIgnoreCase); | ||
_logPath = Path.Combine(outputPath, buildArtifactsLogName); | ||
try | ||
{ | ||
if (File.Exists(_logPath)) | ||
{ | ||
foreach (var line in File.ReadAllLines(_logPath)) | ||
{ | ||
_artifacts.Add(line); | ||
} | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
_logger.LogWarning($"Unable to read file {_logPath}"); | ||
_logger.LogWarningFromException(e); | ||
} | ||
} | ||
|
||
public bool TryClearBuildArtifactsLog() | ||
{ | ||
return Try(() => File.Delete(_logPath), $"Unable to clean file '{_logPath}'", true); | ||
} | ||
|
||
public bool TryAddBuildArtifact(string name) | ||
{ | ||
return Try(() => File.AppendAllLines(_logPath, new[] { name }), $"Unable to update file '{_logPath}'", true); | ||
} | ||
|
||
public bool IsBuildArtifact(string name) | ||
{ | ||
return _artifacts.Contains(name); | ||
} | ||
|
||
private bool Try(Action action, string message, bool isError) | ||
{ | ||
try | ||
{ | ||
action(); | ||
return true; | ||
} | ||
catch (Exception e) | ||
{ | ||
if (isError) | ||
{ | ||
_logger.LogError(message); | ||
_logger.LogErrorFromException(e); | ||
} | ||
else | ||
{ | ||
_logger.LogWarning(message); | ||
_logger.LogWarningFromException(e); | ||
} | ||
return false; | ||
} | ||
} | ||
} | ||
} |
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