-
-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check swinfo deps after multi-host merge
- Loading branch information
Showing
8 changed files
with
111 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
using ICSharpCode.SharpZipLib.Zip; | ||
using log4net; | ||
|
||
using CKAN.NetKAN.Model; | ||
using CKAN.NetKAN.Services; | ||
using CKAN.Games; | ||
using CKAN.NetKAN.Sources.Github; | ||
using CKAN.NetKAN.Sources.SpaceWarp; | ||
|
||
namespace CKAN.NetKAN.Validators | ||
{ | ||
internal sealed class SpaceWarpInfoValidator : IValidator | ||
{ | ||
public SpaceWarpInfoValidator(IHttpService httpSvc, | ||
IGithubApi githubApi, | ||
IModuleService modSvc, | ||
IGame game) | ||
{ | ||
this.httpSvc = httpSvc; | ||
this.githubApi = githubApi; | ||
this.modSvc = modSvc; | ||
this.game = game; | ||
} | ||
|
||
public void Validate(Metadata metadata) | ||
{ | ||
var moduleJson = metadata.Json(); | ||
CkanModule mod = CkanModule.FromJson(moduleJson.ToString()); | ||
GameInstance inst = new GameInstance(game, "/", "dummy", new NullUser()); | ||
if (httpSvc.DownloadModule(metadata) is string file | ||
&& new ZipFile(file) is ZipFile zip | ||
&& modSvc.GetSpaceWarpInfo(mod, zip, inst, githubApi, httpSvc) is SpaceWarpInfo swinfo) | ||
{ | ||
var moduleDeps = (mod.depends?.OfType<ModuleRelationshipDescriptor>() | ||
.Select(r => r.name) | ||
?? Enumerable.Empty<string>()) | ||
.ToHashSet(); | ||
var missingDeps = (swinfo.dependencies | ||
?.Select(dep => dep.id) | ||
.OfType<string>() | ||
.Where(depId => !moduleDeps.Contains( | ||
// Remove up to last period | ||
Identifier.Sanitize( | ||
depId[(depId.LastIndexOf('.') + 1)..], ""), | ||
// Case insensitive | ||
StringComparer.InvariantCultureIgnoreCase)) | ||
?? Enumerable.Empty<string>()) | ||
.ToList(); | ||
if (missingDeps.Any()) | ||
{ | ||
log.WarnFormat("Dependencies from swinfo.json missing from module: {0}", | ||
string.Join(", ", missingDeps)); | ||
} | ||
} | ||
} | ||
|
||
private readonly IHttpService httpSvc; | ||
private readonly IGithubApi githubApi; | ||
private readonly IModuleService modSvc; | ||
private readonly IGame game; | ||
|
||
private static readonly ILog log = LogManager.GetLogger(typeof(SpaceWarpInfoValidator)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters