Updating NuGet integration

Using latest version
Namespace change from NuPack to NuGet
Adding tests for package creation

--HG--
branch : nuget
extra : transplant_source : H%D0%91G%21%E4%22x%00%B6eX%8E%98%04%FE%2B%B57%28
This commit is contained in:
Louis DeJardin
2010-10-29 12:17:26 -07:00
parent 7b8deeb33c
commit 36c1a85b7d
6 changed files with 168 additions and 26 deletions

View File

@@ -1 +1 @@
230ef1360257ef0ac622f6e85a94323ef2e49cae external/nupack 349ebd349ca931cb634439e10a7916ab307ab596 external/nupack

View File

@@ -122,10 +122,12 @@
</Reference> </Reference>
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="CodeGeneration\Commands\CodeGenerationCommandsTests.cs" /> <Compile Include="CodeGeneration\Commands\CodeGenerationCommandsTests.cs" />
<Compile Include="DatabaseEnabledTestsBase.cs" /> <Compile Include="DatabaseEnabledTestsBase.cs" />
<Compile Include="Packaging\PackageBuilderTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Roles\Controllers\AdminControllerTests.cs" /> <Compile Include="Roles\Controllers\AdminControllerTests.cs" />
<Compile Include="Roles\Services\RoleServiceTests.cs" /> <Compile Include="Roles\Services\RoleServiceTests.cs" />
@@ -158,6 +160,10 @@
<Project>{17F86780-9A1F-4AA1-86F1-875EEC2730C7}</Project> <Project>{17F86780-9A1F-4AA1-86F1-875EEC2730C7}</Project>
<Name>Orchard.Modules</Name> <Name>Orchard.Modules</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\Orchard.Web\Modules\Orchard.Packaging\Orchard.Packaging.csproj">
<Project>{DFD137A2-DDB5-4D22-BE0D-FA9AD4C8B059}</Project>
<Name>Orchard.Packaging</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard.Web\Modules\Orchard.Roles\Orchard.Roles.csproj"> <ProjectReference Include="..\Orchard.Web\Modules\Orchard.Roles\Orchard.Roles.csproj">
<Project>{D10AD48F-407D-4DB5-A328-173EC7CB010F}</Project> <Project>{D10AD48F-407D-4DB5-A328-173EC7CB010F}</Project>
<Name>Orchard.Roles</Name> <Name>Orchard.Roles</Name>
@@ -200,7 +206,9 @@
<Install>true</Install> <Install>true</Install>
</BootstrapperPackage> </BootstrapperPackage>
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup>
<EmbeddedResource Include="Packaging\Hello.World.csproj.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Packaging;
using System.Linq;
using System.Text;
using Autofac;
using NUnit.Framework;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.FileSystems.WebSite;
using Orchard.Packaging.Services;
using Orchard.Tests.Stubs;
namespace Orchard.Tests.Modules.Packaging {
[TestFixture]
public class PackageBuilderTests : ContainerTestBase {
protected override void Register(Autofac.ContainerBuilder builder) {
builder.RegisterType<PackageBuilder>().As<IPackageBuilder>();
builder.RegisterType<InMemoryWebSiteFolder>().As<IWebSiteFolder>()
.As<InMemoryWebSiteFolder>().InstancePerLifetimeScope();
}
private Stream BuildHelloWorld(IPackageBuilder packageBuilder) {
return packageBuilder.BuildPackage(new ExtensionDescriptor {
ExtensionType = "Module",
Name = "Hello.World",
Version = "1.0",
Description = "a",
Author = "b"
});
}
[Test]
public void PackageForModuleIsOpcPackage() {
var packageBuilder = _container.Resolve<IPackageBuilder>();
var stream = BuildHelloWorld(packageBuilder);
var package = Package.Open(stream);
Assert.That(package, Is.Not.Null);
Assert.That(package.PackageProperties.Identifier, Is.EqualTo("Orchard.Module.Hello.World"));
}
[Test]
public void PropertiesPassThroughAsExpected() {
var packageBuilder = _container.Resolve<IPackageBuilder>();
var stream = BuildHelloWorld(packageBuilder);
var package = Package.Open(stream);
Assert.That(package.PackageProperties.Description, Is.EqualTo("a"));
Assert.That(package.PackageProperties.Creator, Is.EqualTo("b"));
Assert.That(package.PackageProperties.Version, Is.EqualTo("1.0"));
}
[Test]
public void ProjectFileIsAdded() {
var packageBuilder = _container.Resolve<IPackageBuilder>();
var folder = _container.Resolve<InMemoryWebSiteFolder>();
string content;
using (var sourceStream = GetType().Assembly.GetManifestResourceStream(GetType(), "Hello.World.csproj.txt")) {
content = new StreamReader(sourceStream).ReadToEnd();
}
folder.AddFile("~/Modules/Hello.World/Hello.World.csproj", content);
var stream = BuildHelloWorld(packageBuilder);
var package = Package.Open(stream);
var projectUri = PackUriHelper.CreatePartUri(new Uri("/Content/Modules/Hello.World/Hello.World.csproj", UriKind.Relative));
var projectPart = package.GetPart(projectUri);
using (var projectStream = projectPart.GetStream()) {
var projectContent = new StreamReader(projectStream).ReadToEnd();
Assert.That(projectContent, Is.EqualTo(content));
}
}
}
}

View File

@@ -245,6 +245,7 @@
<Compile Include="Mvc\Routes\UrlPrefixTests.cs" /> <Compile Include="Mvc\Routes\UrlPrefixTests.cs" />
<Compile Include="Records\BigRecord.cs" /> <Compile Include="Records\BigRecord.cs" />
<Compile Include="Scripting\ScriptingTests.cs" /> <Compile Include="Scripting\ScriptingTests.cs" />
<Compile Include="Stubs\InMemoryWebSiteFolder.cs" />
<Compile Include="Stubs\StubWorkContextAccessor.cs" /> <Compile Include="Stubs\StubWorkContextAccessor.cs" />
<Compile Include="Stubs\StubExtensionManager.cs" /> <Compile Include="Stubs\StubExtensionManager.cs" />
<Compile Include="Stubs\StubReportsCoordinator.cs" /> <Compile Include="Stubs\StubReportsCoordinator.cs" />

View File

@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Orchard.Caching;
using Orchard.FileSystems.WebSite;
namespace Orchard.Tests.Stubs {
public class InMemoryWebSiteFolder : IWebSiteFolder {
Dictionary<string, string> _contents = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
public void AddFile(string virtualPath, string contents) {
_contents[Canonical(virtualPath)] = contents;
}
private string Canonical(string virtualPath) {
return virtualPath.Replace("\\", "/");
}
public IEnumerable<string> ListDirectories(string virtualPath) {
throw new NotImplementedException();
}
public IEnumerable<string> ListFiles(string virtualPath, bool recursive) {
throw new NotImplementedException();
}
public bool FileExists(string virtualPath) {
return _contents.ContainsKey(virtualPath);
}
public string ReadFile(string virtualPath) {
string value;
return _contents.TryGetValue(Canonical(virtualPath), out value) ? value : null;
}
public string ReadFile(string virtualPath, bool actualContent) {
throw new NotImplementedException();
}
public void CopyFileTo(string virtualPath, Stream destination) {
string value;
if (_contents.TryGetValue(Canonical(virtualPath), out value)) {
var bytes = Encoding.Default.GetBytes(value);
destination.Write(bytes, 0, bytes.Length);
}
}
public void CopyFileTo(string virtualPath, Stream destination, bool actualContent) {
throw new NotImplementedException();
}
public IVolatileToken WhenPathChanges(string virtualPath) {
throw new NotImplementedException();
}
}
}

View File

@@ -4,21 +4,17 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Net.Mime; using System.Net.Mime;
using System.Reflection; using System.Reflection;
using System.Web;
using System.Web.Hosting;
using System.Xml.Linq; using System.Xml.Linq;
using NuPack; using NuGet;
using Orchard.Environment.Extensions; using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models; using Orchard.Environment.Extensions.Models;
using Orchard.FileSystems.WebSite; using Orchard.FileSystems.WebSite;
using NuPack_PackageBuilder = NuPack.PackageBuilder; using NuGetPackageBuilder = NuGet.PackageBuilder;
using NuPack_IPackageBuilder = NuPack.IPackageBuilder;
namespace Orchard.Packaging.Services { namespace Orchard.Packaging.Services {
[OrchardFeature("PackagingServices")] [OrchardFeature("PackagingServices")]
public class PackageBuilder : IPackageBuilder { public class PackageBuilder : IPackageBuilder {
private readonly IExtensionManager _extensionManager;
private readonly IWebSiteFolder _webSiteFolder; private readonly IWebSiteFolder _webSiteFolder;
private static readonly string[] _ignoredThemeExtensions = new[] { private static readonly string[] _ignoredThemeExtensions = new[] {
@@ -34,8 +30,7 @@ namespace Orchard.Packaging.Services {
_ignoredThemeExtensions.Contains(Path.GetExtension(filePath) ?? ""); _ignoredThemeExtensions.Contains(Path.GetExtension(filePath) ?? "");
} }
public PackageBuilder(IExtensionManager extensionManager, IWebSiteFolder webSiteFolder) { public PackageBuilder(IWebSiteFolder webSiteFolder) {
_extensionManager = extensionManager;
_webSiteFolder = webSiteFolder; _webSiteFolder = webSiteFolder;
} }
@@ -72,7 +67,7 @@ namespace Orchard.Packaging.Services {
private void SetCoreProperties(CreateContext context, ExtensionDescriptor extensionDescriptor) { private void SetCoreProperties(CreateContext context, ExtensionDescriptor extensionDescriptor) {
context.Builder.Id = extensionDescriptor.Name; context.Builder.Id = "Orchard." + extensionDescriptor.ExtensionType + "." + extensionDescriptor.Name;
context.Builder.Version = new Version(extensionDescriptor.Version); context.Builder.Version = new Version(extensionDescriptor.Version);
context.Builder.Title = extensionDescriptor.DisplayName ?? extensionDescriptor.Name; context.Builder.Title = extensionDescriptor.DisplayName ?? extensionDescriptor.Name;
context.Builder.Description = extensionDescriptor.Description; context.Builder.Description = extensionDescriptor.Description;
@@ -140,7 +135,8 @@ namespace Orchard.Packaging.Services {
private static void BeginPackage(CreateContext context) { private static void BeginPackage(CreateContext context) {
context.Builder = new NuPack_PackageBuilder(); context.Stream = new MemoryStream();
context.Builder = new NuGetPackageBuilder();
} }
private static void EstablishPaths(CreateContext context, IWebSiteFolder webSiteFolder, string locationPath, string moduleName, string moduleType) { private static void EstablishPaths(CreateContext context, IWebSiteFolder webSiteFolder, string locationPath, string moduleName, string moduleType) {
@@ -151,7 +147,7 @@ namespace Orchard.Packaging.Services {
else { else {
context.SourcePath = "~/Modules/" + moduleName + "/"; context.SourcePath = "~/Modules/" + moduleName + "/";
} }
context.TargetPath = "\\" + moduleName + "\\"; context.TargetPath = "\\Content\\Modules\\" + moduleName + "\\";
} }
private static bool LoadProject(CreateContext context, string relativePath) { private static bool LoadProject(CreateContext context, string relativePath) {
@@ -164,13 +160,15 @@ namespace Orchard.Packaging.Services {
} }
private static void EmbedVirtualFile(CreateContext context, string relativePath, string contentType) { private static void EmbedVirtualFile(CreateContext context, string relativePath, string contentType) {
var file = new VirtualPackageFile(context.SourceFolder, context.SourcePath + relativePath); var file = new VirtualPackageFile(
context.SourceFolder,
context.SourcePath + relativePath,
context.TargetPath + relativePath);
context.Builder.Files.Add(file); context.Builder.Files.Add(file);
} }
private static void EndPackage(CreateContext context) { private static void EndPackage(CreateContext context) {
context.Stream = new MemoryStream();
context.Builder.Save(context.Stream); context.Builder.Save(context.Stream);
} }
@@ -178,9 +176,7 @@ namespace Orchard.Packaging.Services {
private class CreateContext { private class CreateContext {
public Stream Stream { get; set; } public Stream Stream { get; set; }
//public Package Package { get; set; } public NuGetPackageBuilder Builder { get; set; }
//public Manifest Manifest { get; set; }
public NuPack_PackageBuilder Builder { get; set; }
public IWebSiteFolder SourceFolder { get; set; } public IWebSiteFolder SourceFolder { get; set; }
public string SourcePath { get; set; } public string SourcePath { get; set; }
@@ -191,28 +187,31 @@ namespace Orchard.Packaging.Services {
#endregion #endregion
#region Nested type: CreateContext #region Nested type: CreateContext
private class VirtualPackageFile : IPackageFile { private class VirtualPackageFile : IPackageFile {
private readonly IWebSiteFolder _sourceFolder; private readonly IWebSiteFolder _webSiteFolder;
private readonly string _virtualPath;
private readonly string _packagePath;
public VirtualPackageFile(IWebSiteFolder sourceFolder, string path) { public VirtualPackageFile(IWebSiteFolder webSiteFolder, string virtualPath, string packagePath) {
Path = path; _webSiteFolder = webSiteFolder;
_sourceFolder = sourceFolder; _virtualPath = virtualPath;
_packagePath = packagePath;
} }
public string Path { get; private set; } public string Path { get { return _packagePath; } }
public Stream GetStream() { public Stream GetStream() {
var stream = new MemoryStream(); var stream = new MemoryStream();
_sourceFolder.CopyFileTo(Path, stream); _webSiteFolder.CopyFileTo(_virtualPath, stream);
stream.Seek(0, SeekOrigin.Begin); stream.Seek(0, SeekOrigin.Begin);
return stream; return stream;
} }
} }
#endregion #endregion
} }
} }