Feature complete

This commit is contained in:
piotrp 2016-03-27 22:24:20 -07:00 committed by Piotr Puszkiewicz
parent d85e516c23
commit 6f37e87a42
6 changed files with 80 additions and 89 deletions

View file

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14 # Visual Studio 14
VisualStudioVersion = 14.0.25029.0 VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{ED2FE3E2-F7E7-4389-8231-B65123F2076F}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{ED2FE3E2-F7E7-4389-8231-B65123F2076F}"
EndProject EndProject
@ -95,6 +95,12 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.Testin
EndProject EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.Testing.Abstractions.UnitTests", "test\TestingAbstractions\Microsoft.Extensions.Testing.Abstractions.UnitTests\Microsoft.Extensions.Testing.Abstractions.UnitTests.xproj", "{DEB3AB06-FCD8-4119-B8CA-B7AA6CE2F22D}" Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.Testing.Abstractions.UnitTests", "test\TestingAbstractions\Microsoft.Extensions.Testing.Abstractions.UnitTests\Microsoft.Extensions.Testing.Abstractions.UnitTests.xproj", "{DEB3AB06-FCD8-4119-B8CA-B7AA6CE2F22D}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestAssets", "TestAssets", "{ADA7052B-884B-4776-8B8D-D04191D0AA70}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestPackages", "TestPackages", "{1AB5B24B-B317-4142-A5D1-A6E84F15BA34}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-dependency-tool-invoker", "TestAssets\TestPackages\dotnet-dependency-tool-invoker\dotnet-dependency-tool-invoker.xproj", "{C26A48BB-193F-450C-AB09-4D3324C78188}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -683,6 +689,22 @@ Global
{DEB3AB06-FCD8-4119-B8CA-B7AA6CE2F22D}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU {DEB3AB06-FCD8-4119-B8CA-B7AA6CE2F22D}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{DEB3AB06-FCD8-4119-B8CA-B7AA6CE2F22D}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU {DEB3AB06-FCD8-4119-B8CA-B7AA6CE2F22D}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{DEB3AB06-FCD8-4119-B8CA-B7AA6CE2F22D}.RelWithDebInfo|x64.Build.0 = Release|Any CPU {DEB3AB06-FCD8-4119-B8CA-B7AA6CE2F22D}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{C26A48BB-193F-450C-AB09-4D3324C78188}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C26A48BB-193F-450C-AB09-4D3324C78188}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C26A48BB-193F-450C-AB09-4D3324C78188}.Debug|x64.ActiveCfg = Debug|Any CPU
{C26A48BB-193F-450C-AB09-4D3324C78188}.Debug|x64.Build.0 = Debug|Any CPU
{C26A48BB-193F-450C-AB09-4D3324C78188}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
{C26A48BB-193F-450C-AB09-4D3324C78188}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
{C26A48BB-193F-450C-AB09-4D3324C78188}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{C26A48BB-193F-450C-AB09-4D3324C78188}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{C26A48BB-193F-450C-AB09-4D3324C78188}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C26A48BB-193F-450C-AB09-4D3324C78188}.Release|Any CPU.Build.0 = Release|Any CPU
{C26A48BB-193F-450C-AB09-4D3324C78188}.Release|x64.ActiveCfg = Release|Any CPU
{C26A48BB-193F-450C-AB09-4D3324C78188}.Release|x64.Build.0 = Release|Any CPU
{C26A48BB-193F-450C-AB09-4D3324C78188}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
{C26A48BB-193F-450C-AB09-4D3324C78188}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{C26A48BB-193F-450C-AB09-4D3324C78188}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{C26A48BB-193F-450C-AB09-4D3324C78188}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -727,5 +749,8 @@ Global
{7B0EFBB4-4669-4B83-B47C-7F3E6DB07AF9} = {EB0F5F8C-0991-49AC-B188-A9869476C7DF} {7B0EFBB4-4669-4B83-B47C-7F3E6DB07AF9} = {EB0F5F8C-0991-49AC-B188-A9869476C7DF}
{09C61BD7-C6DB-4F89-85BF-4EB3C196049D} = {EB0F5F8C-0991-49AC-B188-A9869476C7DF} {09C61BD7-C6DB-4F89-85BF-4EB3C196049D} = {EB0F5F8C-0991-49AC-B188-A9869476C7DF}
{DEB3AB06-FCD8-4119-B8CA-B7AA6CE2F22D} = {EB0F5F8C-0991-49AC-B188-A9869476C7DF} {DEB3AB06-FCD8-4119-B8CA-B7AA6CE2F22D} = {EB0F5F8C-0991-49AC-B188-A9869476C7DF}
{ADA7052B-884B-4776-8B8D-D04191D0AA70} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F}
{1AB5B24B-B317-4142-A5D1-A6E84F15BA34} = {ADA7052B-884B-4776-8B8D-D04191D0AA70}
{C26A48BB-193F-450C-AB09-4D3324C78188} = {1AB5B24B-B317-4142-A5D1-A6E84F15BA34}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

View file

@ -22,6 +22,12 @@
"net451":{} "net451":{}
}, },
"tools": { "tools": {
"dotnet-dependency-tool-invoker":"1.0.0-*" "dotnet-dependency-tool-invoker": {
"version": "1.0.0-*",
"imports": [
"dnxcore50",
"portable-net45+win8"
]
}
} }
} }

View file

@ -10,8 +10,8 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
public interface IPackagedCommandSpecFactory public interface IPackagedCommandSpecFactory
{ {
CommandSpec CreateCommandSpecFromLibrary( CommandSpec CreateCommandSpecFromRuntimeAssembly(
LockFilePackageLibrary library, LockFileTargetLibrary toolLibrary,
string commandName, string commandName,
IEnumerable<string> commandArguments, IEnumerable<string> commandArguments,
IEnumerable<string> allowedExtensions, IEnumerable<string> allowedExtensions,

View file

@ -2,20 +2,16 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.ProjectModel.Compilation;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks;
using NuGet.Packaging; using NuGet.Packaging;
namespace Microsoft.DotNet.Cli.Utils namespace Microsoft.DotNet.Cli.Utils
{ {
public class PackagedCommandSpecFactory : IPackagedCommandSpecFactory public class PackagedCommandSpecFactory : IPackagedCommandSpecFactory
{ {
public CommandSpec CreateCommandSpecFromLibrary( public CommandSpec CreateCommandSpecFromRuntimeAssembly(
LockFilePackageLibrary library, LockFileTargetLibrary toolLibrary,
string commandName, string commandName,
IEnumerable<string> commandArguments, IEnumerable<string> commandArguments,
IEnumerable<string> allowedExtensions, IEnumerable<string> allowedExtensions,
@ -23,22 +19,22 @@ namespace Microsoft.DotNet.Cli.Utils
CommandResolutionStrategy commandResolutionStrategy, CommandResolutionStrategy commandResolutionStrategy,
string depsFilePath) string depsFilePath)
{ {
var packageDirectory = GetPackageDirectoryFullPath(library, nugetPackagesRoot);
if (!Directory.Exists(packageDirectory)) var toolAssembly = toolLibrary?.RuntimeAssemblies
.FirstOrDefault(r => Path.GetFileNameWithoutExtension(r.Path) == commandName);
if (toolAssembly == null)
{ {
return null; return null;
} }
var commandFile = GetCommandFileRelativePath(library, commandName, allowedExtensions); var commandPath = GetCommandFilePath(nugetPackagesRoot, toolLibrary, toolAssembly);
if (commandFile == null) if (!File.Exists(commandPath))
{ {
return null; return null;
} }
var commandPath = Path.Combine(packageDirectory, commandFile);
var isPortable = DetermineIfPortableApp(commandPath); var isPortable = DetermineIfPortableApp(commandPath);
return CreateCommandSpecWrappingWithCorehostfDll( return CreateCommandSpecWrappingWithCorehostfDll(
@ -50,24 +46,14 @@ namespace Microsoft.DotNet.Cli.Utils
isPortable); isPortable);
} }
private string GetPackageDirectoryFullPath(LockFilePackageLibrary library, string nugetPackagesRoot) private string GetCommandFilePath(string nugetPackagesRoot, LockFileTargetLibrary toolLibrary, LockFileItem runtimeAssembly)
{ {
var packageDirectory = new VersionFolderPathResolver(nugetPackagesRoot) var packageDirectory = new VersionFolderPathResolver(nugetPackagesRoot)
.GetInstallPath(library.Name, library.Version); .GetInstallPath(toolLibrary.Name, toolLibrary.Version);
return packageDirectory; var filePath = Path.Combine(packageDirectory, runtimeAssembly.Path);
}
private string GetCommandFileRelativePath( return filePath;
LockFilePackageLibrary library,
string commandName,
IEnumerable<string> allowedExtensions)
{
// TODO: Should command names be case sensitive?
return library.Files
.Where(f => Path.GetFileNameWithoutExtension(f) == commandName)
.Where(e => allowedExtensions.Contains(Path.GetExtension(e)))
.FirstOrDefault();
} }
private CommandSpec CreateCommandSpecWrappingWithCorehostfDll( private CommandSpec CreateCommandSpecWrappingWithCorehostfDll(
@ -102,7 +88,7 @@ namespace Microsoft.DotNet.Cli.Utils
string nugetPackagesRoot, string nugetPackagesRoot,
bool isPortable) bool isPortable)
{ {
string host = string.Empty; var host = string.Empty;
var arguments = new List<string>(); var arguments = new List<string>();
if (isPortable) if (isPortable)

View file

@ -2,12 +2,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks; using NuGet.Frameworks;
using NuGet.Packaging;
namespace Microsoft.DotNet.Cli.Utils namespace Microsoft.DotNet.Cli.Utils
{ {
@ -16,8 +14,8 @@ namespace Microsoft.DotNet.Cli.Utils
private static readonly CommandResolutionStrategy s_commandResolutionStrategy = private static readonly CommandResolutionStrategy s_commandResolutionStrategy =
CommandResolutionStrategy.ProjectDependenciesPackage; CommandResolutionStrategy.ProjectDependenciesPackage;
private IEnvironmentProvider _environment; private readonly IEnvironmentProvider _environment;
private IPackagedCommandSpecFactory _packagedCommandSpecFactory; private readonly IPackagedCommandSpecFactory _packagedCommandSpecFactory;
public ProjectDependenciesCommandResolver( public ProjectDependenciesCommandResolver(
IEnvironmentProvider environment, IEnvironmentProvider environment,
@ -80,10 +78,10 @@ namespace Microsoft.DotNet.Cli.Utils
var depsFilePath = var depsFilePath =
projectContext.GetOutputPaths(configuration, buildBasePath, outputPath).RuntimeFiles.DepsJson; projectContext.GetOutputPaths(configuration, buildBasePath, outputPath).RuntimeFiles.DepsJson;
var dependencyLibraries = GetAllDependencyLibraries(projectContext); var toolLibrary = GetToolLibraryForContext(projectContext, commandName);
return ResolveFromDependencyLibraries( return ResolveFromDependencyLibrary(
dependencyLibraries, toolLibrary,
depsFilePath, depsFilePath,
commandName, commandName,
allowedExtensions, allowedExtensions,
@ -91,43 +89,16 @@ namespace Microsoft.DotNet.Cli.Utils
projectContext); projectContext);
} }
private CommandSpec ResolveFromDependencyLibraries(
IEnumerable<LockFilePackageLibrary> dependencyLibraries,
string depsFilePath,
string commandName,
IEnumerable<string> allowedExtensions,
IEnumerable<string> commandArguments,
ProjectContext projectContext)
{
foreach (var dependencyLibrary in dependencyLibraries)
{
var commandSpec = ResolveFromDependencyLibrary(
dependencyLibrary,
depsFilePath,
commandName,
allowedExtensions,
commandArguments,
projectContext);
if (commandSpec != null)
{
return commandSpec;
}
}
return null;
}
private CommandSpec ResolveFromDependencyLibrary( private CommandSpec ResolveFromDependencyLibrary(
LockFilePackageLibrary dependencyLibrary, LockFileTargetLibrary toolLibrary,
string depsFilePath, string depsFilePath,
string commandName, string commandName,
IEnumerable<string> allowedExtensions, IEnumerable<string> allowedExtensions,
IEnumerable<string> commandArguments, IEnumerable<string> commandArguments,
ProjectContext projectContext) ProjectContext projectContext)
{ {
return _packagedCommandSpecFactory.CreateCommandSpecFromLibrary( return _packagedCommandSpecFactory.CreateCommandSpecFromRuntimeAssembly(
dependencyLibrary, toolLibrary,
commandName, commandName,
commandArguments, commandArguments,
allowedExtensions, allowedExtensions,
@ -136,13 +107,15 @@ namespace Microsoft.DotNet.Cli.Utils
depsFilePath); depsFilePath);
} }
private IEnumerable<LockFilePackageLibrary> GetAllDependencyLibraries( private LockFileTargetLibrary GetToolLibraryForContext(
ProjectContext projectContext) ProjectContext projectContext, string commandName)
{ {
return projectContext.LibraryManager.GetLibraries() var toolLibrary = projectContext.LockFile.Targets
.Where(l => l.GetType() == typeof(PackageDescription)) .FirstOrDefault(t => t.TargetFramework.GetShortFolderName()
.Select(l => l as PackageDescription) .Equals(projectContext.TargetFramework.GetShortFolderName()))
.Select(p => p.Library); ?.Libraries.FirstOrDefault(l => l.Name == commandName);
return toolLibrary;
} }
private ProjectContext GetProjectContextFromDirectory(string directory, NuGetFramework framework) private ProjectContext GetProjectContextFromDirectory(string directory, NuGetFramework framework)

View file

@ -95,28 +95,29 @@ namespace Microsoft.DotNet.Cli.Utils
} }
private CommandSpec ResolveCommandSpecFromToolLibrary( private CommandSpec ResolveCommandSpecFromToolLibrary(
LibraryRange toolLibrary, LibraryRange toolLibraryRange,
string commandName, string commandName,
IEnumerable<string> args, IEnumerable<string> args,
ProjectContext projectContext) ProjectContext projectContext)
{ {
var nugetPackagesRoot = projectContext.PackagesDirectory; var nugetPackagesRoot = projectContext.PackagesDirectory;
var lockFile = GetToolLockFile(toolLibrary, nugetPackagesRoot); var lockFile = GetToolLockFile(toolLibraryRange, nugetPackagesRoot);
var lockFilePackageLibrary = lockFile.PackageLibraries.FirstOrDefault(l => l.Name == toolLibrary.Name);
var toolLibrary = lockFile.Targets
.FirstOrDefault(t => t.TargetFramework.GetShortFolderName().Equals(s_toolPackageFramework.GetShortFolderName()))
?.Libraries.FirstOrDefault(l => l.Name == toolLibraryRange.Name);
if (toolLibrary == null)
{
return null;
}
var depsFileRoot = Path.GetDirectoryName(lockFile.LockFilePath); var depsFileRoot = Path.GetDirectoryName(lockFile.LockFilePath);
var depsFilePath = GetToolDepsFilePath(toolLibrary, lockFile, depsFileRoot); var depsFilePath = GetToolDepsFilePath(toolLibraryRange, lockFile, depsFileRoot);
var toolProjectContext = new ProjectContextBuilder() return _packagedCommandSpecFactory.CreateCommandSpecFromRuntimeAssembly(
.WithLockFile(lockFile) toolLibrary,
.WithTargetFramework(s_toolPackageFramework.ToString())
.Build();
var exporter = toolProjectContext.CreateExporter(Constants.DefaultConfiguration);
return _packagedCommandSpecFactory.CreateCommandSpecFromLibrary(
lockFilePackageLibrary,
commandName, commandName,
args, args,
_allowedCommandExtensions, _allowedCommandExtensions,