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
# Visual Studio 14
VisualStudioVersion = 14.0.25029.0
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{ED2FE3E2-F7E7-4389-8231-B65123F2076F}"
EndProject
@ -95,6 +95,12 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.Testin
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}"
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
GlobalSection(SolutionConfigurationPlatforms) = preSolution
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|x64.ActiveCfg = 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
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -727,5 +749,8 @@ Global
{7B0EFBB4-4669-4B83-B47C-7F3E6DB07AF9} = {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}
{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
EndGlobal

View file

@ -22,6 +22,12 @@
"net451":{}
},
"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
{
CommandSpec CreateCommandSpecFromLibrary(
LockFilePackageLibrary library,
CommandSpec CreateCommandSpecFromRuntimeAssembly(
LockFileTargetLibrary toolLibrary,
string commandName,
IEnumerable<string> commandArguments,
IEnumerable<string> allowedExtensions,

View file

@ -2,20 +2,16 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.ProjectModel.Compilation;
using Microsoft.Extensions.PlatformAbstractions;
using NuGet.Frameworks;
using NuGet.Packaging;
namespace Microsoft.DotNet.Cli.Utils
{
public class PackagedCommandSpecFactory : IPackagedCommandSpecFactory
{
public CommandSpec CreateCommandSpecFromLibrary(
LockFilePackageLibrary library,
public CommandSpec CreateCommandSpecFromRuntimeAssembly(
LockFileTargetLibrary toolLibrary,
string commandName,
IEnumerable<string> commandArguments,
IEnumerable<string> allowedExtensions,
@ -23,22 +19,22 @@ namespace Microsoft.DotNet.Cli.Utils
CommandResolutionStrategy commandResolutionStrategy,
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;
}
var commandPath = GetCommandFilePath(nugetPackagesRoot, toolLibrary, toolAssembly);
var commandFile = GetCommandFileRelativePath(library, commandName, allowedExtensions);
if (commandFile == null)
if (!File.Exists(commandPath))
{
return null;
}
var commandPath = Path.Combine(packageDirectory, commandFile);
var isPortable = DetermineIfPortableApp(commandPath);
return CreateCommandSpecWrappingWithCorehostfDll(
@ -50,24 +46,14 @@ namespace Microsoft.DotNet.Cli.Utils
isPortable);
}
private string GetPackageDirectoryFullPath(LockFilePackageLibrary library, string nugetPackagesRoot)
private string GetCommandFilePath(string nugetPackagesRoot, LockFileTargetLibrary toolLibrary, LockFileItem runtimeAssembly)
{
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(
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();
return filePath;
}
private CommandSpec CreateCommandSpecWrappingWithCorehostfDll(
@ -102,7 +88,7 @@ namespace Microsoft.DotNet.Cli.Utils
string nugetPackagesRoot,
bool isPortable)
{
string host = string.Empty;
var host = string.Empty;
var arguments = new List<string>();
if (isPortable)

View file

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

View file

@ -95,28 +95,29 @@ namespace Microsoft.DotNet.Cli.Utils
}
private CommandSpec ResolveCommandSpecFromToolLibrary(
LibraryRange toolLibrary,
LibraryRange toolLibraryRange,
string commandName,
IEnumerable<string> args,
ProjectContext projectContext)
{
var nugetPackagesRoot = projectContext.PackagesDirectory;
var lockFile = GetToolLockFile(toolLibraryRange, nugetPackagesRoot);
var lockFile = GetToolLockFile(toolLibrary, 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 depsFilePath = GetToolDepsFilePath(toolLibrary, lockFile, depsFileRoot);
var toolProjectContext = new ProjectContextBuilder()
.WithLockFile(lockFile)
.WithTargetFramework(s_toolPackageFramework.ToString())
.Build();
var exporter = toolProjectContext.CreateExporter(Constants.DefaultConfiguration);
return _packagedCommandSpecFactory.CreateCommandSpecFromLibrary(
lockFilePackageLibrary,
var depsFilePath = GetToolDepsFilePath(toolLibraryRange, lockFile, depsFileRoot);
return _packagedCommandSpecFactory.CreateCommandSpecFromRuntimeAssembly(
toolLibrary,
commandName,
args,
_allowedCommandExtensions,