void PushFiles(BuildContext ctx, SourceInfo source, SourceTagInfo stag, bool safe) { try { ctx.Status = "Uploading files for project " + source.ProjectName; foreach (string file in Directory.GetFiles(stag.GetPackagePath(ctx))) { ctx.Log(LogSeverity.Info, "Uploading [" + source.ProjectName + "] " + Path.GetFileName(file)); WebRequest req = HttpWebRequest.Create(ctx.ServerUrl + "/package/upload"); req.Headers ["applicationId"] = ctx.AppId.ToString(); req.Headers ["sourceTagId"] = stag.Id.ToString(); req.Headers ["fileName"] = Path.GetFileName(file); req.Method = "POST"; req.GetRequestStream().WriteFile(file); using (StreamReader s = new StreamReader(req.GetResponse().GetResponseStream())) { if (s.ReadToEnd() != "OK") { throw new Exception("File upload failed"); } } } } catch { if (!safe) { throw; } } finally { ctx.Status = "Files uploaded"; } }
public static void CleanSources(this SourceInfo source, BuildContext ctx, SourceTagInfo sourceTag) { if (Directory.Exists(sourceTag.GetPackagePath(ctx))) { Directory.Delete(sourceTag.GetPackagePath(ctx), true); } }
public override void Fetch(BuildContext ctx, int sourceId, SourceTagInfo stag, StringBuilder output, StringBuilder error) { int i = stag.Url.IndexOf('|'); string bname = stag.Url.Substring(i + 2); string url = stag.Url.Substring(0, i); UpdateRepo(ctx, sourceId, url, output); }
public override void PrepareForBuild(BuildContext ctx, int sourceId, SourceTagInfo stag) { int i = stag.Url.IndexOf('|'); string bname = stag.Url.Substring(i + 2); string gitDir = GetGitPath(ctx, sourceId); RunCommand(gitDir, "reset --hard", null); RunCommand(gitDir, "checkout " + bname, null); RunCommand(gitDir, "submodule update --init --recursive", null); }
void FetchSource(BuildContext ctx, SourceInfo vcs, SourceTagInfo stag, string logFile) { StringBuilder sb = new StringBuilder(); try { SourcePuller sp = VersionControl.GetSourcePuller(vcs.Type); sp.Fetch(ctx, vcs.Id, stag, sb, sb); } finally { File.AppendAllText(logFile, "<pre>" + HttpUtility.HtmlEncode(sb.ToString()) + "</pre><br/><br/>"); } }
public override void Fetch(BuildContext ctx, int sourceId, SourceTagInfo stag, StringBuilder output, StringBuilder error) { string command; string args; string targetPath = GetSourceTagPath(ctx, sourceId, stag.Id); Util.ResetFolder(targetPath); command = SubversionCommand; args = "export --force " + stag.Url + " \"" + targetPath + "\""; output.AppendLine(command + " " + args); BuildService.RunCommand(false, command, args, output, error, Timeout); }
public void UpdateSourceTags(BuildContext ctx, SourceInfo source, bool force) { if (!force && (DateTime.Now - source.LastFetchTime).TotalMinutes < 5) { return; } ctx.Server.SetSourceStatus(ctx.AppId, source.Id, SourceTagStatus.Fetching, ""); try { List <SourceTagInfo> newTags = new List <SourceTagInfo> (source.SourceTags); HashSet <string> newUrls = new HashSet <string> (); SourcePuller sp = VersionControl.GetSourcePuller(source.Type); foreach (SourceTagInfo st in sp.GetChildUrls(ctx, source)) { newUrls.Add(st.Url); SourceTagInfo currentTag = source.GetSourceTag(st.Url); if (currentTag == null) { st.Status = SourceTagStatus.Waiting; newTags.Add(st); } else { if (currentTag.LastRevision != st.LastRevision) { source.CleanSources(ctx, currentTag); currentTag.LastRevision = st.LastRevision; currentTag.Status = SourceTagStatus.Waiting; } } } foreach (SourceTagInfo st in source.SourceTags) { if (!newUrls.Contains(st.Url)) { newTags.Remove(st); } } source.LastFetchTime = DateTime.Now; ctx.Server.UpdateSourceTags(ctx.AppId, source.Id, DateTime.Now, newTags.ToArray()); ctx.Server.SetSourceStatus(ctx.AppId, source.Id, SourceTagStatus.Ready, ""); } catch (Exception ex) { ctx.Server.SetSourceStatus(ctx.AppId, source.Id, SourceTagStatus.FetchError, ex.Message); ctx.Log(ex); } }
public override void Fetch(BuildContext ctx, int sourceId, SourceTagInfo stag, StringBuilder output, StringBuilder error) { string bzrDir = GetBzrPath(ctx, sourceId); string url = stag.Url; int i = stag.Url.IndexOf('|'); if (i != -1) { url = url.Substring(0, i); UpdateRepo(ctx, sourceId, url, output); string bname = stag.Url.Substring(i + 2); RunCommand(bzrDir, "export -r tag:" + bname + " " + base.GetSourceTagPath(ctx, sourceId, stag.Id), output); } else { UpdateRepo(ctx, sourceId, url, output); } }
bool BuildSource(BuildContext ctx, SourceInfo vcs, SourceTagInfo stag) { // Fetch the source ctx.Status = "Fetching project " + vcs.ProjectName + " (" + stag.Name + ")"; Util.ResetFolder(stag.GetPackagePath(ctx)); string logFile = stag.GetLogFile(ctx); File.AppendAllText(logFile, "<p><b>Fetching Source</b></p>"); ctx.Server.SetSourceTagStatus(ctx.AppId, stag.Id, SourceTagStatus.Fetching); try { FetchSource(ctx, vcs, stag, logFile); } catch (Exception ex) { File.AppendAllText(logFile, HttpUtility.HtmlEncode(ex.Message) + "<br/><br/>"); PushFiles(ctx, vcs, stag, true); ctx.Server.SetSourceTagStatus(ctx.AppId, stag.Id, SourceTagStatus.FetchError); ctx.Log(ex); return(false); } // Build the add-in ctx.Status = "Building project " + vcs.ProjectName; File.AppendAllText(logFile, "<p><b>Building Solution</b></p>"); ctx.Server.SetSourceTagStatus(ctx.AppId, stag.Id, SourceTagStatus.Building); try { BuildSource(ctx, vcs, stag, logFile); } catch (Exception ex) { File.AppendAllText(logFile, "<p>" + HttpUtility.HtmlEncode(ex.Message) + "</p>"); PushFiles(ctx, vcs, stag, true); ctx.Server.SetSourceTagStatus(ctx.AppId, stag.Id, SourceTagStatus.BuildError); ctx.Log(ex); return(false); } PushFiles(ctx, vcs, stag, false); ctx.Server.SetSourceTagBuiltAsync(ctx.AppId, stag.Id); return(true); }
public static string GetLogFile(this SourceTagInfo stag, BuildContext ctx) { return(Path.Combine(stag.GetPackagePath(ctx), "log.html")); }
public virtual void PrepareForBuild(BuildContext ctx, int sourceId, SourceTagInfo stag) { }
public void UpdateSourceTagsAsync(int appId, int sourceId, System.DateTime fetchTime, SourceTagInfo[] sourceTags) { this.UpdateSourceTagsAsync(appId, sourceId, fetchTime, sourceTags, null); }
AddinData BuildProjectAddin(BuildContext ctx, SourceTagInfo stag, string logFile, string sourcePath, AppReleaseInfo rel, AddinProjectAddin addin) { SetupService ss = new SetupService(); bool generatedXplatPackage = false; HashSet <string> foundPlatforms = new HashSet <string> (); AddinData ainfo = new AddinData(); foreach (AddinProjectSource psource in addin.Sources) { if (string.IsNullOrEmpty(psource.AddinFile)) { throw new Exception("AddinFile element not found in addin-project.xml"); } string platforms = psource.Platforms; if (string.IsNullOrEmpty(platforms)) { platforms = ctx.Application.Platforms; } string[] platformList = platforms.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); foreach (string plat in platformList) { if (!foundPlatforms.Add(plat)) { throw new Exception("Platform " + plat + " specificed in more than open Project element"); } } string outFile = NormalizePath(psource.AddinFile); if (!string.IsNullOrEmpty(psource.BuildFile)) { // Build the project // Move the sources to the work area (which is sandboxed) if (!Directory.Exists(ctx.LocalSettings.WorkAreaPath)) { Directory.CreateDirectory(ctx.LocalSettings.WorkAreaPath); } string workArea = Path.Combine(ctx.LocalSettings.WorkAreaPath, "builder"); if (Directory.Exists(workArea)) { Directory.Delete(workArea, true); } Directory.Move(sourcePath, workArea); StringBuilder output = new StringBuilder(); try { string solFile = Path.Combine(workArea, NormalizePath(psource.BuildFile)); // Restore packages RunCommand(true, "nuget", "restore \"" + solFile + "\"", output, output, Timeout.Infinite); string refPath = rel.GetAssembliesPath(ctx); if (ContaintsMdTargetsFile(workArea) && !string.IsNullOrEmpty(ctx.LocalSettings.LocalAppInstallPath)) { foreach (var p in ctx.LocalSettings.LocalAppInstallPath.Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { var ip = Path.Combine(refPath, "__install", p); if (Directory.Exists(ip)) { refPath = ip; break; } } } string ops = " \"/p:ReferencePath=" + refPath + "\""; if (!string.IsNullOrEmpty(psource.BuildConfiguration)) { ops += " \"/property:Configuration=" + psource.BuildConfiguration + "\""; } ops = ops + " \"" + solFile + "\""; // Clean the project RunCommand(true, ctx.LocalSettings.MSBuildCommand, "/t:Clean " + ops, output, output, Timeout.Infinite); // Build RunCommand(true, ctx.LocalSettings.MSBuildCommand, ops, output, output, Timeout.Infinite); } finally { output = output.Replace(workArea, "/build"); File.AppendAllText(logFile, "<pre>" + HttpUtility.HtmlEncode(output.ToString()) + "</pre>"); Directory.Move(workArea, sourcePath); } } // Generate the package string tmpPath = Path.Combine(sourcePath, "tmp"); File.AppendAllText(logFile, "<p><b>Building Package</b></p>"); LocalStatusMonitor monitor = new LocalStatusMonitor(); try { if (Directory.Exists(tmpPath)) { Directory.Delete(tmpPath, true); } Directory.CreateDirectory(tmpPath); ss.BuildPackage(monitor, tmpPath, Path.Combine(sourcePath, outFile)); string file = Directory.GetFiles(tmpPath, "*.mpack").FirstOrDefault(); if (file == null) { throw new Exception("Add-in generation failed"); } AddinInfo ai = ReadAddinInfo(file); ainfo.AddinVersion = ai.Version; ainfo.AddinId = Mono.Addins.Addin.GetIdName(ai.Id); if (!generatedXplatPackage && platformList.Length > 0) { File.Copy(file, Path.Combine(stag.GetPackagePath(ctx), "All.mpack"), true); generatedXplatPackage = true; } else { foreach (string plat in platformList) { File.Copy(file, Path.Combine(stag.GetPackagePath(ctx), plat + ".mpack"), true); } } } finally { try { Directory.Delete(tmpPath, true); } catch { } File.AppendAllText(logFile, "<pre>" + HttpUtility.HtmlEncode(monitor.ToString()) + "</pre>"); } } ainfo.Platforms = string.Join(" ", foundPlatforms.ToArray()); ainfo.AppVersion = rel.AppVersion; return(ainfo); }
void BuildSource(BuildContext ctx, SourceInfo source, SourceTagInfo stag, string logFile) { SourcePuller sp = VersionControl.GetSourcePuller(source.Type); sp.PrepareForBuild(ctx, source.Id, stag); string destPath = Path.GetFullPath(source.GetAddinSourcePath(ctx, stag)); string sourcePath = destPath; if (!string.IsNullOrEmpty(source.Directory)) { sourcePath = Path.Combine(sourcePath, NormalizePath(source.Directory)); } sourcePath = Path.GetFullPath(sourcePath); if (sourcePath != destPath && !sourcePath.StartsWith(destPath)) { throw new Exception("Invalid source directory: " + source.Directory); } string projectFile = sourcePath; if (!File.Exists(projectFile) && !projectFile.EndsWith(".xml")) { projectFile = Path.Combine(sourcePath, "addin-project.xml"); } else { sourcePath = Path.GetDirectoryName(projectFile); } if (!File.Exists(projectFile)) { string msg = "addin-project.xml file not found"; if (!string.IsNullOrEmpty(source.Directory)) { msg += " (looked in '" + source.Directory + "')"; } throw new Exception(msg); } AddinProject addinProject; StreamReader sr = new StreamReader(projectFile); using (sr) { XmlSerializer ser = new XmlSerializer(typeof(AddinProject)); addinProject = (AddinProject)ser.Deserialize(sr); } if (string.IsNullOrEmpty(addinProject.AppVersion)) { throw new Exception("Target application version not specified in addin-project.xml"); } AppReleaseInfo rel = ctx.Server.GetAppReleases(ctx.AppId).Where(r => r.AppVersion == addinProject.AppVersion).FirstOrDefault(); if (rel == null) { throw new Exception("Application release " + addinProject.AppVersion + " not found."); } RefreshAppRelease(ctx, rel); // Delete old packages foreach (string f in Directory.GetFiles(sourcePath, "*.mpack")) { File.Delete(f); } List <AddinData> addins = new List <AddinData> (); foreach (AddinProjectAddin addin in addinProject.Addins) { addins.Add(BuildProjectAddin(ctx, stag, logFile, sourcePath, rel, addin)); } ctx.Server.SetSourceTagBuildData(ctx.AppId, stag.Id, addins.ToArray()); }
public System.IAsyncResult BeginUpdateSourceTags(int appId, int sourceId, System.DateTime fetchTime, SourceTagInfo[] sourceTags, System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("UpdateSourceTags", new object[] { appId, sourceId, fetchTime, sourceTags}, callback, asyncState); }
public static string GetPackagePath(this SourceTagInfo stag, BuildContext ctx) { string path = ctx.LocalSettings.PackagesPath; return(Path.GetFullPath(Path.Combine(path, stag.Id.ToString()))); }
public void UpdateSourceTags(int appId, int sourceId, System.DateTime fetchTime, SourceTagInfo[] sourceTags) { this.Invoke("UpdateSourceTags", new object[] { appId, sourceId, fetchTime, sourceTags}); }
public static string GetAddinSourcePath(this SourceInfo source, BuildContext ctx, SourceTagInfo stag) { SourcePuller sp = VersionControl.GetSourcePuller(source.Type); return(sp.GetSourceTagPath(ctx, source.Id, stag.Id)); }
public void UpdateSourceTagsAsync(int appId, int sourceId, System.DateTime fetchTime, SourceTagInfo[] sourceTags, object userState) { if ((this.UpdateSourceTagsOperationCompleted == null)) { this.UpdateSourceTagsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnUpdateSourceTagsCompleted); } this.InvokeAsync("UpdateSourceTags", new object[] { appId, sourceId, fetchTime, sourceTags}, this.UpdateSourceTagsOperationCompleted, userState); }
public abstract void Fetch(BuildContext ctx, int sourceId, SourceTagInfo stag, StringBuilder output, StringBuilder error);