Beispiel #1
0
 public static ResolvedTokens ResolveTokens(Config cfg)
 {
     var tokens = new ResolvedTokens(cfg);
     tokens.Codebase = cfg.ProjectDir;
     tokens.Revision = "N/A";
     return tokens;
 }
Beispiel #2
0
        public static ResolvedTokens ResolveTokens(Config cfg)
        {
            var subwcrev = AutodetectPathToSubWCRev(cfg);
            if (subwcrev == null) return null;

            var subwcrevTokens = new Dictionary<String, String>();
            var probeIn = @".\probe.in";
            var probeOut = @".\probe.out";
            try
            {
                var tokenNames = new List<String>();
                tokenNames.Add("$WCREV$");
                tokenNames.Add("$WCURL$");
                File.WriteAllText(probeIn, String.Join(Environment.NewLine, tokenNames.ToArray()));

                if (cfg.IsVerbose) Console.WriteLine("Launching SubWCRev.exe for a synthetic file that contains the following text:");
                if (cfg.IsVerbose) Console.WriteLine(File.ReadAllText(probeIn.ToTrace()));
                var psi = new ProcessStartInfo(subwcrev);
                psi.Arguments = String.Format("\"{0}\" \"{1}\" \"{2}\"",
                    cfg.ProjectDir, probeIn, probeOut);
                psi.UseShellExecute = false;
                psi.CreateNoWindow = true;

                Process.Start(psi).WaitForExit();
                if (!File.Exists(probeOut))
                {
                    Console.WriteLine("SubWCRev has failed due to an unknown reason.");
                    return null;
                }
                else
                {
                    if (cfg.IsVerbose) Console.WriteLine("SubWCRev.exe has completed and produced the following output:");
                    if (cfg.IsVerbose) Console.WriteLine(File.ReadAllText(probeOut.ToTrace()));

                    var tokenValues = File.ReadAllLines(probeOut);
                    for (var i = 0; i < tokenNames.Count(); ++i)
                    {
                        subwcrevTokens.Add(tokenNames[i], tokenValues[i]);
                    }
                }
            }
            finally
            {
                File.Delete(probeIn);
                File.Delete(probeOut);
            }

            var codebase = subwcrevTokens["$WCURL$"].Replace(@"\", "/");
            var revision = subwcrevTokens["$WCREV$"];
            if (cfg.IsVerbose) Console.WriteLine("Codebase is successfully detected as: {0}", codebase.ToTrace());
            if (cfg.IsVerbose) Console.WriteLine("Revision is successfully detected as: {0}", revision.ToTrace());

            var tokens = new ResolvedTokens(cfg);
            tokens.Codebase = codebase;
            tokens.Revision = revision;
            return tokens;
        }
Beispiel #3
0
        public static ResolvedTokens ResolveTokens(Config cfg)
        {
            var hgexe = AutodetectPathToHgExe(cfg);
            if (hgexe == null) return null;

            var psi = new ProcessStartInfo(hgexe);
            psi.Arguments = String.Format("log");
            psi.WorkingDirectory = cfg.ProjectDir;
            psi.UseShellExecute = false;
            psi.RedirectStandardOutput = true;
            psi.CreateNoWindow = true;

            if (cfg.IsVerbose) Console.WriteLine("Launching \"hg.exe log\"...");
            var p = Process.Start(psi);
            var stdout = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            if (cfg.IsVerbose) Console.WriteLine("\"hg.exe log\" has completed and produced the following output:");
            if (cfg.IsVerbose) Console.WriteLine(stdout.ToTrace());

            if (cfg.IsVerbose) Console.WriteLine("Detecting the changeset in the output of hg.exe...");
            var lines = stdout.Split('\n').Select(ln => ln.Trim()).ToArray();
            var first = lines.FirstOrDefault();

            String changeset;
            if (String.IsNullOrEmpty(first))
            {
                if (cfg.IsVerbose) Console.WriteLine("[Warning] Output of \"hg.exe log\" is empty.");
                changeset = "N/A";
                if (cfg.IsVerbose) Console.WriteLine("Changeset is successfully detected as: {0}", changeset.ToTrace());
            }
            else
            {
                var match = Regex.Match(first, @"^changeset:.*:(?<changeset>.*)$");
                if (!match.Success)
                {
                    if (cfg.IsVerbose) Console.WriteLine("Detection failed: first line of the output didn't match the \"^changeset:.*:(?<changeset>.*)$\" regex.");
                    return null;
                }

                changeset = match.Result("${changeset}");
                if (cfg.IsVerbose) Console.WriteLine("Changeset is successfully detected as: {0}", changeset.ToTrace());
            }

            var tokens = new ResolvedTokens(cfg);
            tokens.Codebase = cfg.ProjectDir;
            tokens.Revision = changeset;
            return tokens;
        }