Skip to content

Commit

Permalink
Merge branch 'dev' into pre-release
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed Dec 4, 2024
2 parents a7bba30 + ecba420 commit fdd09dc
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 42 deletions.
6 changes: 3 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
<Version>4.18.1</Version>
</PackageVersion>
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
<PackageVersion Include="FluentAssertions" Version="6.12.2" />
<PackageVersion Include="FluentAssertions" Version="7.0.0" />
<PackageVersion Include="GitHubDependents" Version="1.2.0" />
<PackageVersion Include="GitVersion.MsBuild" Version="6.0.5" />
<PackageVersion Include="Humanizer.Core" Version="2.14.1" />
<PackageVersion Include="LibGit2Sharp">
<Version>0.30.0</Version>
<Version>0.31.0</Version>
</PackageVersion>
<PackageVersion Include="Microsoft.Build" Version="17.12.6" />
<PackageVersion Include="Microsoft.Build.Tasks.Core" Version="17.12.6" />
Expand Down Expand Up @@ -42,7 +42,7 @@
<PackageVersion Include="Noggog.CSharpExt.Json" Version="2.69.0" />
<PackageVersion Include="Noggog.CSharpExt.Windows" Version="2.69.0" />
<PackageVersion Include="Noggog.GitRepository">
<Version>1.3</Version>
<Version>1.5</Version>
</PackageVersion>
<PackageVersion Include="Noggog.SourceGenerators" Version="2.69.0" />
<PackageVersion Include="Noggog.Testing">
Expand Down
13 changes: 13 additions & 0 deletions Mutagen.Bethesda.Synthesis/States/IPatcherState.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Mutagen.Bethesda.Plugins.Allocators;
using Mutagen.Bethesda.Plugins.Cache;
using Mutagen.Bethesda.Plugins.Order;
using Mutagen.Bethesda.Plugins.Records;
using Noggog;
Expand Down Expand Up @@ -41,6 +42,12 @@ public interface IPatcherState : IBaseRunState, IDisposable
CancellationToken Cancel { get; }

internal ILoadOrderGetter<IModListingGetter<IModFlagsGetter>> LoadOrderForPipeline { get; }

/// <summary>
/// Convenience Link Cache to use created from the provided Load Order object.<br />
/// The patch mod is marked as safe for mutation, and will not make the cache invalid.
/// </summary>
ILinkCache LinkCache { get; }
}

public interface IPatcherState<TModSetter, TModGetter> : IBaseRunState<TModSetter, TModGetter>, IPatcherState
Expand All @@ -56,4 +63,10 @@ public interface IPatcherState<TModSetter, TModGetter> : IBaseRunState<TModSette
/// upon that content as appropriate, and mesh any changes to produce the final patch file.
/// </summary>
new TModSetter PatchMod { get; }

/// <summary>
/// Convenience Link Cache to use created from the provided Load Order object.<br />
/// The patch mod is marked as safe for mutation, and will not make the cache invalid.
/// </summary>
new ILinkCache<TModSetter, TModGetter> LinkCache { get; }
}
2 changes: 2 additions & 0 deletions Mutagen.Bethesda.Synthesis/States/SynthesisState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class SynthesisState<TModSetter, TModGetter> : IPatcherState<TModSetter,
public CancellationToken Cancel { get; }

public ILoadOrderGetter<IModListingGetter<IModFlagsGetter>> LoadOrderForPipeline => LoadOrder;

ILinkCache IPatcherState.LinkCache => LinkCache;

/// <inheritdoc />
public DirectoryPath? ExtraSettingsDataPath { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
using System.Xml.Linq;
using Mutagen.Bethesda;
using Noggog;
using NuGet.Versioning;

namespace Synthesis.Bethesda.Execution.Patchers.Git.Services.ModifyProject;

public class AddAllReleasesToOldVersions
{
public static readonly Version IntroducingSynthesisVersion = new Version(0, 29);
public static readonly SemanticVersion IntroducingSynthesisVersion = new(0, 29, 0);

public void Add(
XElement proj,
Version? curSynthVersion,
Version targetMutagenVersion,
Version? targetSynthVersion)
SemanticVersion? curSynthVersion,
SemanticVersion targetMutagenVersion,
SemanticVersion? targetSynthVersion)
{
if (targetSynthVersion != null
&& curSynthVersion != null
Expand All @@ -25,6 +27,10 @@ public void Add(
if (!elem.Name.LocalName.Equals("PackageReference")) continue;
if (!elem.TryGetAttribute("Include", out var include)) continue;
if (include.Value.Equals("Mutagen.Bethesda")) return;
foreach (var cat in Enums<GameCategory>.Values)
{
if (include.Value.Equals($"Mutagen.Bethesda.{cat}")) return;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
using System.Xml.Linq;
using Mutagen.Bethesda.Synthesis.Versioning;
using Noggog;
using NuGet.Versioning;

namespace Synthesis.Bethesda.Execution.Patchers.Git.Services.ModifyProject;

public interface IAddNewtonsoftToOldSetups
{
void Add(
XElement proj,
Version? mutaVersion,
Version? synthVersion);
SemanticVersion? mutaVersion,
SemanticVersion? synthVersion);
}

public class AddNewtonsoftToOldSetups : IAddNewtonsoftToOldSetups
{
private readonly IProvideCurrentVersions _provideCurrentVersions;
public static readonly System.Version NewtonSoftAddMutaVersion = new(0, 26);
public static readonly System.Version NewtonSoftAddSynthVersion = new(0, 14, 1);
public static readonly SemanticVersion NewtonSoftAddMutaVersion = new(0, 26, 0);
public static readonly SemanticVersion NewtonSoftAddSynthVersion = new(0, 14, 1);

public AddNewtonsoftToOldSetups(IProvideCurrentVersions provideCurrentVersions)
{
Expand All @@ -25,8 +26,8 @@ public AddNewtonsoftToOldSetups(IProvideCurrentVersions provideCurrentVersions)

public void Add(
XElement proj,
Version? mutaVersion,
Version? synthVersion)
SemanticVersion? mutaVersion,
SemanticVersion? synthVersion)
{
if ((mutaVersion != null
&& mutaVersion <= NewtonSoftAddMutaVersion)
Expand All @@ -39,7 +40,7 @@ public void Add(
{
if (!elem.Name.LocalName.Equals("PackageReference")) continue;
if (!elem.TryGetAttribute("Include", out var include)) continue;
if (include.Equals("Newtonsoft.Json")) return;
if (include.Value.Equals("Newtonsoft.Json")) return;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ void Modify(

public class ModifyRunnerProjects : IModifyRunnerProjects
{
public static readonly System.Version NewtonSoftRemoveMutaVersion = new(0, 28);
public static readonly System.Version NewtonSoftRemoveSynthVersion = new(0, 17, 5);
public static readonly System.Version NamespaceMutaVersion = new(0, 30, 0);
public static readonly SemanticVersion NewtonSoftRemoveMutaVersion = new(0, 28, 0);
public static readonly SemanticVersion NewtonSoftRemoveSynthVersion = new(0, 17, 5);
public static readonly SemanticVersion NamespaceMutaVersion = new(0, 30, 0);
private readonly ILogger _logger;
private readonly IFileSystem _fileSystem;
private readonly IAvailableProjectsRetriever _availableProjectsRetriever;
Expand Down Expand Up @@ -65,6 +65,46 @@ public ModifyRunnerProjects(
_removeProject = removeProject;
_addAllReleasesToOldVersions = addAllReleasesToOldVersions;
}

string? TrimVersion(string? version, out string? prereleaseLabel)
{
if (version == null)
{
prereleaseLabel = null;
return null;
}
var index = version.IndexOf('-');
if (index == -1)
{
prereleaseLabel = null;
return version;
}

prereleaseLabel = version.Substring(index + 1);
return version.Substring(0, index);
}

private SemanticVersion? SemanticVersionParse(string? str)
{
if (str == null) return null;
if (SemanticVersion.TryParse(str, out var semVer))
{
return semVer;
}

var trimmed = TrimVersion(str, out var prereleaseLabel);

if (Version.TryParse(trimmed, out var vers))
{
if (prereleaseLabel == null)
{
return new SemanticVersion(vers.Major, vers.Minor, vers.Build == -1 ? 0 : vers.Build);
}
return new SemanticVersion(vers.Major, vers.Minor, vers.Build == -1 ? 0 : vers.Build, prereleaseLabel);
}

return null;
}

public void Modify(
FilePath solutionPath,
Expand All @@ -74,16 +114,6 @@ public void Modify(
{
listedVersions = new NugetVersionPair(null, null);

string? TrimVersion(string? version)
{
if (version == null) return null;
var index = version.IndexOf('-');
if (index == -1) return version;
return version.Substring(0, index);
}

var trimmedMutagenVersion = TrimVersion(versions.Mutagen);
var trimmedSynthesisVersion = TrimVersion(versions.Synthesis);
foreach (var subProj in _availableProjectsRetriever.Get(solutionPath))
{
var proj = Path.Combine(Path.GetDirectoryName(solutionPath)!, subProj);
Expand All @@ -97,11 +127,11 @@ public void Modify(
_turnOffNullability.TurnOff(projXml);
_removeGitInfo.Remove(projXml);
_turnOffWindowsSpec.TurnOff(projXml);
System.Version.TryParse(TrimVersion(curListedVersions.Mutagen), out var mutaVersion);
System.Version.TryParse(TrimVersion(curListedVersions.Synthesis), out var synthVersion);
var mutaVersion = SemanticVersionParse(curListedVersions.Mutagen);
var synthVersion = SemanticVersionParse(curListedVersions.Synthesis);
_addNewtonsoftToOldSetups.Add(projXml, mutaVersion, synthVersion);
System.Version.TryParse(trimmedMutagenVersion, out var targetMutaVersion);
System.Version.TryParse(trimmedSynthesisVersion, out var targetSynthesisVersion);
var targetMutaVersion = SemanticVersionParse(versions.Mutagen);
var targetSynthesisVersion = SemanticVersionParse(versions.Synthesis);
if ((targetMutaVersion != null
&& targetMutaVersion >= NewtonSoftRemoveMutaVersion)
|| (targetSynthesisVersion != null
Expand All @@ -120,7 +150,9 @@ public void Modify(
_addAllReleasesToOldVersions.Add(projXml, synthVersion, targetMutaVersion, targetSynthesisVersion);
}

if (targetMutaVersion >= NamespaceMutaVersion
if (targetMutaVersion != null
&& mutaVersion != null
&& targetMutaVersion >= NamespaceMutaVersion
&& mutaVersion < NamespaceMutaVersion)
{
_processProjUsings.Process(proj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,35 @@
using System.Xml.Linq;
using Serilog;
using Noggog;
using NuGet.Versioning;

namespace Synthesis.Bethesda.Execution.Patchers.Git.Services.ModifyProject;

public interface ISwapToProperNetVersion
{
void Swap(XElement proj, Version targetMutagenVersion);
void Swap(XElement proj, SemanticVersion targetMutagenVersion);
}

public class SwapToProperNetVersion : ISwapToProperNetVersion
{
private readonly ILogger _logger;
private readonly Version Net8Version = new Version(0, 45);
private readonly SemanticVersion Net8Version = new(0, 45, 0);
// private readonly Version Net9Version = new Version(0, 49);
private readonly CultureInfo Culture = new CultureInfo("en");
private readonly CultureInfo Culture = new("en");

private readonly SortedList<Version, byte> _netMapping;
private readonly SortedList<SemanticVersion, byte> _netMapping;

public SwapToProperNetVersion(ILogger logger)
{
_logger = logger;
_netMapping = new SortedList<Version, byte>()
_netMapping = new SortedList<SemanticVersion, byte>()
{
{ Net8Version, 8 },
// { Net9Version, 9 }
};
}

private void ProcessTargetFrameworkNode(XElement elem, Version targetMutagenVersion)
private void ProcessTargetFrameworkNode(XElement elem, SemanticVersion targetMutagenVersion)
{
if (!elem.Name.LocalName.Equals("TargetFramework")) return;
_logger.Information("Target mutagen version: {Target}", targetMutagenVersion);
Expand Down Expand Up @@ -75,7 +76,7 @@ private bool NeedsUpgrade(string elem, byte target)
return true;
}

private void ProcessNormal(XElement elem, Version targetMutagenVersion)
private void ProcessNormal(XElement elem, SemanticVersion targetMutagenVersion)
{
if (!_netMapping.TryGetInDirection(targetMutagenVersion, higher: false, out var targetNetVersion))
{
Expand All @@ -88,7 +89,7 @@ private void ProcessNormal(XElement elem, Version targetMutagenVersion)
_logger.Information("Swapping to {Target}", elem.Value);
}

public void Swap(XElement proj, Version targetMutagenVersion)
public void Swap(XElement proj, SemanticVersion targetMutagenVersion)
{
foreach (var group in proj.Elements("PropertyGroup"))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
</ItemGroup>
<ItemGroup />
<ItemGroup>
<PackageReference Include="Mutagen.Bethesda" Version="0.45" />
<PackageReference Include="Mutagen.Bethesda" Version="0.45.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Mutagen.Bethesda.Skyrim" Version="0.49.0-alpha.7" />
<PackageReference Include="Mutagen.Bethesda.Synthesis" Version="0.29" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Mutagen.Bethesda.Skyrim" Version="0.49.0-alpha.7" />
<PackageReference Include="Mutagen.Bethesda.Synthesis" Version="0.29" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,44 @@ public async Task Legacy(
out var pair);
await Verify(fileSystem.File.ReadAllText(projPath));
}

[Theory, DefaultAutoData]
public async Task LegacySpecificMutagenCategoryLib(
IFileSystem fileSystem,
FilePath existingSlnPath)
{
var subPath = Path.Combine("SomeProj", "SomeProj.csproj");
fileSystem.File.WriteAllText(existingSlnPath, Sln);
var projPath = Path.Combine(Path.GetDirectoryName(existingSlnPath)!, subPath);
fileSystem.Directory.CreateDirectory(Path.GetDirectoryName(projPath)!);

string proj =
"""
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Mutagen.Bethesda.Skyrim" Version="0.39.5" />
<PackageReference Include="Mutagen.Bethesda.Synthesis" Version="0.24.1" />
</ItemGroup>
</Project>
""";
fileSystem.File.WriteAllText(projPath, proj);
var sut = new ModifyRunnerProjectsContainer(fileSystem);
sut.Resolve().Value.Modify(
existingSlnPath,
subPath,
new NugetVersionPair(
"0.49.0-alpha.7",
"0.29"),
out var pair);
await Verify(fileSystem.File.ReadAllText(projPath));
}

[Theory, DefaultAutoData]
public async Task NetCoreApp(
Expand Down
Loading

0 comments on commit fdd09dc

Please sign in to comment.