Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Add entrypoint to analyze request, pipeline, and reports for dependency ordering #906

Merged
merged 3 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "3.1.201",
"version": "3.1.301",
"rollForward": "feature",
"allowPrerelease": false
}
Expand Down
60 changes: 0 additions & 60 deletions src/ApiPort/ApiPort.VisualStudio.Common/Analyze/AnalysisOptions.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
using ApiPortVS.Resources;
using ApiPortVS.ViewModels;
using Microsoft.Fx.Portability;
using Microsoft.Fx.Portability.ObjectModel;
using Microsoft.Fx.Portability.Reporting;
using Microsoft.Fx.Portability.Reporting.ObjectModel;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Globalization;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -38,6 +40,7 @@ public ApiPortVsAnalyzer(
}

public async Task<ReportingResult> WriteAnalysisReportsAsync(
string entrypoint,
IEnumerable<string> assemblyPaths,
IEnumerable<string> installedPackages,
IFileWriter reportWriter,
Expand All @@ -53,7 +56,7 @@ public async Task<ReportingResult> WriteAnalysisReportsAsync(
var outputFormats = _optionsViewModel.Formats.Where(f => f.IsSelected).Select(f => f.DisplayName);
var reportFileName = _optionsViewModel.DefaultOutputName;

var analysisOptions = await GetOptionsAsync(assemblyPaths, outputFormats, installedPackages, Path.Combine(reportDirectory, reportFileName));
var analysisOptions = await GetOptionsAsync(entrypoint, assemblyPaths, outputFormats, installedPackages, Path.Combine(reportDirectory, reportFileName));
var issuesBefore = _reporter.Issues.Count;

var result = await _client.WriteAnalysisReportsAsync(analysisOptions, includeJson);
Expand All @@ -73,7 +76,12 @@ public async Task<ReportingResult> WriteAnalysisReportsAsync(
return result.Result;
}

private async Task<IApiPortOptions> GetOptionsAsync(IEnumerable<string> assemblyPaths, IEnumerable<string> formats, IEnumerable<string> referencedNugetPackages, string reportFileName)
private async Task<IApiPortOptions> GetOptionsAsync(
string entrypoint,
IEnumerable<string> assemblyPaths,
IEnumerable<string> formats,
IEnumerable<string> referencedNugetPackages,
string reportFileName)
{
await _optionsViewModel.UpdateAsync().ConfigureAwait(false);
await Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
Expand All @@ -98,21 +106,26 @@ private async Task<IApiPortOptions> GetOptionsAsync(IEnumerable<string> assembly
_outputWindow.WriteLine(LocalizedStrings.TargetSelectionGuidance);
}

// TODO: Allow setting description
string description = null;

// NuGet packages referenced in the project system are not
// explicitly passed in, so we'll not want to see their portability
// statistics.
return new AnalysisOptions(
description,
assemblyPaths,
targets,
formats,
referencedNugetPackages,
!_optionsViewModel.SaveMetadata,
reportFileName,
isAssemblySpecified: false);
var flags = AnalyzeRequestFlags.ShowNonPortableApis;

if (!_optionsViewModel.SaveMetadata)
{
flags |= AnalyzeRequestFlags.NoTelemetry;
}

return new ReadWriteApiPortOptions
{
Entrypoint = entrypoint,
OutputFileName = reportFileName,
InputAssemblies = assemblyPaths.Select(target => new KeyValuePair<IAssemblyFile, bool>(new AssemblyFile(target), false)).ToImmutableDictionary(),
Targets = targets,
OutputFormats = formats,
RequestFlags = flags,
ReferencedNuGetPackages = referencedNugetPackages ?? Enumerable.Empty<string>(),
IgnoredAssemblyFiles = Enumerable.Empty<string>(),
BreakingChangeSuppressions = Enumerable.Empty<string>(),
InvalidInputFiles = Enumerable.Empty<string>(),
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public FileListAnalyzer(IVsApiPortAnalyzer analyzer, IFileWriter reportWriter)

public async Task AnalyzeProjectAsync(IEnumerable<string> inputAssemblyPaths)
{
await _analyzer.WriteAnalysisReportsAsync(inputAssemblyPaths, Enumerable.Empty<string>(), _reportWriter, false).ConfigureAwait(false);
await _analyzer.WriteAnalysisReportsAsync(null, inputAssemblyPaths, Enumerable.Empty<string>(), _reportWriter, false).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace ApiPortVS.Analyze
public interface IVsApiPortAnalyzer
{
Task<ReportingResult> WriteAnalysisReportsAsync(
string entrypoint,
IEnumerable<string> inputAssemblyPaths,
IEnumerable<string> installedPackages,
IFileWriter reportWriter,
Expand Down
14 changes: 11 additions & 3 deletions src/ApiPort/ApiPort.VisualStudio.Common/Analyze/ProjectAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -50,7 +51,7 @@ public ProjectAnalyzer(
_outputWindowWriter = outputWindowWriter;
}

public async Task AnalyzeProjectAsync(ICollection<Project> projects, CancellationToken cancellationToken = default(CancellationToken))
public async Task AnalyzeProjectAsync(ICollection<Project> projects, Project entryproject, CancellationToken cancellationToken = default(CancellationToken))
{
var buildSucceeded = await _builder.BuildAsync(projects).ConfigureAwait(false);

Expand All @@ -61,6 +62,8 @@ public ProjectAnalyzer(

// TODO: Add option to include everything in output, not just build artifacts
var targetAssemblies = new ConcurrentBag<string>();
var projectName = entryproject?.Name;
var entrypoint = default(string);

var referencedNuGetPackages = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (var project in projects)
Expand All @@ -73,9 +76,14 @@ public ProjectAnalyzer(
continue;
}

if (string.Equals(projectName, project.Name, StringComparison.OrdinalIgnoreCase))
{
entrypoint = output.FirstOrDefault();
}

foreach (var file in output)
{
targetAssemblies.Add(file);
targetAssemblies.Add(Path.GetFileName(file));
}

referencedNuGetPackages.UnionWith(GetPackageReferences(project));
Expand All @@ -86,7 +94,7 @@ public ProjectAnalyzer(
throw new PortabilityAnalyzerException(LocalizedStrings.FailedToLocateBuildOutputDir);
}

var result = await _analyzer.WriteAnalysisReportsAsync(targetAssemblies, referencedNuGetPackages, _reportWriter, true).ConfigureAwait(false);
var result = await _analyzer.WriteAnalysisReportsAsync(entrypoint, targetAssemblies, referencedNuGetPackages, _reportWriter, true).ConfigureAwait(false);
var sourceItems = await Task.Run(() => _sourceLineMapper.GetSourceInfo(targetAssemblies, result)).ConfigureAwait(false);

var dictionary = new ConcurrentBag<CalculatedProject>();
Expand Down
8 changes: 4 additions & 4 deletions src/ApiPort/ApiPort.VisualStudio/AnalyzeMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ public async Task AnalyzeSelectedProjectsAsync(bool includeDependencies)
{
var projects = GetSelectedProjects();

await AnalyzeProjectsAsync(includeDependencies ? GetTransitiveReferences(projects, new HashSet<Project>()) : projects).ConfigureAwait(false);
await AnalyzeProjectsAsync(includeDependencies ? GetTransitiveReferences(projects, new HashSet<Project>()) : projects, projects.FirstOrDefault()).ConfigureAwait(false);
}

public async void SolutionContextMenuItemCallback(object sender, EventArgs e)
{
await Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
await AnalyzeProjectsAsync(_dte.Solution.GetProjects().Where(x => x.IsDotNetProject()).ToList()).ConfigureAwait(false);
await AnalyzeProjectsAsync(_dte.Solution.GetProjects().Where(x => x.IsDotNetProject()).ToList(), null).ConfigureAwait(false);
}

private async Task AnalyzeProjectsAsync(ICollection<Project> projects)
private async Task AnalyzeProjectsAsync(ICollection<Project> projects, Project entrypoint)
{
if (!projects.Any())
{
Expand All @@ -63,7 +63,7 @@ private async Task AnalyzeProjectsAsync(ICollection<Project> projects)
{
var projectAnalyzer = innerScope.Resolve<ProjectAnalyzer>();

await projectAnalyzer.AnalyzeProjectAsync(projects).ConfigureAwait(false);
await projectAnalyzer.AnalyzeProjectAsync(projects, entrypoint).ConfigureAwait(false);
}
}
catch (PortabilityAnalyzerException ex)
Expand Down
3 changes: 3 additions & 0 deletions src/ApiPort/ApiPort/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static ICommandLineOptions ParseCommandLineOptions(string[] args)
IReadOnlyList<string> file = Array.Empty<string>();
string outFile = DefaultName;
string description = string.Empty;
string entrypoint = string.Empty;
IReadOnlyList<string> target = Array.Empty<string>();
IReadOnlyList<string> result = Array.Empty<string>();
bool showNonPortableApis = true;
Expand All @@ -47,6 +48,7 @@ public static ICommandLineOptions ParseCommandLineOptions(string[] args)
syntax.DefineOption("o|out", ref outFile, LocalizedStrings.CmdAnalyzeOutputFileName);
syntax.DefineOption("d|description", ref description, LocalizedStrings.CmdAnalyzeDescription);
syntax.DefineOption("e|endpoint", ref endpoint, LocalizedStrings.CmdEndpoint);
syntax.DefineOption("entrypoint", ref entrypoint, LocalizedStrings.CmdEntrypoint);
syntax.DefineOptionList("t|target", ref target, LocalizedStrings.CmdAnalyzeTarget);
syntax.DefineOptionList("r|resultFormat", ref result, LocalizedStrings.CmdAnalyzeResultFormat);
syntax.DefineOption("p|showNonPortableApis", ref showNonPortableApis, LocalizedStrings.CmdAnalyzeShowNonPortableApis);
Expand Down Expand Up @@ -103,6 +105,7 @@ public static ICommandLineOptions ParseCommandLineOptions(string[] args)
{
BreakingChangeSuppressions = suppressBreakingChange,
Description = description,
Entrypoint = entrypoint,
IgnoredAssemblyFiles = ignoreAssemblyFile,
InputAssemblies = inputFiles,
InvalidInputFiles = invalidFiles,
Expand Down
4 changes: 4 additions & 0 deletions src/ApiPort/ApiPort/DependencyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public static IContainer Build(ICommandLineOptions options, ProductInformation p
.As<IEnumerable<IgnoreAssemblyInfo>>()
.SingleInstance();

builder.RegisterType<DependencyOrderer>()
.As<IDependencyOrderer>()
.SingleInstance();

builder.RegisterType<ReflectionMetadataDependencyFinder>()
.As<IDependencyFinder>()
.SingleInstance();
Expand Down
9 changes: 9 additions & 0 deletions src/ApiPort/ApiPort/Resources/LocalizedStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/ApiPort/ApiPort/Resources/LocalizedStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,7 @@ Versions marked with an asterisk (*) implies that these are default targets if n
<data name="CmdAnalyzeShowExceptionApis" xml:space="preserve">
<value>Include the Apis that may throw PlatformNotSupported or NotImplemented exceptions</value>
</data>
<data name="CmdEntrypoint" xml:space="preserve">
<value>Application that will be run after porting</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Drawing.Charts;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using Microsoft.Fx.OpenXmlExtensions;
Expand Down Expand Up @@ -75,6 +74,11 @@ public async Task WriteToAsync(Stream outputStream)
GenerateUnreferencedAssembliesPage(spreadsheet.AddWorksheet(LocalizedStrings.UnresolvedUsedAssembly), _response);
}

if (_response.RecommendedOrder.Any())
{
GenerateOrderPage(spreadsheet.AddWorksheet(LocalizedStrings.RecommendedOrderHeader), _response);
}

if (_response.BreakingChanges.Any())
{
GenerateBreakingChangesPage(spreadsheet.AddWorksheet(LocalizedStrings.BreakingChanges), _response.BreakingChanges);
Expand Down Expand Up @@ -226,6 +230,27 @@ private static void GenerateUnreferencedAssembliesPage(Worksheet missingAssembli
missingAssembliesPage.AddColumnWidth(40, 40, 30);
}

private static void GenerateOrderPage(Worksheet page, AnalyzeResponse response)
{
page.AddRow(new[] { LocalizedStrings.RecommendedOrderDetails });
page.AddRow();

var header = new[] { LocalizedStrings.AssemblyHeader };
page.AddRow(header);

int detailsRows = 1;

foreach (var assembly in response.RecommendedOrder)
{
page.AddRow(assembly);
detailsRows++;
}

// Generate the pretty table
page.AddTable(3, detailsRows, 1, header.ToArray());
page.AddColumnWidth(100);
}

private void GenerateDetailsPage(Worksheet detailsPage, ReportingResult analysisResult)
{
var showAssemblyColumn = analysisResult.GetAssemblyUsageInfo().Any();
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@
<data name="NoExceptionNoted" xml:space="preserve">
<value>No Notable Exceptions</value>
</data>
<data name="RecommendedOrderDetails" xml:space="preserve">
<value>Migration is much easier by following a bottom up approach. Projects with less dependencies should be migrated to .NET Standard or .NET Core first, followed by the ones that may depend on that. For this submission, the following is the recommended order:</value>
</data>
<data name="RecommendedOrderHeader" xml:space="preserve">
<value>Recommended Order</value>
</data>
<data name="SkippedAssembly" xml:space="preserve">
<value>Skipped Assembly</value>
</data>
Expand Down
Loading