50 lines
1.7 KiB
C#
50 lines
1.7 KiB
C#
|
7 years ago
|
using System;
|
||
|
7 years ago
|
using System.Diagnostics;
|
||
|
|
using System.IO;
|
||
|
|
|
||
|
7 years ago
|
namespace Yavsc.Server.Models.IT.SourceCode
|
||
|
7 years ago
|
{
|
||
|
7 years ago
|
public class ProjectBuild : SingleCmdProjectBatch
|
||
|
7 years ago
|
{
|
||
|
7 years ago
|
public ProjectBuild(string repoRoot): base(repoRoot, "make")
|
||
|
7 years ago
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
public override void Launch(Project input)
|
||
|
|
{
|
||
|
7 years ago
|
if (input==null) throw new ArgumentNullException("input");
|
||
|
7 years ago
|
LogPath = $"{input.Name}.{_cmdPath}.ansi.log";
|
||
|
|
|
||
|
7 years ago
|
// TODO honor Args property
|
||
|
|
// Model annotations => input.Repository!=null => input.Name == input.Repository.Path
|
||
|
|
var prjPath = Path.Combine(WorkingDir, input.Name);
|
||
|
|
var repoInfo = new DirectoryInfo(prjPath);
|
||
|
7 years ago
|
var args = string.Join(" ", Args);
|
||
|
7 years ago
|
|
||
|
|
var cloneStart = new ProcessStartInfo
|
||
|
7 years ago
|
( _cmdPath, args )
|
||
|
7 years ago
|
{
|
||
|
7 years ago
|
WorkingDirectory = prjPath,
|
||
|
7 years ago
|
RedirectStandardOutput = true,
|
||
|
|
UseShellExecute = false
|
||
|
|
};
|
||
|
|
// TODO make `.ansi.log` a defined constant.
|
||
|
|
var logFile = new FileInfo
|
||
|
|
( Path.Combine
|
||
|
|
( _repositoryRootPath, $"{input.Name}.ansi.log" ));
|
||
|
|
using (var stream = logFile.Create())
|
||
|
|
using (var writer = new StreamWriter(stream))
|
||
|
|
{
|
||
|
|
var process = Process.Start(cloneStart);
|
||
|
|
// TODO announce ...
|
||
|
|
while (!process.HasExited)
|
||
|
|
{
|
||
|
|
if (process.StandardOutput.Peek() > -1)
|
||
|
|
writer.WriteLine(process.StandardOutput.ReadLine());
|
||
|
|
}
|
||
|
|
}
|
||
|
7 years ago
|
if (ResultHandler!=null) ResultHandler(true);
|
||
|
7 years ago
|
}
|
||
|
7 years ago
|
|
||
|
7 years ago
|
}
|
||
|
7 years ago
|
}
|