fix nuget runner crash if non-local nuget.exe was used
authorEugene Petrenko <eugene.petrenko@gmail.com>
Thu, 14 Jul 2011 14:08:15 +0000 (18:08 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Thu, 14 Jul 2011 14:08:15 +0000 (18:08 +0400)
nuget-extensions/nuget-runner/App.config [new file with mode: 0644]
nuget-extensions/nuget-runner/nuget-runner.csproj
nuget-extensions/nuget-runner/src/NuGetInstallExtensions.cs
nuget-extensions/nuget-runner/src/NuGetRunner.cs

diff --git a/nuget-extensions/nuget-runner/App.config b/nuget-extensions/nuget-runner/App.config
new file mode 100644 (file)
index 0000000..607f96c
--- /dev/null
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8" ?>\r
+<configuration>\r
+\r
+</configuration>
\ No newline at end of file
index 54d3922c985e1532ccafb6f031330c16a03004fe..2cd630b5dadcef97bca9b3a1f93e442346d4c82c 100644 (file)
@@ -51,6 +51,9 @@
     <Compile Include="src\Program.cs" />\r
     <Compile Include="Properties\AssemblyInfo.cs" />\r
   </ItemGroup>\r
+  <ItemGroup>\r
+    <None Include="App.config" />\r
+  </ItemGroup>\r
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />\r
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. \r
        Other similar extension points exist, see Microsoft.Common.targets.\r
index d0d53b9d47ff45db36c3cfaacbdce4b80b1cd47d..3cc11d9fd5d379835b8289d109eba47223bb4630 100644 (file)
@@ -17,7 +17,8 @@ namespace JetBrains.TeamCity.NuGetRunner
 \r
                                        foreach (var ext in extensions)\r
                                        {\r
-                                         File.Copy(ext, Path.Combine(home, Path.GetFileName(ext)));\r
+                                         var destFileName = Path.Combine(home, Path.GetFileName(ext));\r
+                                         File.Copy(ext, destFileName);\r
                                        }\r
                                      };\r
 \r
index e27d3003c3a33f3be96a348420b5b49e6773dfb7..728d8c4eca89e3490f7ed7aff6057715c66a372c 100644 (file)
@@ -1,8 +1,11 @@
 using System;\r
 using System.Collections.Generic;\r
+using System.Diagnostics;\r
 using System.IO;\r
 using System.Reflection;\r
 using System.Linq;\r
+using System.Text;\r
+using System.Threading;\r
 \r
 namespace JetBrains.TeamCity.NuGetRunner\r
 {\r
@@ -71,19 +74,49 @@ namespace JetBrains.TeamCity.NuGetRunner
       }\r
     }\r
 \r
-    public int Run(string[] argz)\r
+    public int Run(IEnumerable<string> argz)\r
     {\r
       CallEvents(myStartEvents);\r
 \r
       try\r
       {\r
-        var result = myNuGetAssembly.EntryPoint.Invoke(null, new[] {argz});\r
+        var process = Process.Start(new ProcessStartInfo\r
+                                      {\r
+                                        FileName = myNuGetExe,\r
+                                        //TODO use escapring safe escaping here.\r
+                                        Arguments = string.Join(" ", argz.Select(x=>x.IndexOfAny(" \t\n\r".ToCharArray()) >=0 ? "\"" + x + "\"" : x)),\r
+                                        UseShellExecute = false,\r
+                                        RedirectStandardInput = true, \r
+                                        RedirectStandardError = true, \r
+                                        RedirectStandardOutput = true\r
+                                      });\r
 \r
-        if (result is int)\r
-          return (int) result;\r
+        process.StandardInput.Close();\r
+        Func<StreamReader, TextWriter, Thread> readOutput = (si, so) =>\r
+        {\r
+          var th = new Thread(delegate()\r
+          {\r
+            int i;\r
+            while ((i = si.Read()) >= 0) so.Write((char)i);            \r
+          }) { Name = "Process output reader " + process.Id };\r
+          th.Start();\r
+          return th;\r
+        };\r
+\r
+        var t1 = readOutput(process.StandardOutput, Console.Out);\r
+        var t2 = readOutput(process.StandardError, Console.Error);\r
+        \r
+        process.WaitForExit();\r
 \r
-        return 0;\r
-      } finally\r
+        t1.Join(TimeSpan.FromMinutes(5));\r
+        t2.Join(TimeSpan.FromMinutes(5));\r
+\r
+        return process.ExitCode;\r
+        /*AppDomain dom = AppDomain.CreateDomain("NuGet Launcher Domain");\r
+        var result = dom.ExecuteAssembly(myNuGetExe, argz);\r
+        return result is int ? (int) result : 0;*/\r
+      }\r
+      finally\r
       {\r
         CallEvents(myFinishEvents);\r
       }\r