예제 #1
0
        public void BuildRepository()
        {
            InitRepository();
            setup.BuildRepository(monitor, repoDir);

            Assert.IsTrue(File.Exists(Path.Combine(repoDir, "main.mrep")));
            Assert.IsTrue(File.Exists(Path.Combine(repoDir, "root.mrep")));
            Assert.IsTrue(File.Exists(Path.Combine(repoExtrasDir, "main.mrep")));
        }
예제 #2
0
        static void UpdateRepos(int appId, bool updateAll)
        {
            using (UserModel m = UserModel.GetAdmin(appId)) {
                string basePath = AddinsPath;
                cachedCompatibleVersions = new Dictionary <string, string[]> ();

                SetupService       setupService = new SetupService();
                LocalStatusMonitor monitor      = new LocalStatusMonitor();

                HashSet <string> fileList = new HashSet <string> ();
                FindFiles(fileList, basePath);
                HashSet <string> reposToBuild = new HashSet <string> ();

                HashSet <Release> releases = new HashSet <Release> ();
                var allReleases            = m.GetReleases().ToList();

                List <AppRelease> allAppReleases = m.GetAppReleases().ToList();

                foreach (Release rel in allReleases)
                {
                    if (rel.Status == ReleaseStatus.Deleted)
                    {
                        continue;
                    }

                    // Register the add-in for each compatible repo
                    foreach (var appVersion in GetNewerCompatibleAppVersions(m, allAppReleases, rel.TargetAppVersion))
                    {
                        foreach (string plat in rel.PlatformsList)
                        {
                            if (!IsLatestRelease(m, allAppReleases, allReleases, rel, plat, appVersion))
                            {
                                continue;
                            }
                            string repoPath = Path.Combine(basePath, rel.DevStatus.ToString());
                            repoPath = Path.Combine(repoPath, plat);
                            repoPath = Path.Combine(repoPath, appVersion);
                            string path = Path.GetFullPath(Path.Combine(repoPath, rel.AddinId + "-" + rel.Version + ".mpack"));
                            fileList.Remove(path);
                            if (rel.Status == ReleaseStatus.PendingPublish || updateAll)
                            {
                                if (!Directory.Exists(repoPath))
                                {
                                    Directory.CreateDirectory(repoPath);
                                }
                                var relPath = rel.SourceTagId != null?rel.GetFilePath(plat) : rel.GetPublishedPath(plat);

                                if (!File.Exists(relPath))
                                {
                                    Log(LogSeverity.Error, "Could not publish release " + rel.Version + " of add-in " + rel.AddinId + ". File " + relPath + " not found");
                                    continue;
                                }
                                if (Path.GetFullPath(relPath) != path)
                                {
                                    File.Copy(relPath, path, true);
                                }
                                GenerateInstallerFile(m, path, rel, plat);
                                reposToBuild.Add(repoPath);
                                if (!releases.Contains(rel) && rel.Status == ReleaseStatus.PendingPublish)
                                {
                                    releases.Add(rel);
                                }
                            }
                        }
                    }
                }
                foreach (AppRelease arel in allAppReleases)
                {
                    foreach (object status in Enum.GetValues(typeof(DevStatus)))
                    {
                        foreach (string plat in m.CurrentApplication.PlatformsList)
                        {
                            string repoPath = Path.Combine(basePath, status.ToString());
                            repoPath = Path.Combine(repoPath, plat);
                            repoPath = Path.Combine(repoPath, arel.AppVersion);
                            if (!Directory.Exists(repoPath))
                            {
                                Directory.CreateDirectory(repoPath);
                                reposToBuild.Add(repoPath);
                            }
                            else if (!File.Exists(Path.Combine(repoPath, "main.mrep")) || updateAll)
                            {
                                reposToBuild.Add(repoPath);
                            }
                        }
                    }
                }

                // Remove old add-ins

                foreach (string f in fileList)
                {
                    try {
                        reposToBuild.Add(Path.GetFullPath(Path.GetDirectoryName(f)));
                        File.Delete(f);
                        string f2 = Path.ChangeExtension(f, m.CurrentApplication.AddinPackageExtension);
                        if (File.Exists(f2))
                        {
                            File.Delete(f2);
                        }
                    }
                    catch (Exception ex) {
                        Log(ex);
                    }
                }

                // Update the repos

                var sortedRepos = reposToBuild.ToList();
                sortedRepos.Sort((p1, p2) => Mono.Addins.Addin.CompareVersions(Path.GetFileName(Path.GetDirectoryName(p2)), Path.GetFileName(Path.GetDirectoryName(p1))));

                foreach (string r in sortedRepos)
                {
                    string mainFile = Path.Combine(r, "main.mrep");
                    if (File.Exists(mainFile))
                    {
                        File.Delete(mainFile);
                    }
                    setupService.BuildRepository(monitor, r);
                    string ds = r.Substring(basePath.Length + 1);
                    int    i  = ds.IndexOf(Path.DirectorySeparatorChar);
                    ds = ds.Substring(0, i);
                    string title = m.CurrentApplication.Name + " Add-in Repository";
                    if (ds != DevStatus.Stable.ToString())
                    {
                        title += " (" + ds + " channel)";
                    }
                    AppendName(mainFile, title);
                    AppendName(Path.Combine(r, "root.mrep"), title);
                }

                foreach (Release rel in releases)
                {
                    m.SetPublished(rel);
                }
            }
        }