static void YearFromSubversion(string fileName, ref int minYearFrom)
 {
     try
     {
         ProcessStartInfo psi = new ProcessStartInfo(_subversion);
         psi.Arguments              = String.Format("log --xml --non-interactive \"{0}\"", fileName);
         psi.CreateNoWindow         = true;
         psi.UseShellExecute        = false;
         psi.RedirectStandardOutput = true;
         psi.RedirectStandardInput  = true;
         Trace.WriteLine(_subversion + " " + psi.Arguments);
         Process p = Process.Start(psi);
         p.StandardInput.Close();
         OutputCapture capture = new OutputCapture(p);
         p.WaitForExit(60000);
         if (p.ExitCode == 0)
         {
             XmlDocument doc = new XmlDocument();
             doc.LoadXml(capture.Output);
             foreach (XmlElement e in doc.SelectNodes("/log/logentry/date"))
             {
                 int tmp;
                 if (int.TryParse(e.InnerText.Substring(0, 4), out tmp) && tmp > 1900 && tmp <= DateTime.Now.Year)
                 {
                     minYearFrom = Math.Min(minYearFrom, tmp);
                 }
             }
         }
         else
         {
             Trace.WriteLine(_subversion + " failed: " + p.ExitCode);
         }
     }
     catch { return; }
 }
Exemple #2
0
        private static OutputCapture RunProcessAndCapture(ITestOutputHelper testOutputHelper, string cwd, string tool, string arguments, string writeBatchFile = null)
        {
            ProcessStartInfo i = new ProcessStartInfo(tool, arguments);

            testOutputHelper.WriteLine("Running '{0}'", i.FileName);
            testOutputHelper.WriteLine("         {0}", i.Arguments);
            i.RedirectStandardOutput = true;
            i.RedirectStandardError  = true;
            i.UseShellExecute        = false;
            i.CreateNoWindow         = true;
            i.WorkingDirectory       = cwd;
            i.ErrorDialog            = false;

            if (writeBatchFile != null)
            {
                var file = new StreamWriter(Path.Combine(cwd, writeBatchFile + ".bat"));
                file.WriteLine("\"{0}\" {1} %1 %2 %3 %4 %5", i.FileName, i.Arguments);
                file.Close();
            }

            var capture = new OutputCapture(testOutputHelper);

            using (Process p = Process.Start(i))
            {
                p.OutputDataReceived += capture.OutputDataReceived;
                p.ErrorDataReceived  += capture.ErrorDataReceived;
                p.BeginOutputReadLine();
                p.BeginErrorReadLine();

                Assert.True(p.WaitForExit(200000), String.Format("{0} timed out", i.FileName));
                capture.ExitCode = p.ExitCode;
                return(capture);
            }
        }
Exemple #3
0
        public static async Task <Project> FromFileAsync(string file, string framework = null, string configuration = null, string runtime = null, CancellationToken cancellationToken = default)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            var args = new List <string>
            {
                "msbuild",
                file,
                "/nologo",
                "/v:n",
                "/t:" + GetMetadataTargetName,
            };

            if (framework != null)
            {
                args.Add("/p:TargetFramework=" + framework);
            }

            if (configuration != null)
            {
                args.Add("/p:Configuration=" + configuration);
            }

            if (runtime != null)
            {
                args.Add("/p:RuntimeIdentifier=" + runtime);
            }

            var capture = new OutputCapture();

            var processSpec = new ProcessSpec
            {
                Executable    = "dotnet",
                Arguments     = args,
                OutputCapture = capture
            };

            Reporter.WriteVerbose($"Running MSBuild target '{GetMetadataTargetName}' on '{file}'");

            var exitCode = await ProcessRunner.Default.RunAsync(processSpec, cancellationToken);

            if (exitCode != 0)
            {
                DumpMSBuildOutput(capture);
                throw new CommandException("Unable to retrieve project metadata. Please ensure it's an MSBuild-based .NET Core project which references " + BundleBuilderProxy.BundlingAssemblyName + " 3.0.0 or newer explicitly. " +
                                           "If it's a multi-targeted project, you need to select one of the target frameworks by the '--framework' option.");
            }

            var metadata = capture.Lines
                           .Select(line => Regex.Match(line, @"^\s*Bundling\.(\w+)=(.*)$"))
                           .Where(match => match.Success)
                           .ToDictionary(match => match.Groups[1].Value, match => match.Groups[2].Value);

            return(FromMetadata(metadata, file, framework, configuration, runtime));
        }
Exemple #4
0
        public async Task BuildAsync(CancellationToken cancellationToken)
        {
            var args = new List <string> {
                "build"
            };

            if (_file != null)
            {
                args.Add(_file);
            }

            // TODO: Only build for the first framework when unspecified
            if (_framework != null)
            {
                args.Add("--framework");
                args.Add(_framework);
            }

            if (_configuration != null)
            {
                args.Add("--configuration");
                args.Add(_configuration);
            }

            if (_runtime != null)
            {
                args.Add("--runtime");
                args.Add(_runtime);
            }

            args.Add("/v:q");
            args.Add("/nologo");

            var capture = new OutputCapture();

            var processSpec = new ProcessSpec
            {
                Executable    = "dotnet",
                Arguments     = args,
                OutputCapture = capture
            };

            Reporter.WriteInformation("Build started...");

            var exitCode = await ProcessRunner.Default.RunAsync(processSpec, cancellationToken);

            if (exitCode != 0)
            {
                DumpMSBuildOutput(capture);
                throw new CommandException("Build failed.");
            }

            Reporter.WriteInformation("Build succeeded.");
            Reporter.WriteInformation(string.Empty);
        }
Exemple #5
0
        private static void DumpMSBuildOutput(OutputCapture capture)
        {
            Reporter.WriteInformation($"MSBuild output:");
            Reporter.WriteInformation(string.Empty);

            foreach (var line in capture.Lines)
            {
                Reporter.WriteInformation($"  {line}");
            }

            Reporter.WriteInformation(string.Empty);
        }
Exemple #6
0
        private static void CompareExpectedOutput(Options options, OutputCapture capture)
        {
            var expected      = File.ReadAllLines(options.MakeAbsolute(@"Foxtrot\Tests\CheckerTests\" + Path.GetFileNameWithoutExtension(options.SourceFile) + ".Expected"));
            var expectedIndex = 0;
            var absoluteFile  = options.MakeAbsolute(options.SourceFile);

            for (int i = 0; i < capture.stdOut.Count; i++)
            {
                var actual = capture.stdOut[i];

                if (actual.StartsWith("Trace:"))
                {
                    continue;
                }
                if (actual.StartsWith("elapsed time:"))
                {
                    continue;
                }
                if (expectedIndex >= expected.Length)
                {
                    Assert.Null(actual);
                }
                var expectedLine = expected[expectedIndex++];

                if (actual.StartsWith(absoluteFile, StringComparison.InvariantCultureIgnoreCase))
                {
                    actual       = TrimFilePath(actual, options.SourceFile);
                    expectedLine = TrimFilePath(expectedLine, options.SourceFile);
                }
                Assert.Equal(expectedLine, actual);
            }
            if (expectedIndex < expected.Length)
            {
                Assert.Equal(expected[expectedIndex], null);
            }
        }
Exemple #7
0
 public OutputCapture StartCapture()
 {
     return(Current = new OutputCapture());
 }
        static void YearFromSubversion(string fileName, ref int minYearFrom)
	    {
            try
            {
                ProcessStartInfo psi = new ProcessStartInfo(_subversion);
                psi.Arguments = String.Format("log --xml --non-interactive \"{0}\"", fileName);
                psi.CreateNoWindow = true;
                psi.UseShellExecute = false;
                psi.RedirectStandardOutput = true;
                psi.RedirectStandardInput = true;
                Trace.WriteLine(_subversion + " " + psi.Arguments);
                Process p = Process.Start(psi);
                p.StandardInput.Close();
                OutputCapture capture = new OutputCapture(p);
                p.WaitForExit(60000);
                if (p.ExitCode == 0)
                {
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(capture.Output);
                    foreach (XmlElement e in doc.SelectNodes("/log/logentry/date"))
                    {
                        int tmp;
                        if (int.TryParse(e.InnerText.Substring(0, 4), out tmp) && tmp > 1900 && tmp <= DateTime.Now.Year)
                            minYearFrom = Math.Min(minYearFrom, tmp);
                    }
                }
                else
                    Trace.WriteLine(_subversion + " failed: " + p.ExitCode);
            }
            catch { return; }
	    }
Exemple #9
0
        private static void CompareExpectedOutput(Options options, OutputCapture capture)
        {
            var expected = File.ReadAllLines(options.MakeAbsolute(@"Foxtrot\Tests\CheckerTests\" + Path.GetFileNameWithoutExtension(options.SourceFile) + ".Expected"));
            var expectedIndex = 0;
            var absoluteFile = options.MakeAbsolute(options.SourceFile);
            for (int i = 0; i < capture.stdOut.Count; i++)
            {
                var actual = capture.stdOut[i];

                if (actual.StartsWith("Trace:")) continue;
                if (actual.StartsWith("elapsed time:")) continue;
                if (expectedIndex >= expected.Length)
                {
                    Assert.AreEqual(null, actual);
                }
                var expectedLine = expected[expectedIndex++];

                if (actual.StartsWith(absoluteFile, StringComparison.InvariantCultureIgnoreCase))
                {
                    actual = TrimFilePath(actual, options.SourceFile);
                    expectedLine = TrimFilePath(expectedLine, options.SourceFile);
                }
                Assert.AreEqual(expectedLine, actual);
            }
            if (expectedIndex < expected.Length)
            {
                Assert.AreEqual(expected[expectedIndex], null);
            }
        }
Exemple #10
0
        private static OutputCapture RunProcessAndCapture(string cwd, string tool, string arguments, string writeBatchFile = null)
        {
            ProcessStartInfo i = new ProcessStartInfo(tool, arguments);
            Console.WriteLine("Running '{0}'", i.FileName);
            Console.WriteLine("         {0}", i.Arguments);
            i.RedirectStandardOutput = true;
            i.RedirectStandardError = true;
            i.UseShellExecute = false;
            i.CreateNoWindow = true;
            i.WorkingDirectory = cwd;
            i.ErrorDialog = false;

            if (writeBatchFile != null)
            {
                var file = new StreamWriter(Path.Combine(cwd, writeBatchFile + ".bat"));
                file.WriteLine("\"{0}\" {1} %1 %2 %3 %4 %5", i.FileName, i.Arguments);
                file.Close();
            }

            var capture = new OutputCapture();

            using (Process p = Process.Start(i))
            {
                p.OutputDataReceived += capture.OutputDataReceived;
                p.ErrorDataReceived += capture.ErrorDataReceived;
                p.BeginOutputReadLine();
                p.BeginErrorReadLine();

                Assert.IsTrue(p.WaitForExit(200000), String.Format("{0} timed out", i.FileName));
                capture.ExitCode = p.ExitCode;
                return capture;
            }
        }