- Timestamp:
- 04/14/21 19:57:29 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Tests/HeuristicLab-3.3/PluginDependenciesTest.cs
r17781 r17940 34 34 private static Dictionary<Assembly, Type> loadedPlugins; 35 35 private static Dictionary<string, string> pluginNames; 36 private static Dictionary<string, Version> pluginVersions; 36 37 private static Dictionary<string, Assembly> pluginFilesToPluginLookup = new Dictionary<string, Assembly>(); 37 38 … … 47 48 48 49 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)); 49 51 50 52 foreach (Assembly pluginAssembly in loadedPlugins.Keys) { … … 71 73 var referencedAssemblies = pluginAssemblies.SelectMany(a => a.GetReferencedAssemblies()).ToList(); 72 74 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])); 74 80 75 81 foreach (AssemblyName referencedAssemblyName in referencedAssemblies) { 76 82 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] + "."); 79 85 } else { //no plugin assembly => test if the assembly is delivered by another plugin 80 86 if (pluginFilesToPluginLookup.ContainsKey(referencedAssemblyName.Name)) { 81 87 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 + "."); 84 90 } 85 91 } … … 136 142 } 137 143 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 138 153 private static bool IsPluginAssemblyName(AssemblyName assemblyName) { 139 154 return pluginNames.ContainsKey(assemblyName.FullName);
Note: See TracChangeset
for help on using the changeset viewer.