2016-10-28 01:46:43 +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.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;
|
|
|
|
|
|
2016-11-14 22:26:03 +00:00
|
|
|
|
private string _runtime;
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
private bool _noDependencies;
|
|
|
|
|
|
|
|
|
|
private DirectoryInfo _outputPath;
|
|
|
|
|
|
|
|
|
|
private FileInfo _projectFile;
|
|
|
|
|
|
|
|
|
|
private DirectoryInfo _workingDirectory;
|
|
|
|
|
|
|
|
|
|
public BuildPJCommand()
|
|
|
|
|
: base(new RepoDirectoriesProvider().PjDotnet)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override CommandResult Execute(string args = "")
|
|
|
|
|
{
|
2016-11-14 22:26:03 +00:00
|
|
|
|
args = $"build {GetNoDependencies()} {GetProjectFile()} {GetOutputPath()} {GetConfiguration()} {GetFramework()} {GetRuntime()} {args}";
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-14 22:26:03 +00:00
|
|
|
|
public BuildPJCommand WithRuntime(string runtime)
|
|
|
|
|
{
|
|
|
|
|
_runtime = runtime;
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
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()}";
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-14 22:26:03 +00:00
|
|
|
|
private string GetRuntime()
|
|
|
|
|
{
|
|
|
|
|
if (_runtime == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $"--runtime {_runtime}";
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
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}\"";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|