From d8a10024e50ad4f5696a75fcde66bb39e392c4da Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Thu, 13 Oct 2016 21:42:19 -0700 Subject: [PATCH] Addressing code review comments by removing unnecessary test artifacts. --- .../dotnet-dependency-tool-invoker/Program.cs | 80 ++++++++++++++----- .../project.json | 3 +- .../dotnet-invoke-portable/Program.cs | 27 ------- .../dotnet-invoke-portable/project.json | 22 ----- ...SBuildTestAppWithToolInDependencies.csproj | 4 +- build/test/TestPackageProjects.targets | 9 --- test/EndToEnd/GivenDotNetUsesMSBuild.cs | 2 +- 7 files changed, 66 insertions(+), 81 deletions(-) delete mode 100644 TestAssets/TestPackages/dotnet-invoke-portable/Program.cs delete mode 100644 TestAssets/TestPackages/dotnet-invoke-portable/project.json diff --git a/TestAssets/TestPackages/dotnet-dependency-tool-invoker/Program.cs b/TestAssets/TestPackages/dotnet-dependency-tool-invoker/Program.cs index 53e103eaa..9db2e07b3 100644 --- a/TestAssets/TestPackages/dotnet-dependency-tool-invoker/Program.cs +++ b/TestAssets/TestPackages/dotnet-dependency-tool-invoker/Program.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.Cli.Utils; +using NuGet.Frameworks; namespace Microsoft.DotNet.Tools.DependencyInvoker { @@ -36,32 +37,73 @@ namespace Microsoft.DotNet.Tools.DependencyInvoker dotnetParams.Config, dotnetParams.Output, dotnetParams.BuildBasePath, - projectContexts.First().ProjectDirectory); - + dotnetParams.ProjectPath); + + var result = 0; + if(projectContexts.Any()) + { + result = InvokeDependencyToolForProjectJson(projectContexts, commandFactory, dotnetParams); + } + else + { + result = InvokeDependencyToolForMSBuild(commandFactory, dotnetParams); + } + + return result; + } + + private static int InvokeDependencyToolForMSBuild( + ProjectDependenciesCommandFactory commandFactory, + DotnetBaseParams dotnetParams) + { + Console.WriteLine($"Invoking '{dotnetParams.Command}' for '{dotnetParams.Framework.GetShortFolderName()}'."); + + return InvokeDependencyTool(commandFactory, dotnetParams, dotnetParams.Framework); + } + + private static int InvokeDependencyToolForProjectJson( + IEnumerable projectContexts, + ProjectDependenciesCommandFactory commandFactory, + DotnetBaseParams dotnetParams) + { foreach (var projectContext in projectContexts) { Console.WriteLine($"Invoking '{dotnetParams.Command}' for '{projectContext.TargetFramework}'."); - try + if (InvokeDependencyTool(commandFactory, dotnetParams, projectContext.TargetFramework) != 0) { - var exitCode = commandFactory.Create( - $"dotnet-{dotnetParams.Command}", - dotnetParams.RemainingArguments, - projectContext.TargetFramework, - dotnetParams.Config) - .ForwardStdErr() - .ForwardStdOut() - .Execute() - .ExitCode; - - Console.WriteLine($"Command returned {exitCode}"); - } - catch (CommandUnknownException) - { - Console.WriteLine($"Command not found"); return 1; } } + + return 0; + } + + private static int InvokeDependencyTool( + ProjectDependenciesCommandFactory commandFactory, + DotnetBaseParams dotnetParams, + NuGetFramework framework) + { + try + { + var exitCode = commandFactory.Create( + $"dotnet-{dotnetParams.Command}", + dotnetParams.RemainingArguments, + framework, + dotnetParams.Config) + .ForwardStdErr() + .ForwardStdOut() + .Execute() + .ExitCode; + + Console.WriteLine($"Command returned {exitCode}"); + } + catch (CommandUnknownException) + { + Console.WriteLine($"Command not found"); + return 1; + } + return 0; } @@ -76,7 +118,7 @@ namespace Microsoft.DotNet.Tools.DependencyInvoker if (!File.Exists(projectPath)) { - throw new InvalidOperationException($"{projectPath} does not exist."); + return Enumerable.Empty(); } return ProjectContext.CreateContextForEachFramework(projectPath); diff --git a/TestAssets/TestPackages/dotnet-dependency-tool-invoker/project.json b/TestAssets/TestPackages/dotnet-dependency-tool-invoker/project.json index 8bf2cd784..f02530564 100644 --- a/TestAssets/TestPackages/dotnet-dependency-tool-invoker/project.json +++ b/TestAssets/TestPackages/dotnet-dependency-tool-invoker/project.json @@ -22,7 +22,8 @@ }, "Microsoft.DotNet.Compiler.Common": { "target": "project" - } + }, + "NuGet.Frameworks": "3.6.0-rc-1979" }, "frameworks": { "netcoreapp1.0": { diff --git a/TestAssets/TestPackages/dotnet-invoke-portable/Program.cs b/TestAssets/TestPackages/dotnet-invoke-portable/Program.cs deleted file mode 100644 index 1d7be4391..000000000 --- a/TestAssets/TestPackages/dotnet-invoke-portable/Program.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.IO; -using Microsoft.DotNet.Cli.Utils; -using NuGet.Frameworks; - -namespace ConsoleApplication -{ - public class Program - { - public static void Main(string[] args) - { - var environment = new EnvironmentProvider(); - var packagedCommandSpecFactory = new PackagedCommandSpecFactory(); - - var projectDependenciesCommandFactory = new ProjectDependenciesCommandFactory( - FrameworkConstants.CommonFrameworks.NetCoreApp10, - "Debug", - null, - null, - Directory.GetCurrentDirectory()); - - var command = projectDependenciesCommandFactory.Create("dotnet-portable", null); - - command.Execute(); - } - } -} diff --git a/TestAssets/TestPackages/dotnet-invoke-portable/project.json b/TestAssets/TestPackages/dotnet-invoke-portable/project.json deleted file mode 100644 index 86cada978..000000000 --- a/TestAssets/TestPackages/dotnet-invoke-portable/project.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "version": "1.0.0-rc-*", - "buildOptions": { - "emitEntryPoint": true - }, - "dependencies": { - "Microsoft.DotNet.Cli.Utils": { - "target": "project" - }, - "NuGet.Frameworks": "3.6.0-rc-1954" - }, - "frameworks": { - "netcoreapp1.0": { - "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.1" - } - } - } - } -} diff --git a/TestAssets/TestProjects/MSBuildTestAppWithToolInDependencies/MSBuildTestAppWithToolInDependencies.csproj b/TestAssets/TestProjects/MSBuildTestAppWithToolInDependencies/MSBuildTestAppWithToolInDependencies.csproj index 6bed7f3ab..7d998ff6b 100644 --- a/TestAssets/TestProjects/MSBuildTestAppWithToolInDependencies/MSBuildTestAppWithToolInDependencies.csproj +++ b/TestAssets/TestProjects/MSBuildTestAppWithToolInDependencies/MSBuildTestAppWithToolInDependencies.csproj @@ -27,8 +27,8 @@ - - 1.0.0-rc-* + + 1.0.0-* diff --git a/build/test/TestPackageProjects.targets b/build/test/TestPackageProjects.targets index a0b4fc311..a22571df6 100644 --- a/build/test/TestPackageProjects.targets +++ b/build/test/TestPackageProjects.targets @@ -142,15 +142,6 @@ True netcoreapp1.0 - - dotnet-invoke-portable - True - True - 1.0.0-rc- - $(TestPackageBuildVersionSuffix) - True - netcoreapp1.0 - dotnet-tool-with-output-name ToolWithOutputName diff --git a/test/EndToEnd/GivenDotNetUsesMSBuild.cs b/test/EndToEnd/GivenDotNetUsesMSBuild.cs index a88e4b0f3..3f20ec23b 100644 --- a/test/EndToEnd/GivenDotNetUsesMSBuild.cs +++ b/test/EndToEnd/GivenDotNetUsesMSBuild.cs @@ -108,7 +108,7 @@ namespace Microsoft.DotNet.Tests.EndToEnd new DotnetCommand() .WithWorkingDirectory(testProjectDirectory) - .ExecuteWithCapturedOutput("invoke-portable") + .ExecuteWithCapturedOutput("dependency-tool-invoker -f netcoreapp1.0 portable") .Should() .Pass() .And