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

Commit

Permalink
Send project format warnings & update diagnostics message
Browse files Browse the repository at this point in the history
Also support DTH protocol versioning
  • Loading branch information
troydai committed Mar 24, 2015
1 parent da990a9 commit ac2f433
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 55 deletions.
46 changes: 23 additions & 23 deletions DNX.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.22710.0
VisualStudioVersion = 14.0.22712.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{189961D1-DFF4-406A-9D42-39B61221A73A}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -110,7 +110,7 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Framework.Runtime
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "NuGet.Packaging.Core.Types", "submodules\NuGet.Packaging\src\NuGet.Packaging.Core.Types\NuGet.Packaging.Core.Types.xproj", "{46275450-3B62-4E89-8F7E-3FE2EE8513D2}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "NuGet.ProjectModel", "submodules\NuGet.Packaging\src\NuGet.ProjectModel\NuGet.ProjectModel.xproj", "{18006692-AFCC-49FD-95F6-66E8A0C49E9B}"
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "NuGet.ProjectModel", "submodules\NuGet.Packaging\src\NuGet.ProjectModel\NuGet.ProjectModel.xproj", "{F013E43F-B6D5-4F59-ACF0-EECEC2C794F5}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "NuGet.LibraryModel", "submodules\NuGet.Packaging\src\NuGet.LibraryModel\NuGet.LibraryModel.xproj", "{13883E8E-7DE1-4EDD-8E4A-C5357BA8CD81}"
EndProject
Expand Down Expand Up @@ -804,26 +804,26 @@ Global
{46275450-3B62-4E89-8F7E-3FE2EE8513D2}.Release|x64.Build.0 = Release|Any CPU
{46275450-3B62-4E89-8F7E-3FE2EE8513D2}.Release|x86.ActiveCfg = Release|Any CPU
{46275450-3B62-4E89-8F7E-3FE2EE8513D2}.Release|x86.Build.0 = Release|Any CPU
{18006692-AFCC-49FD-95F6-66E8A0C49E9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{18006692-AFCC-49FD-95F6-66E8A0C49E9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{18006692-AFCC-49FD-95F6-66E8A0C49E9B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{18006692-AFCC-49FD-95F6-66E8A0C49E9B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{18006692-AFCC-49FD-95F6-66E8A0C49E9B}.Debug|Win32.ActiveCfg = Debug|Any CPU
{18006692-AFCC-49FD-95F6-66E8A0C49E9B}.Debug|Win32.Build.0 = Debug|Any CPU
{18006692-AFCC-49FD-95F6-66E8A0C49E9B}.Debug|x64.ActiveCfg = Debug|Any CPU
{18006692-AFCC-49FD-95F6-66E8A0C49E9B}.Debug|x64.Build.0 = Debug|Any CPU
{18006692-AFCC-49FD-95F6-66E8A0C49E9B}.Debug|x86.ActiveCfg = Debug|Any CPU
{18006692-AFCC-49FD-95F6-66E8A0C49E9B}.Debug|x86.Build.0 = Debug|Any CPU
{18006692-AFCC-49FD-95F6-66E8A0C49E9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{18006692-AFCC-49FD-95F6-66E8A0C49E9B}.Release|Any CPU.Build.0 = Release|Any CPU
{18006692-AFCC-49FD-95F6-66E8A0C49E9B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{18006692-AFCC-49FD-95F6-66E8A0C49E9B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{18006692-AFCC-49FD-95F6-66E8A0C49E9B}.Release|Win32.ActiveCfg = Release|Any CPU
{18006692-AFCC-49FD-95F6-66E8A0C49E9B}.Release|Win32.Build.0 = Release|Any CPU
{18006692-AFCC-49FD-95F6-66E8A0C49E9B}.Release|x64.ActiveCfg = Release|Any CPU
{18006692-AFCC-49FD-95F6-66E8A0C49E9B}.Release|x64.Build.0 = Release|Any CPU
{18006692-AFCC-49FD-95F6-66E8A0C49E9B}.Release|x86.ActiveCfg = Release|Any CPU
{18006692-AFCC-49FD-95F6-66E8A0C49E9B}.Release|x86.Build.0 = Release|Any CPU
{F013E43F-B6D5-4F59-ACF0-EECEC2C794F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F013E43F-B6D5-4F59-ACF0-EECEC2C794F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F013E43F-B6D5-4F59-ACF0-EECEC2C794F5}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{F013E43F-B6D5-4F59-ACF0-EECEC2C794F5}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{F013E43F-B6D5-4F59-ACF0-EECEC2C794F5}.Debug|Win32.ActiveCfg = Debug|Any CPU
{F013E43F-B6D5-4F59-ACF0-EECEC2C794F5}.Debug|Win32.Build.0 = Debug|Any CPU
{F013E43F-B6D5-4F59-ACF0-EECEC2C794F5}.Debug|x64.ActiveCfg = Debug|Any CPU
{F013E43F-B6D5-4F59-ACF0-EECEC2C794F5}.Debug|x64.Build.0 = Debug|Any CPU
{F013E43F-B6D5-4F59-ACF0-EECEC2C794F5}.Debug|x86.ActiveCfg = Debug|Any CPU
{F013E43F-B6D5-4F59-ACF0-EECEC2C794F5}.Debug|x86.Build.0 = Debug|Any CPU
{F013E43F-B6D5-4F59-ACF0-EECEC2C794F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F013E43F-B6D5-4F59-ACF0-EECEC2C794F5}.Release|Any CPU.Build.0 = Release|Any CPU
{F013E43F-B6D5-4F59-ACF0-EECEC2C794F5}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{F013E43F-B6D5-4F59-ACF0-EECEC2C794F5}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{F013E43F-B6D5-4F59-ACF0-EECEC2C794F5}.Release|Win32.ActiveCfg = Release|Any CPU
{F013E43F-B6D5-4F59-ACF0-EECEC2C794F5}.Release|Win32.Build.0 = Release|Any CPU
{F013E43F-B6D5-4F59-ACF0-EECEC2C794F5}.Release|x64.ActiveCfg = Release|Any CPU
{F013E43F-B6D5-4F59-ACF0-EECEC2C794F5}.Release|x64.Build.0 = Release|Any CPU
{F013E43F-B6D5-4F59-ACF0-EECEC2C794F5}.Release|x86.ActiveCfg = Release|Any CPU
{F013E43F-B6D5-4F59-ACF0-EECEC2C794F5}.Release|x86.Build.0 = Release|Any CPU
{13883E8E-7DE1-4EDD-8E4A-C5357BA8CD81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{13883E8E-7DE1-4EDD-8E4A-C5357BA8CD81}.Debug|Any CPU.Build.0 = Debug|Any CPU
{13883E8E-7DE1-4EDD-8E4A-C5357BA8CD81}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -1052,7 +1052,7 @@ Global
{AF8C0E0F-D6F2-4F22-BF0D-0E904F46DD95} = {A6FE6180-B68C-447F-9CD6-66287B329B80}
{209FE200-D4E8-4E52-9AEA-7F77A10696A8} = {AF391791-F4B7-41AC-8F08-9485DAC543C5}
{46275450-3B62-4E89-8F7E-3FE2EE8513D2} = {CAF3AE3C-D013-43E7-9AFD-AC6956B2999F}
{18006692-AFCC-49FD-95F6-66E8A0C49E9B} = {CAF3AE3C-D013-43E7-9AFD-AC6956B2999F}
{F013E43F-B6D5-4F59-ACF0-EECEC2C794F5} = {CAF3AE3C-D013-43E7-9AFD-AC6956B2999F}
{13883E8E-7DE1-4EDD-8E4A-C5357BA8CD81} = {CAF3AE3C-D013-43E7-9AFD-AC6956B2999F}
{CF8E1753-EE98-410F-BB4B-6624B19C6B64} = {CAF3AE3C-D013-43E7-9AFD-AC6956B2999F}
{24DE9E2C-4ADC-48E6-ADF0-1E2B00596ECD} = {CAF3AE3C-D013-43E7-9AFD-AC6956B2999F}
Expand Down
97 changes: 77 additions & 20 deletions src/Microsoft.Framework.DesignTimeHost/ApplicationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class ApplicationContext
private readonly Dictionary<FrameworkName, ProjectCompilation> _compilations = new Dictionary<FrameworkName, ProjectCompilation>();
private readonly PluginHandler _pluginHandler;

private int _protocolVersion;

public ApplicationContext(IServiceProvider services,
ICache cache,
ICacheContextAccessor cacheContextAccessor,
Expand All @@ -61,12 +63,38 @@ public class ApplicationContext
_pluginHandler = new PluginHandler(services, SendPluginMessage);

Id = id;

ProtocolVersion = 1;
}

public int Id { get; private set; }

public string ApplicationPath { get { return _appPath.Value; } }

public int ProtocolVersion
{
get
{
return _protocolVersion;
}
set
{
// protocol
var strProtocol = Environment.GetEnvironmentVariable("DTH_PROTOCOL");
int intProtocol;
if (!string.IsNullOrEmpty(strProtocol) && Int32.TryParse(strProtocol, out intProtocol))
{
Logger.TraceInformation("[{0}]: Set DTH protocol version to {1}. Source is environment variable DTH_PROTOCOL.", GetType().Name, intProtocol);
_protocolVersion = intProtocol;
}
else
{
Logger.TraceInformation("[{0}]: Set DTH protocol version to {1}.", GetType().Name, value);
_protocolVersion = value;
}
}
}

public void OnReceive(Message message)
{
lock (_inbox)
Expand Down Expand Up @@ -221,12 +249,14 @@ private bool ProcessMessage()

var data = new InitializeMessage
{
Version = GetValue<int>(message.Payload, "Version"),
Configuration = GetValue(message.Payload, "Configuration"),
ProjectFolder = GetValue(message.Payload, "ProjectFolder")
};

_appPath.Value = data.ProjectFolder;
_configuration.Value = data.Configuration ?? "Debug";
ProtocolVersion = data.Version;
}
else
{
Expand Down Expand Up @@ -373,6 +403,8 @@ private bool ResolveDependencies()
GlobalJsonPath = state.GlobalJsonPath
};

_local.ProjectWarningMessage = new ProjectWarningsMessage(state.FileFormatWarnings);

foreach (var project in state.Projects)
{
var frameworkData = project.TargetFramework;
Expand Down Expand Up @@ -438,11 +470,9 @@ private bool PerformCompilation()
{
projectCompilationChanged = UpdateProjectCompilation(project, out compilation);

project.Diagnostics = new DiagnosticsMessage
{
Framework = project.Sources.Framework,
Diagnostics = compilation.Diagnostics
};
project.Diagnostics = new DiagnosticsMessage(
compilation.Diagnostics,
project.Sources.Framework);
}

Trigger<Void> requiresAssemblies;
Expand Down Expand Up @@ -482,11 +512,9 @@ private bool PerformCompilation()

if (project.Diagnostics == null)
{
project.Diagnostics = new DiagnosticsMessage
{
Framework = project.Sources.Framework,
Diagnostics = compilation.Diagnostics,
};
project.Diagnostics = new DiagnosticsMessage(
compilation.Diagnostics,
project.Sources.Framework);
}
}
}
Expand Down Expand Up @@ -575,8 +603,14 @@ private void SendOutgoingMessages()
_remote.ProjectInformation = _local.ProjectInformation;
}

var unprocessedFrameworks = new HashSet<FrameworkName>(_remote.Projects.Keys);
if (IsDifferent(_local.ProjectWarningMessage, _remote.ProjectWarningMessage))
{
SendProjectFormatWarnings(_local.ProjectWarningMessage);
_remote.ProjectWarningMessage = _local.ProjectWarningMessage;
}

var allDiagnostics = new List<DiagnosticsMessage>();
var unprocessedFrameworks = new HashSet<FrameworkName>(_remote.Projects.Keys);

foreach (var pair in _local.Projects)
{
Expand Down Expand Up @@ -664,21 +698,39 @@ private void SendOutgoingMessages()
}
}

private void SendProjectFormatWarnings(ProjectWarningsMessage message)
{
var payload = message.ConvertToJson(ProtocolVersion);

if (payload != null)
{
Logger.TraceInformation("[{0}]: Sending project format warnings.", GetType().Name);
_initializedContext.Transmit(new Message
{
ContextId = Id,
MessageType = "Diagnostics",
Payload = message.ConvertToJson(_protocolVersion)
});
}
}

private void SendDiagnostics(IList<DiagnosticsMessage> diagnostics)
{
if (diagnostics.Count == 0)
{
return;
}

var payload = JToken.FromObject(diagnostics.Select(d => d.ConvertToJson(ProtocolVersion)));

// Send all diagnostics back
foreach (var connection in _waitingForDiagnostics)
{
connection.Transmit(new Message
{
ContextId = Id,
MessageType = "AllDiagnostics",
Payload = JToken.FromObject(diagnostics)
Payload = payload
});
}

Expand Down Expand Up @@ -796,15 +848,17 @@ private void WriteAssembly(int version, ProjectWorld project, BinaryWriter write
{
writer.Write("Assembly");
writer.Write(Id);
writer.Write(project.Diagnostics.Warnings.Count());

writer.Write(project.Diagnostics.Warnings.Count);
foreach (var warning in project.Diagnostics.Warnings)
{
writer.Write(warning);
writer.Write(warning.FormattedMessage);
}
writer.Write(project.Diagnostics.Errors.Count());

writer.Write(project.Diagnostics.Errors.Count);
foreach (var error in project.Diagnostics.Errors)
{
writer.Write(error);
writer.Write(error.FormattedMessage);
}

WriteAssembly(project, writer);
Expand All @@ -814,7 +868,7 @@ private void WriteAssembly(int version, ProjectWorld project, BinaryWriter write
var obj = new JObject();
obj["MessageType"] = "Assembly";
obj["ContextId"] = Id;
obj[nameof(CompileResponse.Diagnostics)] = ConvertToJArray(project.Diagnostics.Diagnostics);
obj[nameof(CompileResponse.Diagnostics)] = ConvertToJArray(project.Diagnostics.CompilationDiagnostics);
obj[nameof(CompileResponse.AssemblyPath)] = project.Outputs.AssemblyPath;
obj["Blobs"] = 2;
writer.Write(obj.ToString(Formatting.None));
Expand Down Expand Up @@ -871,11 +925,12 @@ private State DoInitialWork(string appPath, string configuration, bool triggerBu
var state = new State
{
Frameworks = new List<FrameworkData>(),
Projects = new List<ProjectInfo>()
Projects = new List<ProjectInfo>(),
FileFormatWarnings = new List<FileFormatWarning>()
};

Project project;
if (!Project.TryGetProject(appPath, out project))
if (!Project.TryGetProject(appPath, out project, state.FileFormatWarnings))
{
throw new InvalidOperationException(string.Format("Unable to find project.json in '{0}'", appPath));
}
Expand Down Expand Up @@ -1198,6 +1253,8 @@ private class State
{
public string Name { get; set; }

public IList<FileFormatWarning> FileFormatWarnings { get; set; }

public IList<string> ProjectSearchPaths { get; set; }

public string GlobalJsonPath { get; set; }
Expand Down Expand Up @@ -1293,4 +1350,4 @@ private struct Void
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace Microsoft.Framework.DesignTimeHost.Models.IncomingMessages
{
public class InitializeMessage
{
public int Version { get; set; }

public string Configuration { get; set; }

public string ProjectFolder { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,65 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
using System.Linq;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Runtime;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Microsoft.Framework.DesignTimeHost.Models.OutgoingMessages
{
public class DiagnosticsMessage
{
public FrameworkData Framework { get; set; }
public DiagnosticsMessage([NotNull] IList<ICompilationMessage> compilationMessages, FrameworkData frameworkData)
{
CompilationDiagnostics = compilationMessages;
Errors = compilationMessages.Where(msg => msg.Severity == CompilationMessageSeverity.Error).ToList();
Warnings = compilationMessages.Where(msg => msg.Severity == CompilationMessageSeverity.Warning).ToList();
Framework = frameworkData;
}

public FrameworkData Framework { get; }

[JsonIgnore]
public IList<ICompilationMessage> Diagnostics { get; set; }
public IList<ICompilationMessage> CompilationDiagnostics { get; }

public IList<ICompilationMessage> Errors { get; }

public IEnumerable<string> Errors => Diagnostics.Where(d => d.Severity == CompilationMessageSeverity.Error)
.Select(d => d.FormattedMessage);
public IList<ICompilationMessage> Warnings { get; }

public IEnumerable<string> Warnings => Diagnostics.Where(d => d.Severity == CompilationMessageSeverity.Warning)
.Select(d => d.FormattedMessage);
public virtual JToken ConvertToJson(int protocolVersion)
{
if (protocolVersion <= 1)
{
var payload = new
{
Framework = Framework,
Errors = Errors.Select(e => e.FormattedMessage),
Warnings = Warnings.Select(w => w.FormattedMessage)
};

return JToken.FromObject(payload);
}
else
{
return JToken.FromObject(this);
}
}

public override bool Equals(object obj)
{
var other = obj as DiagnosticsMessage;

return other != null &&
Enumerable.SequenceEqual(Warnings, other.Warnings) &&
Enumerable.SequenceEqual(Errors, other.Errors);
Enumerable.SequenceEqual(Errors, other.Errors) &&
Enumerable.SequenceEqual(Warnings, other.Warnings) &&
Framework == other.Framework;
}

public override int GetHashCode()
{
// These objects are currently POCOs and we're overriding equals
// so that things like Enumerable.SequenceEqual just work.
return base.GetHashCode();
}
}
Expand Down

0 comments on commit ac2f433

Please sign in to comment.