Пример #1
0
 public static void CleanSources(this SourceInfo source, BuildContext ctx, SourceTagInfo sourceTag)
 {
     if (Directory.Exists (sourceTag.GetPackagePath (ctx)))
         Directory.Delete (sourceTag.GetPackagePath (ctx), true);
 }
Пример #2
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;
        }
Пример #3
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";
     }
 }
Пример #4
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;
        }