public void PackageListUniqueInstanceTest()
        {
            PackageList plA = PackageList.Instance();
            PackageList plB = PackageList.Instance();

            Assert.AreSame(plA, plB);
        }
Exemple #2
0
        public static void UpdatePackage()
        {
            string packageName = LastArgument();

            PackageRepo pr = PackageList.Instance().GetLatestPackage(packageName);

            UpliftManager.Instance().UpdatePackage(pr);
        }
Exemple #3
0
        private PackageRepo[] IdentifyInstallable(DependencyDefinition[] definitions)
        {
            PackageRepo[] result = new PackageRepo[definitions.Length];
            for (int i = 0; i < definitions.Length; i++)
            {
                result[i] = PackageList.Instance().FindPackageAndRepository(definitions[i]);
            }

            return(result);
        }
        private DependencyGraph GenerateGraph(DependencyDefinition[] dependencies)
        {
            DependencyGraph graph       = new DependencyGraph();
            PackageList     packageList = PackageList.Instance();

            foreach (DependencyDefinition dependency in dependencies)
            {
                DependencyNode current;
                graph.LoadDependencies(dependency, packageList, CheckConflict, out current);
            }

            return(graph);
        }
Exemple #5
0
        public void UpdatePackage(PackageRepo newer, bool updateDependencies = true, bool updateLockfile = true)
        {
            InstalledPackage installed = Upbring.Instance().InstalledPackage.First(ip => ip.Name == newer.Package.PackageName);

            // If latest version is greater than the one installed, update to it
            if (string.Equals(newer.Package.PackageVersion, installed.Version))
            {
                UnityEngine.Debug.Log(string.Format("Required version of {0} is already installed ({1})", installed.Name, installed.Version));
                return;
            }
            else
            {
                using (TemporaryDirectory td = newer.Repository.DownloadPackage(newer.Package))
                {
                    Debug.Log("Required version is not installed, updating package");
                    UpdatePackage(newer.Package, td, updateLockfile);
                }
            }

            if (updateDependencies)
            {
                Debug.Log("Update dependencies enabled, starting update :");
                DependencyDefinition[] packageDependencies = PackageList.Instance().ListDependenciesRecursively(
                    GetDependencySolver()
                    .SolveDependencies(upfile.Dependencies)
                    .First(dep => dep.Name == newer.Package.PackageName)
                    );
                foreach (DependencyDefinition def in packageDependencies)
                {
                    PackageRepo dependencyPR = PackageList.Instance().FindPackageAndRepository(def);
                    if (Upbring.Instance().InstalledPackage.Any(ip => ip.Name == def.Name))
                    {
                        UpdatePackage(dependencyPR,
                                      updateDependencies: false,
                                      updateLockfile: updateLockfile
                                      );
                    }
                    else
                    {
                        using (TemporaryDirectory td = dependencyPR.Repository.DownloadPackage(dependencyPR.Package))
                        {
                            InstallPackage(dependencyPR.Package,
                                           td,
                                           def,
                                           updateLockfile: updateLockfile
                                           );
                        }
                    }
                }
            }
        }
        private string RecursivelyListDependencies(DependencyDefinition def, string indent = "")
        {
            string      result = indent + def.Name + " " + def.Requirement + " " + def.Version + "\n";
            PackageRepo pr     = PackageList.Instance().FindPackageAndRepository(def);

            if (pr.Package != null && pr.Package.Dependencies != null)
            {
                foreach (DependencyDefinition packageDefinition in pr.Package.Dependencies)
                {
                    result += RecursivelyListDependencies(packageDefinition, indent + "   ");
                }
            }
            return(result);
        }
Exemple #7
0
        public void InstallDependencies(IDependencySolver dependencySolver)
        {
            //FIXME: We should check for all repositories, not the first one
            //FileRepository rt = (FileRepository) Upfile.Repositories[0];
            upfile = Upfile.Instance();

            PackageList pList = PackageList.Instance();

            DependencyDefinition[] dependencies = dependencySolver.SolveDependencies(upfile.Dependencies);
            foreach (DependencyDefinition packageDefinition in dependencies)
            {
                PackageRepo result = pList.FindPackageAndRepository(packageDefinition);
                if (result.Repository != null)
                {
                    using (TemporaryDirectory td = result.Repository.DownloadPackage(result.Package))
                    {
                        InstallPackage(result.Package, td, packageDefinition);
                    }
                }
            }
        }
Exemple #8
0
        private static void CheckDependencies()
        {
            Upbring     upbring     = Upbring.Instance();
            Upfile      upfile      = Upfile.Instance();
            PackageList packageList = PackageList.Instance();

            PackageRepo[] packageRepos = packageList.GetAllPackages();

            bool any_installed =
                upbring.InstalledPackage != null &&
                upbring.InstalledPackage.Length != 0;

            foreach (DependencyDefinition dependency in upfile.Dependencies)
            {
                string name      = dependency.Name;
                bool   installed =
                    any_installed &&
                    upbring.InstalledPackage.Any(ip => ip.Name == name);
                bool   installable   = packageRepos.Any(pr => pr.Package.PackageName == name);
                string latest        = installable ? packageList.GetLatestPackage(name).Package.PackageVersion : "";
                string string_latest = string.IsNullOrEmpty(latest) ? "No version available in any repository" : "Latest version is " + latest;
                if (installed)
                {
                    string installed_version = upbring.GetInstalledPackage(name).Version;
                    if (installed_version != latest)
                    {
                        Debug.Log(string.Format("Package {0} is outdated: installed version is {1}, latest is {2}", name, installed_version, string_latest));
                    }
                    else
                    {
                        Debug.Log(string.Format("Package {0} is up-to-date ({1})", name, installed_version));
                    }
                }
                else
                {
                    Debug.Log(string.Format("Package {0} is not installed ({1})", name, string_latest));
                }
            }
        }
Exemple #9
0
        private void AppendDependencyState(
            ref List <DependencyState> dependenciesState,
            DependencyDefinition definition,
            PackageRepo[] targets,
            bool anyInstalled,
            bool transitive = false
            )
        {
            Upbring upbring = Upbring.Instance();

            DependencyState state = new DependencyState
            {
                definition = definition,
                latest     = PackageList.Instance().GetLatestPackage(definition.Name)
            };

            state.bestMatch = targets.First(pr => pr.Package.PackageName == definition.Name);
            if (anyInstalled && upbring.InstalledPackage.Any(ip => ip.Name == definition.Name))
            {
                state.installed = upbring.InstalledPackage.First(ip => ip.Name == definition.Name);
            }
            state.transitive = transitive;

            dependenciesState.Add(state);
            if (state.bestMatch.Package.Dependencies != null)
            {
                foreach (DependencyDefinition dependency in state.bestMatch.Package.Dependencies)
                {
                    AppendDependencyState(
                        ref dependenciesState,
                        dependency,
                        targets,
                        anyInstalled,
                        true
                        );
                }
            }
        }
Exemple #10
0
        public void LoadPackageList()
        {
            PackageList pList = PackageList.Instance();

            pList.LoadPackages(Repositories, true);
        }
        protected void OnGUI()
        {
            titleContent.text = "Update Utility";

            UpliftManager manager     = UpliftManager.Instance();
            Upbring       upbring     = Upbring.Instance();
            Upfile        upfile      = Upfile.Instance();
            PackageList   packageList = PackageList.Instance();

            PackageRepo[] packageRepos = packageList.GetAllPackages();

            DependencyDefinition[] dependencies = upfile.Dependencies;
            bool any_installed =
                upbring.InstalledPackage != null &&
                upbring.InstalledPackage.Length != 0;

            if (dependencies.Length == 0)
            {
                EditorGUILayout.HelpBox("It seems that you didn't specify any dependency in the Upfile. Try refreshing it if you did.", MessageType.Warning);
            }
            else
            {
                foreach (DependencyDefinition dependency in dependencies)
                {
                    string name = dependency.Name;
                    EditorGUILayout.LabelField(name + ":", EditorStyles.boldLabel);
                    bool installable = packageRepos.Any(pr => pr.Package.PackageName == name);
                    bool installed   =
                        any_installed &&
                        upbring.InstalledPackage.Any(ip => ip.Name == name);
                    string installed_version = installed ? upbring.GetInstalledPackage(name).Version : "";

                    if (installed)
                    {
                        EditorGUILayout.LabelField("- Installed version is " + installed_version);
                    }
                    else
                    {
                        EditorGUILayout.LabelField("- Not yet installed");
                    }

                    if (!installable)
                    {
                        EditorGUILayout.HelpBox("No repository contains this package. Try specifying one whith this package in.", MessageType.Warning);
                    }
                    else
                    {
                        PackageRepo latestPackageRepo = packageList.GetLatestPackage(name);
                        string      latest_version    = latestPackageRepo.Package.PackageVersion;

                        EditorGUILayout.LabelField(string.Format("- Latest version is: {0} (from {1})", latest_version, latestPackageRepo.Repository.ToString()));

                        GUI.enabled = installed && installed_version != latest_version;
                        if (GUILayout.Button("Update to " + latest_version))
                        {
                            Debug.Log(string.Format("Updating package {0} (to {1})", name, latest_version));
                            manager.UpdatePackage(latestPackageRepo);

                            AssetDatabase.Refresh();

                            Repaint();
                        }
                        GUI.enabled = true;
                    }

                    EditorGUILayout.Space();
                }

                if (GUILayout.Button("Install all dependencies"))
                {
                    manager.InstallDependencies();

                    AssetDatabase.Refresh();

                    Repaint();
                }
                GUI.enabled = any_installed;
                if (GUILayout.Button("Update all installed packages"))
                {
                    foreach (InstalledPackage package in upbring.InstalledPackage)
                    {
                        PackageRepo latestPackageRepo = packageList.GetLatestPackage(package.Name);
                        if (package.Version != latestPackageRepo.Package.PackageVersion)
                        {
                            Debug.Log(string.Format("Updating package {0} (to {1})", package.Name, latestPackageRepo.Package.PackageVersion));
                            manager.UpdatePackage(latestPackageRepo);
                        }
                    }

                    AssetDatabase.Refresh();

                    Repaint();
                }
                GUI.enabled = true;
                if (GUILayout.Button("Refresh Upfile"))
                {
                    Upfile.Instance();

                    Repaint();
                }
            }
        }
Exemple #12
0
        private LockfileSnapshot LoadLockfile()
        {
            string           pattern = @"([\w\.\-]+)\s\(([\w\.\+!\*]+)\)";
            LockfileSnapshot result  = new LockfileSnapshot();

            using (StreamReader file = new StreamReader(lockfilePath))
            {
                string line = file.ReadLine();
                if (line == null || line != "# UPFILE DEPENDENCIES")
                {
                    throw new FileLoadException("Cannot load Upfile.lock, it is missing the \'UPFILE DEPENDENCIES\' header");
                }

                List <DependencyDefinition> upfileDependencyList = new List <DependencyDefinition>();

                Match match;
                while (!string.IsNullOrEmpty(line = file.ReadLine()))
                {
                    match = Regex.Match(line, pattern);
                    if (!match.Success || match.Groups.Count < 3)
                    {
                        throw new FileLoadException("Cannot load Upfile.lock, the line " + line + " does not match \'package_name (version_requirement)\'");
                    }

                    DependencyDefinition temp = new DependencyDefinition
                    {
                        Name    = match.Groups[1].Value,
                        Version = match.Groups[2].Value
                    };
                    upfileDependencyList.Add(temp);
                }
                result.upfileDependencies = upfileDependencyList.ToArray();

                if (line == null)
                {
                    throw new FileLoadException("Cannot load Upfile.lock, it is incomplete");
                }

                line = file.ReadLine();
                if (line == null || line != "# SOLVED DEPENDENCIES")
                {
                    throw new FileLoadException("Cannot load Upfile.lock, it is missing the \'SOLVED DEPENDENCIES\' header");
                }

                List <PackageRepo> installableList = new List <PackageRepo>();
                line = file.ReadLine();
                PackageList packageList = PackageList.Instance();
                while (!string.IsNullOrEmpty(line))
                {
                    match = Regex.Match(line, pattern);
                    if (!match.Success || match.Groups.Count < 3)
                    {
                        throw new FileLoadException("Cannot load Upfile.lock, the line " + line + " does not match \'package_name (installed_version)\'");
                    }

                    PackageRepo temp = packageList.FindPackageAndRepository(new DependencyDefinition
                    {
                        Name    = match.Groups[1].Value,
                        Version = match.Groups[2].Value + "!" // Check for exact version
                    });

                    if (temp.Package != null && temp.Repository != null)
                    {
                        installableList.Add(temp);
                    }
                    else
                    {
                        installableList.Add(new PackageRepo
                        {
                            Package = new Upset
                            {
                                PackageName    = match.Groups[1].Value,
                                PackageVersion = match.Groups[2].Value
                            }
                        });
                    }
                    // Read the dependencies
                    while ((line = file.ReadLine()) != null && line.StartsWith("\t"))
                    {
                        match = Regex.Match(line, pattern);
                        if (!match.Success || match.Groups.Count < 3)
                        {
                            throw new FileLoadException("Cannot load Upfile.lock, the line " + line + " does not match \'package_name (version_requirement)\'");
                        }
                    }
                }
                result.installableDependencies = installableList.ToArray();
            }

            return(result);
        }