Tabs to spaces

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 7 years ago
parent 3964ce1c15
commit f553cff079
  1. 18
      DotNetBuilder/CompileRequest.cs
  2. 210
      DotNetBuilder/Compiler.cs
  3. 52
      DotNetBuilder/Message.cs
  4. 60
      DotNetBuilder/Messages.cs
  5. 418
      DotNetBuilder/NUnitTester.cs
  6. 14
      DotNetBuilder/NuGetPackRequest.cs
  7. 12
      DotNetBuilder/NuGetPushRequest.cs
  8. 10
      DotNetBuilder/NuGetRestoreRequest.cs
  9. 454
      DotNetBuilder/NuGetter.cs
  10. 90
      DotNetBuilder/PathTools.cs
  11. 80
      DotNetBuilder/Program.cs
  12. 48
      DotNetBuilder/Response.cs
  13. 14
      DotNetBuilder/StubWriter.cs
  14. 8
      DotNetBuilder/TestRequest.cs

@ -1,17 +1,17 @@
namespace MicroBuildServer.DotNetBuilder
{
class CompileRequest
{
public string SolutionPath { get; set; }
class CompileRequest
{
public string SolutionPath { get; set; }
public string Target { get; set; }
public string Target { get; set; }
public string Configuration { get; set; }
public string Configuration { get; set; }
public string OutputDirectory { get; set; }
public string OutputDirectory { get; set; }
public string SigningKey { get; set; }
public string SigningKey { get; set; }
public bool SkipCodeAnalysis { get; set; }
}
public bool SkipCodeAnalysis { get; set; }
}
}

@ -11,109 +11,109 @@ using System.IO;
namespace MicroBuildServer.DotNetBuilder
{
static class Compiler
{
private class CompilerLogger : Logger
{
public readonly Messages Messages = new Messages();
private int indent = 0;
public override void Initialize(IEventSource eventSource)
{
if (eventSource == null)
{
throw new ArgumentNullException("eventSource");
}
eventSource.ProjectStarted += OnProjectStarted;
eventSource.ProjectFinished += OnProjectFinished;
eventSource.ErrorRaised += OnError;
eventSource.WarningRaised += OnWarning;
eventSource.MessageRaised += OnMessage;
}
private void OnProjectStarted(object sender, ProjectStartedEventArgs e)
{
Messages.Add(Message.CreateInfo(GetLine("Started {0}", e.ProjectFile)));
indent++;
}
private void OnProjectFinished(object sender, ProjectFinishedEventArgs e)
{
indent--;
Messages.Add(Message.CreateInfo(GetLine("Finished {0}", e.ProjectFile)));
}
private void OnError(object sender, BuildErrorEventArgs e)
{
Messages.Add(Message.CreateError(GetLine("{0} (#{1}, {2}:{3},{4})", e.Message, e.Code, e.File, e.LineNumber, e.ColumnNumber)));
}
private void OnWarning(object sender, BuildWarningEventArgs e)
{
Messages.Add(Message.CreateWarn(GetLine("{0} (#{1}, {2}:{3},{4})", e.Message, e.Code, e.File, e.LineNumber, e.ColumnNumber)));
}
private void OnMessage(object sender, BuildMessageEventArgs e)
{
//if (e.Importance != MessageImportance.High) return;
Messages.Add(Message.CreateInfo(GetLine("{0}: {1}", e.Importance, e.Message)));
}
private string GetLine(string format, params object[] args)
{
var result = new string('\t', indent) + string.Format(format, args);
return result;
}
}
public static readonly string BuilderAssemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
public static Response Compile(CompileRequest request)
{
var logger = new CompilerLogger();
logger.Verbosity = LoggerVerbosity.Detailed;
var pc = new ProjectCollection();
var globalProperty = new Dictionary<string, string>();
globalProperty.Add("Configuration", request.Configuration ?? "Release");
//globalProperty.Add("Platform", "AnyCPU");
globalProperty.Add("VisualStudioVersion", "14.0");
if (!string.IsNullOrEmpty(request.OutputDirectory))
{
globalProperty.Add("OutputDirectory", request.OutputDirectory);
}
if (!string.IsNullOrEmpty(request.SigningKey))
{
globalProperty.Add("SignAssembly", "true");
globalProperty.Add("AssemblyOriginatorKeyFile", request.SigningKey);
}
if (!request.SkipCodeAnalysis)
{
globalProperty.Add("RunCodeAnalysis", "true");
globalProperty.Add("CodeAnalysisRuleSet", Path.Combine(BuilderAssemblyDirectory, "AllRules.ruleset"));
globalProperty.Add("MBSBuilderPath", BuilderAssemblyDirectory);
globalProperty.Add("CustomBeforeMicrosoftCSharpTargets", Path.Combine(BuilderAssemblyDirectory, "ImportStyleCop.targets"));
}
else
{
globalProperty.Add("RunCodeAnalysis", "false");
globalProperty.Add("CodeAnalysisRuleSet", string.Empty);
}
var buildRequest = new BuildRequestData(request.SolutionPath, globalProperty, "14.0", new [] { request.Target }, null);
var parameters = new BuildParameters(pc);
parameters.Loggers = new ILogger[] { logger };
parameters.DetailedSummary = true;
var buildResult = BuildManager.DefaultBuildManager.Build(parameters, buildRequest);
if (buildResult.OverallResult == BuildResultCode.Failure)
{
logger.Messages.Add(Message.CreateError("BuildResult is false"));
}
return new Response(logger.Messages);
}
}
static class Compiler
{
private class CompilerLogger : Logger
{
public readonly Messages Messages = new Messages();
private int indent = 0;
public override void Initialize(IEventSource eventSource)
{
if (eventSource == null)
{
throw new ArgumentNullException("eventSource");
}
eventSource.ProjectStarted += OnProjectStarted;
eventSource.ProjectFinished += OnProjectFinished;
eventSource.ErrorRaised += OnError;
eventSource.WarningRaised += OnWarning;
eventSource.MessageRaised += OnMessage;
}
private void OnProjectStarted(object sender, ProjectStartedEventArgs e)
{
Messages.Add(Message.CreateInfo(GetLine("Started {0}", e.ProjectFile)));
indent++;
}
private void OnProjectFinished(object sender, ProjectFinishedEventArgs e)
{
indent--;
Messages.Add(Message.CreateInfo(GetLine("Finished {0}", e.ProjectFile)));
}
private void OnError(object sender, BuildErrorEventArgs e)
{
Messages.Add(Message.CreateError(GetLine("{0} (#{1}, {2}:{3},{4})", e.Message, e.Code, e.File, e.LineNumber, e.ColumnNumber)));
}
private void OnWarning(object sender, BuildWarningEventArgs e)
{
Messages.Add(Message.CreateWarn(GetLine("{0} (#{1}, {2}:{3},{4})", e.Message, e.Code, e.File, e.LineNumber, e.ColumnNumber)));
}
private void OnMessage(object sender, BuildMessageEventArgs e)
{
//if (e.Importance != MessageImportance.High) return;
Messages.Add(Message.CreateInfo(GetLine("{0}: {1}", e.Importance, e.Message)));
}
private string GetLine(string format, params object[] args)
{
var result = new string('\t', indent) + string.Format(format, args);
return result;
}
}
public static readonly string BuilderAssemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
public static Response Compile(CompileRequest request)
{
var logger = new CompilerLogger();
logger.Verbosity = LoggerVerbosity.Detailed;
var pc = new ProjectCollection();
var globalProperty = new Dictionary<string, string>();
globalProperty.Add("Configuration", request.Configuration ?? "Release");
//globalProperty.Add("Platform", "AnyCPU");
globalProperty.Add("VisualStudioVersion", "14.0");
if (!string.IsNullOrEmpty(request.OutputDirectory))
{
globalProperty.Add("OutputDirectory", request.OutputDirectory);
}
if (!string.IsNullOrEmpty(request.SigningKey))
{
globalProperty.Add("SignAssembly", "true");
globalProperty.Add("AssemblyOriginatorKeyFile", request.SigningKey);
}
if (!request.SkipCodeAnalysis)
{
globalProperty.Add("RunCodeAnalysis", "true");
globalProperty.Add("CodeAnalysisRuleSet", Path.Combine(BuilderAssemblyDirectory, "AllRules.ruleset"));
globalProperty.Add("MBSBuilderPath", BuilderAssemblyDirectory);
globalProperty.Add("CustomBeforeMicrosoftCSharpTargets", Path.Combine(BuilderAssemblyDirectory, "ImportStyleCop.targets"));
}
else
{
globalProperty.Add("RunCodeAnalysis", "false");
globalProperty.Add("CodeAnalysisRuleSet", string.Empty);
}
var buildRequest = new BuildRequestData(request.SolutionPath, globalProperty, "14.0", new [] { request.Target }, null);
var parameters = new BuildParameters(pc);
parameters.Loggers = new ILogger[] { logger };
parameters.DetailedSummary = true;
var buildResult = BuildManager.DefaultBuildManager.Build(parameters, buildRequest);
if (buildResult.OverallResult == BuildResultCode.Failure)
{
logger.Messages.Add(Message.CreateError("BuildResult is false"));
}
return new Response(logger.Messages);
}
}
}

@ -2,36 +2,36 @@
namespace MicroBuildServer.DotNetBuilder
{
public class Message
{
public readonly string Type;
public class Message
{
public readonly string Type;
public readonly string Body;
public readonly string Body;
private Message(string type, string body)
{
Type = type;
Body = body;
}
private Message(string type, string body)
{
Type = type;
Body = body;
}
public static Message CreateInfo(string body)
{
return new Message("info", body);
}
public static Message CreateInfo(string body)
{
return new Message("info", body);
}
public static Message CreateWarn(string body)
{
return new Message("warn", body);
}
public static Message CreateWarn(string body)
{
return new Message("warn", body);
}
public static Message CreateError(string body)
{
return new Message("error", body);
}
public static Message CreateError(string body)
{
return new Message("error", body);
}
public override string ToString()
{
return string.Format("{0}: {1}", Type, Body);
}
}
public override string ToString()
{
return string.Format("{0}: {1}", Type, Body);
}
}
}

@ -6,39 +6,39 @@ using System.Threading.Tasks;
namespace MicroBuildServer.DotNetBuilder
{
internal class Messages
{
private readonly object syncRoot = new object();
internal class Messages
{
private readonly object syncRoot = new object();
private readonly List<Message> storage = new List<Message>();
private readonly List<Message> storage = new List<Message>();
public void Add(Message message)
{
if (message == null)
{
throw new ArgumentNullException(nameof(message));
}
public void Add(Message message)
{
if (message == null)
{
throw new ArgumentNullException(nameof(message));
}
lock(syncRoot)
{
storage.Add(message);
}
}
lock(syncRoot)
{
storage.Add(message);
}
}
public TResult[] ToArray<TResult>(Func<Message, TResult> selector)
{
lock(syncRoot)
{
return storage.Select(selector).ToArray();
}
}
public TResult[] ToArray<TResult>(Func<Message, TResult> selector)
{
lock(syncRoot)
{
return storage.Select(selector).ToArray();
}
}
public bool Any()
{
lock(syncRoot)
{
return storage.Any();
}
}
}
public bool Any()
{
lock(syncRoot)
{
return storage.Any();
}
}
}
}

@ -7,213 +7,213 @@ using NUnit.Core;
namespace MicroBuildServer.DotNetBuilder
{
class NUnitTester
{
private const string DATA_TEST_RESULTS_KEY = "TestResults";
private class Listener : EventListener
{
public readonly Messages Messages = new Messages();
private bool runFail;
private bool suiteFail;
private static bool IsSuccess(TestResult result)
{
return result.IsSuccess || result.ResultState == ResultState.Ignored;
}
private static string FormatResult(TestResult result)
{
var additional = new List<string>();
if (result.IsSuccess)
{
additional.Add("success");
}
else if (result.IsError)
{
additional.Add("error");
}
else if (result.IsFailure)
{
additional.Add("fail");
}
else if (result.ResultState == ResultState.Ignored)
{
additional.Add("ignored");
}
else
{
additional.Add("status unknown");
}
if (!string.IsNullOrEmpty(result.Message))
{
additional.Add("message = " + result.Message);
}
return additional.Any() ? result.Name + "; " + string.Join(", ", additional) : result.Name;
}
public void RunFinished(Exception exception)
{
Messages.Add(Message.CreateError("Run finished: " + exception));
runFail = true;
}
public void RunFinished(TestResult result)
{
var message = string.Format("Run finished: {0}", FormatResult(result));
if (!IsSuccess(result) && !runFail)
{
Messages.Add(Message.CreateError(message));
}
else
{
Messages.Add(Message.CreateInfo(message));
}
}
public void RunStarted(string name, int testCount)
{
Messages.Add(Message.CreateInfo("Run started: " + name));
runFail = false;
}
public void SuiteFinished(TestResult result)
{
var message = string.Format("Suite finished: {0}", FormatResult(result));
if (!IsSuccess(result) && !suiteFail)
{
Messages.Add(Message.CreateError(message));
}
else
{
Messages.Add(Message.CreateInfo(message));
}
if (!result.IsSuccess)
{
runFail = true;
}
}
public void SuiteStarted(TestName testName)
{
Messages.Add(Message.CreateInfo("Suite started: " + testName.Name));
suiteFail = false;
}
public void TestFinished(TestResult result)
{
var message = string.Format("Test finished: {0}", FormatResult(result));
if (!IsSuccess(result))
{
Messages.Add(Message.CreateError(message));
}
else
{
Messages.Add(Message.CreateInfo(message));
}
suiteFail = true;
}
public void TestOutput(TestOutput testOutput)
{
Messages.Add(Message.CreateInfo("Test output: " + testOutput.Text));
}
public void TestStarted(TestName testName)
{
Messages.Add(Message.CreateInfo("Test started: " + testName.Name));
}
public void UnhandledException(Exception exception)
{
Messages.Add(Message.CreateError("Unhandled exception: " + exception));
suiteFail = true;
runFail = true;
}
}
public interface ITestWorker
{
void DoTest(string testLibraryPath);
}
[Serializable]
public class TestWorker : MarshalByRefObject, ITestWorker
{
public void DoTest(string testLibraryPath)
{
Console.SetOut(new StubWriter());
var listener = new Listener();
CoreExtensions.Host.InitializeService();
var package = new TestPackage(testLibraryPath);
//package.AutoBinPath = true;
//package.BasePath = Path.GetDirectoryName(TestLibraryPath);
//package.ConfigurationFile = TestLibraryPath + ".config";
TestRunner runner = new SimpleTestRunner();
if (runner.Load(package))
{
runner.Run(listener, TestFilter.Empty, true, LoggingThreshold.All);
}
//DebugTestResult(Console.Out, result);
if (!listener.Messages.Any())
{
listener.Messages.Add(Message.CreateError("No messages from listener"));
}
AppDomain.CurrentDomain.SetData(DATA_TEST_RESULTS_KEY, new Response(listener.Messages));
}
}
/*private static void DebugTestResult(object rawResult, int level = 0)
{
if (rawResult == null)
{
Console.WriteLine("Result is null");
return;
}
var prefix = new string('\t', level);
Console.WriteLine("{0}RESULT START", prefix);
Console.WriteLine("{0}Type: {1}", prefix, rawResult);
if (rawResult is TestResult)
{
var result = (TestResult) rawResult;
Console.WriteLine("{0}Full name: {1}", prefix, result.FullName);
Console.WriteLine("{0}Has results: {1}", prefix, result.HasResults);
Console.WriteLine("{0}Success? {1}", prefix, result.IsSuccess);
Console.WriteLine("{0}Message: {1}", prefix, result.Message);
Console.WriteLine("{0}Test: {1}", prefix, result.Test.TestName);
if (result.Results != null)
{
Console.WriteLine("{0}Results: {1}", prefix, result.Results.Count);
foreach (var v in result.Results)
{
DebugTestResult(v, level+1);
}
}
}
Console.WriteLine("{0}RESULT END", prefix);
}*/
public static Response Test(TestRequest request)
{
AppDomainSetup setup = new AppDomainSetup();
setup.ConfigurationFile = request.TestLibraryPath + ".config";
setup.ApplicationBase = Path.GetDirectoryName(request.TestLibraryPath);
AppDomain tester = AppDomain.CreateDomain("tester", AppDomain.CurrentDomain.Evidence, setup);
var worker = (ITestWorker) tester.CreateInstanceFromAndUnwrap(Assembly.GetExecutingAssembly().Location, typeof (TestWorker).FullName);
worker.DoTest(request.TestLibraryPath);
return (Response)(tester.GetData(DATA_TEST_RESULTS_KEY));
}
}
class NUnitTester
{
private const string DATA_TEST_RESULTS_KEY = "TestResults";
private class Listener : EventListener
{
public readonly Messages Messages = new Messages();
private bool runFail;
private bool suiteFail;
private static bool IsSuccess(TestResult result)
{
return result.IsSuccess || result.ResultState == ResultState.Ignored;
}
private static string FormatResult(TestResult result)
{
var additional = new List<string>();
if (result.IsSuccess)
{
additional.Add("success");
}
else if (result.IsError)
{
additional.Add("error");
}
else if (result.IsFailure)
{
additional.Add("fail");
}
else if (result.ResultState == ResultState.Ignored)
{
additional.Add("ignored");
}
else
{
additional.Add("status unknown");
}
if (!string.IsNullOrEmpty(result.Message))
{
additional.Add("message = " + result.Message);
}
return additional.Any() ? result.Name + "; " + string.Join(", ", additional) : result.Name;
}
public void RunFinished(Exception exception)
{
Messages.Add(Message.CreateError("Run finished: " + exception));
runFail = true;
}
public void RunFinished(TestResult result)
{
var message = string.Format("Run finished: {0}", FormatResult(result));
if (!IsSuccess(result) && !runFail)
{
Messages.Add(Message.CreateError(message));
}
else
{
Messages.Add(Message.CreateInfo(message));
}
}
public void RunStarted(string name, int testCount)
{
Messages.Add(Message.CreateInfo("Run started: " + name));
runFail = false;
}
public void SuiteFinished(TestResult result)
{
var message = string.Format("Suite finished: {0}", FormatResult(result));
if (!IsSuccess(result) && !suiteFail)
{
Messages.Add(Message.CreateError(message));
}
else
{
Messages.Add(Message.CreateInfo(message));
}
if (!result.IsSuccess)
{
runFail = true;
}
}
public void SuiteStarted(TestName testName)
{
Messages.Add(Message.CreateInfo("Suite started: " + testName.Name));
suiteFail = false;
}
public void TestFinished(TestResult result)
{
var message = string.Format("Test finished: {0}", FormatResult(result));
if (!IsSuccess(result))
{
Messages.Add(Message.CreateError(message));
}
else
{
Messages.Add(Message.CreateInfo(message));
}
suiteFail = true;
}
public void TestOutput(TestOutput testOutput)
{
Messages.Add(Message.CreateInfo("Test output: " + testOutput.Text));
}
public void TestStarted(TestName testName)
{
Messages.Add(Message.CreateInfo("Test started: " + testName.Name));
}
public void UnhandledException(Exception exception)
{
Messages.Add(Message.CreateError("Unhandled exception: " + exception));
suiteFail = true;
runFail = true;
}
}
public interface ITestWorker
{
void DoTest(string testLibraryPath);
}
[Serializable]
public class TestWorker : MarshalByRefObject, ITestWorker
{
public void DoTest(string testLibraryPath)
{
Console.SetOut(new StubWriter());
var listener = new Listener();
CoreExtensions.Host.InitializeService();
var package = new TestPackage(testLibraryPath);
//package.AutoBinPath = true;
//package.BasePath = Path.GetDirectoryName(TestLibraryPath);
//package.ConfigurationFile = TestLibraryPath + ".config";
TestRunner runner = new SimpleTestRunner();
if (runner.Load(package))
{
runner.Run(listener, TestFilter.Empty, true, LoggingThreshold.All);
}
//DebugTestResult(Console.Out, result);
if (!listener.Messages.Any())
{
listener.Messages.Add(Message.CreateError("No messages from listener"));
}
AppDomain.CurrentDomain.SetData(DATA_TEST_RESULTS_KEY, new Response(listener.Messages));
}
}
/*private static void DebugTestResult(object rawResult, int level = 0)
{
if (rawResult == null)
{
Console.WriteLine("Result is null");
return;
}
var prefix = new string('\t', level);
Console.WriteLine("{0}RESULT START", prefix);
Console.WriteLine("{0}Type: {1}", prefix, rawResult);
if (rawResult is TestResult)
{
var result = (TestResult) rawResult;
Console.WriteLine("{0}Full name: {1}", prefix, result.FullName);
Console.WriteLine("{0}Has results: {1}", prefix, result.HasResults);
Console.WriteLine("{0}Success? {1}", prefix, result.IsSuccess);
Console.WriteLine("{0}Message: {1}", prefix, result.Message);
Console.WriteLine("{0}Test: {1}", prefix, result.Test.TestName);
if (result.Results != null)
{
Console.WriteLine("{0}Results: {1}", prefix, result.Results.Count);
foreach (var v in result.Results)
{
DebugTestResult(v, level+1);
}
}
}
Console.WriteLine("{0}RESULT END", prefix);
}*/
public static Response Test(TestRequest request)
{
AppDomainSetup setup = new AppDomainSetup();
setup.ConfigurationFile = request.TestLibraryPath + ".config";
setup.ApplicationBase = Path.GetDirectoryName(request.TestLibraryPath);
AppDomain tester = AppDomain.CreateDomain("tester", AppDomain.CurrentDomain.Evidence, setup);
var worker = (ITestWorker) tester.CreateInstanceFromAndUnwrap(Assembly.GetExecutingAssembly().Location, typeof (TestWorker).FullName);
worker.DoTest(request.TestLibraryPath);
return (Response)(tester.GetData(DATA_TEST_RESULTS_KEY));
}
}
}

@ -5,14 +5,14 @@ using System.Text;
namespace MicroBuildServer.DotNetBuilder
{
class NuGetPackRequest
{
public string BaseDirectory { get; set; }
class NuGetPackRequest
{
public string BaseDirectory { get; set; }
public string SpecPath { get; set; }
public string SpecPath { get; set; }
public string OutputDirectory { get; set; }
public string OutputDirectory { get; set; }
public string Version { get; set; }
}
public string Version { get; set; }
}
}

@ -1,11 +1,11 @@
namespace MicroBuildServer.DotNetBuilder
{
class NuGetPushRequest
{
public string Package { get; set; }
class NuGetPushRequest
{
public string Package { get; set; }
public string NugetHost { get; set; }
public string NugetHost { get; set; }
public string ApiKey { get; set; }
}
public string ApiKey { get; set; }
}
}

@ -1,9 +1,9 @@
namespace MicroBuildServer.DotNetBuilder
{
class NuGetRestoreRequest
{
public string BaseDirectory { get; set; }
class NuGetRestoreRequest
{
public string BaseDirectory { get; set; }
public string SolutionPath { get; set; }
}
public string SolutionPath { get; set; }
}
}

@ -7,235 +7,235 @@ using NuGet.Common;
namespace MicroBuildServer.DotNetBuilder
{
static class NuGetter
{
private class Console : IConsole
{
public readonly Messages Messages = new Messages();
public bool Confirm(string description)
{
throw new NotImplementedException();
}
public int CursorLeft
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
public bool IsNonInteractive
{
get { return true; }
set { throw new NotImplementedException(); }
}
public void PrintJustified(int startIndex, string text, int maxWidth)
{
throw new NotImplementedException();
}
public void PrintJustified(int startIndex, string text)
{
throw new NotImplementedException();
}
public ConsoleKeyInfo ReadKey()
{
throw new NotImplementedException();
}
public string ReadLine()
{
throw new NotImplementedException();
}
public void ReadSecureString(System.Security.SecureString secureString)
{
throw new NotImplementedException();
}
public Verbosity Verbosity
{
get { return Verbosity.Detailed; }
set { throw new NotImplementedException(); }
}
public int WindowWidth
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
public void Write(string format, params object[] args)
{
Write(string.Format(format, args));
}
public void Write(string value)
{
Messages.Add(Message.CreateInfo(value));
}
public void Write(object value)
{
Write(value.ToString());
}
public void WriteError(string format, params object[] args)
{
WriteError(string.Format(format, args));
}
public void WriteError(string value)
{
Messages.Add(Message.CreateError(value));
}
public void WriteError(object value)
{
WriteError(value.ToString());
}
public void WriteLine(ConsoleColor color, string value, params object[] args)
{
WriteLine(value, args);
}
public void WriteLine(string format, params object[] args)
{
Write(format, args);
}
public void WriteLine(string value)
{
Write(value);
}
public void WriteLine(object value)
{
Write(value);
}
public void WriteLine()
{
}
public void WriteWarning(bool prependWarningText, string value, params object[] args)
{
static class NuGetter
{
private class Console : IConsole
{
public readonly Messages Messages = new Messages();
public bool Confirm(string description)
{
throw new NotImplementedException();
}
public int CursorLeft
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
public bool IsNonInteractive
{
get { return true; }
set { throw new NotImplementedException(); }
}
public void PrintJustified(int startIndex, string text, int maxWidth)
{
throw new NotImplementedException();
}
public void PrintJustified(int startIndex, string text)
{
throw new NotImplementedException();
}
public ConsoleKeyInfo ReadKey()
{
throw new NotImplementedException();
}
public string ReadLine()
{
throw new NotImplementedException();
}
public void ReadSecureString(System.Security.SecureString secureString)
{
throw new NotImplementedException();
}
public Verbosity Verbosity
{
get { return Verbosity.Detailed; }
set { throw new NotImplementedException(); }
}
public int WindowWidth
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
public void Write(string format, params object[] args)
{
Write(string.Format(format, args));
}
public void Write(string value)
{
Messages.Add(Message.CreateInfo(value));
}
public void Write(object value)
{
Write(value.ToString());
}
public void WriteError(string format, params object[] args)
{
WriteError(string.Format(format, args));
}
public void WriteError(string value)
{
Messages.Add(Message.CreateError(value));
}
public void WriteError(object value)
{
WriteError(value.ToString());
}
public void WriteLine(ConsoleColor color, string value, params object[] args)
{
WriteLine(value, args);
}
public void WriteLine(string format, params object[] args)
{
Write(format, args);
}
public void WriteLine(string value)
{
Write(value);
}
public void WriteLine(object value)
{
Write(value);
}
public void WriteLine()
{
}
public void WriteWarning(bool prependWarningText, string value, params object[] args)
{
WriteWarning(value, args);
}
}
public void WriteWarning(string value, params object[] args)
{
WriteWarning(string.Format(value, args));
}
public void WriteWarning(string value, params object[] args)
{
WriteWarning(string.Format(value, args));
}
public void WriteWarning(bool prependWarningText, string value)
{
public void WriteWarning(bool prependWarningText, string value)
{
WriteWarning(value);
}
public void WriteWarning(string value)
{
Messages.Add(Message.CreateWarn(value));
}
public void Log(MessageLevel level, string message, params object[] args)
{
switch (level)
{
case MessageLevel.Error:
WriteError(message, args);
return;
case MessageLevel.Warning:
WriteWarning(message, args);
return;
case MessageLevel.Info:
Write(message, args);
return;
}
}
public FileConflictResolution ResolveFileConflict(string message)
{
throw new NotImplementedException();
}
}
public static Response Pack(NuGetPackRequest request)
{
var console = new Console();
PackageBuilder builder = new PackageBuilder();
var command = new PackCommand
{
BasePath = PathTools.OptimizePath(request.BaseDirectory),
OutputDirectory = PathTools.OptimizePath(request.OutputDirectory),
Version = request.Version,
Console = console,
Verbosity = Verbosity.Detailed,
Rules = new IPackageRule[0],
};
command.Arguments.Add(request.SpecPath);
try
{
command.Execute();
}
catch (Exception e)
{
console.WriteError(e);
}
return new Response(console.Messages);
}
public static Response Push(NuGetPushRequest request)
{
var console = new Console();
var command = new PushCommand
{
Source = request.NugetHost,
ApiKey = request.ApiKey,
Console = console,
Verbosity = Verbosity.Detailed,
};
command.Arguments.Add(request.Package);
try
{
command.Execute();
}
catch (Exception e)
{
console.WriteError(e);
}
return new Response(console.Messages);
}
public static Response Restore(NuGetRestoreRequest request)
{
var console = new Console();
PackageBuilder builder = new PackageBuilder();
var command = new RestoreCommand
{
FileSystem = new PhysicalFileSystem(PathTools.OptimizePath(request.BaseDirectory)),
Console = console,
Verbosity = Verbosity.Detailed,
};
command.Arguments.Add(request.SolutionPath);
try
{
command.Execute();
}
catch (Exception e)
{
console.WriteError(e);
}
return new Response(console.Messages);
}
}
}
public void WriteWarning(string value)
{
Messages.Add(Message.CreateWarn(value));
}
public void Log(MessageLevel level, string message, params object[] args)
{
switch (level)
{
case MessageLevel.Error:
WriteError(message, args);
return;
case MessageLevel.Warning:
WriteWarning(message, args);
return;
case MessageLevel.Info:
Write(message, args);
return;
}
}
public FileConflictResolution ResolveFileConflict(string message)
{
throw new NotImplementedException();
}
}
public static Response Pack(NuGetPackRequest request)
{
var console = new Console();
PackageBuilder builder = new PackageBuilder();
var command = new PackCommand
{
BasePath = PathTools.OptimizePath(request.BaseDirectory),
OutputDirectory = PathTools.OptimizePath(request.OutputDirectory),
Version = request.Version,
Console = console,
Verbosity = Verbosity.Detailed,
Rules = new IPackageRule[0],
};
command.Arguments.Add(request.SpecPath);
try
{
command.Execute();
}
catch (Exception e)
{
console.WriteError(e);
}
return new Response(console.Messages);
}
public static Response Push(NuGetPushRequest request)
{
var console = new Console();
var command = new PushCommand
{
Source = request.NugetHost,
ApiKey = request.ApiKey,
Console = console,
Verbosity = Verbosity.Detailed,
};
command.Arguments.Add(request.Package);
try
{
command.Execute();
}
catch (Exception e)
{
console.WriteError(e);
}
return new Response(console.Messages);
}
public static Response Restore(NuGetRestoreRequest request)
{
var console = new Console();
PackageBuilder builder = new PackageBuilder();
var command = new RestoreCommand
{
FileSystem = new PhysicalFileSystem(PathTools.OptimizePath(request.BaseDirectory)),
Console = console,
Verbosity = Verbosity.Detailed,
};
command.Arguments.Add(request.SolutionPath);
try
{
command.Execute();
}
catch (Exception e)
{
console.WriteError(e);
}
return new Response(console.Messages);
}
}
}

@ -5,53 +5,53 @@ using System.Text;
namespace MicroBuildServer.DotNetBuilder
{
static class PathTools
{
private const string UNC_PREFIX = "\\\\?\\";
static class PathTools
{
private const string UNC_PREFIX = "\\\\?\\";
const int MAX_PATH = 255;
const int MAX_PATH = 255;
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName(
[MarshalAs(UnmanagedType.LPTStr)] string path,
[MarshalAs(UnmanagedType.LPTStr)] StringBuilder shortPath,
int shortPathLength);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName(
[MarshalAs(UnmanagedType.LPTStr)] string path,
[MarshalAs(UnmanagedType.LPTStr)] StringBuilder shortPath,
int shortPathLength);
private static string GetShortPath(string path)
{
var shortPath = new StringBuilder(MAX_PATH);
GetShortPathName(path, shortPath, MAX_PATH);
return shortPath.ToString();
}
private static string GetShortPath(string path)
{
var shortPath = new StringBuilder(MAX_PATH);
GetShortPathName(path, shortPath, MAX_PATH);
return shortPath.ToString();
}
private static string OptimizeDirectoryPath(string fullPath)
{
var uncPath = UNC_PREFIX + fullPath;
var shortPath = GetShortPath(uncPath);
if (shortPath.StartsWith(UNC_PREFIX))
{
shortPath = shortPath.Substring(UNC_PREFIX.Length);
}
return shortPath;
}
public static string OptimizePath(string rawPath)
{
//Console.WriteLine(rawPath);
var fullPath = Path.GetFullPath(new Uri(rawPath).LocalPath);
string result;
if (Directory.Exists(fullPath))
{
result = OptimizeDirectoryPath(fullPath);
}
else
{
var directoryPath = Path.GetDirectoryName(fullPath);
var optimizedDirectoryPath = OptimizeDirectoryPath(directoryPath);
result = Path.Combine(optimizedDirectoryPath, Path.GetFileName(fullPath));
}
//Console.WriteLine(result);
return result;
}
}
private static string OptimizeDirectoryPath(string fullPath)
{
var uncPath = UNC_PREFIX + fullPath;
var shortPath = GetShortPath(uncPath);
if (shortPath.StartsWith(UNC_PREFIX))
{
shortPath = shortPath.Substring(UNC_PREFIX.Length);
}
return shortPath;
}
public static string OptimizePath(string rawPath)
{
//Console.WriteLine(rawPath);
var fullPath = Path.GetFullPath(new Uri(rawPath).LocalPath);
string result;
if (Directory.Exists(fullPath))
{
result = OptimizeDirectoryPath(fullPath);
}
else
{
var directoryPath = Path.GetDirectoryName(fullPath);
var optimizedDirectoryPath = OptimizeDirectoryPath(directoryPath);
result = Path.Combine(optimizedDirectoryPath, Path.GetFileName(fullPath));
}
//Console.WriteLine(result);
return result;
}
}
}

@ -6,45 +6,45 @@ using Newtonsoft.Json;
namespace MicroBuildServer.DotNetBuilder
{
class Program
{
private static Response Process(string input, string[] args)
{
try
{
switch (args[0])
{
case "compile":
return Compiler.Compile(JsonConvert.DeserializeObject<CompileRequest>(input));
case "nunit":
return NUnitTester.Test(JsonConvert.DeserializeObject<TestRequest>(input));
case "nugetpack":
return NuGetter.Pack(JsonConvert.DeserializeObject<NuGetPackRequest>(input));
case "nugetpush":
return NuGetter.Push(JsonConvert.DeserializeObject<NuGetPushRequest>(input));
case "nugetrestore":
return NuGetter.Restore(JsonConvert.DeserializeObject<NuGetRestoreRequest>(input));
default:
throw new ApplicationException("Unsupported type '" + args[0] + "'");
}
}
catch (Exception e)
{
var messages = new Messages();
messages.Add(Message.CreateError(e.ToString()));
return new Response(messages);
}
}
class Program
{
private static Response Process(string input, string[] args)
{
try
{
switch (args[0])
{
case "compile":
return Compiler.Compile(JsonConvert.DeserializeObject<CompileRequest>(input));
case "nunit":
return NUnitTester.Test(JsonConvert.DeserializeObject<TestRequest>(input));
case "nugetpack":
return NuGetter.Pack(JsonConvert.DeserializeObject<NuGetPackRequest>(input));
case "nugetpush":
return NuGetter.Push(JsonConvert.DeserializeObject<NuGetPushRequest>(input));
case "nugetrestore":
return NuGetter.Restore(JsonConvert.DeserializeObject<NuGetRestoreRequest>(input));
default:
throw new ApplicationException("Unsupported type '" + args[0] + "'");
}
}
catch (Exception e)
{
var messages = new Messages();
messages.Add(Message.CreateError(e.ToString()));
return new Response(messages);
}
}
static void Main(string[] args)
{
Console.InputEncoding = Encoding.UTF8;
Console.OutputEncoding = Encoding.UTF8;
var input = Console.In.ReadToEnd();
var outWriter = Console.Out;
Console.SetOut(new StubWriter());
var result = Process(input, args);
outWriter.Write(JsonConvert.SerializeObject(result, Formatting.Indented));
}
}
static void Main(string[] args)
{
Console.InputEncoding = Encoding.UTF8;
Console.OutputEncoding = Encoding.UTF8;
var input = Console.In.ReadToEnd();
var outWriter = Console.Out;
Console.SetOut(new StubWriter());
var result = Process(input, args);
outWriter.Write(JsonConvert.SerializeObject(result, Formatting.Indented));
}
}
}

@ -3,31 +3,31 @@ using System;
namespace MicroBuildServer.DotNetBuilder
{
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
[Serializable]
class Response
{
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
[Serializable]
private class ResponseMessage
{
[JsonProperty(Required = Required.Always)]
public string Type { get; set; }
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
[Serializable]
class Response
{
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
[Serializable]
private class ResponseMessage
{
[JsonProperty(Required = Required.Always)]
public string Type { get; set; }
[JsonProperty(Required = Required.Always)]
public string Body { get; set; }
}
[JsonProperty(Required = Required.Always)]
public string Body { get; set; }
}
[JsonProperty(Required = Required.Always, PropertyName = "Messages")]
private ResponseMessage[] Messages { get; set; }
[JsonProperty(Required = Required.Always, PropertyName = "Messages")]
private ResponseMessage[] Messages { get; set; }
public Response(Messages messages)
{
Messages = messages.ToArray(message => new ResponseMessage
{
Type = message.Type,
Body = message.Body,
});
}
}
public Response(Messages messages)
{
Messages = messages.ToArray(message => new ResponseMessage
{
Type = message.Type,
Body = message.Body,
});
}
}
}

@ -3,11 +3,11 @@ using System.Text;
namespace MicroBuildServer.DotNetBuilder
{
class StubWriter : TextWriter
{
public override Encoding Encoding
{
get { return Encoding.Default; }
}
}
class StubWriter : TextWriter
{
public override Encoding Encoding
{
get { return Encoding.Default; }
}
}
}

@ -5,8 +5,8 @@ using System.Text;
namespace MicroBuildServer.DotNetBuilder
{
class TestRequest
{
public string TestLibraryPath { get; set; }
}
class TestRequest
{
public string TestLibraryPath { get; set; }
}
}

Loading…
Cancel
Save