diff --git a/DotNetBuilder/CompileRequest.cs b/DotNetBuilder/CompileRequest.cs index 600382c..5661093 100644 --- a/DotNetBuilder/CompileRequest.cs +++ b/DotNetBuilder/CompileRequest.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; } + } } diff --git a/DotNetBuilder/Compiler.cs b/DotNetBuilder/Compiler.cs index d5e5b46..9f00368 100644 --- a/DotNetBuilder/Compiler.cs +++ b/DotNetBuilder/Compiler.cs @@ -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(); - 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(); + 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); + } + } } diff --git a/DotNetBuilder/Message.cs b/DotNetBuilder/Message.cs index 9b65e83..08bb70c 100644 --- a/DotNetBuilder/Message.cs +++ b/DotNetBuilder/Message.cs @@ -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); + } + } } diff --git a/DotNetBuilder/Messages.cs b/DotNetBuilder/Messages.cs index 3c6653e..0039244 100644 --- a/DotNetBuilder/Messages.cs +++ b/DotNetBuilder/Messages.cs @@ -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 storage = new List(); + private readonly List storage = new List(); - 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(Func selector) - { - lock(syncRoot) - { - return storage.Select(selector).ToArray(); - } - } + public TResult[] ToArray(Func selector) + { + lock(syncRoot) + { + return storage.Select(selector).ToArray(); + } + } - public bool Any() - { - lock(syncRoot) - { - return storage.Any(); - } - } - } + public bool Any() + { + lock(syncRoot) + { + return storage.Any(); + } + } + } } diff --git a/DotNetBuilder/NUnitTester.cs b/DotNetBuilder/NUnitTester.cs index 7a46866..dd5a0a8 100644 --- a/DotNetBuilder/NUnitTester.cs +++ b/DotNetBuilder/NUnitTester.cs @@ -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(); - 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(); + 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)); + } + } } diff --git a/DotNetBuilder/NuGetPackRequest.cs b/DotNetBuilder/NuGetPackRequest.cs index e60aea1..b853803 100644 --- a/DotNetBuilder/NuGetPackRequest.cs +++ b/DotNetBuilder/NuGetPackRequest.cs @@ -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; } + } } diff --git a/DotNetBuilder/NuGetPushRequest.cs b/DotNetBuilder/NuGetPushRequest.cs index 3db7868..904f3e5 100644 --- a/DotNetBuilder/NuGetPushRequest.cs +++ b/DotNetBuilder/NuGetPushRequest.cs @@ -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; } + } } diff --git a/DotNetBuilder/NuGetRestoreRequest.cs b/DotNetBuilder/NuGetRestoreRequest.cs index 15f3ef3..36f24b1 100644 --- a/DotNetBuilder/NuGetRestoreRequest.cs +++ b/DotNetBuilder/NuGetRestoreRequest.cs @@ -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; } + } } diff --git a/DotNetBuilder/NuGetter.cs b/DotNetBuilder/NuGetter.cs index 2bbf7f5..7045c01 100644 --- a/DotNetBuilder/NuGetter.cs +++ b/DotNetBuilder/NuGetter.cs @@ -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); + } + } } diff --git a/DotNetBuilder/PathTools.cs b/DotNetBuilder/PathTools.cs index 4ad967b..c2df52f 100644 --- a/DotNetBuilder/PathTools.cs +++ b/DotNetBuilder/PathTools.cs @@ -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; + } + } } diff --git a/DotNetBuilder/Program.cs b/DotNetBuilder/Program.cs index 68559e7..61c7eb7 100644 --- a/DotNetBuilder/Program.cs +++ b/DotNetBuilder/Program.cs @@ -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(input)); - case "nunit": - return NUnitTester.Test(JsonConvert.DeserializeObject(input)); - case "nugetpack": - return NuGetter.Pack(JsonConvert.DeserializeObject(input)); - case "nugetpush": - return NuGetter.Push(JsonConvert.DeserializeObject(input)); - case "nugetrestore": - return NuGetter.Restore(JsonConvert.DeserializeObject(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(input)); + case "nunit": + return NUnitTester.Test(JsonConvert.DeserializeObject(input)); + case "nugetpack": + return NuGetter.Pack(JsonConvert.DeserializeObject(input)); + case "nugetpush": + return NuGetter.Push(JsonConvert.DeserializeObject(input)); + case "nugetrestore": + return NuGetter.Restore(JsonConvert.DeserializeObject(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)); + } + } } diff --git a/DotNetBuilder/Response.cs b/DotNetBuilder/Response.cs index b8477c2..058f91c 100644 --- a/DotNetBuilder/Response.cs +++ b/DotNetBuilder/Response.cs @@ -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, + }); + } + } } diff --git a/DotNetBuilder/StubWriter.cs b/DotNetBuilder/StubWriter.cs index 3744e8b..b28599f 100644 --- a/DotNetBuilder/StubWriter.cs +++ b/DotNetBuilder/StubWriter.cs @@ -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; } + } + } } diff --git a/DotNetBuilder/TestRequest.cs b/DotNetBuilder/TestRequest.cs index f67df60..62b2f9d 100644 --- a/DotNetBuilder/TestRequest.cs +++ b/DotNetBuilder/TestRequest.cs @@ -5,8 +5,8 @@ using System.Text; namespace MicroBuildServer.DotNetBuilder { - class TestRequest - { - public string TestLibraryPath { get; set; } - } + class TestRequest + { + public string TestLibraryPath { get; set; } + } }