2016-03-03 23:31:04 +00:00
|
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
2016-08-05 23:54:41 +00:00
|
|
|
|
using Microsoft.DotNet.PlatformAbstractions;
|
2016-03-03 23:31:04 +00:00
|
|
|
|
using NuGet.Frameworks;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Cli.Utils
|
|
|
|
|
{
|
|
|
|
|
public class ProjectDependenciesCommandFactory : ICommandFactory
|
|
|
|
|
{
|
|
|
|
|
private readonly NuGetFramework _nugetFramework;
|
|
|
|
|
private readonly string _configuration;
|
|
|
|
|
private readonly string _outputPath;
|
2016-03-11 23:30:37 +00:00
|
|
|
|
private readonly string _buildBasePath;
|
2016-03-03 23:31:04 +00:00
|
|
|
|
private readonly string _projectDirectory;
|
|
|
|
|
|
|
|
|
|
public ProjectDependenciesCommandFactory(
|
2016-03-11 23:30:37 +00:00
|
|
|
|
NuGetFramework nugetFramework,
|
|
|
|
|
string configuration,
|
2016-03-03 23:31:04 +00:00
|
|
|
|
string outputPath,
|
2016-03-11 23:30:37 +00:00
|
|
|
|
string buildBasePath,
|
2016-03-03 23:31:04 +00:00
|
|
|
|
string projectDirectory)
|
|
|
|
|
{
|
|
|
|
|
_nugetFramework = nugetFramework;
|
|
|
|
|
_configuration = configuration;
|
|
|
|
|
_outputPath = outputPath;
|
2016-03-11 23:30:37 +00:00
|
|
|
|
_buildBasePath = buildBasePath;
|
2016-03-03 23:31:04 +00:00
|
|
|
|
_projectDirectory = projectDirectory;
|
2016-04-18 17:51:15 +00:00
|
|
|
|
|
|
|
|
|
if (_configuration == null)
|
|
|
|
|
{
|
|
|
|
|
_configuration = Constants.DefaultConfiguration;
|
|
|
|
|
}
|
2016-03-03 23:31:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ICommand Create(
|
|
|
|
|
string commandName,
|
|
|
|
|
IEnumerable<string> args,
|
|
|
|
|
NuGetFramework framework = null,
|
2016-04-18 17:51:15 +00:00
|
|
|
|
string configuration = null)
|
2016-03-03 23:31:04 +00:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(configuration))
|
|
|
|
|
{
|
|
|
|
|
configuration = _configuration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (framework == null)
|
|
|
|
|
{
|
|
|
|
|
framework = _nugetFramework;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var commandSpec = FindProjectDependencyCommands(
|
2016-03-11 23:30:37 +00:00
|
|
|
|
commandName,
|
|
|
|
|
args,
|
|
|
|
|
configuration,
|
|
|
|
|
framework,
|
2016-03-03 23:31:04 +00:00
|
|
|
|
_outputPath,
|
2016-03-11 23:30:37 +00:00
|
|
|
|
_buildBasePath,
|
2016-03-03 23:31:04 +00:00
|
|
|
|
_projectDirectory);
|
|
|
|
|
|
|
|
|
|
return Command.Create(commandSpec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private CommandSpec FindProjectDependencyCommands(
|
|
|
|
|
string commandName,
|
|
|
|
|
IEnumerable<string> commandArgs,
|
|
|
|
|
string configuration,
|
|
|
|
|
NuGetFramework framework,
|
|
|
|
|
string outputPath,
|
2016-03-11 23:30:37 +00:00
|
|
|
|
string buildBasePath,
|
2016-03-03 23:31:04 +00:00
|
|
|
|
string projectDirectory)
|
|
|
|
|
{
|
|
|
|
|
var commandResolverArguments = new CommandResolverArguments
|
|
|
|
|
{
|
|
|
|
|
CommandName = commandName,
|
|
|
|
|
CommandArguments = commandArgs,
|
|
|
|
|
Framework = framework,
|
|
|
|
|
Configuration = configuration,
|
|
|
|
|
OutputPath = outputPath,
|
2016-03-11 23:30:37 +00:00
|
|
|
|
BuildBasePath = buildBasePath,
|
2016-03-03 23:31:04 +00:00
|
|
|
|
ProjectDirectory = projectDirectory
|
|
|
|
|
};
|
|
|
|
|
|
2016-04-06 03:13:06 +00:00
|
|
|
|
var commandResolver = GetProjectDependenciesCommandResolver(framework);
|
2016-03-03 23:31:04 +00:00
|
|
|
|
|
|
|
|
|
var commandSpec = commandResolver.Resolve(commandResolverArguments);
|
|
|
|
|
if (commandSpec == null)
|
|
|
|
|
{
|
|
|
|
|
throw new CommandUnknownException(commandName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return commandSpec;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-06 03:13:06 +00:00
|
|
|
|
private ICommandResolver GetProjectDependenciesCommandResolver(NuGetFramework framework)
|
2016-03-03 23:31:04 +00:00
|
|
|
|
{
|
|
|
|
|
var environment = new EnvironmentProvider();
|
|
|
|
|
|
2016-04-06 03:13:06 +00:00
|
|
|
|
if (framework.IsDesktop())
|
|
|
|
|
{
|
2016-04-06 22:29:10 +00:00
|
|
|
|
IPlatformCommandSpecFactory platformCommandSpecFactory = null;
|
2016-04-28 23:30:32 +00:00
|
|
|
|
if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
|
2016-04-06 03:13:06 +00:00
|
|
|
|
{
|
|
|
|
|
platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
platformCommandSpecFactory = new GenericPlatformCommandSpecFactory();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new OutputPathCommandResolver(environment, platformCommandSpecFactory);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var packagedCommandSpecFactory = new PackagedCommandSpecFactory();
|
|
|
|
|
return new ProjectDependenciesCommandResolver(environment, packagedCommandSpecFactory);
|
|
|
|
|
}
|
2016-03-03 23:31:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|