public IGeneratorPlugin LoadPlugin(PluginDescriptor pluginDescriptor) { var generatorPluginAssemblyPath = GetGeneratorPluginAssemblies(pluginDescriptor).FirstOrDefault(); if (generatorPluginAssemblyPath == null) throw new SpecFlowException(string.Format("Unable to find plugin in the plugin search path: {0}. Please check http://go.specflow.org/doc-plugins for details.", pluginDescriptor.Name)); Assembly pluginAssembly; try { pluginAssembly = Assembly.LoadFrom(generatorPluginAssemblyPath); } catch(Exception ex) { throw new SpecFlowException(string.Format("Unable to load plugin assembly: {0}. Please check http://go.specflow.org/doc-plugins for details.", generatorPluginAssemblyPath), ex); } var pluginAttribute = (GeneratorPluginAttribute)Attribute.GetCustomAttribute(pluginAssembly, typeof(GeneratorPluginAttribute)); if (pluginAttribute == null) throw new SpecFlowException("Missing [assembly:GeneratorPlugin] attribute in " + generatorPluginAssemblyPath); if (!typeof(IGeneratorPlugin).IsAssignableFrom((pluginAttribute.PluginType))) throw new SpecFlowException(string.Format("Invalid plugin attribute in {0}. Plugin type must implement IGeneratorPlugin. Please check http://go.specflow.org/doc-plugins for details.", generatorPluginAssemblyPath)); IGeneratorPlugin plugin; try { plugin = (IGeneratorPlugin)Activator.CreateInstance(pluginAttribute.PluginType); } catch (Exception ex) { throw new SpecFlowException(string.Format("Invalid plugin in {0}. Plugin must have a default constructor that does not throw exception. Please check http://go.specflow.org/doc-plugins for details.", generatorPluginAssemblyPath), ex); } return plugin; }
public IRuntimePlugin LoadPlugin(PluginDescriptor pluginDescriptor) { var assemblyName = string.Format(ASSEMBLY_NAME_PATTERN, pluginDescriptor.Name); Assembly assembly; try { assembly = Assembly.Load(assemblyName); } catch(Exception ex) { throw new SpecFlowException(string.Format("Unable to load plugin: {0}. Please check http://go.specflow.org/doc-plugins for details.", pluginDescriptor.Name), ex); } var pluginAttribute = (RuntimePluginAttribute)Attribute.GetCustomAttribute(assembly, typeof(RuntimePluginAttribute)); if (pluginAttribute == null) throw new SpecFlowException(string.Format("Missing [assembly:RuntimePlugin] attribute in {0}. Please check http://go.specflow.org/doc-plugins for details.", assembly.FullName)); if (!typeof(IRuntimePlugin).IsAssignableFrom((pluginAttribute.PluginType))) throw new SpecFlowException(string.Format("Invalid plugin attribute in {0}. Plugin type must implement IRuntimePlugin. Please check http://go.specflow.org/doc-plugins for details.", assembly.FullName)); IRuntimePlugin plugin; try { plugin = (IRuntimePlugin)Activator.CreateInstance(pluginAttribute.PluginType); } catch (Exception ex) { throw new SpecFlowException(string.Format("Invalid plugin in {0}. Plugin must have a default constructor that does not throw exception. Please check http://go.specflow.org/doc-plugins for details.", assembly.FullName), ex); } return plugin; }
private IEnumerable<string> GetGeneratorPluginAssemblies(PluginDescriptor pluginDescriptor) { foreach (var pluginGeneratorFolder in GetPluginGeneratorFolders(pluginDescriptor)) { string generatorSpecificAssembly = Path.GetFullPath(Path.Combine(pluginGeneratorFolder, string.Format("{0}.Generator.SpecFlowPlugin.dll", pluginDescriptor.Name))); if (File.Exists(generatorSpecificAssembly)) yield return generatorSpecificAssembly; string genericAssembly = Path.GetFullPath(Path.Combine(pluginGeneratorFolder, string.Format("{0}.SpecFlowPlugin.dll", pluginDescriptor.Name))); if (File.Exists(genericAssembly)) yield return genericAssembly; } }
protected virtual IRuntimePlugin LoadPlugin(IRuntimePluginLoader pluginLoader, PluginDescriptor pluginDescriptor) { return pluginLoader.LoadPlugin(pluginDescriptor); }
private static IRuntimePlugin LoadPlugin(IRuntimePluginLoader pluginLoader, PluginDescriptor pluginDescriptor) { return pluginLoader.LoadPlugin(pluginDescriptor); }
private IEnumerable<string> GetPluginGeneratorFolders(PluginDescriptor pluginDescriptor) { var pluginGeneratorFolders = (new[] { @"" }) .Concat(GetSpecFlowVersionSpecifiers().Select(v => @"tools\SpecFlowPlugin" + v)) .Concat(new[] { @"tools", @"lib\net45", @"lib\net40", @"lib\net35", @"lib"}); return GetPluginFolders(pluginDescriptor).SelectMany(pluginFolder => pluginGeneratorFolders, Path.Combine); }
private IEnumerable<string> GetNuGetPluginFolders(PluginDescriptor pluginDescriptor) { string nuGetPackagesFolder = GetNuGetPackagesFolder(); return pluginPostfixes .Select(pluginPostfix => pluginDescriptor.Name + pluginPostfix) .Select(packageName => GetLatestPackage(nuGetPackagesFolder, packageName)) .Where(pluginFolder => pluginFolder != null); }
private IEnumerable<string> GetPluginFolders(PluginDescriptor pluginDescriptor) { if (pluginDescriptor.Path != null) { yield return Path.Combine(projectSettings.ProjectFolder, pluginDescriptor.Path); yield break; } yield return generatorFolder; foreach (var nuGetPluginFolder in GetNuGetPluginFolders(pluginDescriptor)) yield return nuGetPluginFolder; }
private static IGeneratorPlugin LoadPlugin(IGeneratorPluginLoader pluginLoader, PluginDescriptor pluginDescriptor) { return pluginLoader.LoadPlugin(pluginDescriptor); }