Skip to content

Commit

Permalink
Move GetVersion to IProject.cs and modify on IProvider.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
tekgator committed May 31, 2023
1 parent 016dba3 commit 165e97d
Show file tree
Hide file tree
Showing 21 changed files with 180 additions and 59 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ All notable changes to this project will be documented in this file.

## [Unreleased]


## [1.2.3] - 2023-05-31
### Changed
- GetVersion on IProvider now returns all versions for all projects

### Added
- GetVersion on IProject returns all versions for that project


## [1.2.2] - 2023-05-30
### Added
- Add version option to include snapshots during load, by default this is false
Expand Down
11 changes: 10 additions & 1 deletion MinecraftJars.Core/Projects/IProject.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace MinecraftJars.Core.Projects;
using MinecraftJars.Core.Versions;

namespace MinecraftJars.Core.Projects;

public interface IProject
{
Expand Down Expand Up @@ -26,4 +28,11 @@ public interface IProject
/// PNG logo of the project
/// </summary>
byte[] Logo { get; }

/// <summary>
/// Get available versions for the project from the provider
/// </summary>
public Task<IEnumerable<IVersion>> GetVersions(
VersionOptions? options = null,
CancellationToken cancellationToken = default!);
}
3 changes: 1 addition & 2 deletions MinecraftJars.Core/Providers/IProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ public interface IProvider
IEnumerable<IProject> Projects { get; }

/// <summary>
/// Get available versions for a project from the provider
/// Get available versions for all projects from the provider
/// </summary>
public Task<IEnumerable<IVersion>> GetVersions(
string projectName,
VersionOptions? options = null,
CancellationToken cancellationToken = default!);
}
2 changes: 1 addition & 1 deletion MinecraftJars.Demo/MinecraftJars.Demo.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{
Console.WriteLine($"\t{project}");

foreach (var version in await provider.GetVersions(project.Name, new VersionOptions { MaxRecords = 10}))
foreach (var version in await project.GetVersions(new VersionOptions { MaxRecords = 10 }))
{
Console.WriteLine($"\t\t{version}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ public FabricProvider(ProviderOptions? options)
public IEnumerable<IProject> Projects => FabricProjectFactory.Projects;

public async Task<IEnumerable<IVersion>> GetVersions(
string projectName,
VersionOptions? options = null,
CancellationToken cancellationToken = default)
{
return await FabricVersionFactory.GetVersion(projectName, options ?? new VersionOptions(), cancellationToken);
var versionOptions = options ?? new VersionOptions();
var versions = new List<IVersion>();

foreach (var project in Projects)
{
versions.AddRange(await project.GetVersions(versionOptions, cancellationToken));
}

return versions;
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MinecraftJars.Core.Projects;
using MinecraftJars.Core.Versions;

namespace MinecraftJars.Plugin.Fabric.Model;

Expand All @@ -7,4 +8,12 @@ public record FabricProject(
string Name,
string Description,
string Url,
byte[] Logo) : IProject;
byte[] Logo) : IProject
{
public async Task<IEnumerable<IVersion>> GetVersions(
VersionOptions? options = null,
CancellationToken cancellationToken = default!)
{
return await FabricVersionFactory.GetVersion(Name, options ?? new VersionOptions(), cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ public record MohistProject(
string Name,
string Description,
string Url,
byte[] Logo) : IProject;
byte[] Logo) : IProject
{
public async Task<IEnumerable<IVersion>> GetVersions(
VersionOptions? options = null,
CancellationToken cancellationToken = default!)
{
return await MohistVersionFactory.GetVersion(Name, options ?? new VersionOptions(), cancellationToken);
}
}
13 changes: 10 additions & 3 deletions MinecraftJars.Plugin/MinecraftJars.Plugin.Mohist/MohistProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ public MohistProvider(ProviderOptions? options)
public IEnumerable<IProject> Projects => MohistProjectFactory.Projects;

public async Task<IEnumerable<IVersion>> GetVersions(
string projectName,
VersionOptions? options = null,
CancellationToken cancellationToken = default)
{
return await MohistVersionFactory.GetVersion(projectName, options ?? new VersionOptions(), cancellationToken);
}
var versionOptions = options ?? new VersionOptions();
var versions = new List<IVersion>();

foreach (var project in Projects)
{
versions.AddRange(await project.GetVersions(versionOptions, cancellationToken));
}

return versions;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MinecraftJars.Core.Projects;
using MinecraftJars.Core.Versions;

namespace MinecraftJars.Plugin.Mojang.Models;

Expand All @@ -7,4 +8,12 @@ public record MojangProject(
string Name,
string Description,
string Url,
byte[] Logo) : IProject;
byte[] Logo) : IProject
{
public async Task<IEnumerable<IVersion>> GetVersions(
VersionOptions? options = null,
CancellationToken cancellationToken = default!)
{
return await MojangVersionFactory.GetVersion(Name, options ?? new VersionOptions(), cancellationToken);
}
}
15 changes: 11 additions & 4 deletions MinecraftJars.Plugin/MinecraftJars.Plugin.Mojang/MojangProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ public MojangProvider(ProviderOptions? options)
public IEnumerable<IProject> Projects => MojangProjectFactory.Projects;

public async Task<IEnumerable<IVersion>> GetVersions(
string projectName,
VersionOptions? versionOptions = null,
CancellationToken cancellationToken = default!)
VersionOptions? options = null,
CancellationToken cancellationToken = default)
{
return await MojangVersionFactory.GetVersion(projectName, versionOptions ?? new VersionOptions(), cancellationToken);
var versionOptions = options ?? new VersionOptions();
var versions = new List<IVersion>();

foreach (var project in Projects)
{
versions.AddRange(await project.GetVersions(versionOptions, cancellationToken));
}

return versions;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MinecraftJars.Core.Projects;
using MinecraftJars.Core.Versions;

namespace MinecraftJars.Plugin.Paper.Model;

Expand All @@ -7,4 +8,12 @@ public record PaperProject(
string Name,
string Description,
string Url,
byte[] Logo) : IProject;
byte[] Logo) : IProject
{
public async Task<IEnumerable<IVersion>> GetVersions(
VersionOptions? options = null,
CancellationToken cancellationToken = default!)
{
return await PaperVersionFactory.GetVersion(Name, options ?? new VersionOptions(), cancellationToken);
}
}
11 changes: 9 additions & 2 deletions MinecraftJars.Plugin/MinecraftJars.Plugin.Paper/PaperProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ public PaperProvider(ProviderOptions? options)
public IEnumerable<IProject> Projects => PaperProjectFactory.Projects;

public async Task<IEnumerable<IVersion>> GetVersions(
string projectName,
VersionOptions? options = null,
CancellationToken cancellationToken = default)
{
return await PaperVersionFactory.GetVersion(projectName, options ?? new VersionOptions(), cancellationToken);
var versionOptions = options ?? new VersionOptions();
var versions = new List<IVersion>();

foreach (var project in Projects)
{
versions.AddRange(await project.GetVersions(versionOptions, cancellationToken));
}

return versions;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MinecraftJars.Core.Projects;
using MinecraftJars.Core.Versions;

namespace MinecraftJars.Plugin.Pocketmine.Model;

Expand All @@ -7,4 +8,12 @@ public record PocketmineProject(
string Name,
string Description,
string Url,
byte[] Logo) : IProject;
byte[] Logo) : IProject
{
public async Task<IEnumerable<IVersion>> GetVersions(
VersionOptions? options = null,
CancellationToken cancellationToken = default!)
{
return await PocketmineVersionFactory.GetVersion(Name, options ?? new VersionOptions(), cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ public PocketmineProvider(ProviderOptions? options)
public IEnumerable<IProject> Projects => PocketmineProjectFactory.Projects;

public async Task<IEnumerable<IVersion>> GetVersions(
string projectName,
VersionOptions? options = null,
CancellationToken cancellationToken = default)
{
return await PocketmineVersionFactory.GetVersion(projectName, options ?? new VersionOptions(), cancellationToken);
var versionOptions = options ?? new VersionOptions();
var versions = new List<IVersion>();

foreach (var project in Projects)
{
versions.AddRange(await project.GetVersions(versionOptions, cancellationToken));
}

return versions;
}


}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MinecraftJars.Core.Projects;
using MinecraftJars.Core.Versions;

namespace MinecraftJars.Plugin.Purpur.Model;

Expand All @@ -7,4 +8,12 @@ public record PurpurProject(
string Name,
string Description,
string Url,
byte[] Logo) : IProject;
byte[] Logo) : IProject
{
public async Task<IEnumerable<IVersion>> GetVersions(
VersionOptions? options = null,
CancellationToken cancellationToken = default!)
{
return await PurpurVersionFactory.GetVersion(Name, options ?? new VersionOptions(), cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ public PurpurProvider(ProviderOptions? options)
public IEnumerable<IProject> Projects => PurpurProjectFactory.Projects;

public async Task<IEnumerable<IVersion>> GetVersions(
string projectName,
VersionOptions? options = null,
CancellationToken cancellationToken = default)
{
return await PurpurVersionFactory.GetVersion(projectName, options ?? new VersionOptions(), cancellationToken);
var versionOptions = options ?? new VersionOptions();
var versions = new List<IVersion>();

foreach (var project in Projects)
{
versions.AddRange(await project.GetVersions(versionOptions, cancellationToken));
}

return versions;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MinecraftJars.Core.Projects;
using MinecraftJars.Core.Versions;

namespace MinecraftJars.Plugin.Spigot.Model;

Expand All @@ -7,4 +8,12 @@ public record SpigotProject(
string Name,
string Description,
string Url,
byte[] Logo) : IProject;
byte[] Logo) : IProject
{
public async Task<IEnumerable<IVersion>> GetVersions(
VersionOptions? options = null,
CancellationToken cancellationToken = default!)
{
return await SpigotVersionFactory.GetVersion(Name, options ?? new VersionOptions(), cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ public SpigotProvider(ProviderOptions? options)
public IEnumerable<IProject> Projects => SpigotProjectFactory.Projects;

public async Task<IEnumerable<IVersion>> GetVersions(
string projectName,
VersionOptions? options = null,
CancellationToken cancellationToken = default)
{
return await SpigotVersionFactory.GetVersion(projectName, options ?? new VersionOptions(), cancellationToken);
var versionOptions = options ?? new VersionOptions();
var versions = new List<IVersion>();

foreach (var project in Projects)
{
versions.AddRange(await project.GetVersions(versionOptions, cancellationToken));
}

return versions;
}
}
12 changes: 4 additions & 8 deletions MinecraftJars.Tests/DownloadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ public class DownloadTests
[Values(true, false)] bool loadFileSize)
{
var project = ProviderManager.GetProjects().Single(p => p.Name.Equals(projectName));
var provider = ProviderManager.GetProvider(project);

foreach (var version in await provider.GetVersions(project.Name))
foreach (var version in await project.GetVersions())
{
TestContext.Progress.WriteLine("{0}: Retrieving download for version {1}",
nameof(GetDownloads_Success), version.Version);
Expand All @@ -44,8 +43,7 @@ public class DownloadTests
[Values(true, false)] bool loadFileSize)
{
var project = ProviderManager.GetProjects().Single(p => p.Name.Equals(projectName));
var provider = ProviderManager.GetProvider(project);
var version = (await provider.GetVersions(project.Name, new VersionOptions { MaxRecords = 1 })).First();
var version = (await project.GetVersions(new VersionOptions { MaxRecords = 1 })).First();

TestContext.Progress.WriteLine("{0}: Retrieving download for version {1}",
nameof(GetDownloads_LatestVersion), version.Version);
Expand All @@ -66,8 +64,7 @@ public class DownloadTests
public async Task BuildSpigot_Success(string projectName)
{
var project = ProviderManager.GetProjects().Single(p => p.Name.Equals(projectName));
var provider = ProviderManager.GetProvider(project);
var version = (await provider.GetVersions(project.Name, new VersionOptions { MaxRecords = 1 })).First();
var version = (await project.GetVersions(new VersionOptions { MaxRecords = 1 })).First();

TestContext.Progress.WriteLine("{0}: Start building {1} version {2}",
nameof(BuildSpigot_Success), projectName, version.Version);
Expand Down Expand Up @@ -102,8 +99,7 @@ public async Task BuildSpigot_Success(string projectName)
public async Task BuildSpigot_Cancel(string projectName)
{
var project = ProviderManager.GetProjects().Single(p => p.Name.Equals(projectName));
var provider = ProviderManager.GetProvider(project);
var version = (await provider.GetVersions(project.Name, new VersionOptions { MaxRecords = 1 })).First();
var version = (await project.GetVersions(new VersionOptions { MaxRecords = 1 })).First();

TestContext.Progress.WriteLine("{0}: Start building {1} version {2}",
nameof(BuildSpigot_Success), projectName, version.Version);
Expand Down

0 comments on commit 165e97d

Please sign in to comment.