|
From: <fli...@us...> - 2008-10-17 14:40:39
|
Revision: 182
http://structuremap.svn.sourceforge.net/structuremap/?rev=182&view=rev
Author: flimflan
Date: 2008-10-17 14:40:26 +0000 (Fri, 17 Oct 2008)
Log Message:
-----------
- Added ability to scan all assemblies in a path of the file system.
- Now includes the .pdb and intellisense .xml in the build output
Modified Paths:
--------------
trunk/Source/StructureMap/Graph/AssemblyScanner.cs
trunk/Source/StructureMap/StructureMap.csproj
trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs
trunk/cruise.build
Modified: trunk/Source/StructureMap/Graph/AssemblyScanner.cs
===================================================================
--- trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2008-10-10 21:11:00 UTC (rev 181)
+++ trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2008-10-17 14:40:26 UTC (rev 182)
@@ -227,5 +227,33 @@
{
Exclude(type => type == typeof (T));
}
+
+ public void AssembliesFromPath(string path)
+ {
+ AssembliesFromPath(path, a => true);
+ }
+
+ public void AssembliesFromPath(string path, Predicate<Assembly> assemblyFilter)
+ {
+ var assemblyPaths = System.IO.Directory.GetFiles(path).Where(file =>
+ System.IO.Path.GetExtension(file).Equals(
+ ".exe", StringComparison.OrdinalIgnoreCase)
+ ||
+ System.IO.Path.GetExtension(file).Equals(
+ ".dll", StringComparison.OrdinalIgnoreCase));
+
+ foreach (var assemblyPath in assemblyPaths)
+ {
+ Assembly assembly = null;
+ try
+ {
+ assembly = System.Reflection.Assembly.LoadFrom(assemblyPath);
+ }
+ catch
+ {
+ }
+ if (assembly != null && assemblyFilter(assembly)) Assembly(assembly);
+ }
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/StructureMap.csproj
===================================================================
--- trunk/Source/StructureMap/StructureMap.csproj 2008-10-10 21:11:00 UTC (rev 181)
+++ trunk/Source/StructureMap/StructureMap.csproj 2008-10-17 14:40:26 UTC (rev 182)
@@ -75,9 +75,8 @@
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>TRACE</DefineConstants>
- <DocumentationFile>
- </DocumentationFile>
- <DebugSymbols>false</DebugSymbols>
+ <DocumentationFile>bin\Release\StructureMap.XML</DocumentationFile>
+ <DebugSymbols>true</DebugSymbols>
<FileAlignment>4096</FileAlignment>
<NoStdLib>false</NoStdLib>
<NoWarn>
@@ -87,7 +86,7 @@
<RemoveIntegerChecks>false</RemoveIntegerChecks>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel>
- <DebugType>none</DebugType>
+ <DebugType>pdbonly</DebugType>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Build|AnyCPU' ">
Modified: trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs 2008-10-10 21:11:00 UTC (rev 181)
+++ trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs 2008-10-17 14:40:26 UTC (rev 182)
@@ -1,8 +1,10 @@
using System;
+using System.IO;
using NUnit.Framework;
using StructureMap.Configuration.DSL;
using StructureMap.Graph;
using StructureMap.Testing.Widget;
+using System.Linq;
using StructureMap.Testing.Widget5;
namespace StructureMap.Testing.Graph
@@ -29,17 +31,32 @@
{
#region Setup/Teardown
+ [TestFixtureSetUp]
+ public void FixtureSetUp()
+ {
+ var binFolder = Path.GetDirectoryName(GetType().Assembly.Location);
+ assemblyScanningFolder = Path.Combine(binFolder, "DynamicallyLoaded");
+ if (!Directory.Exists(assemblyScanningFolder)) Directory.CreateDirectory(assemblyScanningFolder);
+
+ var assembly1 = typeof (RedGreenRegistry).Assembly.Location;
+ var assembly2 = typeof(Widget3.IWorker).Assembly.Location;
+
+ File.Copy(assembly1, Path.Combine(assemblyScanningFolder, Path.GetFileName(assembly1)), true);
+ File.Copy(assembly2, Path.Combine(assemblyScanningFolder, Path.GetFileName(assembly2)), true);
+ }
+
[SetUp]
public void SetUp()
{
TestingRegistry.Reset();
-
+
theGraph = null;
}
#endregion
private PluginGraph theGraph;
+ private string assemblyScanningFolder;
private void Scan(Action<AssemblyScanner> action)
{
@@ -57,9 +74,22 @@
private void shouldNotHaveFamily<T>()
{
- theGraph.PluginFamilies.Contains(typeof (T)).ShouldBeFalse();
+ theGraph.PluginFamilies.Contains(typeof(T)).ShouldBeFalse();
}
+
+ private void shouldHaveFamilyWithSameName<T>()
+ {
+ // The Types may not be "Equal" if their assemblies were loaded in different load contexts (.LoadFrom)
+ // so we will consider them equal if their names match.
+ theGraph.PluginFamilies.Any(family => family.PluginType.FullName == typeof (T).FullName).ShouldBeTrue();
+ }
+
+ private void shouldNotHaveFamilyWithSameName<T>()
+ {
+ theGraph.PluginFamilies.Any(family => family.PluginType.FullName == typeof(T).FullName).ShouldBeFalse();
+ }
+
[Test]
public void AssemblyScanner_will_scan_for_attributes_by_default()
{
@@ -111,6 +141,24 @@
}
[Test]
+ public void scan_all_assemblies_in_a_folder()
+ {
+ Scan(x => x.AssembliesFromPath(assemblyScanningFolder) );
+ shouldHaveFamilyWithSameName<IInterfaceInWidget5>();
+ shouldHaveFamilyWithSameName<Widget3.IWorker>();
+ }
+
+ [Test]
+ public void scan_specific_assemblies_in_a_folder()
+ {
+ var assemblyToSpecificallyExclude = typeof(Widget3.IWorker).Assembly.GetName().Name;
+ Scan(x => x.AssembliesFromPath(assemblyScanningFolder, asm => asm.GetName().Name != assemblyToSpecificallyExclude));
+
+ shouldHaveFamilyWithSameName<IInterfaceInWidget5>();
+ shouldNotHaveFamilyWithSameName<Widget3.IWorker>();
+ }
+
+ [Test]
public void test_the_family_attribute_scanner()
{
var scanner = new FamilyAttributeScanner();
Modified: trunk/cruise.build
===================================================================
--- trunk/cruise.build 2008-10-10 21:11:00 UTC (rev 181)
+++ trunk/cruise.build 2008-10-17 14:40:26 UTC (rev 182)
@@ -69,6 +69,7 @@
<fileset basedir="source\">
<include name="**\bin\${project.config}\*.dll" />
<include name="**\bin\${project.config}\*.exe" />
+ <include name="**\bin\${project.config}\*.pdb" />
<include name="**\bin\${project.config}\*.xml" />
<include name="**\bin\${project.config}\*.xml.actual" />
<include name="StructureMap.Testing\*.config" />
@@ -126,6 +127,7 @@
<fileset basedir="${build.dir}">
<include name="*.xml" />
<include name="*.config" />
+ <exclude name="structuremap.xml" />
</fileset>
</delete>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|