aboutsummaryrefslogtreecommitdiff
path: root/src/Projects/NativeProjectDom.cs
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2024-05-07 17:01:22 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2024-05-07 17:01:22 -0400
commit79d824cfb0e0cc9ff4fab0e0c546a83c0edaae1c (patch)
treed69e962a15493b2e36882810a2cc43d5a0de1a0b /src/Projects/NativeProjectDom.cs
parentb3015399591bd81b8519f0efa2ec177163f7d04a (diff)
initial commit
Diffstat (limited to 'src/Projects/NativeProjectDom.cs')
-rw-r--r--src/Projects/NativeProjectDom.cs57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/Projects/NativeProjectDom.cs b/src/Projects/NativeProjectDom.cs
new file mode 100644
index 0000000..f23a4a5
--- /dev/null
+++ b/src/Projects/NativeProjectDom.cs
@@ -0,0 +1,57 @@
+using System;
+using System.IO;
+using System.Text.Json;
+using System.Collections.Generic;
+
+using VNLib.Tools.Build.Executor.Model;
+
+namespace VNLib.Tools.Build.Executor.Projects
+{
+ internal sealed class NativeProjectDom : IProjectData
+ {
+ private Dictionary<string, string> _properties;
+
+ internal NativeProjectDom()
+ {
+ _properties = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
+ }
+
+ public string? this[string index] => _properties.GetValueOrDefault(index);
+
+ public string? Description => this["description"];
+ public string? Authors => this["author"];
+ public string? Copyright => this["copyright"];
+ public string? VersionString => this["version"];
+ public string? CompanyName => this["company"];
+ public string? Product => this["name"];
+ public string? RepoUrl => this["repository"];
+ public string? OutputDir => this["output_dir"];
+
+ public string[] GetProjectRefs()
+ {
+ return Array.Empty<string>();
+ }
+
+ public void Load(Stream stream)
+ {
+ //Read the json file
+ using JsonDocument doc = JsonDocument.Parse(stream, new JsonDocumentOptions
+ {
+ CommentHandling = JsonCommentHandling.Skip,
+ AllowTrailingCommas = true,
+ });
+
+ //Clear old properties
+ _properties.Clear();
+
+ //Load new properties that are strings only
+ foreach (JsonProperty prop in doc.RootElement.EnumerateObject())
+ {
+ if(prop.Value.ValueKind == JsonValueKind.String)
+ {
+ _properties[prop.Name] = prop.Value.GetString() ?? string.Empty;
+ }
+ }
+ }
+ }
+} \ No newline at end of file