Skip to content

Commit 9bff257

Browse files
authored
Simplify HOCON data structure. (akkadotnet#240)
* Move Hocon.Immutable into Hocon namespace * Mark old classes as internal classes * Convert old data type to new ones * Convert old data type to new data type * Improve backward compatibility * Convert old Config to use the new data structure. * Add caching to Config * Update ApiApprover text file to reflect the new data structure. * Bump Linux .NET SDK version from 2.1.500 to 2.1.504 to match the windows SDK version. * force csproj LangVersion tag to 7.2 * Remove throw statement, throw does not make sense since this is not an irrepairable critical error. * Add missing getters needed for Akka compatibility * Add serialization hacks (surrogate) from Akka.NET to fix serialization in Akka * Remove Newtonsoft.Json nuget dependency * Defensive coding * Adjust surface API * Clean ghost Immutable projects from .sln file. Prevented CI build from running. * Prepend Hocon to classes names that are too generic * Remove caching from Config * Force garbage collection so that memory allocation stat result only reflects the memory cost of the lookup spec * Update the approved API list to reflect the static extension class name refactor
1 parent 204f64c commit 9bff257

File tree

60 files changed

+6632
-3135
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+6632
-3135
lines changed

Hocon.sln

-12
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hocon.Extensions.Configurat
2929
EndProject
3030
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hocon.Extensions.Configuration.Tests", "src\Hocon.Extensions.Configuration.Tests\Hocon.Extensions.Configuration.Tests.csproj", "{F7862234-3330-43DE-86BB-D6E67F2146BC}"
3131
EndProject
32-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hocon.Immutable", "src\Hocon.Immutable\Hocon.Immutable.csproj", "{FB439177-CA10-4BA8-993D-A51D1BEE2A0E}"
33-
EndProject
34-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hocon.Immutable.Tests", "src\Hocon.Immutable.Tests\Hocon.Immutable.Tests.csproj", "{FEEC6F6B-2511-4BEC-9568-4E6AE6C1D275}"
35-
EndProject
3632
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SerializationDebug", "src\examples\SerializationDebug\SerializationDebug.csproj", "{6D1D4813-7AB6-4268-A9DF-627A60E08FB1}"
3733
EndProject
3834
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hocon.API.Tests", "src\Hocon.API.Tests\Hocon.API.Tests.csproj", "{2EC48C29-E5A7-4C3F-AB26-1C121E098867}"
@@ -93,14 +89,6 @@ Global
9389
{F7862234-3330-43DE-86BB-D6E67F2146BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
9490
{F7862234-3330-43DE-86BB-D6E67F2146BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
9591
{F7862234-3330-43DE-86BB-D6E67F2146BC}.Release|Any CPU.Build.0 = Release|Any CPU
96-
{FB439177-CA10-4BA8-993D-A51D1BEE2A0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
97-
{FB439177-CA10-4BA8-993D-A51D1BEE2A0E}.Debug|Any CPU.Build.0 = Debug|Any CPU
98-
{FB439177-CA10-4BA8-993D-A51D1BEE2A0E}.Release|Any CPU.ActiveCfg = Release|Any CPU
99-
{FB439177-CA10-4BA8-993D-A51D1BEE2A0E}.Release|Any CPU.Build.0 = Release|Any CPU
100-
{FEEC6F6B-2511-4BEC-9568-4E6AE6C1D275}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
101-
{FEEC6F6B-2511-4BEC-9568-4E6AE6C1D275}.Debug|Any CPU.Build.0 = Debug|Any CPU
102-
{FEEC6F6B-2511-4BEC-9568-4E6AE6C1D275}.Release|Any CPU.ActiveCfg = Release|Any CPU
103-
{FEEC6F6B-2511-4BEC-9568-4E6AE6C1D275}.Release|Any CPU.Build.0 = Release|Any CPU
10492
{6D1D4813-7AB6-4268-A9DF-627A60E08FB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
10593
{6D1D4813-7AB6-4268-A9DF-627A60E08FB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
10694
{6D1D4813-7AB6-4268-A9DF-627A60E08FB1}.Release|Any CPU.ActiveCfg = Release|Any CPU

build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ NUGET_EXE=$TOOLS_DIR/nuget.exe
1111
NUGET_URL=https://dist.nuget.org/win-x86-commandline/v4.0.0/nuget.exe
1212
FAKE_VERSION=4.61.2
1313
FAKE_EXE=$TOOLS_DIR/FAKE/tools/FAKE.exe
14-
DOTNET_VERSION=2.1.500
14+
DOTNET_VERSION=2.1.504
1515
DOTNET_INSTALLER_URL=https://raw.githubusercontent.com/dotnet/cli/v$DOTNET_VERSION/scripts/obtain/dotnet-install.sh
1616
DOTNET_CHANNEL=LTS;
1717
DOCFX_VERSION=2.40.5

src/Hocon.Immutable.Tests/ApiTest.cs renamed to src/HOCON.Tests/ApiTest.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
using System.Collections.Generic;
99
using System.Linq;
1010
using System.Numerics;
11-
using Hocon.Immutable.Extensions;
1211
using Xunit;
1312

14-
namespace Hocon.Immutable.Tests
13+
namespace Hocon.Tests
1514
{
1615
public class ApiTest
1716
{
@@ -56,7 +55,7 @@ public class ApiTest
5655
[MemberData(nameof(ObjectArrayData))]
5756
public void CanIntelligentlyUseIndexerTypeToAccessMembers(string hocon)
5857
{
59-
var config = HoconParser.Parse(hocon).ToHoconImmutable();
58+
var config = HoconParser.Parse(hocon);
6059

6160
Assert.Equal(1, config["a"][0]["a"].GetInt());
6261
Assert.Equal(2, config["a"][0]["b"].GetInt());
@@ -128,7 +127,7 @@ public void CanAutomaticallyCastValuesToPrimitives()
128127
129128
root_2 : 1234
130129
}";
131-
var config = HoconParser.Parse(hocon).ToHoconImmutable();
130+
var config = HoconParser.Parse(hocon);
132131

133132
#pragma warning disable 618
134133
Assert.True(config.Value.GetBoolean("root.bool")); // legacy

src/HOCON.Tests/Extensions/IsStringTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class IsStringTests
2424
}
2525
";
2626

27-
public HoconRoot TestHocon => HoconParser.Parse(RawTestHocon);
27+
public HoconObject TestHocon => HoconParser.Parse(RawTestHocon);
2828

2929
[Fact]
3030
public void IsString_should_detect_String_literals()

src/HOCON.Tests/QuotedString.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ public void Bugfix_190_should_unquote_quotedstrings_on_parse()
2626
";
2727

2828
var parsed = HoconParser.Parse(hocon);
29-
var unwrapped = parsed.GetObject("adapters").ToDictionary(x => x.Key, v => v.Value.GetString());
29+
var unwrapped = parsed.GetObject("adapters").Unwrapped;
3030

3131
// check to make sure these strings aren't quoted
32-
unwrapped["gremlin"].Should().Be("Akka.Remote.Transport.FailureInjectorProvider,Akka.Remote");
33-
unwrapped["trttl"].Should().Be("Akka.Remote.Transport.ThrottlerProvider,Akka.Remote");
32+
unwrapped["gremlin"].Should().Equals("Akka.Remote.Transport.FailureInjectorProvider,Akka.Remote");
33+
unwrapped["trttl"].Should().Equals("Akka.Remote.Transport.ThrottlerProvider,Akka.Remote");
3434
}
3535
}
3636
}

src/Hocon.API.Tests/Hocon.API.Tests.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
<ItemGroup>
4646
<ProjectReference Include="..\Hocon.Configuration\Hocon.Configuration.csproj" />
4747
<ProjectReference Include="..\Hocon.Extensions.Configuration\Hocon.Extensions.Configuration.csproj" />
48-
<ProjectReference Include="..\Hocon.Immutable\Hocon.Immutable.csproj" />
4948
<ProjectReference Include="..\Hocon\Hocon.csproj" />
5049
</ItemGroup>
5150

src/Hocon.API.Tests/HoconAPISpec.ApproveConfiguration.approved.txt

+13-15
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,29 @@ namespace Hocon
77
protected CDataConfigurationElement() { }
88
protected override void DeserializeElement(System.Xml.XmlReader reader, bool serializeCollectionKey) { }
99
}
10-
public class Config : Hocon.HoconRoot, System.IEquatable<Hocon.Config>, System.Runtime.Serialization.ISerializable
10+
public class Config : Hocon.HoconObject, System.IEquatable<Hocon.Config>, System.Runtime.Serialization.ISerializable
1111
{
12-
[System.ObsoleteAttribute("For json serialization/deserialization only", true)]
13-
protected Config() { }
14-
protected Config(Hocon.HoconValue value) { }
15-
protected Config(Hocon.HoconValue value, Hocon.Config fallback) { }
16-
public Config(Hocon.HoconRoot root) { }
17-
public Config(Hocon.HoconRoot root, Hocon.Config fallback) { }
12+
public Config(Hocon.HoconElement root) { }
1813
[System.ObsoleteAttribute("Used for serialization only", true)]
19-
public Config(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
14+
protected Config(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
2015
public static Hocon.Config Empty { get; }
21-
public virtual System.Collections.Generic.IReadOnlyList<Hocon.HoconValue> Fallbacks { get; }
16+
public virtual System.Collections.Generic.IReadOnlyList<Hocon.HoconObject> Fallbacks { get; }
2217
public virtual bool IsEmpty { get; }
23-
public Hocon.HoconValue Root { get; }
24-
protected System.Collections.Generic.List<Hocon.HoconValue> _fallbacks { get; }
25-
public override System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, Hocon.HoconField>> AsEnumerable() { }
18+
public Hocon.HoconObject Root { get; }
19+
protected System.Collections.Generic.List<Hocon.HoconObject> _fallbacks { get; }
20+
public override System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, Hocon.HoconElement>> AsEnumerable() { }
21+
public static Hocon.Config Create(Hocon.HoconElement root) { }
22+
public static Hocon.Config Deserialize(string raw) { }
2623
public virtual bool Equals(Hocon.Config other) { }
2724
public override bool Equals(object obj) { }
2825
public virtual Hocon.Config GetConfig(string path) { }
2926
public virtual Hocon.Config GetConfig(Hocon.HoconPath path) { }
30-
protected override Hocon.HoconValue GetNode(Hocon.HoconPath path) { }
27+
[System.ObsoleteAttribute("Used for serialization only", true)]
3128
public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
29+
public override Hocon.HoconElement GetValue(Hocon.HoconPath path) { }
30+
public string Serialize() { }
3231
public string ToString(bool useFallbackValues) { }
33-
protected override bool TryGetNode(Hocon.HoconPath path, out Hocon.HoconValue result) { }
32+
public override bool TryGetValue(Hocon.HoconPath path, out Hocon.HoconElement result) { }
3433
public virtual Hocon.Config WithFallback(Hocon.Config fallback) { }
3534
public static Hocon.Config +(Hocon.Config config, string fallback) { }
3635
public static Hocon.Config +(string configHocon, Hocon.Config fallbackConfig) { }
@@ -66,7 +65,6 @@ namespace Hocon
6665
public static Hocon.Config FromResource(string resourceName, object instanceInAssembly) { }
6766
public static Hocon.Config FromResource<TAssembly>(string resourceName) { }
6867
public static Hocon.Config FromResource(string resourceName, System.Reflection.Assembly assembly) { }
69-
[System.ObsoleteAttribute("Call the ConfigurationFactory.Default method instead.")]
7068
public static Hocon.Config Load() { }
7169
public static Hocon.Config Load(string sectionName) { }
7270
public static Hocon.Config ParseString(string hocon, Hocon.HoconIncludeCallbackAsync includeCallback) { }

0 commit comments

Comments
 (0)