Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/22/12 11:11:38 (12 years ago)
Author:
jkarder
Message:

#1331:

  • synced branch with trunk
  • added custom interface (ISimilarityBasedOperator) to mark operators that conduct similarity calculation
  • similarity calculators are now parameterized by the algorithm
  • deleted SolutionPool2TierUpdateMethod
  • deleted KnapsackMultipleGuidesPathRelinker
  • moved IImprovementOperator, IPathRelinker and ISimilarityCalculator to HeuristicLab.Optimization
  • added parameter descriptions
  • fixed plugin references
  • fixed count of EvaluatedSolutions
  • fixed check for duplicate solutions
  • minor code improvements
Location:
branches/ScatterSearch (trunk integration)
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/ScatterSearch (trunk integration)

  • branches/ScatterSearch (trunk integration)/HeuristicLab.Tests

  • branches/ScatterSearch (trunk integration)/HeuristicLab.Tests/HeuristicLab-3.3

    • Property bugtraq:label deleted
    • Property bugtraq:logregex deleted
    • Property bugtraq:url deleted
    • Property bugtraq:warnifnoissue deleted
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Tests/HeuristicLab-3.3/PluginDependenciesTest.cs

    r7450 r8086  
    2222using System;
    2323using System.Collections.Generic;
     24using System.IO;
    2425using System.Linq;
    2526using System.Reflection;
     
    3334    private static Dictionary<Assembly, Type> loadedPlugins;
    3435    private static Dictionary<string, string> pluginNames;
    35     private static HashSet<string> extLibPluginNames;
     36    private static Dictionary<string, Assembly> pluginFilesToPluginLookup = new Dictionary<string, Assembly>();
     37    //private static Dictionary<string, string> pluginToPluginFilesLookup = new Dictionary<string, string>();
    3638
    3739    // Use ClassInitialize to run code before running the first test in the class
    3840    [ClassInitialize]
    3941    public static void MyClassInitialize(TestContext testContext) {
    40       loadedPlugins = PluginLoader.Assemblies.Where(x => PluginLoader.IsPluginAssembly(x)).ToDictionary(a => a, GetPluginFromAssembly);
     42      loadedPlugins = PluginLoader.Assemblies.Where(PluginLoader.IsPluginAssembly).ToDictionary(a => a, GetPluginFromAssembly);
    4143      pluginNames = loadedPlugins.ToDictionary(a => a.Key.GetName().FullName, a => GetPluginName(a.Value));
    4244
    43       extLibPluginNames = new HashSet<string>();
    44       extLibPluginNames.Add("HeuristicLab.ALGLIB");
    45       extLibPluginNames.Add("HeuristicLab.LibSVM");
    46       extLibPluginNames.Add("HeuristicLab.log4net");
    47       extLibPluginNames.Add("HeuristicLab.MathJax");
    48       extLibPluginNames.Add("HeuristicLab.Netron");
    49       extLibPluginNames.Add("HeuristicLab.ProtobufCS");
    50       extLibPluginNames.Add("HeuristicLab.SharpDevelop");
    51       extLibPluginNames.Add("HeuristicLab.WinFormsUI");
     45      foreach (Assembly pluginAssembly in loadedPlugins.Keys) {
     46        Type pluginType = GetPluginFromAssembly(pluginAssembly);
     47        var pluginFileAttributes = Attribute.GetCustomAttributes(pluginType, false).OfType<PluginFileAttribute>();
     48        foreach (var pluginFileAttribute in pluginFileAttributes) {
     49          string fillNameWithoutExtension = Path.GetFileNameWithoutExtension(pluginFileAttribute.FileName);
     50          pluginFilesToPluginLookup.Add(fillNameWithoutExtension, pluginAssembly);
     51        }
     52      }
    5253    }
    5354
     
    5758      foreach (Assembly pluginAssembly in loadedPlugins.Keys) {
    5859        Type plugin = loadedPlugins[pluginAssembly];
    59         Dictionary<string, PluginDependencyAttribute> pluginDependencies =
    60           Attribute.GetCustomAttributes(plugin, false).OfType<PluginDependencyAttribute>().ToDictionary(a => a.Dependency);
    61         foreach (AssemblyName referencedPluginName in pluginAssembly.GetReferencedAssemblies())
    62           if (pluginNames.ContainsKey(referencedPluginName.FullName)) {  //check if reference assembly is a plugin
    63             if (!pluginDependencies.ContainsKey(pluginNames[referencedPluginName.FullName]))
    64               errorMessage.AppendLine("Missing dependency in plugin " + plugin + " to referenced plugin " + pluginNames[referencedPluginName.FullName] + ".");
     60        Dictionary<string, PluginDependencyAttribute> pluginDependencies = Attribute.GetCustomAttributes(plugin, false).OfType<PluginDependencyAttribute>().ToDictionary(a => a.Dependency);
     61
     62        foreach (AssemblyName referencedAssemblyName in pluginAssembly.GetReferencedAssemblies()) {
     63          if (IsPluginAssemblyName(referencedAssemblyName)) {
     64            if (!pluginDependencies.ContainsKey(pluginNames[referencedAssemblyName.FullName]))
     65              errorMessage.AppendLine("Missing dependency in plugin " + plugin + " to referenced plugin " + pluginNames[referencedAssemblyName.FullName] + ".");
     66          } else { //no plugin assembly => test if the assembly is delivered by another plugin
     67            if (pluginFilesToPluginLookup.ContainsKey(referencedAssemblyName.Name)) {
     68              string containingPluginFullName = pluginFilesToPluginLookup[referencedAssemblyName.Name].FullName;
     69              if (containingPluginFullName != pluginAssembly.FullName && !pluginDependencies.ContainsKey(pluginNames[containingPluginFullName]))
     70                errorMessage.AppendLine("Missing dependency in plugin " + plugin + " to plugin " + pluginNames[containingPluginFullName] + " due to a reference to " + referencedAssemblyName.FullName + ".");
     71            }
    6572          }
     73        }
    6674      }
    67 
    6875      Assert.IsTrue(errorMessage.Length == 0, errorMessage.ToString());
    6976    }
     
    7481      foreach (Assembly pluginAssembly in loadedPlugins.Keys) {
    7582        Type plugin = loadedPlugins[pluginAssembly];
    76         Dictionary<PluginDependencyAttribute, string> pluginDependencies =
    77           Attribute.GetCustomAttributes(plugin, false).OfType<PluginDependencyAttribute>().ToDictionary(a => a, a => a.Dependency);
     83        Dictionary<PluginDependencyAttribute, string> pluginDependencies = Attribute.GetCustomAttributes(plugin, false).OfType<PluginDependencyAttribute>().ToDictionary(a => a, a => a.Dependency);
    7884
    7985        foreach (PluginDependencyAttribute attribute in pluginDependencies.Keys) {
    8086          string pluginDependencyName = pluginDependencies[attribute];
    81           //do not check extlib plugins, because the transport assemblies are never referenced in the assemblies
    82           if (extLibPluginNames.Contains(pluginDependencyName)) continue;
    83           if (pluginAssembly.GetReferencedAssemblies().Where(a => pluginNames.ContainsKey(a.FullName))
    84             .All(a => pluginNames[a.FullName] != pluginDependencyName)) {
    85             errorMessage.AppendLine("Unnecessary plugin dependency in " + GetPluginName(plugin) + " to " + pluginDependencyName + ".");
    86           }
     87
     88          if (pluginDependencyName == "HeuristicLab.MathJax") continue; //is never referenced as this plugin contains HTML files
     89          var referencedPluginAssemblies = pluginAssembly.GetReferencedAssemblies().Where(IsPluginAssemblyName);
     90          if (referencedPluginAssemblies.Any(a => pluginNames[a.FullName] == pluginDependencyName)) continue;
     91
     92          var referencedNonPluginAssemblies = pluginAssembly.GetReferencedAssemblies().Where(a => !IsPluginAssemblyName(a));
     93          bool found = (from referencedNonPluginAssemblie in referencedNonPluginAssemblies
     94                        select referencedNonPluginAssemblie.Name into assemblyName
     95                        where pluginFilesToPluginLookup.ContainsKey(assemblyName)
     96                        select GetPluginFromAssembly(pluginFilesToPluginLookup[assemblyName]) into pluginType
     97                        select GetPluginName(pluginType)).Any(pluginName => pluginName == pluginDependencyName);
     98
     99          if (!found) errorMessage.AppendLine("Unnecessary plugin dependency in " + GetPluginName(plugin) + " to " + pluginDependencyName + ".");
    87100        }
    88101      }
    89 
    90102      Assert.IsTrue(errorMessage.Length == 0, errorMessage.ToString());
    91103    }
     
    94106      return assembly.GetExportedTypes().Where(t => typeof(IPlugin).IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface).FirstOrDefault();
    95107    }
     108
    96109    private static string GetPluginName(Type plugin) {
    97110      string name = string.Empty;
     
    101114      return name;
    102115    }
     116
     117    private static bool IsPluginAssemblyName(AssemblyName assemblyName) {
     118      return pluginNames.ContainsKey(assemblyName.FullName);
     119    }
    103120  }
    104121}
Note: See TracChangeset for help on using the changeset viewer.