Using hintpath on package builder

--HG--
branch : dev
This commit is contained in:
andrerod
2011-03-21 20:37:10 -07:00
parent 0099cdd2b7
commit f93fe67649
4 changed files with 46 additions and 28 deletions

View File

@@ -8,14 +8,16 @@ using System.Xml.Linq;
using NuGet;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.FileSystems.VirtualPath;
using Orchard.FileSystems.WebSite;
using Orchard.Utility.Extensions;
using NuGetPackageBuilder = NuGet.PackageBuilder;
namespace Orchard.Packaging.Services {
[OrchardFeature("PackagingServices")]
public class PackageBuilder : IPackageBuilder {
private readonly IWebSiteFolder _webSiteFolder;
private readonly IVirtualPathProvider _virtualPathProvider;
private static readonly string[] _ignoredThemeExtensions = new[] {
"obj", "pdb", "exclude"
@@ -31,8 +33,10 @@ namespace Orchard.Packaging.Services {
_ignoredThemeExtensions.Contains(Path.GetExtension(filePath) ?? "");
}
public PackageBuilder(IWebSiteFolder webSiteFolder) {
public PackageBuilder(IWebSiteFolder webSiteFolder,
IVirtualPathProvider virtualPathProvider) {
_webSiteFolder = webSiteFolder;
_virtualPathProvider = virtualPathProvider;
}
public Stream BuildPackage(ExtensionDescriptor extensionDescriptor) {
@@ -95,7 +99,7 @@ namespace Orchard.Packaging.Services {
}
}
private static void EmbedReferenceFiles(CreateContext context) {
private void EmbedReferenceFiles(CreateContext context) {
var entries = context.Project
.Elements(Ns("Project"))
.Elements(Ns("ItemGroup"))
@@ -108,13 +112,11 @@ namespace Orchard.Packaging.Services {
foreach (var entry in entries) {
var assemblyName = new AssemblyName(entry.Include.Value);
string hintPath = entry.HintPath != null ? entry.HintPath.Value : null;
string virtualPath = _virtualPathProvider.GetReferenceVirtualPath(context.SourcePath, assemblyName.Name, entry.HintPath != null ? entry.HintPath.Value : null);
string virtualPath = "bin/" + assemblyName.Name + ".dll";
if (context.SourceFolder.FileExists(context.SourcePath + virtualPath)) {
if (!string.IsNullOrEmpty(virtualPath)) {
EmbedVirtualFile(context, virtualPath, MediaTypeNames.Application.Octet);
}
else if (hintPath != null) { }
}
}

View File

@@ -9,6 +9,7 @@ using Orchard.Environment.Extensions.Models;
using Orchard.FileSystems.Dependencies;
using Orchard.FileSystems.VirtualPath;
using Orchard.Logging;
using Orchard.Utility.Extensions;
namespace Orchard.Environment.Extensions.Loaders {
public class DynamicExtensionLoader : ExtensionLoaderBase {
@@ -94,14 +95,14 @@ namespace Orchard.Environment.Extensions.Loaders {
if (projectPath == null)
return Enumerable.Empty<ExtensionReferenceProbeEntry>();
using(var stream = _virtualPathProvider.OpenFile(projectPath)) {
using (var stream = _virtualPathProvider.OpenFile(projectPath)) {
var projectFile = _projectFileParser.Parse(stream);
return projectFile.References.Select(r => new ExtensionReferenceProbeEntry {
Descriptor = descriptor,
Loader = this,
Name = r.SimpleName,
VirtualPath = GetReferenceVirtualPath(projectPath, r.SimpleName, r.Path)
VirtualPath = _virtualPathProvider.GetProjectReferenceVirtualPath(projectPath, r.SimpleName, r.Path)
});
}
}
@@ -129,24 +130,6 @@ namespace Orchard.Environment.Extensions.Loaders {
}
}
private string GetReferenceVirtualPath(string projectPath, string referenceName, string hintPath) {
var path = _virtualPathProvider.GetDirectoryName(projectPath);
// Check if hint path is valid
if (!string.IsNullOrEmpty(hintPath)) {
hintPath = _virtualPathProvider.Combine(path, hintPath);
if (_virtualPathProvider.FileExists(hintPath))
return hintPath;
}
// Fall back to bin directory
path = _virtualPathProvider.Combine(path, "bin", referenceName + ".dll");
if (_virtualPathProvider.FileExists(path))
return path;
return null;
}
public override Assembly LoadReference(DependencyReferenceDescriptor reference) {
// DynamicExtensionLoader has 2 types of references: assemblies from module bin directory
// and .csproj.
@@ -207,7 +190,7 @@ namespace Orchard.Environment.Extensions.Loaders {
// Add Project and Library References
foreach (ReferenceDescriptor referenceDescriptor in projectFile.References.Where(reference => !string.IsNullOrEmpty(reference.Path))) {
string path = referenceDescriptor.ReferenceType == ReferenceType.Library
? GetReferenceVirtualPath(projectPath, referenceDescriptor.SimpleName, referenceDescriptor.Path)
? _virtualPathProvider.GetProjectReferenceVirtualPath(projectPath, referenceDescriptor.SimpleName, referenceDescriptor.Path)
: _virtualPathProvider.Combine(basePath, referenceDescriptor.Path);
if (_virtualPathProvider.FileExists(path)) {

View File

@@ -488,6 +488,7 @@
<Compile Include="Messaging\Services\IMessagingChannel.cs" />
<Compile Include="IWorkContextAccessor.cs" />
<Compile Include="Utility\Extensions\ControllerExtensions.cs" />
<Compile Include="Utility\Extensions\VirtualPathProviderExtensions.cs" />
<Compile Include="Validation\PathValidation.cs" />
<Compile Include="WorkContextExtensions.cs" />
<Compile Include="Mvc\ViewEngines\Razor\RazorCompilationEventsShim.cs" />

View File

@@ -0,0 +1,32 @@
using Orchard.FileSystems.VirtualPath;
namespace Orchard.Utility.Extensions {
public static class VirtualPathProviderExtensions {
public static string GetProjectReferenceVirtualPath(this IVirtualPathProvider virtualPathProvider, string projectPath, string referenceName, string hintPath) {
string basePath = virtualPathProvider.GetDirectoryName(projectPath);
string virtualPath = virtualPathProvider.GetReferenceVirtualPath(basePath, referenceName, hintPath);
if (!string.IsNullOrEmpty(virtualPath)) {
return virtualPathProvider.Combine(basePath, virtualPath);
}
return null;
}
public static string GetReferenceVirtualPath(this IVirtualPathProvider virtualPathProvider, string basePath, string referenceName, string hintPath) {
// Check if hint path is valid
if (!string.IsNullOrEmpty(hintPath)) {
if (virtualPathProvider.FileExists(virtualPathProvider.Combine(basePath, hintPath)))
return hintPath;
}
// Fall back to bin directory
string relativePath = virtualPathProvider.Combine("bin", referenceName + ".dll");
if (virtualPathProvider.FileExists(virtualPathProvider.Combine(basePath, relativePath)))
return relativePath;
return null;
}
}
}