Esempio n. 1
0
        public void RefreshAppRelease(BuildContext ctx, AppReleaseInfo release)
        {
            string filePath = release.GetAssembliesPath (ctx);
            string file = Path.Combine (filePath, "__release.zip");

            string timestamp = release.LastUpdateTime.ToString ();
            string timestampFile = Path.Combine (filePath, "__timestamp");
            try {
                if (File.Exists (timestampFile)) {
                    string date = File.ReadAllText (timestampFile);
                    if (date == timestamp)
                        return;
                }
            } catch (Exception ex) {
                ctx.Log (ex);
            }

            Util.ResetFolder (filePath);

            ctx.Status = "Downloading assembly package for release " + release.AppVersion;

            WebRequest req = HttpWebRequest.Create (ctx.ServerUrl + release.ZipUrl);
            WebResponse res = req.GetResponse ();
            res.GetResponseStream ().SaveToFile (file);

            ctx.Status = "Extracting assemblies for release " + release.AppVersion;

            using (Stream fs = File.OpenRead (file)) {
                ZipFile zfile = new ZipFile (fs);
                foreach (ZipEntry ze in zfile) {
                    string fname = ze.Name.ToLower ();
                    if (fname.EndsWith (".dll") || fname.EndsWith (".exe")) {
                        using (Stream s = zfile.GetInputStream (ze)) {
                            s.SaveToFile (Path.Combine (filePath, Path.GetFileName (ze.Name)));
                        }
                    }
                }
            }
            File.Delete (file);
            File.WriteAllText (timestampFile, timestamp);
            ctx.Status = "Assembly package for release " + release.AppVersion + " isntalled";
        }
Esempio n. 2
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;
        }
Esempio n. 3
0
        public void RefreshAppRelease(BuildContext ctx, AppReleaseInfo release)
        {
            string filePath = release.GetAssembliesPath (ctx);

            string installPath = Path.Combine (filePath, "__install");
            string timestamp = release.LastUpdateTime.ToString ();
            string timestampFile = Path.Combine (filePath, "__timestamp");
            try {
                if (File.Exists (timestampFile) && Directory.Exists (installPath)) {
                    string date = File.ReadAllText (timestampFile);
                    if (date == timestamp)
                        return;
                }
            } catch (Exception ex) {
                ctx.Log (ex);
            }

            Util.ResetFolder (filePath);

            ctx.Status = "Downloading assembly package for release " + release.AppVersion;

            WebRequest req = HttpWebRequest.Create (ctx.ServerUrl + release.ZipUrl);
            WebResponse res = req.GetResponse ();
            string wfname = res.Headers["Content-Disposition"];
            string ext;
            if (string.IsNullOrEmpty (wfname))
                ext = ".zip";
            else
                ext = Path.GetExtension (wfname);

            string file = Path.Combine (filePath, "__release" + ext);
            res.GetResponseStream ().SaveToFile (file);

            ctx.Status = "Extracting assemblies for release " + release.AppVersion;

            if (ext == ".dmg") {
                ExtractDmg (ctx, filePath, file);
            }
            else {
                try {
                    using (Stream fs = File.OpenRead (file)) {
                        ZipFile zfile = new ZipFile (fs);
                        foreach (ZipEntry ze in zfile) {
                            string fname = ze.Name.ToLower ();
                            if (fname.EndsWith (".dll") || fname.EndsWith (".exe")) {
                                using (Stream s = zfile.GetInputStream (ze)) {
                                    s.SaveToFile (Path.Combine (filePath, Path.GetFileName (ze.Name)));
                                }
                            }
                        }
                    }
                } catch (ZipException) {
                    // Maybe it is a dmg after all
                    ExtractDmg (ctx, filePath, file);
                }
            }

            // Extract the whole app, keeping the directory structure

            Run7z (file, installPath);

            File.Delete (file);
            File.WriteAllText (timestampFile, timestamp);
            ctx.Status = "Assembly package for release " + release.AppVersion + " isntalled";
        }