Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manual updates 20240807 support for nonstandard maven versions #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions MavenNet.Tests/MavenNet.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
Expand Down
8 changes: 8 additions & 0 deletions MavenNet.Tests/MavenVersioningTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ public class MavenVersioningTests
[InlineData("(,1.0],[1.2,)", "1.2", true)]
[InlineData("(,1.0],[1.2,)", "1.3", true)]
[InlineData("(,1.0],[1.2,)", "1.1", false)]
[InlineData("(,1.0],[2.2,)", "1.0.1.262e11d", false)]
[InlineData("(,0.8],[2.2,)", "0.11.1.647c3c2", false)]
[InlineData("(,0.8],[2.2,)", "0.11.1.3c786d2", false)]
[InlineData("(,0.8],[2.2,)", "0.10.1.2e8fe11", false)]
[InlineData("(,0.8],[2.2,)", "0.10.1.e92f734", false)]
[InlineData("(,0.8],[2.2,)", "0.10.1.d22d4de", false)]
[InlineData("(,0.8],[2.2,)", "0.9.3.545a756", false)]
[InlineData("(,0.8],[2.2,)", "0.9.3.a319893", false)]
public void Satisfy_Versions(string range, string version, bool satisfies)
{
var mvr = new MavenVersionRange(range);
Expand Down
4 changes: 2 additions & 2 deletions MavenNet/MavenNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<Compile Remove="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NuGet.Versioning" Version="5.9.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NuGet.Versioning" Version="6.10.1" />
</ItemGroup>
</Project>
36 changes: 35 additions & 1 deletion MavenNet/MavenVersionRange.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;

Expand All @@ -16,7 +17,40 @@ public MavenVersionRange(string value)

public bool Satisfies(string version)
{
var nugetVersion = NuGet.Versioning.NuGetVersion.Parse(version);
var nugetVersion = default(NuGet.Versioning.NuGetVersion);

try
{
nugetVersion = NuGet.Versioning.NuGetVersion.Parse(version);
}
catch (Exception e)
{
if (e is System.ArgumentException && e.Message.Contains(" is not a valid version string."))
{
try
{
int idx = version.LastIndexOf('.');
// creating valid SemVer from invalid Maven
string semver = version.Substring(0, idx);
nugetVersion = NuGet.Versioning.NuGetVersion.Parse(semver);
string release_textual = version.Substring(idx + 1, version.Length - idx - 1);
try
{
int release_numeric = int.Parse(release_textual, NumberStyles.HexNumber);
nugetVersion = NuGet.Versioning.NuGetVersion.Parse($"{semver}.{release_numeric}");
}
catch (Exception exception)
{
nugetVersion = NuGet.Versioning.NuGetVersion.Parse($"{semver}+{release_textual}");
}
}
catch (Exception ei)
{
Console.WriteLine(ei);
throw;
}
}
}

var v = Regex.Replace(Value, "\\s", "");

Expand Down
Loading