• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

KSP-CKAN / CKAN / 16536075576

26 Jul 2025 04:27AM UTC coverage: 56.351% (+8.5%) from 47.804%
16536075576

push

github

HebaruSan
Merge #4408 Add tests for CmdLine

4558 of 8422 branches covered (54.12%)

Branch coverage included in aggregate %.

148 of 273 new or added lines in 28 files covered. (54.21%)

18 existing lines in 5 files now uncovered.

9719 of 16914 relevant lines covered (57.46%)

1.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

48.94
/Netkan/Validators/ModuleManagerDependsValidator.cs
1
using System.IO;
2
using System.Linq;
3
using System.Text.RegularExpressions;
4
using Newtonsoft.Json.Linq;
5
using ICSharpCode.SharpZipLib.Zip;
6
using log4net;
7

8
using CKAN.NetKAN.Services;
9
using CKAN.NetKAN.Model;
10
using CKAN.Extensions;
11
using CKAN.Games;
12

13
namespace CKAN.NetKAN.Validators
14
{
15
    internal sealed class ModuleManagerDependsValidator : IValidator
16
    {
17
        public ModuleManagerDependsValidator(IHttpService http, IModuleService moduleService, IGame game)
2✔
18
        {
2✔
19
            _http          = http;
2✔
20
            _moduleService = moduleService;
2✔
21
            _game          = game;
2✔
22
        }
2✔
23

24
        public void Validate(Metadata metadata)
25
        {
2✔
26
            Log.Debug("Validating that metadata dependencies are consistent with cfg file syntax");
2✔
27

28
            JObject    json = metadata.AllJson;
2✔
29
            CkanModule mod  = CkanModule.FromJson(json.ToString());
2✔
30
            if (!mod.IsDLC)
2!
31
            {
2✔
32
                var package = _http.DownloadModule(metadata);
2✔
33
                if (!string.IsNullOrEmpty(package))
2!
34
                {
×
35
                    ZipFile zip = new ZipFile(package);
×
36
                    GameInstance inst = new GameInstance(_game, "/", "dummy", new NullUser());
×
37
                    var mmConfigs = _moduleService.GetConfigFiles(mod, zip, inst)
×
38
                        .Where(cfg => moduleManagerRegex.IsMatch(
×
39
                            new StreamReader(zip.GetInputStream(cfg.source)).ReadToEnd()))
40
                        .Memoize();
41

42
                    bool dependsOnMM = mod?.depends?.Any(r => r.ContainsAny(identifiers)) ?? false;
×
43

44
                    if (!dependsOnMM && mmConfigs.Any())
×
45
                    {
×
46
                        Log.WarnFormat(
×
47
                            "ModuleManager syntax used without ModuleManager dependency: {0}",
NEW
48
                            string.Join(", ", mmConfigs.Select(cfg => cfg.source.Name).Order())
×
49
                        );
50
                    }
×
51
                    else if (dependsOnMM && !mmConfigs.Any())
×
52
                    {
×
53
                        Log.Warn("ModuleManager dependency may not be needed, no ModuleManager syntax found");
×
54
                    }
×
55
                }
×
56
            }
2✔
57
        }
2✔
58

59
        private readonly string[] identifiers = new string[] { "ModuleManager" };
2✔
60

61
        private static readonly Regex moduleManagerRegex = new Regex(
2✔
62
            @"^\s*[@+$\-!%]|^\s*[a-zA-Z0-9_]+:",
63
            RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline
64
        );
65

66
        private readonly IHttpService   _http;
67
        private readonly IModuleService _moduleService;
68
        private readonly IGame          _game;
69

70
        private static readonly ILog Log = LogManager.GetLogger(typeof(ModuleManagerDependsValidator));
2✔
71
    }
72
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc