Ejemplo n.º 1
0
 public void CreateExtensionAssemblies()
 {
     _ea = new ExtensionAssembly(THIS_ASSEMBLY_PATH, false);
     _eaCopy = new ExtensionAssembly(THIS_ASSEMBLY_PATH, false);
     _eaBetter = new ExtensionAssembly(THIS_ASSEMBLY_PATH, false);
     _eaBetter.Assembly.Name.Version = new Version(7, 0);
     _eaOther = new ExtensionAssembly(ENGINE_ASSEMBLY_PATH, false);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new instance of the <see cref="TaskBuilder" /> class
 /// for the specified <see cref="Task" /> class in the specified
 /// <see cref="ExtensionAssembly" />.
 /// </summary>
 /// <param name="extensionAssembly">The <see cref="ExtensionAssembly" /> containing the <see cref="Task" />.</param>
 /// <param name="className">The class representing the <see cref="Task" />.</param>
 internal TaskBuilder(ExtensionAssembly extensionAssembly, string className) : base(extensionAssembly)
 {
     _className = className;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates a new instance of the <see cref="TaskBuilder" /> class
 /// for the specified <see cref="Task" /> class in the specified
 /// <see cref="Assembly" />.
 /// </summary>
 /// <remarks>
 /// An <see cref="ExtensionAssembly" /> for the specified <see cref="Assembly" />
 /// is cached for future use.
 /// </remarks>
 /// <param name="assembly">The <see cref="Assembly" /> containing the <see cref="Task" />.</param>
 /// <param name="className">The class representing the <see cref="Task" />.</param>
 public TaskBuilder(Assembly assembly, string className)
     : this(ExtensionAssembly.Create(assembly), className)
 {
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Scan a single assembly for extensions marked by ExtensionAttribute.
        /// For each extension, create an ExtensionNode and link it to the
        /// correct ExtensionPoint. Public for testing.
        /// </summary>
        internal void FindExtensionsInAssembly(ExtensionAssembly assembly)
        {
            log.Info("Scanning {0} assembly for Extensions", assembly.FilePath);

            if (CanLoadTargetFramework(Assembly.GetEntryAssembly(), assembly))
            {
                IRuntimeFramework assemblyTargetFramework = null;
#if !NETSTANDARD2_0
                //var currentFramework = RuntimeFramework.CurrentFramework;
                //assemblyTargetFramework = assembly.TargetFramework;
                //if (!currentFramework.CanLoad(assemblyTargetFramework))
                //{
                //    if (!assembly.FromWildCard)
                //    {
                //        throw new NUnitEngineException($"Extension {assembly.FilePath} targets {assemblyTargetFramework.DisplayName}, which is not available.");
                //    }
                //    else
                //    {
                //        log.Info($"Assembly {assembly.FilePath} targets {assemblyTargetFramework.DisplayName}, which is not available. Assembly found via wildcard.");
                //        return;
                //    }
                //}
#endif

                foreach (var type in assembly.MainModule.GetTypes())
                {
                    CustomAttribute extensionAttr = type.GetAttribute("NUnit.Engine.Extensibility.ExtensionAttribute");

                    if (extensionAttr == null)
                    {
                        continue;
                    }

                    object versionArg = extensionAttr.GetNamedArgument("EngineVersion");
                    if (versionArg != null && new Version((string)versionArg) > ENGINE_VERSION)
                    {
                        continue;
                    }

                    var node = new ExtensionNode(assembly.FilePath, assembly.AssemblyVersion, type.FullName, assemblyTargetFramework);
                    node.Path        = extensionAttr.GetNamedArgument("Path") as string;
                    node.Description = extensionAttr.GetNamedArgument("Description") as string;

                    object enabledArg = extensionAttr.GetNamedArgument("Enabled");
                    node.Enabled = enabledArg != null
                        ? (bool)enabledArg : true;

                    log.Info("  Found ExtensionAttribute on Type " + type.Name);

                    foreach (var attr in type.GetAttributes("NUnit.Engine.Extensibility.ExtensionPropertyAttribute"))
                    {
                        string name  = attr.ConstructorArguments[0].Value as string;
                        string value = attr.ConstructorArguments[1].Value as string;

                        if (name != null && value != null)
                        {
                            node.AddProperty(name, value);
                            log.Info("        ExtensionProperty {0} = {1}", name, value);
                        }
                    }

                    _extensions.Add(node);

                    ExtensionPoint ep;
                    if (node.Path == null)
                    {
                        ep = DeduceExtensionPointFromType(type);
                        if (ep == null)
                        {
                            string msg = string.Format(
                                "Unable to deduce ExtensionPoint for Type {0}. Specify Path on ExtensionAttribute to resolve.",
                                type.FullName);
                            throw new NUnitEngineException(msg);
                        }

                        node.Path = ep.Path;
                    }
                    else
                    {
                        ep = GetExtensionPoint(node.Path);
                        if (ep == null)
                        {
                            string msg = string.Format(
                                "Unable to locate ExtensionPoint for Type {0}. The Path {1} cannot be found.",
                                type.FullName,
                                node.Path);
                            throw new NUnitEngineException(msg);
                        }
                    }

                    ep.Install(node);
                }
            }
        }
Ejemplo n.º 5
0
 internal FrameworkCombo(Assembly runnerAsm, ExtensionAssembly extensionAsm)
 {
     RunnerAssembly    = runnerAsm;
     ExtensionAssembly = extensionAsm;
 }
 /// <summary>
 /// Creates a new instance of the <see cref="DataTypeBaseBuilder" />
 /// class for the specified <see cref="DataTypeBase" /> class in the
 /// <see cref="ExtensionAssembly" /> specified.
 /// </summary>
 /// <param name="extensionAssembly">The <see cref="ExtensionAssembly" /> containing the <see cref="DataTypeBase" />.</param>
 /// <param name="className">The class representing the <see cref="DataTypeBase" />.</param>
 internal DataTypeBaseBuilder(ExtensionAssembly extensionAssembly, string className) : base(extensionAssembly)
 {
     _className = className;
 }
 /// <summary>
 /// Creates a new instance of the <see cref="DataTypeBaseBuilder" /> class
 /// for the specified <see cref="DataTypeBase" /> class in the specified
 /// <see cref="Assembly" />.
 /// </summary>
 /// <remarks>
 /// An <see cref="ExtensionAssembly" /> for the specified <see cref="Assembly" />
 /// is cached for future use.
 /// </remarks>
 /// <param name="assembly">The <see cref="Assembly" /> containing the <see cref="DataTypeBase" />.</param>
 /// <param name="className">The class representing the <see cref="DataTypeBase" />.</param>
 public DataTypeBaseBuilder(Assembly assembly, string className)
     : this(ExtensionAssembly.Create(assembly), className)
 {
 }
Ejemplo n.º 8
0
        public static bool ScanAssembly(Assembly assembly, Task task)
        {
            task.Log(Level.Verbose, "Scanning assembly \"{0}\" for extensions.",
                     assembly.GetName().Name);

            foreach (Type type in assembly.GetExportedTypes())
            {
                foreach (MethodInfo methodInfo in type.GetMethods())
                {
                    if (methodInfo.IsStatic)
                    {
                        task.Log(Level.Verbose, "Found method {0}.",
                                 methodInfo.Name);
                    }
                }
            }

            bool isExtensionAssembly = false;

            ExtensionAssembly extensionAssembly = new ExtensionAssembly(
                assembly);

            Type[] types;

            try {
                types = assembly.GetTypes();
            }
            catch (ReflectionTypeLoadException ex) {
                if (ex.LoaderExceptions != null && ex.LoaderExceptions.Length > 0)
                {
                    throw ex.LoaderExceptions[0];
                }

                throw;
            }

            foreach (Type type in types)
            {
                //
                // each extension type is exclusive, meaning a given type
                // cannot be both a task and data type
                //
                // so it doesn't make sense to scan a type for, for example,
                // data types if the type has already been positively
                // identified as a task
                //

                bool extensionFound = ScanTypeForTasks(extensionAssembly,
                                                       type, task);

                if (!extensionFound)
                {
                    extensionFound = ScanTypeForDataTypes(extensionAssembly,
                                                          type, task);
                }

                if (!extensionFound)
                {
                    extensionFound = ScanTypeForFunctions(type, task);
                }

                if (!extensionFound)
                {
                    extensionFound = ScanTypeForFilters(extensionAssembly,
                                                        type, task);
                }

                if (!extensionFound)
                {
                    extensionFound = _pluginScanner.ScanTypeForPlugins(
                        extensionAssembly, type, task);
                }

                // if extension is found in type, then mark assembly as
                // extension assembly
                isExtensionAssembly = isExtensionAssembly || extensionFound;
            }

            // if no extension could be found at all, then we might be dealing
            // with an extension assembly that was built using an older version
            // of NAnt(.Core)
            if (!isExtensionAssembly)
            {
                AssemblyName coreAssemblyName = Assembly.GetExecutingAssembly().
                                                GetName(false);

                foreach (AssemblyName assemblyName in assembly.GetReferencedAssemblies())
                {
                    if (assemblyName.Name == coreAssemblyName.Name)
                    {
                        // the given assembly references NAnt.Core, so check whether
                        // it doesn't reference an older version of NAnt.Core
                        if (assemblyName.Version != coreAssemblyName.Version)
                        {
                            task.Log(Level.Warning, "Assembly \"{0}\" is built"
                                     + " using version {1} of NAnt. If any problems"
                                     + " arise, then try using a version that is built"
                                     + " for NAnt version {2}.", assembly.GetName().Name,
                                     assemblyName.Version, coreAssemblyName.Version);
                        }
                    }
                }
            }

            return(isExtensionAssembly);
        }
Ejemplo n.º 9
0
 public void IsBetterVersionOf_SameVersion_OneWildCard()
 {
     var eaWild = new ExtensionAssembly(THIS_ASSEMBLY_PATH, true);
     Assert.True(_ea.IsBetterVersionOf(eaWild));
     Assert.False(eaWild.IsBetterVersionOf(_ea));
 }
Ejemplo n.º 10
0
 public void CreateExtensionAssemblies()
 {
     _ea = new ExtensionAssembly(THIS_ASSEMBLY_PATH, false);
 }