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

HicServices / RDMP / 9988321408

18 Jul 2024 08:39AM UTC coverage: 57.299% (+0.6%) from 56.679%
9988321408

push

github

web-flow
marge develop into main (#1890)

* add cron test

* fix yaml

* fix yaml

* update spacing

* use example

* update cron

* update to push

* add 2am cron

* update yaml

* use utc

* add first update

* add populate function

* add changelog

* update tests

* fix test

* attempt to fix test

* interim

* interim

* add label

* add description field

* add vertical scaling

* working UI

* add tooltips

* working ui

* add to cignorelist

* add changelog entry

* tidy up

* fix typo

* fix codeql

* Task/rdmp-1  Update Ticketing System (#1870)

* add initial ticketing update

* fix patch

* interim

* allow blanks

* pass statuses around

* update tests

* add image

* add resources

* tidy up

* tidy up

* fix build

* add icon

* add image

* fix test

* add changelog

* fix error not poping

* add missing line

* fix typo

* tidy up

* Bump ObjectListView.Repack.NET6Plus from 2.9.4 to 2.9.5

Bumps ObjectListView.Repack.NET6Plus from 2.9.4 to 2.9.5.

---
updated-dependencies:
- dependency-name: ObjectListView.Repack.NET6Plus
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump Terminal.Gui from 1.17.0 to 1.17.1 (#1879)

Bumps Terminal.Gui from 1.17.0 to 1.17.1.

---
updated-dependencies:
- dependency-name: Terminal.Gui
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump actions/setup-dotnet from 4.0.0 to 4.0.1 (#1875)

Bumps [actions/setup-dotnet](https://github.com/actions/setup-dotnet) from 4.0.0 to 4.0.1.
- [Release notes](https://github.com/actions/setup-dotnet/releases)
- [Commits](https://github.com/actions/setup-dotnet/compare/v4.0.0...v4.0.1)

---... (continued)

11072 of 20790 branches covered (53.26%)

Branch coverage included in aggregate %.

49 of 83 new or added lines in 17 files covered. (59.04%)

45 existing lines in 12 files now uncovered.

31313 of 53181 relevant lines covered (58.88%)

7890.17 hits per line

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

8.21
/Rdmp.Core/Curation/Data/LoadModuleAssembly.cs
1
// Copyright (c) The University of Dundee 2018-2024
2
// This file is part of the Research Data Management Platform (RDMP).
3
// RDMP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
4
// RDMP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
5
// You should have received a copy of the GNU General Public License along with RDMP. If not, see <https://www.gnu.org/licenses/>.
6

7
using System;
8
using System.Collections.Generic;
9
using System.IO;
10
using System.Linq;
11
using System.Xml;
12
using ICSharpCode.SharpZipLib.Zip;
13
using Rdmp.Core.ReusableLibraryCode.Checks;
14

15
namespace Rdmp.Core.Curation.Data;
16

17
/// <summary>
18
/// This entity wraps references to plugin .nupkg files on disk.
19
/// </summary>
20
public sealed class LoadModuleAssembly
21
{
22
    private static readonly bool IsWin = AppDomain.CurrentDomain.GetAssemblies()
4✔
23
        .Any(static a => a.FullName?.StartsWith("Rdmp.UI", StringComparison.Ordinal) == true);
354!
24

25
    private static readonly string PluginsList = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "rdmpplugins.txt");
4✔
26

27
    internal static readonly List<LoadModuleAssembly> Assemblies = [];
4✔
28
    private readonly FileInfo _file;
29

30
    private LoadModuleAssembly(FileInfo file)
×
31
    {
32
        _file = file;
×
33
    }
×
34

35

36
    private static bool IsReleaseCandidcate(string filename)
37
    {
38
        return filename.Split('.')[^2].Contains("-rc");
×
39
    }
40

41
    private static int GetReleaseCandidateId(string filename)
42
    {
43
        //expects the rc to be something like My.Plugin.3.0.0-rc2
44
        int.TryParse(filename.Split("-rc")[1].Split('.')[0], out var result);
×
45
        return result;
×
46
    }
47

48
    private static Dictionary<string, string> HandlePluginVersioning()
49
    {
50
        var PluginVersionLookup = new Dictionary<string, string>();
×
51
        var PluginPathLookup = new Dictionary<string, string>();
×
52
        var pluginFiles = Directory.EnumerateFiles(AppDomain.CurrentDomain.BaseDirectory, "*.rdmp");
×
53
        foreach (var pluginFile in pluginFiles)
×
54
        {
NEW
55
            using FileStream fs = new(pluginFile, FileMode.Open,FileAccess.Read);
×
56
            using ZipFile zip = new(fs);
×
57
            foreach (ZipEntry ze in zip)
×
58
            {
59
                if (ze.Name.Contains(".nuspec"))
×
60
                {
61
                    using StreamReader sr = new StreamReader(zip.GetInputStream(ze.ZipFileIndex));
×
62
                    var content = sr.ReadToEnd();
×
63
                    var xmlDoc = new XmlDocument();
×
64
                    xmlDoc.LoadXml(content);
×
65

66
                    var name = xmlDoc.GetElementsByTagName("id").Item(0).InnerText;
×
67
                    var version = xmlDoc.GetElementsByTagName("version").Item(0).InnerText;
×
68
                    if (PluginVersionLookup.TryGetValue(name, out var currentVersion))
×
69
                    {
70
                        //already found a version
71
                        var result = new Version(currentVersion).CompareTo(new Version(version));
×
72
                        if (result < 0)
×
73
                        {
74
                            //this version is the latest version
75
                            PluginVersionLookup[name] = version;
×
76
                            PluginPathLookup[name] = pluginFile;
×
77
                        }
78
                        if(result == 0)
×
79
                        {
80
                            //check for RC in the name
81
                            var currentIsReleaseCandidate = IsReleaseCandidcate(PluginPathLookup[name]);
×
82
                            var newIsReleaseCandidate = IsReleaseCandidcate(pluginFile);
×
83
                            if(newIsReleaseCandidate && currentIsReleaseCandidate)
×
84
                            {
85
                                var newIsLatest = GetReleaseCandidateId(pluginFile) > GetReleaseCandidateId(PluginPathLookup[name]);
×
86
                                if (newIsLatest)
×
87
                                {
88
                                    PluginVersionLookup[name] = version;
×
89
                                    PluginPathLookup[name] = pluginFile;
×
90
                                }
91
                            } else if (newIsReleaseCandidate)
×
92
                            {
93
                                //new version is the latest
94
                                PluginVersionLookup[name] = version;
×
95
                                PluginPathLookup[name] = pluginFile;
×
96
                            }
97
                        }
98
                    }
99
                    else
100
                    {
101
                        PluginVersionLookup[name] = version;
×
102
                        PluginPathLookup[name] = pluginFile;
×
103
                    }
104
                    break;
×
105
                }
106

107
            }
108

109
        }
110

111
        return PluginPathLookup;
×
112
    }
113

114
    /// <summary>
115
    /// List the plugin files to load
116
    /// </summary>
117
    /// <returns></returns>
118
    internal static IEnumerable<string> PluginFiles()
119
    {
120
        if (Directory.EnumerateFiles(AppDomain.CurrentDomain.BaseDirectory, "*.rdmp").Count() > 0)
16!
121
        {
122
            //use the modern .RDMP plugins
123
            var plugins = HandlePluginVersioning();
×
124
            return plugins.Values.ToArray();
×
125

126
        }
127
        return File.Exists(PluginsList)
16!
128
            ? File.ReadAllLines(PluginsList)
16✔
129
                .Select(static name => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, name))
×
130
            : Directory.EnumerateFiles(AppDomain.CurrentDomain.BaseDirectory, "*.nupkg");
16✔
131
    }
132

133
    /// <summary>
134
    /// Unpack the plugin DLL files, excluding any Windows UI specific dlls when not running a Windows GUI
135
    /// </summary>
136
    internal static IEnumerable<(string, MemoryStream)> GetContents(string path)
137
    {
138
        var info = new FileInfo(path);
×
139
        if (!info.Exists || info.Length < 100) yield break; // Ignore missing or empty files
×
140

141
        var pluginStream = info.OpenRead();
×
142
        if (!pluginStream.CanSeek)
×
143
            throw new ArgumentException("Seek needed", nameof(path));
×
144

145
        Assemblies.Add(new LoadModuleAssembly(info));
×
146

147
        using var zip = new ZipFile(pluginStream);
×
148
        foreach (var e in zip.Cast<ZipEntry>()
×
149
                     .Where(static e => e.IsFile && e.Name.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) &&
150
                                        (IsWin || !e.Name.Contains("/windows/"))))
151
        {
152
            using var s = zip.GetInputStream(e);
×
153
            using var ms2 = new MemoryStream();
×
154
            s.CopyTo(ms2);
×
155
            ms2.Position = 0;
×
156
            yield return (e.Name, ms2);
×
157
        }
×
158
    }
×
159

160
    /// <summary>
161
    /// Copy the plugin nupkg to the given directory
162
    /// </summary>
163
    /// <param name="downloadDirectory"></param>
164
    public void DownloadAssembly(DirectoryInfo downloadDirectory)
165
    {
166
        if (!downloadDirectory.Exists)
×
167
            downloadDirectory.Create();
×
168
        var targetFile = Path.Combine(downloadDirectory.FullName, _file.Name);
×
169
        _file.CopyTo(targetFile, true);
×
170
    }
×
171

172
    /// <summary>
173
    /// Delete the plugin file from disk, and remove it from rdmpplugins.txt if in use
174
    /// </summary>
175
    public void Delete()
176
    {
177
        _file.Delete();
×
178
        if (!File.Exists(PluginsList)) return;
×
179

180
        var tmp = $"{PluginsList}.tmp";
×
181
        File.WriteAllLines(tmp, File.ReadAllLines(PluginsList).Where(l => !l.Contains(_file.Name)));
×
182
        File.Move(tmp, PluginsList, true);
×
183
    }
×
184

185
    public override string ToString() => _file.Name;
×
186

187
    public static void UploadFile(ICheckNotifier checkNotifier, FileInfo toCommit)
188
    {
189
        try
190
        {
191
            toCommit.CopyTo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, toCommit.Name), true);
×
192
            if (!File.Exists(PluginsList)) return;
×
193

194
            // Now the tricky bit: add this new file, and remove any other versions of the same
195
            // e.g. adding DummyPlugin-1.2.3 should delete DummyPlugin-2.0 and DummyPlugin-1.0 if present
196
            var list = File.ReadAllLines(PluginsList);
×
197
            var tmp = $"{PluginsList}.tmp";
×
198

199
            var versionPos = toCommit.Name.IndexOf('-');
×
200
            if (versionPos != -1)
×
201
            {
202
                var stub = toCommit.Name[..(versionPos + 1)];
×
203
                list = list.Where(l => !l.StartsWith(stub, StringComparison.OrdinalIgnoreCase)).ToArray();
×
204
            }
205

206
            File.WriteAllLines(tmp, list.Union([toCommit.Name]));
×
207
            File.Move(tmp, PluginsList, true);
×
208
        }
×
209
        catch (Exception e)
×
210
        {
211
            checkNotifier.OnCheckPerformed(new CheckEventArgs($"Failed copying plugin {toCommit.Name}",
×
212
                CheckResult.Fail, e));
×
213
            throw;
×
214
        }
215
    }
×
216
}
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

© 2025 Coveralls, Inc