Skip to content

Commit ff1bfa4

Browse files
committed
Add property OS to VersionOptions in case a project is for a certain OS only (currently Mojang Bedrock only)
1 parent 4e50eb7 commit ff1bfa4

File tree

8 files changed

+66
-18
lines changed

8 files changed

+66
-18
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ All notable changes to this project will be documented in this file.
33

44
## [Unreleased]
55

6+
7+
## [1.4.5] - 2023-06-04
8+
69
### Fixed
710
- Mojang Bedrock versions are now sorted newest to oldest
811

12+
### Added
13+
- Add property OS to VersionOptions in case a project is for a certain OS only (currently Mojang Bedrock only)
14+
915

1016
## [1.4.4] - 2023-06-03
1117

MinecraftJars.Core/Versions/IMinecraftVersion.cs

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public interface IMinecraftVersion
1919
/// Indicates whether this version experimental
2020
/// </summary>
2121
bool IsSnapShot { get; }
22+
23+
/// <summary>
24+
/// Indicates whether this version requires a specific operating system
25+
/// </summary>
26+
VersionOs Os => VersionOs.None;
2227

2328
/// <summary>
2429
/// Indicates TRUE in case the plugin needs to build the JAR file instead of providing download information

MinecraftJars.Core/Versions/VersionOptions.cs

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ public class VersionOptions
1313
/// Indicates to return snapshot / experimental / preview / beta / alpha builds as well
1414
/// </summary>
1515
public bool IncludeSnapshotBuilds { get; set; }
16+
17+
/// <summary>
18+
/// Only return versions Valid for this system e.g. if Windows is specified all
19+
/// versions with NONE or WINDOWS are returned
20+
/// </summary>
21+
public VersionOs VersionOs { get; set; } = VersionOs.None;
1622

1723
/// <summary>
1824
/// Limit the amount of records returned by the plugin API. Useful if only
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace MinecraftJars.Core.Versions;
2+
3+
public enum VersionOs
4+
{
5+
None = 0,
6+
Windows = 1,
7+
Linux = 2
8+
}

MinecraftJars.Plugin/MinecraftJars.Plugin.Mojang/Models/MojangVersion.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public record MojangVersion(
88
IMinecraftProject Project,
99
string Version,
1010
bool IsSnapShot,
11-
Os? Os = null) : IMinecraftVersion
11+
VersionOs Os = VersionOs.None) : IMinecraftVersion
1212
{
1313
internal DateTime? ReleaseTime { get; init; }
1414
internal string DetailUrl { get; init; } = string.Empty;

MinecraftJars.Plugin/MinecraftJars.Plugin.Mojang/MojangVersionFactory.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ where string.IsNullOrWhiteSpace(options.Version) || version.Equals(options.Versi
8989
let isPreview = !string.IsNullOrWhiteSpace(match.Groups["preview"].Value)
9090
where options.IncludeSnapshotBuilds || !isPreview
9191
let url = match.Value
92-
let platform = match.Groups["platform"].Value.Equals("linux", StringComparison.OrdinalIgnoreCase) ? Os.Linux : Os.Windows
92+
let platform = match.Groups["platform"].Value.Equals("linux", StringComparison.OrdinalIgnoreCase)
93+
? VersionOs.Linux
94+
: VersionOs.Windows
95+
where options.VersionOs == VersionOs.None || platform == options.VersionOs
9396
orderby version descending
9497
select new MojangVersion(
9598
Project: project,

MinecraftJars.Plugin/MinecraftJars.Plugin.Mojang/Os.cs

-8
This file was deleted.

MinecraftJars.Tests/VersionTests.cs

+36-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using MinecraftJars.Core.Versions;
2-
using MinecraftJars.Plugin.Mojang.Models;
32

43
namespace MinecraftJars.Tests;
54

@@ -51,30 +50,59 @@ public async Task GetVersions_MaxRecordsMax(
5150
[TestCaseSource(nameof(Projects)), Order(4)]
5251
public async Task GetVersions_SpecificVersion(string projectName)
5352
{
53+
5454
var project = MinecraftJar.GetProjects().Single(p => p.Name.Equals(projectName));
55-
var version = (await project.GetVersions()).First();
55+
var platform = OperatingSystem.IsWindows() ? VersionOs.Windows : VersionOs.Linux;
56+
57+
var version = (await project.GetVersions(new VersionOptions
58+
{
59+
VersionOs = platform
60+
})).First();
61+
5662
var versions = (await project.GetVersions(new VersionOptions
5763
{
58-
Version = version.Version
64+
Version = version.Version,
65+
VersionOs = platform
5966
})).ToList();
6067

61-
var count = version is MojangVersion { Os: not null } ? 2 : 1;
62-
63-
Assert.That(versions, Has.Count.EqualTo(count));
68+
Assert.That(versions, Has.Count.EqualTo(1));
6469
Assert.That(versions.First(), Is.EqualTo(version));
6570

6671
TestContext.Progress.WriteLine("{0}: Specific version {1} found",
6772
nameof(GetVersions_SpecificVersion), version.Version);
6873
}
6974

75+
[TestCase("Bedrock"), Order(5)]
76+
public async Task GetVersions_SpecificOs(string projectName)
77+
{
78+
var project = MinecraftJar.GetProjects().Single(p => p.Name.Equals(projectName));
79+
80+
foreach (var versionOs in Enum.GetValues<VersionOs>().Where(e => e != VersionOs.None))
81+
{
82+
var versions = (await project.GetVersions(new VersionOptions
83+
{
84+
VersionOs = versionOs
85+
})).ToList();
86+
87+
Assert.Multiple(() =>
88+
{
89+
Assert.That(versions.Any(v => v.Os != versionOs), Is.False);
90+
Assert.That(versions.Any(), Is.True);
91+
});
92+
93+
TestContext.Progress.WriteLine("{0}: Search for {1} successful, no other Os found",
94+
nameof(GetVersions_SpecificOs), versionOs);
95+
}
96+
}
97+
7098
[TestCase("Vanilla")]
7199
[TestCase("Bedrock")]
72100
[TestCase("Fabric")]
73101
[TestCase("Pocketmine")]
74102
[TestCase("Spigot")]
75103
[TestCase("Paper")]
76104
[TestCase("Velocity")]
77-
[Order(5)]
105+
[Order(6)]
78106
public async Task GetVersions_ContainsSnapshot(string projectName)
79107
{
80108
var project = MinecraftJar.GetProjects().Single(p => p.Name.Equals(projectName));
@@ -97,7 +125,7 @@ public async Task GetVersions_ContainsSnapshot(string projectName)
97125
[TestCase("Spigot")]
98126
[TestCase("Paper")]
99127
[TestCase("Velocity")]
100-
[Order(6)]
128+
[Order(7)]
101129
public async Task GetVersions_ContainsNoSnapshot(string projectName)
102130
{
103131
var project = MinecraftJar.GetProjects().Single(p => p.Name.Equals(projectName));

0 commit comments

Comments
 (0)