mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Making dynamic compilation project hash aware of dependencies.
--HG-- branch : dev
This commit is contained in:
@@ -191,7 +191,7 @@ Features:
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<string> GetFileDependencies(DependencyDescriptor dependency, string virtualPath) {
|
public IEnumerable<string> GetDynamicModuleDependencies(DependencyDescriptor dependency, string virtualPath) {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -112,7 +112,7 @@ namespace Orchard.Tests.Environment.Extensions {
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<string> GetFileDependencies(DependencyDescriptor dependency, string virtualPath) {
|
public IEnumerable<string> GetDynamicModuleDependencies(DependencyDescriptor dependency, string virtualPath) {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -116,7 +116,7 @@ namespace Orchard.Tests.Environment.Extensions {
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<string> GetFileDependencies(DependencyDescriptor dependency, string virtualPath) {
|
public IEnumerable<string> GetDynamicModuleDependencies(DependencyDescriptor dependency, string virtualPath) {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -39,15 +39,33 @@ namespace Orchard.Environment.Extensions.Compilers {
|
|||||||
.Elements(ns("Project"))
|
.Elements(ns("Project"))
|
||||||
.Elements(ns("ItemGroup"))
|
.Elements(ns("ItemGroup"))
|
||||||
.Elements(ns("Reference"))
|
.Elements(ns("Reference"))
|
||||||
.Attributes("Include")
|
.Where(c => c.Attribute("Include") != null)
|
||||||
.Select(c => new ReferenceDescriptor { SimpleName = ExtractAssemblyName(c.Value), FullName = c.Value });
|
.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
|
var projectReferences = document
|
||||||
.Elements(ns("Project"))
|
.Elements(ns("Project"))
|
||||||
.Elements(ns("ItemGroup"))
|
.Elements(ns("ItemGroup"))
|
||||||
.Elements(ns("ProjectReference"))
|
.Elements(ns("ProjectReference"))
|
||||||
.Attributes("Include")
|
.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);
|
return assemblyReferences.Union(projectReferences);
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,11 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Orchard.Environment.Extensions.Compilers {
|
namespace Orchard.Environment.Extensions.Compilers {
|
||||||
|
public enum ReferenceType {
|
||||||
|
Library,
|
||||||
|
Project
|
||||||
|
}
|
||||||
|
|
||||||
public class ProjectFileDescriptor {
|
public class ProjectFileDescriptor {
|
||||||
public string AssemblyName { get; set; }
|
public string AssemblyName { get; set; }
|
||||||
public IEnumerable<string> SourceFilenames { get; set; }
|
public IEnumerable<string> SourceFilenames { get; set; }
|
||||||
@@ -9,5 +14,7 @@ namespace Orchard.Environment.Extensions.Compilers {
|
|||||||
public class ReferenceDescriptor {
|
public class ReferenceDescriptor {
|
||||||
public string SimpleName { get; set; }
|
public string SimpleName { get; set; }
|
||||||
public string FullName { get; set; }
|
public string FullName { get; set; }
|
||||||
|
public string Path { get; set; }
|
||||||
|
public ReferenceType ReferenceType { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -54,13 +54,13 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
return GetDependencies(dependency.VirtualPath);
|
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);
|
virtualPath = _virtualPathProvider.ToAppRelative(virtualPath);
|
||||||
|
|
||||||
if (StringComparer.OrdinalIgnoreCase.Equals(virtualPath, dependency.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) {
|
public override void Monitor(ExtensionDescriptor descriptor, Action<IVolatileToken> monitor) {
|
||||||
@@ -184,17 +184,31 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<string> GetDependencies(string projectPath) {
|
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);
|
var basePath = _virtualPathProvider.GetDirectoryName(projectPath);
|
||||||
|
|
||||||
using (var stream = _virtualPathProvider.OpenFile(projectPath)) {
|
using (var stream = _virtualPathProvider.OpenFile(projectPath)) {
|
||||||
var projectFile = _projectFileParser.Parse(stream);
|
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) {
|
private string GetProjectPath(ExtensionDescriptor descriptor) {
|
||||||
|
@@ -58,7 +58,7 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
return Enumerable.Empty<string>();
|
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>();
|
return Enumerable.Empty<string>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -41,6 +41,6 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
|
|
||||||
string GetWebFormAssemblyDirective(DependencyDescriptor dependency);
|
string GetWebFormAssemblyDirective(DependencyDescriptor dependency);
|
||||||
IEnumerable<string> GetWebFormVirtualDependencies(DependencyDescriptor dependency);
|
IEnumerable<string> GetWebFormVirtualDependencies(DependencyDescriptor dependency);
|
||||||
IEnumerable<string> GetFileDependencies(DependencyDescriptor dependency, string virtualPath);
|
IEnumerable<string> GetDynamicModuleDependencies(DependencyDescriptor dependency, string virtualPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -47,7 +47,7 @@ namespace Orchard.FileSystems.Dependencies {
|
|||||||
var loader = _loaders.Where(l => l.Name == desc.LoaderName).FirstOrDefault();
|
var loader = _loaders.Where(l => l.Name == desc.LoaderName).FirstOrDefault();
|
||||||
if (loader != null) {
|
if (loader != null) {
|
||||||
|
|
||||||
var otherDependencies = loader.GetFileDependencies(desc, virtualPath);
|
var otherDependencies = loader.GetDynamicModuleDependencies(desc, virtualPath);
|
||||||
if (otherDependencies.Any()) {
|
if (otherDependencies.Any()) {
|
||||||
|
|
||||||
var allDependencies = virtualPathDependencies.OfType<string>().Concat(otherDependencies);
|
var allDependencies = virtualPathDependencies.OfType<string>().Concat(otherDependencies);
|
||||||
|
@@ -58,7 +58,12 @@ namespace Orchard.FileSystems.VirtualPath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bool FileExists(string 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) {
|
public bool DirectoryExists(string virtualPath) {
|
||||||
|
Reference in New Issue
Block a user