Making dynamic compilation project hash aware of dependencies.

--HG--
branch : dev
This commit is contained in:
Andre Rodrigues
2011-03-21 12:50:19 -07:00
parent daadf90cd3
commit 6a4e5f1c34
10 changed files with 61 additions and 17 deletions

View File

@@ -191,7 +191,7 @@ Features:
throw new NotImplementedException();
}
public IEnumerable<string> GetFileDependencies(DependencyDescriptor dependency, string virtualPath) {
public IEnumerable<string> GetDynamicModuleDependencies(DependencyDescriptor dependency, string virtualPath) {
throw new NotImplementedException();
}

View File

@@ -112,7 +112,7 @@ namespace Orchard.Tests.Environment.Extensions {
throw new NotImplementedException();
}
public IEnumerable<string> GetFileDependencies(DependencyDescriptor dependency, string virtualPath) {
public IEnumerable<string> GetDynamicModuleDependencies(DependencyDescriptor dependency, string virtualPath) {
throw new NotImplementedException();
}

View File

@@ -116,7 +116,7 @@ namespace Orchard.Tests.Environment.Extensions {
throw new NotImplementedException();
}
public IEnumerable<string> GetFileDependencies(DependencyDescriptor dependency, string virtualPath) {
public IEnumerable<string> GetDynamicModuleDependencies(DependencyDescriptor dependency, string virtualPath) {
throw new NotImplementedException();
}

View File

@@ -39,15 +39,33 @@ namespace Orchard.Environment.Extensions.Compilers {
.Elements(ns("Project"))
.Elements(ns("ItemGroup"))
.Elements(ns("Reference"))
.Attributes("Include")
.Select(c => new ReferenceDescriptor { SimpleName = ExtractAssemblyName(c.Value), FullName = c.Value });
.Where(c => c.Attribute("Include") != null)
.Select(c => {
string path = null;
XElement attribute = c.Elements(ns("HintPath")).FirstOrDefault();
if (attribute != null) {
path = attribute.Value;
}
return new ReferenceDescriptor {
SimpleName = ExtractAssemblyName(c.Attribute("Include").Value),
FullName = c.Attribute("Include").Value,
Path = path,
ReferenceType = ReferenceType.Library
};
});
var projectReferences = document
.Elements(ns("Project"))
.Elements(ns("ItemGroup"))
.Elements(ns("ProjectReference"))
.Attributes("Include")
.Select(c => new ReferenceDescriptor { SimpleName = Path.GetFileNameWithoutExtension(c.Value), FullName = Path.GetFileNameWithoutExtension(c.Value) });
.Select(c => new ReferenceDescriptor {
SimpleName = Path.GetFileNameWithoutExtension(c.Value),
FullName = Path.GetFileNameWithoutExtension(c.Value),
Path = c.Value,
ReferenceType = ReferenceType.Project
});
return assemblyReferences.Union(projectReferences);
}

View File

@@ -1,6 +1,11 @@
using System.Collections.Generic;
namespace Orchard.Environment.Extensions.Compilers {
public enum ReferenceType {
Library,
Project
}
public class ProjectFileDescriptor {
public string AssemblyName { get; set; }
public IEnumerable<string> SourceFilenames { get; set; }
@@ -9,5 +14,7 @@ namespace Orchard.Environment.Extensions.Compilers {
public class ReferenceDescriptor {
public string SimpleName { get; set; }
public string FullName { get; set; }
public string Path { get; set; }
public ReferenceType ReferenceType { get; set; }
}
}

View File

@@ -54,13 +54,13 @@ namespace Orchard.Environment.Extensions.Loaders {
return GetDependencies(dependency.VirtualPath);
}
public override IEnumerable<string> GetFileDependencies(DependencyDescriptor dependency, string virtualPath){
public override IEnumerable<string> GetDynamicModuleDependencies(DependencyDescriptor dependency, string virtualPath) {
virtualPath = _virtualPathProvider.ToAppRelative(virtualPath);
if (StringComparer.OrdinalIgnoreCase.Equals(virtualPath, dependency.VirtualPath)) {
return GetSourceFiles(virtualPath);
return GetDependencies(virtualPath);
}
return base.GetFileDependencies(dependency, virtualPath);
return base.GetDynamicModuleDependencies(dependency, virtualPath);
}
public override void Monitor(ExtensionDescriptor descriptor, Action<IVolatileToken> monitor) {
@@ -184,17 +184,31 @@ namespace Orchard.Environment.Extensions.Loaders {
}
private IEnumerable<string> GetDependencies(string projectPath) {
return new[] {projectPath}.Concat(GetSourceFiles(projectPath));
}
List<string> dependencies = new[] { projectPath }.ToList();
private IEnumerable<string> GetSourceFiles(string projectPath) {
var basePath = _virtualPathProvider.GetDirectoryName(projectPath);
using (var stream = _virtualPathProvider.OpenFile(projectPath)) {
var projectFile = _projectFileParser.Parse(stream);
return projectFile.SourceFilenames.Select(f => _virtualPathProvider.Combine(basePath, f));
// Add source files
dependencies.AddRange(projectFile.SourceFilenames.Select(f => _virtualPathProvider.Combine(basePath, f)));
// Add Project and Library References
foreach (ReferenceDescriptor referenceDescriptor in projectFile.References.Where(reference => !string.IsNullOrEmpty(reference.Path))) {
string path = _virtualPathProvider.Combine(basePath, referenceDescriptor.Path);
if (_virtualPathProvider.FileExists(path)) {
dependencies.Add(path);
if (referenceDescriptor.ReferenceType == ReferenceType.Project) {
dependencies.AddRange(GetDependencies(path));
}
}
}
}
return dependencies;
}
private string GetProjectPath(ExtensionDescriptor descriptor) {

View File

@@ -58,7 +58,7 @@ namespace Orchard.Environment.Extensions.Loaders {
return Enumerable.Empty<string>();
}
public virtual IEnumerable<string> GetFileDependencies(DependencyDescriptor dependency, string virtualPath) {
public virtual IEnumerable<string> GetDynamicModuleDependencies(DependencyDescriptor dependency, string virtualPath) {
return Enumerable.Empty<string>();
}
}

View File

@@ -41,6 +41,6 @@ namespace Orchard.Environment.Extensions.Loaders {
string GetWebFormAssemblyDirective(DependencyDescriptor dependency);
IEnumerable<string> GetWebFormVirtualDependencies(DependencyDescriptor dependency);
IEnumerable<string> GetFileDependencies(DependencyDescriptor dependency, string virtualPath);
IEnumerable<string> GetDynamicModuleDependencies(DependencyDescriptor dependency, string virtualPath);
}
}

View File

@@ -47,7 +47,7 @@ namespace Orchard.FileSystems.Dependencies {
var loader = _loaders.Where(l => l.Name == desc.LoaderName).FirstOrDefault();
if (loader != null) {
var otherDependencies = loader.GetFileDependencies(desc, virtualPath);
var otherDependencies = loader.GetDynamicModuleDependencies(desc, virtualPath);
if (otherDependencies.Any()) {
var allDependencies = virtualPathDependencies.OfType<string>().Concat(otherDependencies);

View File

@@ -58,7 +58,12 @@ namespace Orchard.FileSystems.VirtualPath {
}
public bool FileExists(string virtualPath) {
return HostingEnvironment.VirtualPathProvider.FileExists(virtualPath);
try {
return HostingEnvironment.VirtualPathProvider.FileExists(virtualPath);
} catch {
// Medium Trust or invalid mappings that fall outside the app folder
return false;
}
}
public bool DirectoryExists(string virtualPath) {