< Summary - Jellyfin

Information
Class: MediaBrowser.Common.Plugins.LocalPlugin
Assembly: MediaBrowser.Common
File(s): /srv/git/jellyfin/MediaBrowser.Common/Plugins/LocalPlugin.cs
Line coverage
54%
Covered lines: 13
Uncovered lines: 11
Coverable lines: 24
Total lines: 139
Line coverage: 54.1%
Branch coverage
17%
Covered branches: 5
Total branches: 28
Branch coverage: 17.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Id()100%11100%
get_Name()100%11100%
get_Version()100%22100%
get_IsEnabledAndSupported()50%22100%
Compare(...)0%156120%
GetPluginInfo()50%44100%
Equals(...)0%620%
GetHashCode()100%210%
Equals(...)0%4260%

File(s)

/srv/git/jellyfin/MediaBrowser.Common/Plugins/LocalPlugin.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using MediaBrowser.Model.Plugins;
 4
 5namespace MediaBrowser.Common.Plugins
 6{
 7    /// <summary>
 8    /// Local plugin class.
 9    /// </summary>
 10    public class LocalPlugin : IEquatable<LocalPlugin>
 11    {
 12        private readonly bool _supported;
 13        private Version? _version;
 14
 15        /// <summary>
 16        /// Initializes a new instance of the <see cref="LocalPlugin"/> class.
 17        /// </summary>
 18        /// <param name="path">The plugin path.</param>
 19        /// <param name="isSupported"><b>True</b> if Jellyfin supports this version of the plugin.</param>
 20        /// <param name="manifest">The manifest record for this plugin, or null if one does not exist.</param>
 21        public LocalPlugin(string path, bool isSupported, PluginManifest manifest)
 22        {
 23            Path = path;
 17624            DllFiles = Array.Empty<string>();
 17625            _supported = isSupported;
 26            Manifest = manifest;
 17627        }
 28
 29        /// <summary>
 30        /// Gets the plugin id.
 31        /// </summary>
 1332        public Guid Id => Manifest.Id;
 33
 34        /// <summary>
 35        /// Gets the plugin name.
 36        /// </summary>
 21937        public string Name => Manifest.Name;
 38
 39        /// <summary>
 40        /// Gets the plugin version.
 41        /// </summary>
 42        public Version Version
 43        {
 44            get
 45            {
 16146                if (_version is null)
 47                {
 15448                    _version = Version.Parse(Manifest.Version);
 49                }
 50
 16151                return _version;
 52            }
 53        }
 54
 55        /// <summary>
 56        /// Gets the plugin path.
 57        /// </summary>
 58        public string Path { get; }
 59
 60        /// <summary>
 61        /// Gets or sets the list of dll files for this plugin.
 62        /// </summary>
 63        public IReadOnlyList<string> DllFiles { get; set; }
 64
 65        /// <summary>
 66        /// Gets or sets the instance of this plugin.
 67        /// </summary>
 68        public IPlugin? Instance { get; set; }
 69
 70        /// <summary>
 71        /// Gets a value indicating whether Jellyfin supports this version of the plugin, and it's enabled.
 72        /// </summary>
 373        public bool IsEnabledAndSupported => _supported && Manifest.Status >= PluginStatus.Active;
 74
 75        /// <summary>
 76        /// Gets a value indicating whether the plugin has a manifest.
 77        /// </summary>
 78        public PluginManifest Manifest { get; }
 79
 80        /// <summary>
 81        /// Compare two <see cref="LocalPlugin"/>.
 82        /// </summary>
 83        /// <param name="a">The first item.</param>
 84        /// <param name="b">The second item.</param>
 85        /// <returns>Comparison result.</returns>
 86        public static int Compare(LocalPlugin a, LocalPlugin b)
 87        {
 088            if (a is null || b is null)
 89            {
 090                throw new ArgumentNullException(a is null ? nameof(a) : nameof(b));
 91            }
 92
 093            var compare = string.Compare(a.Name, b.Name, StringComparison.OrdinalIgnoreCase);
 94
 95            // Id is not equal but name is.
 096            if (!a.Id.Equals(b.Id) && compare == 0)
 97            {
 098                compare = a.Id.CompareTo(b.Id);
 99            }
 100
 0101            return compare == 0 ? a.Version.CompareTo(b.Version) : compare;
 102        }
 103
 104        /// <summary>
 105        /// Returns the plugin information.
 106        /// </summary>
 107        /// <returns>A <see cref="PluginInfo"/> instance containing the information.</returns>
 108        public PluginInfo GetPluginInfo()
 109        {
 7110            var inst = Instance?.GetPluginInfo() ?? new PluginInfo(Manifest.Name, Version, Manifest.Description, Manifes
 7111            inst.Status = Manifest.Status;
 7112            inst.HasImage = !string.IsNullOrEmpty(Manifest.ImagePath);
 7113            return inst;
 114        }
 115
 116        /// <inheritdoc />
 117        public override bool Equals(object? obj)
 118        {
 0119            return obj is LocalPlugin other && this.Equals(other);
 120        }
 121
 122        /// <inheritdoc />
 123        public override int GetHashCode()
 124        {
 0125            return Name.GetHashCode(StringComparison.OrdinalIgnoreCase);
 126        }
 127
 128        /// <inheritdoc />
 129        public bool Equals(LocalPlugin? other)
 130        {
 0131            if (other is null)
 132            {
 0133                return false;
 134            }
 135
 0136            return Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase) && Id.Equals(other.Id) && Version.Equals(
 137        }
 138    }
 139}