dotnet-installer/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/BuildPJCommand.cs
Piotr Puszkiewicz 6fcbefa4f7 [WIP] Removes *3 verbs, making msbuild the driver (#4456)
Removes *3 verbs, making msbuild the driver
2016-10-27 18:46:43 -07:00

164 lines
3.8 KiB
C#

// 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.IO;
using Microsoft.DotNet.Cli.Utils;
using NuGet.Frameworks;
namespace Microsoft.DotNet.Tools.Test.Utilities
{
public sealed class BuildPJCommand : TestCommand
{
private bool _captureOutput;
private string _configuration;
private NuGetFramework _framework;
private bool _noDependencies;
private DirectoryInfo _outputPath;
private FileInfo _projectFile;
private DirectoryInfo _workingDirectory;
public BuildPJCommand()
: base(new RepoDirectoriesProvider().PjDotnet)
{
}
public override CommandResult Execute(string args = "")
{
args = $"build {GetNoDependencies()} {GetProjectFile()} {GetOutputPath()} {GetConfiguration()} {GetFramework()} {args}";
if (_workingDirectory != null)
{
this.WithWorkingDirectory(_workingDirectory.FullName);
}
if (_captureOutput)
{
return base.ExecuteWithCapturedOutput(args);
}
else
{
return base.Execute(args);
}
}
public override CommandResult ExecuteWithCapturedOutput(string args = "")
{
WithCapturedOutput();
return Execute(args);
}
public BuildPJCommand WithCapturedOutput()
{
_captureOutput = true;
return this;
}
public BuildPJCommand WithConfiguration(string configuration)
{
_configuration = configuration;
return this;
}
public BuildPJCommand WithFramework(NuGetFramework framework)
{
_framework = framework;
return this;
}
public BuildPJCommand WithNoDependencies()
{
_noDependencies = true;
return this;
}
public BuildPJCommand WithOutputPath(DirectoryInfo outputPath)
{
_outputPath = outputPath;
return this;
}
public BuildPJCommand WithProjectDirectory(DirectoryInfo projectDirectory)
{
_workingDirectory = projectDirectory;
return this;
}
public BuildPJCommand WithProjectFile(FileInfo projectFile)
{
_projectFile = projectFile;
return this;
}
public BuildPJCommand WithWorkingDirectory(DirectoryInfo workingDirectory)
{
_workingDirectory = workingDirectory;
return this;
}
private string GetConfiguration()
{
if (_configuration == null)
{
return null;
}
return $"--configuration {_configuration}";
}
private string GetFramework()
{
if (_framework == null)
{
return null;
}
return $"--framework {_framework.GetShortFolderName()}";
}
private string GetNoDependencies()
{
if (!_noDependencies)
{
return null;
}
return "--no-dependencies";
}
private string GetOutputPath()
{
if (_outputPath == null)
{
return null;
}
return $"\"{_outputPath.FullName}\"";
}
private string GetProjectFile()
{
if (_projectFile == null)
{
return null;
}
return $"\"{_projectFile.FullName}\"";
}
}
}