示例#1
0
        public static SourcePuller GetSourcePuller(string type)
        {
            SourcePuller sp = pullers.FirstOrDefault(p => p.Type == type);

            if (sp == null)
            {
                throw new InvalidOperationException("VCS type not supported: " + type);
            }
            return(sp);
        }
示例#2
0
        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/>");
            }
        }
示例#3
0
        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);
            }
        }
示例#4
0
        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));
        }
示例#5
0
        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());
        }