Update ProjectModel server

1. Rebase on new LibraryExporter
2. Update dependency name to "fx/<name>" for reference assembly
3. Update framework friendly name
4. Fix dependency message regression
5. Update tests
This commit is contained in:
Troy Dai 2016-01-11 22:26:34 -08:00
parent 03885e876f
commit ce3e719a06
9 changed files with 92 additions and 40 deletions

View file

@ -0,0 +1,21 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.DotNet.ProjectModel.Graph;
namespace Microsoft.DotNet.ProjectModel.Server.Helpers
{
public static class LibraryExtensions
{
public static string GetUniqueName(this LibraryDescription library)
{
var identity = library.Identity;
return identity.Type != LibraryType.ReferenceAssembly ? identity.Name : $"fx/{identity.Name}";
}
public static string GetUniqueName(this LibraryRange range)
{
return range.Target != LibraryType.ReferenceAssembly ? range.Name : $"fx/{range.Name}";
}
}
}

View file

@ -14,7 +14,7 @@ namespace Microsoft.DotNet.ProjectModel.Server.Models
{ {
ShortName = framework.GetShortFolderName(), ShortName = framework.GetShortFolderName(),
FrameworkName = framework.DotNetFrameworkName, FrameworkName = framework.DotNetFrameworkName,
FriendlyName = framework.Framework, FriendlyName = FrameworkReferenceResolver.Default.GetFriendlyFrameworkName(framework),
RedistListPath = FrameworkReferenceResolver.Default.GetFrameworkRedistListPath(framework) RedistListPath = FrameworkReferenceResolver.Default.GetFrameworkRedistListPath(framework)
}; };
} }

View file

@ -31,24 +31,29 @@ namespace Microsoft.DotNet.ProjectModel.Server
var diagnosticsLookup = allDependencyDiagnostics.ToLookup(d => d.Source); var diagnosticsLookup = allDependencyDiagnostics.ToLookup(d => d.Source);
var allExports = context.CreateExporter(configuration)
.GetAllExports()
.ToDictionary(export => export.Library.GetUniqueName());
var allSourceFiles = new List<string>(context.ProjectFile.Files.SourceFiles); var allSourceFiles = new List<string>(context.ProjectFile.Files.SourceFiles);
var allFileReferences = new List<string>(); var allFileReferences = new List<string>();
var allProjectReferences = new List<ProjectReferenceDescription>(); var allProjectReferences = new List<ProjectReferenceDescription>();
var allDependencies = new Dictionary<string, DependencyDescription>(); var allDependencies = new Dictionary<string, DependencyDescription>();
foreach (var export in context.CreateExporter(configuration).GetDependencies()) // All exports are returned. When the same library name have a ReferenceAssembly type export and a Package type export
// both will be listed as dependencies. Prefix "fx/" will be added to ReferenceAssembly type dependency.
foreach (var pair in allExports)
{ {
var export = pair.Value;
allSourceFiles.AddRange(export.SourceReferences); allSourceFiles.AddRange(export.SourceReferences);
allFileReferences.AddRange(export.CompilationAssemblies.Select(asset => asset.ResolvedPath)); allFileReferences.AddRange(export.CompilationAssemblies.Select(asset => asset.ResolvedPath));
var library = export.Library; var diagnostics = diagnosticsLookup[export.Library].ToList();
var diagnostics = diagnosticsLookup[library].ToList(); var description = DependencyDescription.Create(export.Library, diagnostics, allExports);
var description = DependencyDescription.Create(library, diagnostics);
allDependencies[description.Name] = description; allDependencies[description.Name] = description;
var projectDescription = library as ProjectDescription; var projectDescription = export.Library as ProjectDescription;
if (projectDescription != null && projectDescription.Identity.Name != context.ProjectFile.Name)
if (projectDescription != null)
{ {
allProjectReferences.Add(ProjectReferenceDescription.Create(projectDescription)); allProjectReferences.Add(ProjectReferenceDescription.Create(projectDescription));
} }

View file

@ -3,7 +3,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Compilation;
using Microsoft.DotNet.ProjectModel.Server.Helpers;
namespace Microsoft.DotNet.ProjectModel.Server.Models namespace Microsoft.DotNet.ProjectModel.Server.Models
{ {
@ -51,20 +52,23 @@ namespace Microsoft.DotNet.ProjectModel.Server.Models
return base.GetHashCode(); return base.GetHashCode();
} }
public static DependencyDescription Create(LibraryDescription library, IEnumerable<DiagnosticMessage> diagnostics) public static DependencyDescription Create(LibraryDescription library,
List<DiagnosticMessage> diagnostics,
Dictionary<string, LibraryExport> allExports)
{ {
var name = library.GetUniqueName();
return new DependencyDescription return new DependencyDescription
{ {
Name = library.Identity.Name, Name = name,
DisplayName = GetLibraryDisplayName(library), DisplayName = library.Identity.Name,
Version = library.Identity.Version?.ToString(), Version = library.Identity.Version?.ToNormalizedString(),
Type = library.Identity.Type.Value, Type = library.Identity.Type.Value,
Resolved = library.Resolved, Resolved = library.Resolved,
Path = library.Path, Path = library.Path,
Dependencies = library.Dependencies.Select(dependency => new DependencyItem Dependencies = library.Dependencies.Select(dependency => new DependencyItem
{ {
Name = dependency.Name, Name = dependency.GetUniqueName(),
Version = dependency.VersionRange?.ToString() // TODO: review Version = allExports[dependency.GetUniqueName()].Library.Identity.Version?.ToNormalizedString()
}), }),
Errors = diagnostics.Where(d => d.Severity == DiagnosticMessageSeverity.Error) Errors = diagnostics.Where(d => d.Severity == DiagnosticMessageSeverity.Error)
.Select(d => new DiagnosticMessageView(d)), .Select(d => new DiagnosticMessageView(d)),
@ -72,16 +76,5 @@ namespace Microsoft.DotNet.ProjectModel.Server.Models
.Select(d => new DiagnosticMessageView(d)) .Select(d => new DiagnosticMessageView(d))
}; };
} }
private static string GetLibraryDisplayName(LibraryDescription library)
{
var name = library.Identity.Name;
if (library.Identity.Type == LibraryType.ReferenceAssembly && name.StartsWith("fx/"))
{
name = name.Substring(3);
}
return name;
}
} }
} }

View file

@ -1,10 +1,8 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. // Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
namespace Microsoft.DotNet.ProjectModel.Compilation namespace Microsoft.DotNet.ProjectModel.Compilation
{ {
@ -45,12 +43,6 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
NativeLibraries = nativeLibraries; NativeLibraries = nativeLibraries;
} }
private string DebuggerDisplay private string DebuggerDisplay => Library.Identity.ToString();
{
get
{
return Library.Identity.ToString();
}
}
} }
} }

View file

@ -1,11 +1,15 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. // Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
namespace Microsoft.DotNet.ProjectModel namespace Microsoft.DotNet.ProjectModel
{ {
internal static class Constants internal static class Constants
{ {
public static readonly string DefaultOutputDirectory = "bin"; public static readonly string DefaultOutputDirectory = "bin";
public static readonly string DefaultConfiguration = "Debug"; public static readonly string DefaultConfiguration = "Debug";
public static readonly Version Version50 = new Version(5, 0);
} }
} }

View file

@ -142,6 +142,38 @@ namespace Microsoft.DotNet.ProjectModel.Resolution
return information.RedistListPath; return information.RedistListPath;
} }
public string GetFriendlyFrameworkName(NuGetFramework targetFramework)
{
var frameworkName = new FrameworkName(targetFramework.DotNetFrameworkName);
// We don't have a friendly name for this anywhere on the machine so hard code it
if (string.Equals(frameworkName.Identifier, VersionUtility.DnxCoreFrameworkIdentifier, StringComparison.OrdinalIgnoreCase))
{
return "DNX Core 5.0";
}
else if (string.Equals(frameworkName.Identifier, VersionUtility.DnxFrameworkIdentifier, StringComparison.OrdinalIgnoreCase))
{
return "DNX " + targetFramework.Version.ToString();
}
else if (string.Equals(frameworkName.Identifier, VersionUtility.NetPlatformFrameworkIdentifier, StringComparison.OrdinalIgnoreCase))
{
var version = targetFramework.Version > Constants.Version50 ?
(" " + targetFramework.Version.ToString()) :
string.Empty;
return ".NET Platform" + version;
}
var information = _cache.GetOrAdd(targetFramework, GetFrameworkInformation);
if (information == null)
{
return SynthesizeFrameworkFriendlyName(targetFramework);
}
return information.Name;
}
private FrameworkInformation GetFrameworkInformation(NuGetFramework targetFramework) private FrameworkInformation GetFrameworkInformation(NuGetFramework targetFramework)
{ {
string referenceAssembliesPath = ReferenceAssembliesPath; string referenceAssembliesPath = ReferenceAssembliesPath;

View file

@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. // Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Runtime.Loader; using System.Runtime.Loader;
using System.Text; using System.Text;
using NuGet.Versioning; using NuGet.Versioning;
@ -10,10 +9,16 @@ namespace Microsoft.DotNet.ProjectModel.Utilities
{ {
public static class VersionUtility public static class VersionUtility
{ {
public static readonly string DnxCoreFrameworkIdentifier = "DNXCore";
public static readonly string DnxFrameworkIdentifier = "DNX";
public static readonly string NetPlatformFrameworkIdentifier = ".NETPlatform";
public static readonly string NetFrameworkIdentifier = ".NETFramework";
internal static NuGetVersion GetAssemblyVersion(string path) internal static NuGetVersion GetAssemblyVersion(string path)
{ {
return new NuGetVersion(AssemblyLoadContext.GetAssemblyName(path).Version); return new NuGetVersion(AssemblyLoadContext.GetAssemblyName(path).Version);
} }
public static string RenderVersion(VersionRange range) public static string RenderVersion(VersionRange range)
{ {
if (range == null) if (range == null)

View file

@ -68,7 +68,7 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests
} }
} }
[Theory] [Fact]
public void DthStartup_ProtocolNegotiation_ZeroIsNoAllowed() public void DthStartup_ProtocolNegotiation_ZeroIsNoAllowed()
{ {
using (var server = new DthTestServer(_testHelper.LoggerFactory)) using (var server = new DthTestServer(_testHelper.LoggerFactory))