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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save