Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17940


Ignore:
Timestamp:
04/14/21 19:57:29 (4 years ago)
Author:
gkronber
Message:

#3117: changed plugin dependency test case to allow plugin dependencies to the same plugin in different versions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Tests/HeuristicLab-3.3/PluginDependenciesTest.cs

    r17781 r17940  
    3434    private static Dictionary<Assembly, Type> loadedPlugins;
    3535    private static Dictionary<string, string> pluginNames;
     36    private static Dictionary<string, Version> pluginVersions;
    3637    private static Dictionary<string, Assembly> pluginFilesToPluginLookup = new Dictionary<string, Assembly>();
    3738
     
    4748
    4849      pluginNames = loadedPlugins.ToDictionary(a => a.Key.GetName().FullName, a => GetPluginName(a.Value));
     50      pluginVersions = loadedPlugins.ToDictionary(a => a.Key.GetName().FullName, a => GetPluginVersion(a.Value));
    4951
    5052      foreach (Assembly pluginAssembly in loadedPlugins.Keys) {
     
    7173        var referencedAssemblies = pluginAssemblies.SelectMany(a => a.GetReferencedAssemblies()).ToList();
    7274
    73         Dictionary<string, PluginDependencyAttribute> pluginDependencies = Attribute.GetCustomAttributes(plugin, false).OfType<PluginDependencyAttribute>().ToDictionary(a => a.Dependency);
     75        var pluginDependencies = Attribute.GetCustomAttributes(plugin, false).OfType<PluginDependencyAttribute>().ToArray();
     76
     77        bool versionLessThan(Version a, Version b) => a.Major < b.Major || ((a.Major == b.Major) && (a.Minor <= b.Minor));
     78
     79        bool compatiblePluginAvailable(string referencedAssemblyName) => pluginDependencies.Any(pd => pd.Dependency == pluginNames[referencedAssemblyName] && versionLessThan(pd.Version, pluginVersions[referencedAssemblyName]));
    7480
    7581        foreach (AssemblyName referencedAssemblyName in referencedAssemblies) {
    7682          if (IsPluginAssemblyName(referencedAssemblyName)) {
    77             if (!pluginDependencies.ContainsKey(pluginNames[referencedAssemblyName.FullName]))
    78               errorMessage.AppendLine("Missing dependency in plugin " + plugin + " to referenced plugin " + pluginNames[referencedAssemblyName.FullName] + ".");
     83            if (!compatiblePluginAvailable(referencedAssemblyName.FullName))
     84              errorMessage.AppendLine("Missing dependency in plugin " + plugin + " to referenced plugin " + pluginNames[referencedAssemblyName.FullName] + " in version >= " + pluginVersions[referencedAssemblyName.FullName] + ".");
    7985          } else { //no plugin assembly => test if the assembly is delivered by another plugin
    8086            if (pluginFilesToPluginLookup.ContainsKey(referencedAssemblyName.Name)) {
    8187              string containingPluginFullName = pluginFilesToPluginLookup[referencedAssemblyName.Name].FullName;
    82               if (containingPluginFullName != pluginAssembly.FullName && !pluginDependencies.ContainsKey(pluginNames[containingPluginFullName]))
    83                 errorMessage.AppendLine("Missing dependency in plugin " + plugin + " to plugin " + pluginNames[containingPluginFullName] + " due to a reference to " + referencedAssemblyName.FullName + ".");
     88              if (containingPluginFullName != pluginAssembly.FullName && !compatiblePluginAvailable(containingPluginFullName))
     89                errorMessage.AppendLine("Missing dependency in plugin " + plugin + " to plugin " + pluginNames[containingPluginFullName] + " in version >= " + pluginVersions[containingPluginFullName] + " due to a reference to " + referencedAssemblyName.FullName + ".");
    8490            }
    8591          }
     
    136142    }
    137143
     144    private static Version GetPluginVersion(Type plugin) {
     145      var version = new Version();
     146      PluginAttribute pluginAttribute = (PluginAttribute)Attribute.GetCustomAttribute(plugin, typeof(PluginAttribute));
     147      if (pluginAttribute != null) {
     148        version = pluginAttribute.Version;
     149      }
     150      return version;
     151    }
     152
    138153    private static bool IsPluginAssemblyName(AssemblyName assemblyName) {
    139154      return pluginNames.ContainsKey(assemblyName.FullName);
Note: See TracChangeset for help on using the changeset viewer.