Skip to content

Commit

Permalink
Merge pull request #209 from akkadotnet/dev
Browse files Browse the repository at this point in the history
v1.3.3 Release
  • Loading branch information
Aaronontheweb authored Jan 27, 2020
2 parents fcf6951 + 6597065 commit c22b2fa
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 21 deletions.
10 changes: 8 additions & 2 deletions Hocon.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.15
# Visual Studio Version 16
VisualStudioVersion = 16.0.29424.173
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hocon", "src\Hocon\Hocon.csproj", "{E945AABA-2779-41E8-9B43-8898FFD64F22}"
EndProject
Expand Down Expand Up @@ -33,6 +33,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hocon.Immutable", "src\Hoco
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hocon.Immutable.Tests", "src\Hocon.Immutable.Tests\Hocon.Immutable.Tests.csproj", "{FEEC6F6B-2511-4BEC-9568-4E6AE6C1D275}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SerializationDebug", "src\examples\SerializationDebug\SerializationDebug.csproj", "{6D1D4813-7AB6-4268-A9DF-627A60E08FB1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -95,6 +97,10 @@ Global
{FEEC6F6B-2511-4BEC-9568-4E6AE6C1D275}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FEEC6F6B-2511-4BEC-9568-4E6AE6C1D275}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FEEC6F6B-2511-4BEC-9568-4E6AE6C1D275}.Release|Any CPU.Build.0 = Release|Any CPU
{6D1D4813-7AB6-4268-A9DF-627A60E08FB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6D1D4813-7AB6-4268-A9DF-627A60E08FB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D1D4813-7AB6-4268-A9DF-627A60E08FB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D1D4813-7AB6-4268-A9DF-627A60E08FB1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
9 changes: 4 additions & 5 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#### 1.3.2 January 24 2020 ####
#### 1.3.3 January 27 2020 ####
**Bugfix release for HOCON v1.3.0**

Key changes include:

* [Critical bugfix: Fallbacks are mutable during traversal](https://github.com/akkadotnet/HOCON/issues/193)
* [Added HOCON Debugger tools](https://github.com/akkadotnet/HOCON/pull/192)
* [Performance: Lookups on configs with fallback are performing merge and allocations each time](https://github.com/akkadotnet/HOCON/issues/195)
* [Make `Config` implement `ISerializable`](https://github.com/akkadotnet/HOCON/pull/207)
* [Implement Akka.NET backwards compatibility fixes](https://github.com/akkadotnet/HOCON/pull/204)

You can [see the full set of changes in the HOCON v1.3.2 milestone](https://github.com/akkadotnet/HOCON/milestone/5).
You can [see the full set of changes in the HOCON v1.3.3 milestone](https://github.com/akkadotnet/HOCON/milestone/6).
33 changes: 32 additions & 1 deletion src/Hocon.Configuration.Test/ConfigurationSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Reflection;
using FluentAssertions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using Xunit;

Expand All @@ -30,6 +31,19 @@ public class MyObjectConfig
public int[] IntergerArray { get; set; }
}

[Fact]
public void Config_should_be_serializable()
{
var config = ConfigurationFactory.ParseString(@"
foo{
bar.biz = 12
baz = ""quoted""
}");
var serialized = JsonConvert.SerializeObject(config);
var deserialized = JsonConvert.DeserializeObject<Config>(serialized);
config.DumpConfig().Should().Be(deserialized.DumpConfig());
}

[Fact]
public void CanEnumerateQuotedKeys()
{
Expand Down Expand Up @@ -434,6 +448,23 @@ public void HoconValue_GetObject_should_use_fallback_values()
rootObject["b"].Raw.Should().Be("3");
}

[Fact]
public void Config_will_not_throw_on_duplicate_fallbacks()
{
var c1 = ConfigurationFactory.ParseString(@"foo.bar = baz");
var c2 = ConfigurationFactory.ParseString(@"bar.biz = fuber");

// normal fallback
var f1 = c1.WithFallback(c2).WithFallback(Config.Empty);
c1.Fallback.Should().BeNull(); // original copy should not have been modified.

// someone adds the same fallback again with realizing it
f1.WithFallback(Config.Empty).GetString("bar.biz").Should().Be("fuber"); // shouldn't throw

var final = f1.WithFallback(c2);
final.GetString("bar.biz").Should().Be("fuber"); // shouldn't throw
}

[Fact]
public void Quoted_key_should_be_parsed()
{
Expand Down Expand Up @@ -549,7 +580,7 @@ public void ShouldSerializeFallbackValues()
/// <summary>
/// Source issue: https://github.com/akkadotnet/HOCON/issues/175
/// </summary>
[Fact]
[Fact(Skip = "This is disabled due to temprorary fix for https://github.com/akkadotnet/HOCON/issues/206")]
public void ShouldDeserializeFromJson()
{
var settings = new JsonSerializerSettings
Expand Down
1 change: 0 additions & 1 deletion src/Hocon.Configuration.Test/DebuggerSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// -----------------------------------------------------------------------

using FluentAssertions;
using Hocon.Debugger;
using Xunit;

namespace Hocon.Configuration.Tests
Expand Down
49 changes: 49 additions & 0 deletions src/Hocon.Configuration.Test/SerializationSpecs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// -----------------------------------------------------------------------
// <copyright file="SerializationSpec.cs" company="Akka.NET Project">
// Copyright (C) 2013 - 2020 .NET Foundation <https://github.com/akkadotnet/hocon>
// </copyright>
// -----------------------------------------------------------------------

using System.Collections.Generic;
using FluentAssertions;
using Newtonsoft.Json;
using Xunit;

namespace Hocon.Configuration.Tests
{
public class SerializationSpecs
{
public static IEnumerable<object[]> HoconGenerator()
{
yield return new object[]
{
@"
foo{
bar.biz = 12
baz = ""quoted""
}
", string.Empty, string.Empty
};
}

[Theory(Skip = "Doesn't work right now")]
[MemberData(nameof(HoconGenerator))]
public void ShouldSerializeHocon(string hocon, string fallback1, string fallback2)
{
var hocon1 = ConfigurationFactory.ParseString(hocon);
var fb1 = string.IsNullOrEmpty(fallback1) ? Config.Empty : ConfigurationFactory.ParseString(fallback1);
var fb2 = string.IsNullOrEmpty(fallback1) ? Config.Empty : ConfigurationFactory.ParseString(fallback2);

var final = hocon1.WithFallback(fb1).WithFallback(fb2);

VerifySerialization(final);
}

private void VerifySerialization(Config config)
{
var serialized = JsonConvert.SerializeObject(config);
var deserialized = (Config)JsonConvert.DeserializeObject(serialized);
config.DumpConfig().Should().Be(deserialized.DumpConfig());
}
}
}
56 changes: 52 additions & 4 deletions src/Hocon.Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

namespace Hocon
{
Expand All @@ -16,8 +17,35 @@ namespace Hocon
/// the internal representation of a HOCON (Human-Optimized Config Object Notation)
/// configuration string.
/// </summary>
public class Config : HoconRoot
[Serializable]
public class Config : HoconRoot, ISerializable
{
/// <summary>
/// INTERNAL API
///
/// Special case for empty configurations. Immutable and can't be added as a fallback.
/// </summary>
internal sealed class EmptyConfig : Config
{
public static EmptyConfig Instance = new EmptyConfig();

private EmptyConfig() : base(new HoconRoot(new HoconEmptyValue(null)))
{
}

protected override Config Copy(Config fallback = null)
{
return Instance;
}

public override Config WithFallback(Config fallback)
{
return fallback;
}
}

public const string SerializedPropertyName = "_dump";

[Obsolete("For json serialization/deserialization only", true)]
private Config()
{
Expand Down Expand Up @@ -89,10 +117,10 @@ public string ToString(bool useFallbackValues)
/// Generates a deep clone of the current configuration.
/// </summary>
/// <returns>A deep clone of the current configuration</returns>
protected Config Copy()
protected virtual Config Copy(Config fallback = null)
{
//deep clone
return new Config((HoconValue) Value.Clone(null), Fallback?.Copy());
return new Config((HoconValue) Value.Clone(null), fallback?.Copy() ?? Fallback?.Copy());
}

protected override HoconValue GetNode(HoconPath path, bool throwIfNotFound = false)
Expand Down Expand Up @@ -137,10 +165,13 @@ public virtual Config WithFallback(Config fallback)
{
if (fallback == this)
throw new ArgumentException("Config can not have itself as fallback", nameof(fallback));

if (fallback == Config.Empty)
return this; // no-op

// If Fallback is not set - we will set it in new copy
// If Fallback was set - just use it, but with adding new fallback values
return new Config((HoconValue) Value.Clone(null), Fallback?.WithFallback(fallback) ?? fallback);
return Copy(Fallback.SafeWithFallback(fallback));
}

/// <summary>
Expand Down Expand Up @@ -206,6 +237,23 @@ private HoconValue GetRootValue()

return aggregated;
}

/// <inheritdoc />
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue(SerializedPropertyName, this.ToString(useFallbackValues: true), typeof(string));
}

[Obsolete("Used for serialization only", true)]
public Config(SerializationInfo info, StreamingContext context)
{
var config = ConfigurationFactory.ParseString(info.GetValue(SerializedPropertyName, typeof(string)) as string);

Value = config.Value;
Fallback = config.Fallback;

Root = GetRootValue();
}
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Hocon.Configuration/ConfigurationFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static class ConfigurationFactory
/// <summary>
/// Generates an empty configuration.
/// </summary>
public static Config Empty => new Config(new HoconRoot(new HoconEmptyValue(null)));
public static Config Empty => Config.EmptyConfig.Instance;

/// <summary>
/// Generates a configuration defined in the supplied
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

using System.Text;


namespace Hocon.Debugger
namespace Hocon
{
/// <summary>
/// Debugging extensions for <see cref="Config"/> objects.
Expand Down
10 changes: 5 additions & 5 deletions src/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
<PropertyGroup>
<Copyright>Copyright © 2014-2019 Akka.NET Team</Copyright>
<Authors>Akka.NET Team</Authors>
<VersionPrefix>1.3.2</VersionPrefix>
<VersionPrefix>1.3.3</VersionPrefix>
<PackageReleaseNotes>Bugfix release for HOCON v1.3.0**
Key changes include:
[Critical bugfix: Fallbacks are mutable during traversal](https://github.com/akkadotnet/HOCON/issues/193)
[Added HOCON Debugger tools](https://github.com/akkadotnet/HOCON/pull/192)
[Performance: Lookups on configs with fallback are performing merge and allocations each time](https://github.com/akkadotnet/HOCON/issues/195)
You can [see the full set of changes in the HOCON v1.3.2 milestone](https://github.com/akkadotnet/HOCON/milestone/5).</PackageReleaseNotes>
[Make `Config` implement `ISerializable`](https://github.com/akkadotnet/HOCON/pull/207)
[Implement Akka.NET backwards compatibility fixes](https://github.com/akkadotnet/HOCON/pull/204)
You can [see the full set of changes in the HOCON v1.3.3 milestone](https://github.com/akkadotnet/HOCON/milestone/6).</PackageReleaseNotes>
<PackageIconUrl>http://getakka.net/images/akkalogo.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/akkadotnet/HOCON</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/akkadotnet/HOCON/blob/master/LICENSE</PackageLicenseUrl>
Expand All @@ -19,6 +18,7 @@ You can [see the full set of changes in the HOCON v1.3.2 milestone](https://gith
<XunitVersion>2.4.1</XunitVersion>
<XunitCliVersion>2.3.1</XunitCliVersion>
<TestSdkVersion>16.4.0</TestSdkVersion>
<NetCoreVersion>netcoreapp2.1</NetCoreVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' ">
<DefineConstants>$(DefineConstants);NETCORE</DefineConstants>
Expand Down
39 changes: 39 additions & 0 deletions src/examples/SerializationDebug/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using FluentAssertions;
using Hocon;
using Newtonsoft.Json;

namespace SerializationDebug
{
class Program
{
static void Main(string[] args)
{
var hocon1 = @"
foo{
bar.biz = 12
baz = ""quoted""
}";

ShouldSerializeHocon(hocon1, string.Empty, string.Empty);
}

public static void ShouldSerializeHocon(string hocon, string fallback1, string fallback2)
{
var hocon1 = ConfigurationFactory.ParseString(hocon);
var fb1 = string.IsNullOrEmpty(fallback1) ? Config.Empty : ConfigurationFactory.ParseString(fallback1);
var fb2 = string.IsNullOrEmpty(fallback1) ? Config.Empty : ConfigurationFactory.ParseString(fallback2);

var final = hocon1.WithFallback(fb1).WithFallback(fb2);

VerifySerialization(final);
}

public static void VerifySerialization(Config config)
{
var serialized = JsonConvert.SerializeObject(config);
var deserialized = (Config)JsonConvert.DeserializeObject(serialized);
config.DumpConfig().Should().Be(deserialized.DumpConfig());
}
}
}
18 changes: 18 additions & 0 deletions src/examples/SerializationDebug/SerializationDebug.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\common.props" />

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>$(NetCoreVersion)</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Hocon.Configuration\Hocon.Configuration.csproj" />
</ItemGroup>

</Project>

0 comments on commit c22b2fa

Please sign in to comment.