Skip to content

Commit

Permalink
COH-30704 Migrate from app.config to appsettings.json (and maybe othe…
Browse files Browse the repository at this point in the history
…r configuration providers)

[git-p4: depot-paths = "//dev/main.net/": change = 111249]
  • Loading branch information
vasac committed Sep 11, 2024
1 parent 9e8b797 commit a6af33f
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 146 deletions.
3 changes: 2 additions & 1 deletion src/Coherence/Coherence.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@

<ItemGroup>
<PackageReference Include="Common.Logging" Version="3.4.1" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
89 changes: 0 additions & 89 deletions src/Coherence/Config/CoherenceConfigHandler.cs

This file was deleted.

62 changes: 46 additions & 16 deletions src/Coherence/Util/ConfigurationUtils.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
* https://oss.oracle.com/licenses/upl.
*/
using System;
using System.Configuration;

using System.Collections;
using System.IO;
using Microsoft.Extensions.Configuration;
using Tangosol.Config;
using Tangosol.IO.Resources;

namespace Tangosol.Util
{
Expand All @@ -21,26 +23,54 @@ public class ConfigurationUtils
/// The name of the configuration element that contains Coherence
/// configuration settings.
/// </summary>
private const string CONFIG_SECTION_NAME = "coherence";

// TODO: remove this constant in a future release
private const string _CONFIG_SECTION_NAME = "tangosol-coherence";
private const string CONFIG_SECTION_NAME = "Coherence";

/// <summary>
/// Parses the Coherence configuration section within the standard
/// .NET configuration file (App.config or Web.config).
/// .NET configuration file (appsettings.json).
/// </summary>
/// <returns>
/// An instance of <see cref="CoherenceConfig"/> created by
/// <see cref="CoherenceConfigHandler"/>.
/// An instance of <see cref="CoherenceConfig"/>
/// </returns>
public static object GetCoherenceConfiguration()
{
// TODO: we still check for the legacy "tangosol-coherence" config
// section for backwards compatibility; this check should be
// removed in a future release
return ConfigurationManager.GetSection(CONFIG_SECTION_NAME)
?? ConfigurationManager.GetSection(_CONFIG_SECTION_NAME);
IConfiguration cohCfg = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", true)
.Build()
.GetSection(CONFIG_SECTION_NAME);

CoherenceConfig config = new CoherenceConfig();
string coherenceConfig = cohCfg["CoherenceConfig"];
string cacheConfig = cohCfg["CacheConfig"];
string pofConfig = cohCfg["PofConfig"];
string messagingDebug = cohCfg["COHERENCE_MESSAGING_DEBUG"];

config.ConfigProperties = new Hashtable();
if (coherenceConfig != null)
{
config.OperationalConfig = ResourceLoader.GetResource(coherenceConfig);
}
if (cacheConfig != null)
{
config.CacheConfig = ResourceLoader.GetResource(cacheConfig);
}
if (pofConfig != null)
{
config.PofConfig = ResourceLoader.GetResource(pofConfig);
}
if (messagingDebug != null)
{
config.ConfigProperties.Add("COHERENCE_MESSAGING_DEBUG", messagingDebug);
}

IConfigurationSection properties = cohCfg.GetSection("Properties");
foreach (var property in properties.GetChildren())
{
config.ConfigProperties.Add(property.Key, property.Value);
}

return config;
}

/// <summary>
Expand Down
37 changes: 0 additions & 37 deletions tests/Coherence.Tests/App.config

This file was deleted.

9 changes: 6 additions & 3 deletions tests/Coherence.Tests/Coherence.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
See https://github.com/dotnet/runtime/issues/22720 for details.
-->
<Target Name="CopyCustomContent" AfterTargets="AfterBuild">
<Copy SourceFiles="App.config" DestinationFiles="$(OutDir)\testhost.dll.config" />
<Copy SourceFiles="App.config" DestinationFiles="$(OutDir)\testhost.x86.dll.config" />
<Copy SourceFiles="App.config" DestinationFiles="$(OutDir)\ReSharperTestRunner64.dll.config" />
<Copy SourceFiles="appsettings.json" DestinationFiles="$(OutDir)\testhost.dll.config" />
<Copy SourceFiles="appsettings.json" DestinationFiles="$(OutDir)\testhost.x86.dll.config" />
<Copy SourceFiles="appsettings.json" DestinationFiles="$(OutDir)\ReSharperTestRunner64.dll.config" />
</Target>

<Target Name="InstallCerts" AfterTargets="AfterBuild">
Expand All @@ -58,6 +58,9 @@

<ItemGroup>
<None Remove="Resources\*.xml" />
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\*.xml" />
Expand Down
17 changes: 17 additions & 0 deletions tests/Coherence.Tests/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"Coherence": {
"CacheConfig": "assembly://Coherence.Tests/Tangosol.Resources/s4hc-cache-config.xml",
"PofConfig": "assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml",
"CoherenceConfig": "assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-coherence.xml",
"Properties": {
"coherence.proxy.port1": "9099",
"coherence.serializer": "pof"
}
}
}

0 comments on commit a6af33f

Please sign in to comment.