public int Run(ProcessUtility exe, string path, string project, XDictionary<string, string> macros) { // Reset my working directory. Environment.CurrentDirectory = path; string tmpFile = Path.GetTempFileName(); File.Move(tmpFile, tmpFile+".bat"); tmpFile += ".bat"; FileStream file = new FileStream(tmpFile,FileMode.Open); StreamWriter FS = new StreamWriter(file); macros.Default = null; foreach (string command in Commands) { FS.WriteLine(command.FormatWithMacros((input) => { string Default = null; if (input.Contains("??")) { var parts = input.Split(new[] { '?' }, StringSplitOptions.RemoveEmptyEntries); Default = parts.Length > 1 ? parts[1].Trim() : string.Empty; input = parts[0]; } return (macros[input.ToLower()] ?? Default) ?? input; } )); } FS.Close(); return exe.Exec(@"/c """ + tmpFile + @""""); }
public int Run(string path, string project, XDictionary<string, string> macros) { ProcessUtility _cmdexe = new ProcessUtility("cmd.exe"); return Run(_cmdexe, path, project, macros); }
private static int doActions(string projectName, IEnumerable <string> commands, BuildStatus status = null, XDictionary <string, string> Macros = null) { if (projectName == null) { throw new ArgumentException("ProjectName cannot be null."); } if (!Projects.ContainsKey(projectName)) { throw new ArgumentException("Project not found: " + projectName); } Macros = Macros ?? new XDictionary <string, string>(); status = status ?? new BuildStatus(); string ArchiveLoc = Path.Combine(MasterConfig.ProjectRoot, projectName, "Archive", status.TimeStamp.ToString(DateTimeDirFormat)); if (!Directory.Exists(ArchiveLoc)) { Directory.CreateDirectory(ArchiveLoc); } ProjectData proj = Projects[projectName]; ProcessUtility _cmdexe = new ProcessUtility("cmd.exe"); // Redirect stdout and stderr to the same output Func <string> getToolSwitches = () => { string ret = String.Empty; foreach ( string s in MasterConfig.VersionControlList[proj.VersionControl].Tool. Switches) { if (s.Contains(" ")) { ret += " \"" + s + "\""; } else { ret += " " + s; } } return(ret); }; Macros["project"] = projectName; Macros["vcstool"] = MasterConfig.VersionControlList[proj.VersionControl].Tool.Path; Macros["vcsswitches"] = getToolSwitches(); Macros["keepclean"] = proj.KeepCleanRepo.ToString(); string rootPath = MasterConfig.ProjectRoot + @"\" + projectName; Macros["projectroot"] = rootPath; Macros["repo_url"] = proj.RepoURL; Macros["build_datetime"] = status.TimeStamp.ToString(DateTimeDirFormat); Macros["archive"] = ArchiveLoc; Macros["output_store"] = MasterConfig.OutputStore; foreach (string command in commands) { StringBuilder std = new StringBuilder(); _cmdexe.ResetStdOut(std); _cmdexe.ResetStdErr(std); status.Append("AutoBuild - Begin command: " + command); Macros["currentcommand"] = command; CommandScript tmp; if (proj.Commands.ContainsKey(command)) { tmp = proj.Commands[command]; } else if (MasterConfig.Commands.ContainsKey(command)) { tmp = MasterConfig.Commands[command]; } else { // Can't locate the specified command. Bail with error. status.Append("AutoBuild Error: Unable to locate command script: " + command); return((int)Errors.NoCommand); } int retVal = tmp.Run(_cmdexe, rootPath, projectName, new XDictionary <string, string>(Macros)); status.Append(_cmdexe.StandardOut); if (retVal != 0) { return(retVal); } } return(0); }
private static int doActions(string projectName, IEnumerable<string> commands, BuildStatus status = null, XDictionary<string, string> Macros = null) { if (projectName == null) throw new ArgumentException("ProjectName cannot be null."); if (!Projects.ContainsKey(projectName)) throw new ArgumentException("Project not found: " + projectName); Macros = Macros ?? new XDictionary<string, string>(); status = status ?? new BuildStatus(); string ArchiveLoc = Path.Combine(MasterConfig.ProjectRoot, projectName, "Archive", status.TimeStamp.ToString(DateTimeDirFormat)); if (!Directory.Exists(ArchiveLoc)) Directory.CreateDirectory(ArchiveLoc); ProjectData proj = Projects[projectName]; ProcessUtility _cmdexe = new ProcessUtility("cmd.exe"); // Redirect stdout and stderr to the same output Func<string> getToolSwitches = () => { string ret = String.Empty; foreach ( string s in MasterConfig.VersionControlList[proj.VersionControl].Tool. Switches) if (s.Contains(" ")) ret += " \"" + s + "\""; else ret += " " + s; return ret; }; Macros["project"] = projectName; Macros["vcstool"] = MasterConfig.VersionControlList[proj.VersionControl].Tool.Path; Macros["vcsswitches"] = getToolSwitches(); Macros["keepclean"] = proj.KeepCleanRepo.ToString(); string rootPath = MasterConfig.ProjectRoot + @"\" + projectName; Macros["projectroot"] = rootPath; Macros["repo_url"] = proj.RepoURL; Macros["build_datetime"] = status.TimeStamp.ToString(DateTimeDirFormat); Macros["archive"] = ArchiveLoc; Macros["output_store"] = MasterConfig.OutputStore; foreach (string command in commands) { StringBuilder std = new StringBuilder(); _cmdexe.ResetStdOut(std); _cmdexe.ResetStdErr(std); status.Append("AutoBuild - Begin command: " + command); Macros["currentcommand"] = command; CommandScript tmp; if (proj.Commands.ContainsKey(command)) { tmp = proj.Commands[command]; } else if (MasterConfig.Commands.ContainsKey(command)) { tmp = MasterConfig.Commands[command]; } else { // Can't locate the specified command. Bail with error. status.Append("AutoBuild Error: Unable to locate command script: " + command); return (int)Errors.NoCommand; } int retVal = tmp.Run(_cmdexe, rootPath, projectName, new XDictionary<string, string>(Macros)); status.Append(_cmdexe.StandardOut); if (retVal != 0) return retVal; } return 0; }
public int Run(string path, string project, XDictionary <string, string> macros) { ProcessUtility _cmdexe = new ProcessUtility("cmd.exe"); return(Run(_cmdexe, path, project, macros)); }