diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..252e2ae
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,12 @@
+bin
+obj
+build
+out
+libs
+.gradle
+*.iml
+*.ipr
+*.iws
+*~
+*.user
+gradle.properties
diff --git a/build.gradle b/build.gradle
new file mode 100755
index 0000000..8b129ab
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,16 @@
+apply plugin: 'idea'
+
+buildscript {
+ repositories {
+ ivy { url '../repository' }
+ ivy { url 'http://unity-technologies.github.com/kaizen/repositories/integration' }
+ }
+ dependencies {
+ classpath group: 'kaizen', name: 'kaizen', version: 'latest.integration'
+ }
+}
+
+apply plugin: 'kaizen-bundle'
+
+version = '1.0'
+
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100755
index 0000000..7f1e239
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100755
index 0000000..c14d177
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Thu Sep 27 09:13:56 BRT 2012
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=http\://services.gradle.org/distributions/gradle-1.2-bin.zip
diff --git a/gradlew b/gradlew
new file mode 100755
index 0000000..e61422d
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,164 @@
+#!/bin/bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/"
+APP_HOME="`pwd -P`"
+cd "$SAVED"
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100755
index 0000000..aec9973
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/settings.gradle b/settings.gradle
new file mode 100755
index 0000000..4b8726d
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1,15 @@
+include 'CodeEditor.Composition'
+
+//include 'CodeEditor.Text'
+//include 'CodeEditor.Collections'
+//include 'CodeEditor.UI.UnityEditor'
+
+rootProject.children.each { project ->
+ def projectDirName = "src/$project.name"
+
+ project.projectDir = new File(settingsDir, projectDirName)
+ assert project.projectDir.isDirectory()
+
+ project.buildFileName = "${project.name}.gradle"
+ assert project.buildFile.isFile()
+}
diff --git a/src/CodeEditor.Composition.Tests/CodeEditor.Composition.Tests.csproj b/src/CodeEditor.Composition.Tests/CodeEditor.Composition.Tests.csproj
new file mode 100755
index 0000000..fa18cc6
--- /dev/null
+++ b/src/CodeEditor.Composition.Tests/CodeEditor.Composition.Tests.csproj
@@ -0,0 +1,71 @@
+
+
+
+ Debug
+ AnyCPU
+ 9.0.21022
+ 2.0
+ {2ED73522-E34D-4CAB-8A42-6421FB9B1E77}
+ Library
+ Properties
+ CodeEditor.Composition.Tests
+ CodeEditor.Composition.Tests
+ v3.5
+ 512
+
+
+ 3.5
+
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+ False
+ ..\..\..\..\NUnit\bin\nunit.framework.dll
+
+
+
+ 3.5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {9DB8BFD3-06C8-4A8C-8842-5931B924B56C}
+ CodeEditor.Composition
+
+
+
+
+
\ No newline at end of file
diff --git a/src/CodeEditor.Composition.Tests/CodeEditor.Composition.Tests.gradle b/src/CodeEditor.Composition.Tests/CodeEditor.Composition.Tests.gradle
new file mode 100644
index 0000000..602d055
--- /dev/null
+++ b/src/CodeEditor.Composition.Tests/CodeEditor.Composition.Tests.gradle
@@ -0,0 +1,4 @@
+dependencies {
+ editor project(path: ':CodeEditor.Composition', configuration: 'editor')
+ editor group: 'nunit', name: 'nunit.framework', version: '2.6.0.12051'
+}
diff --git a/src/CodeEditor.Composition.Tests/CompositionContainerTest.cs b/src/CodeEditor.Composition.Tests/CompositionContainerTest.cs
new file mode 100755
index 0000000..040397b
--- /dev/null
+++ b/src/CodeEditor.Composition.Tests/CompositionContainerTest.cs
@@ -0,0 +1,142 @@
+using CodeEditor.Composition.Hosting;
+using CodeEditor.Composition.Primitives;
+using NUnit.Framework;
+
+namespace CodeEditor.Composition.Tests
+{
+ [TestFixture]
+ public class CompositionContainerTest
+ {
+ private CompositionContainer _container;
+
+ [SetUp]
+ public void SetUp()
+ {
+ _container = new CompositionContainer(GetType().Assembly);
+ }
+
+ [Test]
+ public void ContainerIsExportedAsExportProvider()
+ {
+ Assert.AreSame(_container, GetExportedValue());
+ }
+
+ [Test]
+ public void GetExportedValueAlwaysReturnSameValue()
+ {
+ var service = GetExportedValue();
+ Assert.IsNotNull(service);
+ Assert.AreSame(service, GetExportedValue());
+ }
+
+ [Test]
+ public void GetExportedValueSatisfiesPropertyImports()
+ {
+ Assert.AreSame(GetExportedValue(), GetExportedValue().AService);
+ }
+
+ [Test]
+ public void GetExportedValueSatisfiesFieldImports()
+ {
+ Assert.AreSame(GetExportedValue(), GetExportedValue().AService);
+ }
+
+ [Test]
+ public void GetExportedValueSatisfiesInterfaceImportImplementedByInternalType()
+ {
+ Assert.AreSame(GetExportedValue(), GetExportedValue().AService);
+ }
+
+ [Test]
+ public void GetExportedValueSatisfiesImportingConstructor()
+ {
+ Assert.AreSame(GetExportedValue(), GetExportedValue().AService);
+ }
+
+ [Test]
+ public void PartCanExportMultipleContracts()
+ {
+ Assert.AreSame(GetExportedValue(), GetExportedValue());
+ Assert.IsTrue(GetExportedValue() is PartWithMultipleContracts);
+ }
+
+ private T GetExportedValue()
+ {
+ return _container.GetExportedValue();
+ }
+
+ // ReSharper disable ClassNeverInstantiated.Global
+ [Export]
+ public class AService
+ {
+ }
+
+ [Export]
+ public class AServiceWithDependencies
+ {
+ [Import]
+ // ReSharper disable UnusedAutoPropertyAccessor.Global
+ public AService AService { get; set; }
+ // ReSharper restore UnusedAutoPropertyAccessor.Global
+ }
+
+ [Export]
+ public class AServiceWithFieldDependencies
+ {
+ [Import]
+ public AService AService;
+ }
+
+ public interface IServiceWithDependencies
+ {
+ IService AService { get; }
+ }
+
+ public interface IService
+ {
+ }
+
+ // ReSharper disable UnusedMember.Global
+ [Export(typeof(IService))]
+ internal class ServiceImpl : IService
+ {
+ }
+
+ [Export(typeof(IServiceWithDependencies))]
+ internal class ServiceWithDependenciesImpl : IServiceWithDependencies
+ {
+ [Import]
+ // ReSharper disable UnusedAutoPropertyAccessor.Global
+ public IService AService { get; set; }
+ // ReSharper restore UnusedAutoPropertyAccessor.Global
+ }
+ // ReSharper restore UnusedMember.Global
+
+ [Export]
+ public class ServiceWithImportingConstructor
+ {
+ [ImportingConstructor]
+ ServiceWithImportingConstructor(IService service)
+ {
+ AService = service;
+ }
+
+ public IService AService { get; private set; }
+ }
+ // ReSharper restore ClassNeverInstantiated.Global
+
+ public interface IContract1
+ {
+ }
+
+ public interface IContract2
+ {
+ }
+
+ [Export(typeof(IContract1))]
+ [Export(typeof(IContract2))]
+ public class PartWithMultipleContracts : IContract1, IContract2
+ {
+ }
+ }
+}
diff --git a/src/CodeEditor.Composition.Tests/ImportDefinitionProviderTest.cs b/src/CodeEditor.Composition.Tests/ImportDefinitionProviderTest.cs
new file mode 100755
index 0000000..4a7fb60
--- /dev/null
+++ b/src/CodeEditor.Composition.Tests/ImportDefinitionProviderTest.cs
@@ -0,0 +1,48 @@
+using System.Linq;
+using CodeEditor.Composition.Primitives;
+using NUnit.Framework;
+
+namespace CodeEditor.Composition.Tests
+{
+ [TestFixture]
+ public class ImportDefinitionProviderTest
+ {
+ [Test]
+ public void LazyImport()
+ {
+ var provider = new ImportDefinitionProvider();
+ var import = provider.ImportsFor(typeof(ClassWithLazyImport)).Single();
+ Assert.AreEqual(typeof(IService), import.ContractType);
+ Assert.AreEqual(ImportCardinality.One, import.Cardinality);
+ }
+
+ [Test]
+ public void LazyImportMany()
+ {
+ var provider = new ImportDefinitionProvider();
+ var import = provider.ImportsFor(typeof(ClassWithLazyImportMany)).Single();
+ Assert.AreEqual(typeof(IService), import.ContractType);
+ Assert.AreEqual(ImportCardinality.Many, import.Cardinality);
+ }
+
+ public class ClassWithLazyImport
+ {
+ [Import]
+ public Lazy Service;
+ }
+
+ public class ClassWithLazyImportMany
+ {
+ [ImportMany]
+ public Lazy[] Services;
+ }
+
+ public interface IService
+ {
+ }
+
+ public interface IServiceMetadata
+ {
+ }
+ }
+}
diff --git a/src/CodeEditor.Composition.Tests/LazyImportManyTest.cs b/src/CodeEditor.Composition.Tests/LazyImportManyTest.cs
new file mode 100755
index 0000000..e531164
--- /dev/null
+++ b/src/CodeEditor.Composition.Tests/LazyImportManyTest.cs
@@ -0,0 +1,76 @@
+using System.Linq;
+using CodeEditor.Composition.Hosting;
+using NUnit.Framework;
+
+namespace CodeEditor.Composition.Tests
+{
+ [TestFixture]
+ public class LazyImportManyTest
+ {
+ [Test]
+ public void OnlyServicesWithMatchingMetadataAreProvided()
+ {
+ var container = new CompositionContainer(GetType().Assembly);
+
+ var service = container.GetExportedValue();
+ Assert.IsNotNull(service.Imports);
+
+ var expected = new[]
+ {
+ new {Type = typeof(Service1), Name = "Foo"},
+ new {Type = typeof(Service2), Name = "Bar"}
+ };
+ var actual = service.Imports
+ .Select(import => new {Type = import.Value.GetType(), import.Metadata.Name});
+
+ CollectionAssert.AreEquivalent(expected, actual.ToArray());
+ }
+
+ [Export]
+// ReSharper disable ClassNeverInstantiated.Local
+ class ServiceWithImports
+ {
+ [ImportMany]
+#pragma warning disable 649
+ public Lazy[] Imports;
+#pragma warning restore 649
+ }
+
+ interface IService
+ {
+ }
+
+ [ExportServiceWithMetadata("Foo")]
+ class Service1 : IService
+ {
+ }
+
+ [ExportServiceWithMetadata("Bar")]
+ class Service2 : IService
+ {
+ }
+
+ [Export(typeof(IService))]
+// ReSharper disable UnusedMember.Local
+ class ServiceWithoutMetadata : IService
+// ReSharper restore UnusedMember.Local
+ {
+ }
+ // ReSharper restore ClassNeverInstantiated.Local
+
+ interface IServiceMetadata
+ {
+ string Name { get; }
+ }
+
+ class ExportServiceWithMetadata : ExportAttribute, IServiceMetadata
+ {
+ public string Name { get; private set; }
+
+ public ExportServiceWithMetadata(string name) : base(typeof(IService))
+ {
+ Name = name;
+ }
+ }
+ }
+}
diff --git a/src/CodeEditor.Composition.Tests/LazyImportTest.cs b/src/CodeEditor.Composition.Tests/LazyImportTest.cs
new file mode 100755
index 0000000..6bf33d1
--- /dev/null
+++ b/src/CodeEditor.Composition.Tests/LazyImportTest.cs
@@ -0,0 +1,50 @@
+using CodeEditor.Composition.Hosting;
+using NUnit.Framework;
+
+namespace CodeEditor.Composition.Tests
+{
+ [TestFixture]
+ public class LazyImportTest
+ {
+ [Test]
+ public void MetadataIsProvided()
+ {
+ var container = new CompositionContainer(GetType().Assembly);
+
+ var service = container.GetExportedValue();
+
+ Assert.IsNotNull(service.Import);
+ Assert.AreEqual(42, service.Import.Metadata.Value);
+
+ Assert.IsNotNull(service.Import.Value);
+ Assert.AreSame(service.Import.Value, service.Import.Value);
+ }
+
+ [Export]
+ public class ServiceWithLazyImport
+ {
+ [Import]
+ public Lazy Import;
+ }
+
+ [ExportWithMetadata(42)]
+ public class ServiceWithMetadata
+ {
+ }
+
+ public interface IServiceMetadata
+ {
+ int Value { get; }
+ }
+
+ class ExportWithMetadataAttribute : ExportAttribute, IServiceMetadata
+ {
+ public int Value { get; private set; }
+
+ public ExportWithMetadataAttribute(int value)
+ {
+ Value = value;
+ }
+ }
+ }
+}
diff --git a/src/CodeEditor.Composition.Tests/LazyTest.cs b/src/CodeEditor.Composition.Tests/LazyTest.cs
new file mode 100755
index 0000000..781a99d
--- /dev/null
+++ b/src/CodeEditor.Composition.Tests/LazyTest.cs
@@ -0,0 +1,22 @@
+using NUnit.Framework;
+
+namespace CodeEditor.Composition.Tests
+{
+ [TestFixture]
+ public class LazyTest
+ {
+ [Test]
+ public void FactoryIsInvokedOnlyOnce()
+ {
+ var count = 0;
+ var lazy = new Lazy