Example #1
0
 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);
 }
Example #2
0
        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);

            string gitDir = GetGitPath (ctx, sourceId);

            RunCommand (gitDir, "checkout " + bname, output);
        }
Example #3
0
        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 (command, args, output, error, Timeout);
        }
Example #4
0
 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);
 }
Example #5
0
 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);
 }
Example #6
0
 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, "checkout " + bname, null);
 }
Example #7
0
 public virtual void PrepareForBuild(BuildContext ctx, int sourceId, SourceTagInfo stag)
 {
 }
Example #8
0
 public abstract void Fetch(BuildContext ctx, int sourceId, SourceTagInfo stag, StringBuilder output, StringBuilder error);
Example #9
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);
 }
Example #10
0
 public static void CleanSources(this SourceInfo source, BuildContext ctx, SourceTagInfo sourceTag)
 {
     if (Directory.Exists (sourceTag.GetPackagePath (ctx)))
         Directory.Delete (sourceTag.GetPackagePath (ctx), true);
 }
Example #11
0
 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";
     }
 }
Example #12
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/>");
     }
 }
Example #13
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 = Path.Combine (sourcePath, "addin-project.xml");
            if (!File.Exists (projectFile)) {
                string msg = "addin-project.xml file not found";
                if (!string.IsNullOrEmpty (source.Directory))
                    msg += " (looked in '" + source.Directory + "' 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 ());
        }
Example #14
0
        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;
        }
Example #15
0
        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

                    string solFile = Path.Combine (sourcePath, NormalizePath (psource.BuildFile));

                    string ops = " \"/p:ReferencePath=" + rel.GetAssembliesPath (ctx) + "\"";

                    if (!string.IsNullOrEmpty (psource.BuildConfiguration))
                        ops += " \"/property:Configuration=" + psource.BuildConfiguration + "\"";

                    ops = ops + " \"" + solFile + "\"";

                    StringBuilder output = new StringBuilder ();
                    try {
                        // Clean the project
                        RunCommand (ctx.LocalSettings.MSBuildCommand, "/t:Clean " + ops, output, output, Timeout.Infinite);

                        // Build
                        RunCommand (ctx.LocalSettings.MSBuildCommand, ops, output, output, Timeout.Infinite);
                    }
                    finally {
                        File.AppendAllText (logFile, "<pre>" + HttpUtility.HtmlEncode (output.ToString ()) + "</pre>");
                    }
                }

                // 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;
        }