Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Commit

Permalink
react to DNX renames
Browse files Browse the repository at this point in the history
  • Loading branch information
analogrelay committed Jul 22, 2015
1 parent bb618ac commit 991dff6
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 195 deletions.
10 changes: 5 additions & 5 deletions src/Microsoft.AspNet.Mvc.Core/DefaultAssemblyProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public IEnumerable<Assembly> CandidateAssemblies
{
get
{
return GetCandidateLibraries().SelectMany(l => l.LoadableAssemblies)
return GetCandidateLibraries().SelectMany(l => l.Assemblies)
.Select(Load);
}
}
Expand All @@ -60,12 +60,12 @@ public IEnumerable<Assembly> CandidateAssemblies
/// By default it returns all assemblies that reference any of the primary MVC assemblies
/// while ignoring MVC assemblies.
/// </summary>
/// <returns>A set of <see cref="ILibraryInformation"/>.</returns>
protected virtual IEnumerable<ILibraryInformation> GetCandidateLibraries()
/// <returns>A set of <see cref="Library"/>.</returns>
protected virtual IEnumerable<Library> GetCandidateLibraries()
{
if (ReferenceAssemblies == null)
{
return Enumerable.Empty<ILibraryInformation>();
return Enumerable.Empty<Library>();
}

// GetReferencingLibraries returns the transitive closure of referencing assemblies
Expand All @@ -80,7 +80,7 @@ private static Assembly Load(AssemblyName assemblyName)
return Assembly.Load(assemblyName);
}

private bool IsCandidateLibrary(ILibraryInformation library)
private bool IsCandidateLibrary(Library library)
{
Debug.Assert(ReferenceAssemblies != null);
return !ReferenceAssemblies.Contains(library.Name);
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.AspNet.Mvc.Core/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"Microsoft.Framework.PropertyActivator.Sources": { "version": "1.0.0-*", "type": "build" },
"Microsoft.Framework.PropertyHelper.Sources": { "version": "1.0.0-*", "type": "build" },
"Microsoft.Framework.SecurityHelper.Sources": { "version": "1.0.0-*", "type": "build" },
"Microsoft.Framework.Runtime.Abstractions": "1.0.0-*",
"Microsoft.Framework.Runtime.Compilation.Abstractions": "1.0.0-*",
"Newtonsoft.Json": "6.0.6"
},
"frameworks": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Framework.Runtime;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Runtime.Compilation;

namespace Microsoft.AspNet.Mvc.Razor.Compilation
{
Expand All @@ -20,16 +20,16 @@ public class CompilationFailedException : Exception, ICompilationException
/// <param name="compilationFailures"><see cref="ICompilationFailure"/>s containing
/// details of the compilation failure.</param>
public CompilationFailedException(
[NotNull] IEnumerable<ICompilationFailure> compilationFailures)
[NotNull] IEnumerable<CompilationFailure> compilationFailures)
: base(FormatMessage(compilationFailures))
{
CompilationFailures = compilationFailures;
}

/// <inheritdoc />
public IEnumerable<ICompilationFailure> CompilationFailures { get; }
public IEnumerable<CompilationFailure> CompilationFailures { get; }

private static string FormatMessage(IEnumerable<ICompilationFailure> compilationFailures)
private static string FormatMessage(IEnumerable<CompilationFailure> compilationFailures)
{
return Resources.CompilationFailed + Environment.NewLine +
string.Join(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Microsoft.Framework.Internal;
using Microsoft.Framework.Runtime;
using Microsoft.Framework.Runtime.Compilation;
using Microsoft.Framework.Runtime.Roslyn;

namespace Microsoft.AspNet.Mvc.Razor.Compilation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Runtime;
using Microsoft.Framework.Runtime.Compilation;

namespace Microsoft.AspNet.Mvc.Razor.Compilation
{
Expand Down Expand Up @@ -37,7 +38,7 @@ protected CompilationResult()
/// </summary>
/// <remarks>This property is <c>null</c> when compilation succeeded. An empty sequence
/// indicates a failed compilation.</remarks>
public IEnumerable<ICompilationFailure> CompilationFailures { get; private set; }
public IEnumerable<CompilationFailure> CompilationFailures { get; private set; }

/// <summary>
/// Gets the <see cref="CompilationResult"/>.
Expand All @@ -57,10 +58,10 @@ public CompilationResult EnsureSuccessful()
/// <summary>
/// Creates a <see cref="CompilationResult"/> for a failed compilation.
/// </summary>
/// <param name="compilationFailures"><see cref="ICompilationFailure"/>s produced from parsing or
/// <param name="compilationFailures"><see cref="CompilationFailure"/>s produced from parsing or
/// compiling the Razor file.</param>
/// <returns>A <see cref="CompilationResult"/> instance for a failed compilation.</returns>
public static CompilationResult Failed([NotNull] IEnumerable<ICompilationFailure> compilationFailures)
public static CompilationResult Failed([NotNull] IEnumerable<CompilationFailure> compilationFailures)
{
return new CompilationResult
{
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using Microsoft.AspNet.Razor.CodeGenerators;
using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel;
using Microsoft.Framework.Runtime;
using Microsoft.Framework.Runtime.Compilation;

namespace Microsoft.AspNet.Mvc.Razor.Compilation
{
Expand Down Expand Up @@ -82,21 +84,34 @@ internal CompilationResult GetCompilationFailedResult(RelativeFileInfo file, IEn
razorError.Location.FilePath ?? file.RelativePath,
StringComparer.Ordinal);

var failures = new List<RazorCompilationFailure>();
var failures = new List<CompilationFailure>();
foreach (var group in messageGroups)
{
var filePath = group.Key;
var fileContent = ReadFileContentsSafely(filePath);
var compilationFailure = new RazorCompilationFailure(
var compilationFailure = new CompilationFailure(
filePath,
fileContent,
group.Select(parserError => new RazorCompilationMessage(parserError, filePath)));
group.Select(parserError => CreateDiagnosticMessage(parserError, filePath)));
failures.Add(compilationFailure);
}

return CompilationResult.Failed(failures);
}

private DiagnosticMessage CreateDiagnosticMessage(RazorError error, string filePath)
{
return new DiagnosticMessage(
error.Message,
$"{error} ({error.Location.LineIndex},{error.Location.CharacterIndex}) {error.Message}",
filePath,
DiagnosticMessageSeverity.Error,
error.Location.LineIndex + 1,
error.Location.CharacterIndex,
error.Location.LineIndex + 1,
error.Location.CharacterIndex + error.Length);
}

private string ReadFileContentsSafely(string relativePath)
{
var fileInfo = _fileProvider.GetFileInfo(relativePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class RoslynCompilationService : ICompilationService
private readonly ConcurrentDictionary<string, AssemblyMetadata> _metadataFileCache =
new ConcurrentDictionary<string, AssemblyMetadata>(StringComparer.OrdinalIgnoreCase);

private readonly ILibraryManager _libraryManager;
private readonly ILibraryExporter _libraryExporter;
private readonly IApplicationEnvironment _environment;
private readonly IAssemblyLoadContext _loader;
private readonly ICompilerOptionsProvider _compilerOptionsProvider;
Expand All @@ -53,14 +53,14 @@ public class RoslynCompilationService : ICompilationService
/// <param name="host">The <see cref="IMvcRazorHost"/> that was used to generate the code.</param>
public RoslynCompilationService(IApplicationEnvironment environment,
IAssemblyLoadContextAccessor loaderAccessor,
ILibraryManager libraryManager,
ILibraryExporter libraryExporter,
ICompilerOptionsProvider compilerOptionsProvider,
IMvcRazorHost host,
IOptions<RazorViewEngineOptions> optionsAccessor)
{
_environment = environment;
_loader = loaderAccessor.GetLoadContext(typeof(RoslynCompilationService).GetTypeInfo().Assembly);
_libraryManager = libraryManager;
_libraryExporter = libraryExporter;
_applicationReferences = new Lazy<List<MetadataReference>>(GetApplicationReferences);
_compilerOptionsProvider = compilerOptionsProvider;
_fileProvider = optionsAccessor.Options.FileProvider;
Expand Down Expand Up @@ -141,7 +141,7 @@ internal CompilationResult GetCompilationFailedResult(
.Where(IsError)
.GroupBy(diagnostic => GetFilePath(relativePath, diagnostic), StringComparer.Ordinal);

var failures = new List<ICompilationFailure>();
var failures = new List<CompilationFailure>();
foreach (var group in diagnosticGroups)
{
var sourceFilePath = group.Key;
Expand All @@ -157,12 +157,7 @@ internal CompilationResult GetCompilationFailedResult(
sourceFileContent = ReadFileContentsSafely(_fileProvider, sourceFilePath);
}

var compilationFailure = new RoslynCompilationFailure(group)
{
CompiledContent = compilationContent,
SourceFileContent = sourceFileContent,
SourceFilePath = sourceFilePath
};
var compilationFailure = new CompilationFailure(sourceFilePath, sourceFileContent, compilationContent, group.Select(d => d.ToDiagnosticMessage(_environment.RuntimeFramework)));

failures.Add(compilationFailure);
}
Expand All @@ -187,7 +182,7 @@ private List<MetadataReference> GetApplicationReferences()
// Get the MetadataReference for the executing application. If it's a Roslyn reference,
// we can copy the references created when compiling the application to the Razor page being compiled.
// This avoids performing expensive calls to MetadataReference.CreateFromImage.
var libraryExport = _libraryManager.GetLibraryExport(_environment.ApplicationName);
var libraryExport = _libraryExporter.GetLibraryExport(_environment.ApplicationName);
if (libraryExport?.MetadataReferences != null && libraryExport.MetadataReferences.Count > 0)
{
Debug.Assert(libraryExport.MetadataReferences.Count == 1,
Expand All @@ -202,7 +197,7 @@ private List<MetadataReference> GetApplicationReferences()
}
}

var export = _libraryManager.GetAllExports(_environment.ApplicationName);
var export = _libraryExporter.GetAllExports(_environment.ApplicationName);
foreach (var metadataReference in export.MetadataReferences)
{
// Taken from https://github.com/aspnet/KRuntime/blob/757ba9bfdf80bd6277e715d6375969a7f44370ee/src/...
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.AspNet.Mvc/RazorPreCompileModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Framework.Caching.Memory;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Runtime;
using Microsoft.Framework.Runtime.Compilation;
using Microsoft.Framework.Runtime.Roslyn;

namespace Microsoft.AspNet.Mvc
Expand Down
Loading

0 comments on commit 991dff6

Please sign in to comment.